我需要在 R 中搜索特定坐标的详细信息。假设我的坐标是:25.34926、51.47819。我使用 nominatim 来解析有关特定坐标的详细信息。
query <- sprintf("http://nominatim.openstreetmap.org/reverse?format=xml& lat=%s&lon=%s",lat,lon)
result <- GET(query)
xml <- content(result, 'parsed')
list_xml = xmlToList(xml)
place_id = list_xml$result$.attrs["osm_id"]
place_id = as.numeric(place_id)
type = list_xml$result$.attrs["osm_type"]
type = as.character(type)
我使用这些代码获取道路类型和唯一 ID。现在,我传递这些参数以获取有关该位置的详细信息。
query <- sprintf("http://www.openstreetmap.org/api/0.6/%s/%s",type,place_id)
结果 <- GET(查询) xml <- 内容(结果,'已解析')
这是 XML 输出,
<?xml version="1.0" encoding="UTF-8"?>
<osm version="0.6" generator="CGImap 0.4.0 (5500 thorn-02.openstreetmap.org)" copyright="OpenStreetMap and contributors" attribution="http://www.openstreetmap.org/copyright" license="http://opendatacommons.org/licenses/odbl/1-0/">
<way id="25935530" visible="true" version="8" changeset="25997075" timestamp="2014-10-11T06:26:45Z" user="Kostik" uid="384084">
<nd ref="2012765518"/>
<nd ref="2012765515"/>
<nd ref="1138152548"/>
<nd ref="1138151957"/>
<nd ref="1138152112"/>
<nd ref="1138152995"/>
<nd ref="1885503851"/>
<nd ref="1138152065"/>
<nd ref="282906579"/>
<nd ref="282905674"/>
<nd ref="282905676"/>
<nd ref="282905677"/>
<nd ref="282905678"/>
<nd ref="282905679"/>
<nd ref="1684400272"/>
<nd ref="1684400191"/>
<nd ref="282906298"/>
<nd ref="1138152685"/>
<nd ref="1138152719"/>
<nd ref="1138151621"/>
<tag k="highway" v="primary"/>
<tag k="name" v="Al Khafaji Street"/>
<tag k="oneway" v="yes"/>
</way>
</osm>
我关心<tag>
标签,如何获取值?我使用下面提到的代码,但我很难解析它。我已经非常疯狂地搜索,但无济于事。
list_xml = xmlToList(xml)
tr <- getNodeSet(xml, "//osm/way/tags")