I am using the OpenStreetMap
library to plot coordinates over an OSM map.
In order to download the tiles, I use the following upper-left and bottom-right latitudes and longitudes:
library(OpenStreetMap);
library(rgdal)
lat_upper_left = 47.417;
lon_upper_left = 8.550;
lat_lower_right = 47.413;
lon_lower_right = 8.556;
map_osm <- openmap(
c(lat_upper_left , lon_upper_left ),
c(lat_lower_right, lon_lower_right),
type = 'osm'
);
plot(map_osm );
The map plots fine.
However, if I want to plot a few coordinate-dots over the map, I have to exchange latitude and longitude. I am not sure why this is:
coords <- data.frame (
lat = c( 8.55336768885581, 8.55464266203301), # Longitudes, really
lon = c(47.4147105656297 , 47.4154560068639) # Latitudes, really
);
coordinates(coords) <- ~lat+lon
proj4string(coords)<-CRS("+init=epsg:4326")
points(spTransform(coords, osm()), col='red', pch=19, cex=5)
I'd appreciate if someone could shed some light on this.
lon
and your lon-columnlat
. Call them whatever you like. But when specifiying the coordinateslon
has to come beforelat
. That's just how some GIS work I guess. – Humpelstielzchencoords
to the console after running your code (sansOpenStreetMap
), it lists the entire CRS as+init=epsg:4326 +proj=longlat +datum=WGS84 +no_defs +ellps=WGS84 +towgs84=0,0,0
... notice the "longlat" suggesting that coordinates are listed longitude-first. – r2evans