【问题标题】:Using Open Street Map in R with get_osm {osmar}在 R 中通过 get_osm {osmar} 使用 Open Street Map
【发布时间】:2012-01-23 23:07:24
【问题描述】:

我想附加一组相关的方式并给出一个地区的边界。 我尝试了以下但卡住了:

require(osmar)
require(XML)

# a set of open street map ways (lines) related as given by a relation..
# (if connected these ways represent the boundary of a political 
#  district in Tyrol/Austria)
myxml <- xmlParse("http://api.openstreetmap.org/api/0.6/relation/85647")

# extracting way ids at the according xml-nodes:
els <- getNodeSet(myxml, "//member[@ref]")
ways <- as.numeric(sapply(els, function(el) xmlGetAttr(el, "ref")))

# now I try to get one of those ways as an osmar-obj and plot it,
# which throws an error:
plot_ways(get_osm(way(ways[1])))

显然缺少一个边界框,但我不知道如何将它分配给这种对象。如果我解决了这个问题,我想用线条/方式制作一个多边形。

【问题讨论】:

    标签: r openstreetmap osmar


    【解决方案1】:

    该软件包的作者非常友好地提供了当前文档中缺少的信息: 参数 get_osm(.., all = T) 只是丢失了...使用 all = T 检索所有相关元素。

    要获得我想要的地区边界,适用以下代码:

    District_Boundary <- get_osm(relation(85647), all = T)
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2021-08-03
      • 2014-05-01
      • 2021-11-28
      • 2013-09-21
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多