Saturday, 4 June 2016

shapefile - The shape does not fit the ggmap


I try to fit my shape to the google map.


require(rgdal)

in.dir <- getwd()

sh <- readOGR(in.dir, layer = "Ytor",
p4s = "+proj=tmerc +lat_0=0 +lon_0=15.80827777777778 +k=1 +x_0=1500000 +y_0=0 +ellps=bessel +units=m +no_defs")



sh@proj4string
sh2 <- spTransform(sh, CRS("+proj=longlat +datum=WGS84 +ellps=WGS84 +no_defs"))

sh2@proj4string

sh2.df <- fortify(sh2)

library(ggplot2)

library(ggmap)

swe <- get_map(location = c(15.3, 63.63, 15.5, 63.68), maptype = 'satellite')
ggmap(swe) + geom_polygon(aes(x = as.numeric(long), y = as.numeric(lat), group = group), data = df, color = "white", fill = "white", alpha = 0.1)

Finally I got the map as belowenter image description here


The borders of the shape are not going as the ggmap borders. What did I wrong that the borders does not fit?



Answer



Your projection string has no towgs84 parameters.


Assuming your data is in EPSG:3021 RT90 2.5 gon V, it should be:



+proj=tmerc +lat_0=0 +lon_0=15.80827777777778 +k=1 +x_0=1500000 +y_0=0 +ellps=bessel +towgs84=414.1,41.3,603.1,-0.855,2.141,-7.023,0 +units=m +no_defs

No comments:

Post a Comment

arcpy - Changing output name when exporting data driven pages to JPG?

Is there a way to save the output JPG, changing the output file name to the page name, instead of page number? I mean changing the script fo...