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 below
The borders of the shape are not going as the ggmap borders. What did I wrong that the borders does not fit?
readOGR
alongside with Google Maps data. Try to manually add the projection of layer "Ytor" (argumentp4s
) toreadOGR
and crosscheck the visualization afterwards.p4s
argument in the functionreadOGR
. How the argument should look like?proj4string
, I suppose. It's detailed in?readOGR
. At least it's worth trying, helped me out back then.p4s
in thereadOGR
function but it did not help? Did I make it right?