【问题标题】:Render shapefile with no projection in leaflet map在传单地图中渲染不带投影的 shapefile
【发布时间】:2017-12-05 04:37:51
【问题描述】:

我想在传单地图中渲染一个 shapefile。

This shapefile 没有投影,所以我想给它一个。

  directions <- readOGR("./directions/", "directions")
  proj4string(directions) <- CRS("+proj=longlat +datum=WGS84 +no_defs")

然后我尝试像这样将它添加到我的地图中:

  map <- leaflet() %>% 
    addProviderTiles("CartoDB.Positron") %>% 

    addPolygons(data=directions,weight=1,col = 'black') %>% 

    setView(lng = -3.8196207,
            lat = 40.4678698,
            zoom = 10)

问题是我收到一条错误消息:

给予不合格数据的地理 CRS:450781.167295 4485221.863980

我尝试使用其他投影作为 CRS,例如

  proj4string(directions) <- CRS("+proj=utm +zone=30 +ellps=GRS80 +units=m +no_defs")

这不会给我一个错误,但 shapefile 也没有被渲染。

我真的不明白为什么会发生这种情况以及如何解决它。

顺便说一句:我从西班牙 website 获得了这个 shapefile,交通和空气质量数据在这里发布

【问题讨论】:

  • 感谢@user6617454 的回复,但我的问题是我不再收到错误消息并且仍然无法在我的地图上看到 shapefile,我不知道为什么会这样。我还查看了坐标coordinates(direction),似乎没有错误。它们似乎和我渲染的一个工作 shapefile 一样好。
  • 好像传单需要 WGS 84 投影才能显示 leaflet for r

标签: r leaflet shapefile map-projections


【解决方案1】:

你们很亲密。您需要做的是将 UTM Zone 17N 的投影转换为经纬度投影。

library(sp)
library(rgdal)
library(leaflet)

# Read the shapefile
directions <- readOGR("directions", "directions")
# Set the projection to be UTM zone 30N
proj4string(directions) <- CRS("+proj=utm +zone=30 +ellps=GRS80 +units=m +no_defs")
# Conduct project transformation from UTM zone 30N to long-lat
directions_longlat <- spTransform(directions, CRS("+proj=longlat +datum=WGS84 +no_defs"))

map <- leaflet() %>% 
  addProviderTiles("CartoDB.Positron") %>% 
  addPolygons(data = directions_longlat, weight=1, col = 'black') %>% 
  setView(lng = -3.8196207,
          lat = 40.4678698,
          zoom = 10)
map

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2012-01-15
    • 2016-11-02
    • 2022-11-15
    • 1970-01-01
    • 2017-06-07
    • 2014-10-07
    • 2017-02-20
    • 1970-01-01
    相关资源
    最近更新 更多