0
votes

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.

1
You don't have to call your lat-column lon and your lon-column lat. Call them whatever you like. But when specifiying the coordinates lon has to come before lat. That's just how some GIS work I guess.Humpelstielzchen
When I print coords to the console after running your code (sans OpenStreetMap), 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

1 Answers

1
votes

There is no global standard whether latitude or longitude comes first. Latitude is always latitude and longitude is always longitude. Their order may vary, however, depending on the software / library you are using.