形状文件的 R 问题传单
leaflet for R issues with shape file
我尝试用Rstudio 上的leaflet 包制作地图。
我尝试了很多示例和自我选择,它们都可以正常工作。
但我想使用工作中的形状文件。
它适用于所有软件(QGIS、R spplot 等),但是当我使用传单中的形状文件时它不起作用,地图顶部出现一条蓝线。
这是我使用的代码:
dat<-readOGR(dsn="shape/Shape ER 2015", layer=filename,encoding='UTF-8')
leaflet(dat)%>%addTiles()%>%
addPolgons(data=dat, weight=2)
这是代码的结果:
这里是用 spplot 得到的地图:
spplot(dat, zcol=1, col.regions="gray", col="blue")
我使用与 http://leaflet.calvinmetcalf.com/ 相同的文件来查看问题是否出自我的数据。但它似乎来自 readOGR
我在这里放了一些 SpatialPolygonDataframe
的信息
str(dat@polygons[[1]],2)
Formal class 'Polygons' [package "sp"] with 5 slots
..@ Polygons :List of 1
..@ plotOrder: int 1
..@ labpt : num [1:2] 953652 6808716
..@ ID : chr "0"
..@ area : num 4.32e+10
str(dat@polygons[[1]]@Polygons[[1]],2)
Formal class 'Polygon' [package "sp"] with 5 slots
..@ labpt : num [1:2] 953652 6808716
..@ area : num 4.32e+10
..@ hole : logi FALSE
..@ ringDir: int 1
..@ coords : num [1:1063, 1:2] 940343 939824 936328 933274 933649 ...
head(dat@polygons[[1]]@Polygons[[1]]@coords)
[,1] [,2]
[1,] 940343 6611180
[2,] 939824 6610705
[3,] 936328 6613788
[4,] 933274 6616467
[5,] 933649 6617058
[6,] 934305 6617147
希望清楚,提前谢谢。
您很可能需要转换投影。
尝试:
PRO <- sp::CRS('+proj=longlat +datum=WGS84 +ellps=WGS84 +towgs84=0,0,0')
DAT <- sp::spTransform(dat,PRO)
我尝试用Rstudio 上的leaflet 包制作地图。 我尝试了很多示例和自我选择,它们都可以正常工作。
但我想使用工作中的形状文件。 它适用于所有软件(QGIS、R spplot 等),但是当我使用传单中的形状文件时它不起作用,地图顶部出现一条蓝线。
这是我使用的代码:
dat<-readOGR(dsn="shape/Shape ER 2015", layer=filename,encoding='UTF-8') leaflet(dat)%>%addTiles()%>% addPolgons(data=dat, weight=2)
这是代码的结果:
这里是用 spplot 得到的地图:
spplot(dat, zcol=1, col.regions="gray", col="blue")
我使用与 http://leaflet.calvinmetcalf.com/ 相同的文件来查看问题是否出自我的数据。但它似乎来自 readOGR
我在这里放了一些 SpatialPolygonDataframe
str(dat@polygons[[1]],2)
Formal class 'Polygons' [package "sp"] with 5 slots ..@ Polygons :List of 1 ..@ plotOrder: int 1 ..@ labpt : num [1:2] 953652 6808716 ..@ ID : chr "0" ..@ area : num 4.32e+10
str(dat@polygons[[1]]@Polygons[[1]],2)
Formal class 'Polygon' [package "sp"] with 5 slots ..@ labpt : num [1:2] 953652 6808716 ..@ area : num 4.32e+10 ..@ hole : logi FALSE ..@ ringDir: int 1 ..@ coords : num [1:1063, 1:2] 940343 939824 936328 933274 933649 ...
head(dat@polygons[[1]]@Polygons[[1]]@coords)
[,1] [,2] [1,] 940343 6611180 [2,] 939824 6610705 [3,] 936328 6613788 [4,] 933274 6616467 [5,] 933649 6617058 [6,] 934305 6617147
希望清楚,提前谢谢。
您很可能需要转换投影。 尝试:
PRO <- sp::CRS('+proj=longlat +datum=WGS84 +ellps=WGS84 +towgs84=0,0,0')
DAT <- sp::spTransform(dat,PRO)