使用R将我的shapefile数据投影到传单地图上 [英] Projecting my shapefile data on leaflet map using R

查看:132
本文介绍了使用R将我的shapefile数据投影到传单地图上的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我(在Win7上)尝试获取我的shapefile数据(此处是数据文件.)将使用leaflet程序包显示.但是没有任何成功.我只得到背景地图图块,但没有得到我的数据.我可以在QGIS中看到我的数据.我从此处获得了以下代码和说明.

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") 

这是我在Internet浏览器中看到的内容.我看不到shapeData被投影在上面:

This is what I see in my internet browser. I do not see the shapeData being projected on it:

推荐答案

Victorp的答案有效.但是我建议使用:

The answer of Victorp works. However I would suggest to use:

shapeData <- spTransform(shapeData, CRS("+proj=longlat +datum=WGS84 +no_defs"))

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

This CRS corresponds to EPSG:4326. Leaflet actually takes care of transforming from EPSG:4326 to EPSG:3857 (known as "Google Mercator").

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

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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆