I am very new to geographic data, so I am sorry for the stupidity of the question.

I need to plot some data that are in this projection

Projection: Transverse_Mercator 
False_Easting: 500000,000000
False_Northing: 0,000000
Central_Meridian: 27,000000
Scale_Factor: 0,999600
Latitude_Of_Origin: 0,000000
Linear Unit: Meter
Datum: D_ETRS_1989

in R in openstreetmap. I do not understand how the openproj works and looking at the guide here http://cran.r-project.org/web/packages/OpenStreetMap/OpenStreetMap.pdf did not help.

What I came up with is this

a<-min(min(samples$lon))#, min(samples_all$lon))
b<-min(min(samples$lat))#, min(samples_all$lat))
c<-max(max(samples$lon))#, max(samples_all$lon))
d<-max(max(samples$lat))#, max(samples_all$lat))

map = openmap(c(lat= d,   lon= a),
              c(lat= b,   lon= c))
              #              ,minNumTiles=9,type=nm[i])

map_fin <- openproj(map.in, projection =
                      "+proj=utm +zone=35 +ellps=GRS80 +units=m +no_defs")

that of course does not work, can you please help and maybe tell me where to find information about projection in R and openproj? I struggled a lot but could not find any.

Also how does this work with ggmap?


The openmap() function expects geographic lat/lon coordinates as input. If the data you want to layer on top of such a basemap are not in WGS84, you need to reproject in order to retrieve the appropriate tiles.

So the steps are:

  • reproject your data to WGS84,
  • retrieve the basemap using geographic coordinates,
  • reproject the basemap to your desired projection and plot

Below is the code for using the OpenStreetMap library, with some made-up points.

library (sp)
library (rgdal)
library (OpenStreetMap)

# make up some points 
pts.euref <- SpatialPoints(cbind(lon = sample (300000:500000, 100),lat = sample (6800000:7000000,100)))
proj4string(pts.euref) <- CRS("+proj=utm +zone=35 +ellps=GRS80 +units=m +no_defs")

# reproject to geographic coordinates
pts.wgs84<- spTransform(pts.euref, CRS("+proj=longlat +ellps=WGS84 +datum=WGS84 +no_defs"))

# retrieve basemap
osm <- openmap (c(bbox(pts.wgs84)[2,2] + 1, bbox(pts.wgs84)[1,1] - 1), c(bbox(pts.wgs84)[2,1] - 1, bbox(pts.wgs84)[1,2] + 1))

# reproject basemap
osm.euref <- openproj (osm, proj4string(pts.euref))

plot (osm.euref)
plot (pts.euref, add=T, pch=20)

enter image description here

Here is the option using ggmap:

autoplot(osm.euref) + 
    geom_point(data = data.frame(pts.euref@coords), aes(x = lon, y = lat)) + 
  • I'm confused by your example initial data points in the statement cbind(lon = sample (300000:500000, 100),lat = sample (6800000:7000000,100)). I have latitude and longitude data that doesn't look anything like that; they have values like lat=37.5 and long=-122.5. How can I project lat, long values like those to an OSM map obtained through openmap()? – stackoverflowuser2010 Feb 21 '14 at 1:36
  • @stackoverflowuser2010 This question was asked for a "different projection", namely UTM Zone North 35. My sample points are UTM coordinates. If you have lat lon as you describe, there is no need to go through any reprojection. Just use the bounding box of your points as parameters for the extent in openmap(). – cengel Feb 21 '14 at 4:57
  • Your code osm.wgs84 <- openmap (...) suggests that openmap() returns a map in WGS84. However, other webpages state that openmap returns tiles in the Mercator projection. (For example: Maps are initially put in a sperical mercator projection which is the standard for most (all?) map tiling systems at r-bloggers.com/the-openstreetmap-package-opens-up). Is your code correct? – stackoverflowuser2010 Feb 21 '14 at 5:12
  • @stackoverflowuser2010 you are absolutely correct in that osm tiles are retrieved as spherical mercator. However, the openmap() function takes geographic lat/lon coordinates as input to retrieve the map. So the code is correct, but I have edited my post to hopefully make things clearer. Thank you for pointing this out. – cengel Feb 21 '14 at 6:58

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.