Why is it returning null?

I am using OSMPYTHONTOOLS and this code is returning null. I was told that it’s a server problem and not my problem, but I tested a different piece of code and there weren’t no issues.

from OSMPythonTools.nominatim import Nominatim

nominatim = Nominatim()

areaId = nominatim.query(‘Tehran, Iran’).areaId()

from OSMPythonTools.overpass import overpassQueryBuilder, Overpass

overpass = Overpass()

query = overpassQueryBuilder(area=areaId, elementType=[‘area’,‘node’],selector=‘“building”=“hospital”’, out=‘body’)

result = overpass.query(query)

for i in range(0,10):

elemens = result.elements()[i]

print(elemens.tag(‘name:en’))

Please read and follow Nominatim Usage Policy (aka Geocoding Policy) if you use server running at nominatim.openstreetmap.org

For start read and follow

Requirements

  • No heavy uses (an absolute maximum of 1 request per second).
  • Provide a valid HTTP Referer or User-Agent identifying the application (stock User-Agents as set by http libraries will not do).
  • Clearly display attribution as suitable for your medium.
  • Data is provided under the ODbL license which requires to share alike (although small extractions are likely to be covered by fair usage / fair dealing).

who or what told you that?

I asked on the IRC channel

which one?

The oftc one? Should I even use nominatim here?

If you are search for the nearest X in an area, and there are not many X there in total, you can just download all the data and filter it.

OSM thinks there are about 2000 hospitals in Iran, which isn’t a lot to just download and store the location of.

If you do that you will no longer need to query an external service for results.

That’s a good idea, but how much space does it take? I need the program to be light… Also idk how to download it

If you needed to store 100 bytes for each hospital (name, plus a bit for location) then it’d be 200k bytes, which isn’t a huge amount.

Hospitals don’t change much - you don’t need to re-query every day in case some new ones have appeared.

“All the OSM data in Iran” is at https://download.geofabrik.de/asia/iran.html.

You can then filter that with something like osmium.

For those that care, see (direct link to Matrix channel) here.

Here’s an Overpasst Turbo link to all building=hospital in Tehran: overpass turbo
Here’s the same query for all of Iran: overpass turbo. If you want amenity=hospital, these are found here: overpass turbo