[英]R / leaflet - drawing numerous polygons
I am trying to draw numerous polygons with the leaflet package but I can't understand what's going wrong. 我试图用传单包绘制多个多边形,但我无法理解出了什么问题。
The shapefile I use can be found here: https://www.data.gouv.fr/en/datasets/fond-de-carte-des-codes-postaux/ 我使用的shapefile可以在这里找到: https : //www.data.gouv.fr/en/datasets/fond-de-carte-des-codes-postaux/
library(leaflet)
library(rgdal)
df <- readOGR("C:/Users/me/codes_postaux","codes_postaux_region")
plot(df)
The shapefile seems ok to me and the code I use is rather simple. shapefile对我来说似乎没问题,我使用的代码相当简单。 However I only get the map as an output and no Polygons.
但是我只将地图作为输出而没有多边形。 I've been struggling with this issue for quite a long time, I would really appreciate if someone could help me here.
很长一段时间我一直在努力解决这个问题,如果有人能在这里帮助我,我真的很感激。
map <- leaflet(df) %>%
addProviderTiles("CartoDB.Positron")%>%
fitBounds(10,38,10,55) %>%
addPolygons(fillOpacity = 0.8, color = "Blue", weight = 1)
map
Look at df@proj4string
and the output of plot(df); axis(1); axis(2)
看看
df@proj4string
和plot(df); axis(1); axis(2)
的输出plot(df); axis(1); axis(2)
plot(df); axis(1); axis(2)
plot(df); axis(1); axis(2)
. plot(df); axis(1); axis(2)
。 Your shapefile uses a specific CRS. 您的shapefile使用特定的CRS。 You need to transform your
SpatialPolygonsDataFrame
with a common CRSobj
(I got the CRS code from here: Leaflet for R: Raster Images ). 你需要用一个普通的
CRSobj
转换你的SpatialPolygonsDataFrame
(我从这里得到了CRS代码: Leaflet for R:Raster Images )。
library(sp)
pj <- CRS("+proj=longlat +ellps=WGS84 +datum=WGS84 +no_defs")
df2 <- spTransform(df, pj)
map2 <- leaflet(df2) %>%
addProviderTiles("CartoDB.Positron")%>%
fitBounds(10,38,10,55) %>%
addPolygons(fillOpacity = 0.8, color = "Blue", weight = 1)
map2
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.