def test_nominatim(): import pytest from collections import OrderedDict params = OrderedDict() params['format'] = "json" params['address_details'] = 0 # Bad Address - should return an empty response params['q'] = "AAAAAAAAAAA" response_json = ox.nominatim_request(params = params, type = "search") # Good Address - should return a valid response with a valid osm_id params['q'] = "Newcastle A186 Westgate Rd" response_json = ox.nominatim_request(params = params, type = "search") # Lookup params = OrderedDict() params['format'] = "json" params['address_details'] = 0 params['osm_ids'] = "W68876073" response_json = ox.nominatim_request(params = params, type = "lookup") # Invalid nominatim query type with pytest.raises(ValueError): response_json = ox.nominatim_request( params = params, type = "transfer")
def test_nominatim(): import pytest from collections import OrderedDict params = OrderedDict() params['format'] = "json" params['address_details'] = 0 # Bad Address - should return an empty response params['q'] = "AAAAAAAAAAA" response_json = ox.nominatim_request(params = params, type = "search") # Good Address - should return a valid response with a valid osm_id params['q'] = "Newcastle A186 Westgate Rd" response_json = ox.nominatim_request(params = params, type = "search") # Lookup params = OrderedDict() params['format'] = "json" params['address_details'] = 0 params['osm_ids'] = "W68876073" response_json = ox.nominatim_request(params = params, type = "lookup") # Invalid nominatim query type with pytest.raises(ValueError): response_json = ox.nominatim_request( params = params, type = "transfer")
def search_address(address, email=None): """ Find the OpenStreetMap ways that match a given address. Parameters ---------- address : string Address to search for email : string Valid email address in case you are making a large number of requests. Returns ------- list of int List of osm ids for ways that match the given address query """ params = OrderedDict() params['format'] = "json" params['address_details'] = 0 if email: params['email'] = email params['q'] = address response_json = ox.nominatim_request(params=params, type='search') ways = filter(lambda x: x['osm_type'] == "way", response_json) osmids = map(lambda x: int(x["osm_id"]), ways) return list(osmids)
def getIdFromLocationName(name): if name == "": return None item = next((x for x in ox.nominatim_request({ "q": name, 'format': 'json' }) if x['osm_type'] != 'node'), None) if item is None: return item id = item['osm_id'] if item['osm_type'] == 'relation': id += 3600000000 elif item['osm_type'] != 'node': id += 2400000000 return id
def test_nominatim(): import pytest from collections import OrderedDict params = OrderedDict() params['format'] = "json" params['address_details'] = 0 # Bad Address - should return an empty response params['q'] = "AAAAAAAAAAA" response_json = ox.nominatim_request(params = params, type = "search") # Good Address - should return a valid response with a valid osm_id params['q'] = "Newcastle A186 Westgate Rd" response_json = ox.nominatim_request(params = params, type = "search") # Lookup params = OrderedDict() params['format'] = "json" params['address_details'] = 0 params['osm_ids'] = "W68876073" response_json = ox.nominatim_request(params = params, type = "lookup") # Invalid nominatim query type with pytest.raises(ValueError): response_json = ox.nominatim_request( params = params, type = "transfer") # Searching on public nominatim should work even if a key was provided ox.config( nominatim_key="NOT_A_KEY" ) response_json = ox.nominatim_request(params = params, type = "search") # Test changing the endpoint. It should fail because we didn't provide a valid key ox.config( nominatim_endpoint="http://open.mapquestapi.com/nominatim/v1/" ) with pytest.raises(Exception): response_json = ox.nominatim_request(params=params, type="search") ox.config(log_console=True, log_file=True, use_cache=True, data_folder='.temp/data', logs_folder='.temp/logs', imgs_folder='.temp/imgs', cache_folder='.temp/cache')
def lookup_address(osmids, entity, drop_keys=[ 'place_id', 'license', 'osm_type', 'osm_id', ' lat', 'lon', 'display_name', 'country', 'country_code', 'state', 'state_district', 'county', 'city' ], email=None): """ Lookup the address of multiple OSM ids that share the same entity type. Parameters ---------- osmids : array-like OSMids for address lookup. Hard limit of 50 ids as indicated in wiki.openstreetmap.org/wiki/Nominatim drop_keys : list keys to ignore from the nominatim response containing address details entity : string OSM entity of osmids. Valid values are 'N' for Node, 'W' for Way and 'R' for Relation. email : string Valid email address in case you are making a large number of requests. Returns ------- details : list of dict Address details for each input osmid """ if entity not in {'N', 'W', 'R'}: raise ValueError("Not valid OSM entity. Choose one of 'N', 'W' or 'R'") if len(osmids) > 50: raise ValueError( "Nominatim supports a maximum of 50 osmids in a lookup request.") params = OrderedDict() params['format'] = "json" params['address_details'] = 1 if email: params['email'] = email osmids = np.array(list(map(str, osmids))) entities = np.repeat(entity, len(osmids)) params['osm_ids'] = ",".join(np.core.defchararray.add(entities, osmids)) response_json = ox.nominatim_request(params=params, type='lookup') details = [] for dict_ in response_json: flattened_dict = flatten_dict(dict_, inherit_parent_key=False) if drop_keys: for key in drop_keys: flattened_dict.pop(key, None) details.append(flattened_dict) return details