pyrosm.geocode#
- pyrosm.geocode(query, polygon=True, base_url='https://nominatim.openstreetmap.org', user_agent=None, headers=None, timeout=60, opener=None)#
Geocode a place name to a Shapely polygon via Nominatim.
- Parameters:
query (str) – The place name to look up, e.g.
"Brighton and Hove, UK".polygon (bool) – When
True(default), return the place’s boundary polygon if Nominatim provides one; otherwise (or for point-/line-like results such as POIs and addresses) the place’s bounding-box rectangle is returned. The result is always aPolygon/MultiPolygon.base_url (str) – The Nominatim base URL. Defaults to the public server; point it at your own instance for heavy use.
user_agent (str, optional) – The
User-Agentheader sent to Nominatim. Defaults to a pyrosm string. Nominatim rejects requests without a descriptive agent.headers (dict, optional) – Extra HTTP headers for the request;
user_agentreplaces aUser-Agentin them.timeout (float | tuple) – Seconds to wait for the server to accept the connection and then for each read (60 by default), or a
(connect, read)pair, as for downloads.opener (object, optional) – An object with
open(request, timeout=...), e.g. fromurllib.request.build_opener(), that makes the request instead of pyrosm.
- Returns:
The place’s boundary polygon, or its bounding-box rectangle.
- Return type:
shapely.geometry.Polygon or shapely.geometry.MultiPolygon
- Raises:
ValueError – If
queryis empty, the service cannot be reached, or no match is found.