Changing the Projection of Shapefile
Asked Answered
E

1

14

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!

Eleemosynary answered 11/10, 2016 at 14:32 Comment(0)
E
23

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

Eleemosynary answered 11/10, 2016 at 15:2 Comment(1)
Your link to the data does not work anymore. Could you provide a sample with dput?Gentile

© 2022 - 2024 — McMap. All rights reserved.