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") 
小智 10
Victorp的答案有效.不过我建议使用:
shapeData <- spTransform(shapeData, CRS("+proj=longlat +datum=WGS84 +no_defs"))
该CRS对应于EPSG:4326.Leaflet实际上负责从EPSG:4326转换为EPSG:3857(称为"Google Mercator").
现在,差异(GRS80与WGS84)可以忽略不计(在其中一个轴上为0.1 mm).传单似乎认为两者都是相同的椭圆体.但是出于测试目的,建议使用EPSG:4326.
嗨,您必须更改投影:
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") 
但我不能告诉你为什么会这样,我只知道一点关于 geo 和 proj。