【发布时间】:2017-12-05 04:37:51
【问题描述】:
我想在传单地图中渲染一个 shapefile。
This shapefile 没有投影,所以我想给它一个。
directions <- readOGR("./directions/", "directions")
proj4string(directions) <- CRS("+proj=longlat +datum=WGS84 +no_defs")
然后我尝试像这样将它添加到我的地图中:
map <- leaflet() %>%
addProviderTiles("CartoDB.Positron") %>%
addPolygons(data=directions,weight=1,col = 'black') %>%
setView(lng = -3.8196207,
lat = 40.4678698,
zoom = 10)
问题是我收到一条错误消息:
给予不合格数据的地理 CRS:450781.167295 4485221.863980
我尝试使用其他投影作为 CRS,例如
proj4string(directions) <- CRS("+proj=utm +zone=30 +ellps=GRS80 +units=m +no_defs")
这不会给我一个错误,但 shapefile 也没有被渲染。
我真的不明白为什么会发生这种情况以及如何解决它。
顺便说一句:我从西班牙 website 获得了这个 shapefile,交通和空气质量数据在这里发布
【问题讨论】:
-
感谢@user6617454 的回复,但我的问题是我不再收到错误消息并且仍然无法在我的地图上看到 shapefile,我不知道为什么会这样。我还查看了坐标
coordinates(direction),似乎没有错误。它们似乎和我渲染的一个工作 shapefile 一样好。 -
好像传单需要 WGS 84 投影才能显示 leaflet for r。
标签: r leaflet shapefile map-projections