使用R在叶子图上投影我的shapefile数据

Sta*_*t-R 5 gis r shapefile rgdal leaflet

我(在Win7上)试图获取要使用包显示的shapefile数据(是数据文件.)leaflet.但没有任何成功.我只获得背景地图图块而不是我的数据.我能够在QGIS中看到我的数据.我从这里得到以下代码和说明.

library(rgdal)
shapeData <- readOGR(".",'myGIS')
ogrInfo(".",'myGIS')
leaflet()  %>% addTiles() %>% setView(lng = -106.363590, lat=31.968483,zoom=11) %>% addPolygons(data=shapeData,weight=5,col = 'red') %>% addMarkers(lng = -106.363590,lat=31.968483,popup="Hi there") 
Run Code Online (Sandbox Code Playgroud)

这就是我在互联网浏览器中看到的内容.我没有看到shapeData投射在它上面:

小智 10

Victorp的答案有效.不过我建议使用:

shapeData <- spTransform(shapeData, CRS("+proj=longlat +datum=WGS84 +no_defs"))
Run Code Online (Sandbox Code Playgroud)

该CRS对应于EPSG:4326.Leaflet实际上负责从EPSG:4326转换为EPSG:3857(称为"Google Mercator").

现在,差异(GRS80与WGS84)可以忽略不计(在其中一个轴上为0.1 mm).传单似乎认为两者都是相同的椭圆体.但是出于测试目的,建议使用EPSG:4326.


Vic*_*orp 7

嗨,您必须更改投影:

library("rgdal")
shapeData <- readOGR(".",'myGIS')
shapeData <- spTransform(shapeData, CRS("+proj=longlat +ellps=GRS80"))
library("leaflet")
leaflet()  %>% addTiles() %>% 
  setView(lng = -106.363590, lat=31.968483,zoom=11) %>% 
  addPolygons(data=shapeData,weight=5,col = 'red') %>% 
  addMarkers(lng = -106.363590,lat=31.968483,popup="Hi there") 
Run Code Online (Sandbox Code Playgroud)

但我不能告诉你为什么会这样,我只知道一点关于 geo 和 proj。