mocnik-science / osm-python-tools

A library to access OpenStreetMap related services
GNU General Public License v3.0
438 stars 48 forks source link

union of selectors in Overpass query builder #39

Closed mlennert closed 3 years ago

mlennert commented 3 years ago

I don't know if this is something not implemented, yet, or if I just haven't been able to figure this out, but is it possible to create a union of selectors ?

I've tried something like this:

from OSMPythonTools.nominatim import Nominatim
from OSMPythonTools.overpass import overpassQueryBuilder
from OSMPythonTools.overpass import Overpass

nominatim = Nominatim()
rdc = nominatim.query('République démocratique du Congo')

query = overpassQueryBuilder(area=rdc.areaId(), elementType='node', selector=['"amenity"="hospital"'], out='body')

overpass = Overpass()
result = overpass.query(query)

print("Number of nodes found: {}".format(result.countElements()))

and I get as output: 90.

With

query = overpassQueryBuilder(area=rdc.areaId(), elementType='node', selector=['"amenity"="clinic"'], out='body'

the result is 536.

But with

query = overpassQueryBuilder(area=rdc.areaId(), elementType='node', selector=['"amenity"="hospital"', '"amenity"="clinic"'], out='body')

the result is 0 which gives me the impression that the result is the intersection of the selectors and not the union.

If it is possible to make this into a union, could someone point me to where in the docs I can find info on that. If not, is it envisageable to implement this ?

mocnik-science commented 3 years ago

Dear @mlennert, I am sorry to provide a reply first now. I was waiting to someone from the wider community to provide a reply and then did miss that your question remained open. Yes, you are right. The reason behind is that your request is translated by the overpassQueryBuilder to the language used by the Overpass API, which you find described here: https://wiki.openstreetmap.org/wiki/Overpass_API/Language_Guide#Multiple_tags. In your case, I would advise to just run to queries and to then consider them separately. I hope this helps. Best!