将shapefile添加到GGR中的ggmap

将shapefile添加到GGR中的ggmap,r,coordinates,shapefile,ggmap,R,Coordinates,Shapefile,Ggmap,我目前正在尝试使用R中的ggmap将一个shapefile(表示一条河)绘制到Google地图上 我通过以下方式获取地图: map <- get_googlemap(center = c(lon = 13.40, lat = 52.50), zoom = 11, scale = 2, size = c(640,480), color = "bw", maptype = "satellite") 这不是我想要的格式。dhapefile是用Qgis生

我目前正在尝试使用R中的ggmap将一个shapefile(表示一条河)绘制到Google地图上

我通过以下方式获取地图:

map <- get_googlemap(center = c(lon = 13.40, lat = 52.50), zoom = 11, scale = 2,
                     size = c(640,480), color = "bw", maptype = "satellite")

这不是我想要的格式。dhapefile是用Qgis生成的,但是我不能用Qgis来转换坐标。有什么帮助吗

你的问题似乎是坐标系。对于Googlemaps,您需要EPSG3857(请参阅),但您还需要知道原始参考系统是什么(一旦知道,您可以从中获取项目字符串描述符)


如果要绘制多边形,需要将shapefile转换为常规数据帧。在ggplot2包中使用
fortify()
     [,1]    [,2]
0 1483815 6898445
1 1484915 6898293
2 1485984 6898123
3 1486659 6898201
4 1487148 6898012
5 1487569 6897824
library(sp)
# Proj description of Marcator 3857
crs3857 = '+proj=merc +a=6378137 +b=6378137 +lat_ts=0.0 +lon_0=0.0 +x_0=0.0 +y_0=0 +k=1.0 +units=m +nadgrids=@null +wktext +no_defs'
# Find out your coordinate system and get the proj description
original_crs = "<proj description>"
# Make sure that the CRS is correctly referenced in yor polygon
mypolygon@proj4string = CRS(original_crs)
# Convert the polygon to 3857
mypolygon3857 = spTransform(mypolygon, CRS(crs3857))
# Get the coordinates
mydata = coordinates(mypolygon3857)
names(mydata) = c("lon", "lat")
# Plot
map = get_googlemap(center = c(lon = 13.40, lat = 52.50), zoom = 11, scale = 2, size = c(640,480), color = "bw", maptype = "satellite")
ggmap(map) + geom_polygon(mydata, aes(x=lon, y=lat))
library(sp)
library(ggmap)
map = get_googlemap(center = c(lon = 13.40, lat = 52.50), zoom = 11, scale = 2, size = c(640,480), color = "bw", maptype = "satellite")
lat = c(52.5 , 52.5, 52.55,52.55)
lon = c(13.3, 13.4, 13.4, 13.3)
mydata = data.frame(lon,lat)
ggmap(map) + geom_polygon(data=mydata, aes(x=lon, y=lat), col="red", fill=NA)