使用 R 在传单地图上投影我的 shapefile 数据 [英] Projecting my shapefile data on leaflet map using R
问题描述
我(在 Win7 上)试图获取我的 shapefile 数据(
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 毫米).似乎传单认为两者都是同一个椭圆体.但是出于测试目的,建议使用 EPSG:4326.
I (on Win7) was trying to get my shapefile data (Here are the data files.) to be displayed using leaflet
package. But without any success. I only get the background map tile but not my data. I am able to see my data in QGIS though. I got the following code and description from here.
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")
This is what I see in my internet browser. I do not see the shapeData being projected on it:
The answer of Victorp works. However I would suggest to use:
shapeData <- spTransform(shapeData, CRS("+proj=longlat +datum=WGS84 +no_defs"))
This CRS corresponds to EPSG:4326. Leaflet actually takes care of transforming from EPSG:4326 to EPSG:3857 (known as "Google Mercator").
Now, the difference (GRS80 vs WGS84) is negligible (0,1 mm on one of the axis). And it seems that leaflet considers both to be the same Ellipsoid. However for test purposes would be advisable to have EPSG:4326.
这篇关于使用 R 在传单地图上投影我的 shapefile 数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!