Changing the Projection of Shapefile

And_R picture And_R · Oct 11, 2016 · Viewed 15k times · Source

I am trying to change or assign the projection of a Germany-Shapefile from NA to +proj=longlat +datum=WGS84 +no_defs +ellps=WGS84 +towgs84=0,0,0, but somehow it doesn't work well.

Reproducible Example: Shapefile and other files can be downloaded here:

What I tried is the following:

library(maptools)
library(sp)
library(rgeos)
library(rgdal)
projection.x <- CRS("+proj=longlat +ellps=WGS84 +datum=WGS84 +no_defs +towgs84=0,0,0")
mapG <- readShapePoly("vg2500_lan.shp", verbose=TRUE, proj4string=projection.x)
summary(mapG)
mapG <- spTransform(mapG, CRS("+proj=longlat +ellps=WGS84 +datum=WGS84"))

So, the problem is I cannot plot my observations on the map. See below

enter image description here The ponits were detected using geocode function from ggmap package. enter image description here Any idea how to change the projection of the shapefile or the projection of the google coordinates would be highly appreciated!

Answer

And_R picture And_R · Oct 11, 2016

I found my mistake. The solution would be:

mapG <- readOGR("vg2500_lan.shp", layer="vg2500_lan")
summary(mapG)
germG <- spTransform(mapG, CRS("+proj=longlat +datum=WGS84 +no_defs +ellps=WGS84 +towgs84=0,0,0"))
plot(germG, axes=T)

And the desired output: enter image description here