ropensci / osmdata

R package for downloading OpenStreetMap data
https://docs.ropensci.org/osmdata
314 stars 45 forks source link

[FEATURE] Parse latitude and longitude in results from `out * center;` queries #315

Closed jmaspons closed 1 year ago

jmaspons commented 1 year ago

Make it work with osmdata_data_frame

q <- getbb ("Franja de Ponent", featuretype = "relation") %>%
    opq (bb, out = "tags center") %>%
    add_osm_feature ("amenity", "community_center")
res <- osmdata_data_frame(q)

res should contain columns with the latitude and longitude extracted from the xml result.

A simplified xml result looks like:

<osm version="0.6" generator="Overpass API 0.7.59.2 0994154d">
  <note>The data included in this document is from www.openstreetmap.org. The data is made available under ODbL.</note>
  <meta osm_base="2023-03-02T17:46:46Z"/>
  <node id="4282036572" lat="41.1169240" lon="1.2572857">
    <tag k="amenity" v="community_centre"/>
    <tag k="name" v="Casal Popular Sageta de Foc"/>
  </node>
  <way id="311179562">
    <center lat="41.1562828" lon="1.1097734"/>
    <tag k="amenity" v="community_centre"/>
    <tag k="building" v="civic"/>
    <tag k="name" v="Casal Despertaferro"/>
  </way>
  <relation id="5416254">
    <center lat="42.1347037" lon="-0.4061089"/>
    <tag k="amenity" v="community_centre"/>
    <tag k="building" v="yes"/>
    <tag k="community_centre:for" v="juvenile"/>
    <tag k="name" v="Espacio ZETA"/>
  </relation>
</osm>