Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Changing the Projection of Shapefile

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!

like image 870
And_R Avatar asked Oct 11 '16 14:10

And_R


Video Answer


1 Answers

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

like image 195
And_R Avatar answered Oct 17 '22 14:10

And_R