I have a numpy.ndarray of geocoordinates and I want to see which of them lie inside Alaska. For that, I want to get the multipolygon of the state of Alaska from OpenStreetMap and then use some shape library (probably Shapely) to query which of the points lie inside. However, I am stuck at step 1: I cannot get the geometry of the multipolygon. I have the OSMPythonTools installed (but if there is a better tool for the job, I'm happy to switch) and I can query them for Alaska like this
from OSMPythonTools.nominatim import Nominatim
from OSMPythonTools.api import Api
nominatim = Nominatim()
api = Api()
alaska_id = nominatim.query("Alaska, United States of America").areaId()
alaska = api.query('relation/{:}'.format(alaska_id - 3600000000))
I then want to get the geometry of this object using alaska.geometry(), but that returns only
Exception: [OSMPythonTools.Element] Cannot build geometry: geometry information not included. (way/193430587)
This exception is raised because the ways constituting the outer boundary of Alaska in alaska.__members() do not contain geometry, and then the API assumes that a relation has been encountered and raises a confusing exception.
I assume that I need to run an intermediate step that queries all these members from OSM and loads their geometry, how do I do that?
Alternatively, I know that the Overpass API can return geometries, so I assume something like
query = overpassQueryBuilder(
area=alaska_id,
elementType=['relation'],
selector='"id"="1116270"',
includeGeometry=True)
might work, but this specific query is empty and using the Overpass API for a single Relation object whose ID I know feels very wrong, is it not?