I have a simple Overpass XML query, and I'd like to restrict it to search in a manually-specified polygon (NOT to an existing area in OSM). The documentation mentions how to select region by polygon but it doesn't tell me what to use instead of bbox-query to actually use that polygon.

(My use-case: selecting e.g. all the lighthouses in mainland Britain. There are few enough lighthouses that it's OK to query such a big area, but the coast of Britain is far too complex to try and load into the Overpass interpreter so I drew a simplified outline.)

Here is my bbox query, which easily gets all the lighthouses in mainland Britain, but with a couple of extras from Ireland and France:


 {{key=man_made}}
 {{value=lighthouse}}
 <osm-script output="json">
   <union>
     <query type="node">
       <has-kv k="{{key}}" v="{{value}}"/>
       <bbox-query w="-5.95459" s="49.95122" e="1.82373" n="58.66551"/>
     </query>
   </union>
   <print mode="body"/>
   <recurse type="down"/>
   <print mode="skeleton"/>
 </osm-script>

and here are my simplified coordinates, just manually drawn:

 "50.0180967424 -5.7508254114  49.8977876566 -5.1328981537  50.9082889044 1.3228155649  51.2810475111 1.664301681  52.7126227103 1.9570040662  56.1970031699 -2.3893465301  57.6095221438 -1.5614591643  58.6835117066 -2.929773005  58.7133813218 -5.2524570036  57.7202251635 -6.0343506269  57.7570511223 -6.4712911811  57.3685045845 -6.9082317353  56.9193570841 -5.9883568844  56.8188049116 -5.9653600131  56.7573982738 -6.2873162109  56.686249528 -6.253314109  56.664139806 -6.0750883566  56.5375494332 -5.9256086933  56.4296138149 -5.6036524955  56.3118053314 -5.712887634  56.1199894834 -5.6381478024  55.907881817 -5.7818782478  55.7496536432 -5.6783923271  55.2809219893 -5.8681165151  55.3136533443 -5.4829189213  55.7043273009 -5.4024298718  55.7852302943 -5.2299533373  55.5029632207 -4.7872635653  54.8893427316 -5.3161916046  54.5806438387 -4.9194955751  54.6405756493 -4.0858589914  53.7730926517 -3.2407239721  53.4764508768 -3.528184863  53.5003957724 -4.7815143475  51.8269681676 -5.5979032777  51.4093186674 -4.9712385355  51.1215308565 -4.4078151893  50.1847866289 -5.8106243369  50.0180967424 -5.7508254114"

asked 26 May '14, 14:54

mcld's gravatar image

mcld
76127
accept rate: 0%

Why can't you use an existing area - or - combine several existing areas to the one you're looking for? Manually specifying coordinates looks a bit cumbersome to me.

(26 Jul '14, 22:46) mmd

This works better for me. I could use an existing area, but the geometry for the UK has so much detail that the Overpass query takes a long time to run.

(27 Jul '14, 09:32) mcld

This query for United Kingdom based on areas takes just 20s. That's why I thought it's not really worth the effort: http://overpass-turbo.eu/s/4m3

(27 Jul '14, 09:41) mmd

That query does not do what I need. Thanks though.

(27 Jul '14, 09:47) mcld

Right. I didn't spend much time trying to find a matching relation, so the result includes more data than just mainland Britain. But that's absolutely expected behaviour (sorry for being a bit lazy on a Sunday morning :)

My point was: performance wise there's really no heavy penalty in using even a complex geometry originating from existing areas.

(27 Jul '14, 09:56) mmd

It does tell you what to use, but not as you seem to expect. Overpass has two different query language formats: XML and its own language QL. The select region by polygon example query is written in QL but you seem to prefer the XML version. In that case just paste the code into the Overpass API convert form where you can convert between different formats. Converting the example query to XML will result in:

<osm-script>
  <union into="_">
    <polygon-query bounds="50.7 7.1 50.7 7.12 50.71 7.11" into="_"/>
    <recurse from="_" into="_" type="up"/>
  </union>
  <print from="_" limit="" mode="meta" order="id"/>
</osm-script>
permanent link

answered 26 May '14, 15:14

scai's gravatar image

scai ♦
31.4k18285439
accept rate: 23%

Just to spell it out after @scai answered, here is exactly the Overpass XML that carries out my desired query:


{{key=man_made}}
{{value=lighthouse}}
<osm-script output="json">
  <union>
    <query type="node">
      <has-kv k="{{key}}" v="{{value}}"/>
      <polygon-query bounds="50.0180967424 -5.7508254114  49.8977876566 -5.1328981537  50.9082889044 1.3228155649  51.2810475111 1.664301681  52.7126227103 1.9570040662  56.1970031699 -2.3893465301  57.6095221438 -1.5614591643  58.6835117066 -2.929773005  58.7133813218 -5.2524570036  57.7202251635 -6.0343506269  57.7570511223 -6.4712911811  57.3685045845 -6.9082317353  56.9193570841 -5.9883568844  56.8188049116 -5.9653600131  56.7573982738 -6.2873162109  56.686249528 -6.253314109  56.664139806 -6.0750883566  56.5375494332 -5.9256086933  56.4296138149 -5.6036524955  56.3118053314 -5.712887634  56.1199894834 -5.6381478024  55.907881817 -5.7818782478  55.7496536432 -5.6783923271  55.2809219893 -5.8681165151  55.3136533443 -5.4829189213  55.7043273009 -5.4024298718  55.7852302943 -5.2299533373  55.5029632207 -4.7872635653  54.8893427316 -5.3161916046  54.5806438387 -4.9194955751  54.6405756493 -4.0858589914  53.7730926517 -3.2407239721  53.4764508768 -3.528184863  53.5003957724 -4.7815143475  51.8269681676 -5.5979032777  51.4093186674 -4.9712385355  51.1215308565 -4.4078151893  50.1847866289 -5.8106243369  50.0180967424 -5.7508254114"/>
    </query>
  </union>
  <print mode="body"/>
  <recurse type="down"/>
  <print mode="skeleton"/>
</osm-script>
permanent link
This answer is marked "community wiki".

answered 26 May '14, 15:19

mcld's gravatar image

mcld
76127
accept rate: 0%

edited 26 May '14, 15:20

Your answer
toggle preview

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here

By RSS:

Answers

Answers and Comments

Markdown Basics

  • *italic* or _italic_
  • **bold** or __bold__
  • link:[text](http://url.com/ "title")
  • image?![alt text](/path/img.jpg "title")
  • numbered list: 1. Foo 2. Bar
  • to add a line break simply add two spaces to where you would like the new line to be.
  • basic HTML tags are also supported

Question tags:

×355
×74

question asked: 26 May '14, 14:54

question was seen: 3,801 times

last updated: 27 Jul '14, 10:15

powered by OSQA