0

I need all highway type way in certain area, I found this query the result I want, but using overpass-turbo (I would like to use only overpass-api or even better only osmosis):

<osm-script output="json">
  <id-query {{nominatimArea:Temperley,Partido de Lomas de zamora,Buenos Aires,Argentina}} into="area"/> 
    <query type="way">
      <has-kv k="highway"/>
      <area-query from="area"/>
    </query>
  <print mode="body"/>
  <recurse type="down"/>
  <print mode="skeleton" order="quadtile"/>
</osm-script>

I need to perform this task from a backend hundreds of times using differents areas. So I think I should use overpass-api directly (not using the overpass-turbo frontend), doing a POST request here http://overpass-api.de/api/interpreter . The issue is that above query fails using overpass-api, I think because of {{nominatimArea}}. When I inspect the POST made for overpass-turbo, I found that the real query to overpass-api is:

<osm-script output="json">    
<id-query type="area" ref="3602537337" into="area"/> 
        <query type="way">
          <has-kv k="highway"/>
          <area-query from="area"/>
        </query>
      <print mode="body"/>
      <recurse type="down"/>
      <print mode="skeleton" order="quadtile"/>
    </osm-script>

When I run that query in overpass-api directly, I get the desired result.

As you can see, the difference is that {{nominatimArea}} is replaced by type="area" ref="3602537337".

So, Is there a way to know that ref="3602537337" associated to a {{nominatimArea}}?

I have Nominatim installed locally, so I have the relation id too, Is there a way to use that id or maybe something else?

Do I need another approach to this issue?

PD: Perfect scenario for me would be to use osmosis directly but I can't understand documentation ;( I have all the polygons I need, all names and relations ids too.

2

Backend solution (no API)

I found a solution using just backend scripts without overpass or any other api using osmium instead of osmosis.

  • Download the extract you want from geofabrik.de (.pbf file) or the entire planet.
  • Install osmium
  • Extract the polygon (relation id = 2537337) running osmium getid -r -t argentina-latest.osm.pbf r2537337 -o temperley-boundary.osm where r2537337 is the relation id.
  • Extract info inside the previous polygon running osmium extract -p temperley-boundary.osm argentina-latest.osm.pbf -o temperley.pbf.
  • Filter highways running osmium tags-filter temperley.pbf w/highway -o highways_in_temperley.osm.pbf.

I also need to convert .pbf to .json or .geojson so I used osmtogeojson because I'm already in a node app.

Using Overpass API

I found a solution in the Overpass API wiki page

By convention the area id can be calculated from an existing OSM way by adding 2400000000 to its OSM id, or in case of a relation by adding 3600000000 respectively.

So, knowing the osm_id type R (relation id) you have to add 3600000000. The area, "Temperley,Partido de Lomas de zamora,Buenos Aires,Argentina" has the osm id 2537337 and it is a relation, then that number came from 3600000000 + 2537337 = 3602537337

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.