def test_stadtstaat(): """ Test heuristic OSM improvements re. ``city`` attribute for Stadtstaaten. """ location = resolve_location(latitude=53.112, longitude=8.896) improve_location(location) assert location.address.suburb == 'Horn-Lehe' assert location.address.city_district == 'Stadtbezirk Bremen-Ost' assert location.address.city == 'Bremen' assert location.address.state == 'Bremen' name = format_address(location) assert name == 'Flemingstraße, Horn-Lehe, Bremen-Ost, Bremen, DE' location = resolve_location(latitude=52.544, longitude=13.374) improve_location(location) assert location.address.suburb == 'Gesundbrunnen' assert location.address.city_district == 'Mitte' assert location.address.city == 'Berlin' assert location.address.state == 'Berlin' name = format_address(location) assert name == 'Gerichtstraße, Gesundbrunnen, Mitte, Berlin, DE' location = resolve_location(latitude=53.448, longitude=10.228) improve_location(location) assert location.address.suburb == 'Curslack' assert location.address.city_district == 'Bergedorf' assert location.address.city == 'Hamburg' assert location.address.state == 'Hamburg' name = format_address(location) assert name == 'Curslacker Deich, Curslack, Bergedorf, Hamburg, DE'
def test_country_patches(): """ Fix `"country": "RP"` to `"country": "Poland"`. """ location = resolve_location(latitude=51.72, longitude=19.48) improve_location(location) assert location.address.country == 'Poland' name = format_address(location) assert name == 'Rentowna, Górna, Łódź-Górna, Łódź, łódzkie, PL' location = resolve_location(latitude=19.806, longitude=-70.704) improve_location(location) assert location.address.country == 'Dominican Republic' name = format_address(location) assert name == 'Guayacanes, Costámbar, Puerto Plata, DO'
def test_something(): location = resolve_location(latitude=52.181, longitude=7.630) improve_location(location) #log.info(location) name = format_address(location) assert name == 'Holunderbusch, Saerbeck, Steinfurt, Nordrhein-Westfalen, DE'
def test_format_address(): """ Test address formatting. """ location = resolve_location(latitude=48.778, longitude=9.236) improve_location(location) name = format_address(location) assert name == 'Ulmer Straße, Wangen, Stuttgart, Baden-Württemberg, DE'
def test_format_address(): """ Test address formatting with heuristic improvements. """ location = resolve_location(latitude=48.778, longitude=9.236) improve_location(location) name = format_address(location) assert name == 'Zwischenangriff Ulmer Straße, Wangen, Stuttgart, Baden-Württemberg, DE'
def test_road_unknown(): """ Road unknown. """ # From `neighbourhood` attribute (ex). location = resolve_location(latitude=27.222, longitude=78.01) improve_location(location) assert location.address.road == 'Unknown Road' name = format_address(location) assert name == 'Civil Lines, Agra, Uttar Pradesh, IN' # Unknown road. location = resolve_location(latitude=49.342, longitude=8.146) improve_location(location) assert location.address.road == 'Unknown Road' name = format_address(location) assert name == 'Neustadt an der Weinstraße, Rheinland-Pfalz, DE'
def test_city_district_vs_suburb(): """ Check priority control of `city_district` vs. `suburb`. I.e. use `"city_district": "Friedrichshain-Kreuzberg"` over `"suburb": "Fhain"`. """ location = resolve_location(latitude=52.518, longitude=13.442) improve_location(location) name = format_address(location) assert name == 'Weidenweg, Friedrichshain-Kreuzberg, Berlin, DE'
def test_taiwan_poor(): """ LDI station #187 does not have good reverse geocoding information. """ location = resolve_location(latitude=24.074, longitude=120.34) improve_location(location) assert location.address.country_code == 'TW' assert location.address.country == '臺灣' name = format_address(location) assert name == 'TW'
def test_city_patches(): """ Check patched `city` attribute, I.e. use `"city": "Regensburg"` over `"city": "Rgbg"`. """ location = resolve_location(latitude=49.006, longitude=12.104) improve_location(location) assert location.address.city == 'Regensburg' name = format_address(location) assert name == 'Regerstraße, Galgenberg, Regensburg, Bayern, DE'
def test_residential_village(): """ This address has to use information from `residential` and `village` fields. """ location = resolve_location(latitude=48.058, longitude=12.57) improve_location(location) #log.info(location) name = format_address(location) assert name == 'Trostberger Straße, Lengloh, Tacherting, Traunstein, Bayern, DE'
def enrich_station(self, station): # Sanity checks. if ('latitude' not in station.position or 'longitude' not in station.position) or \ (station.position.latitude is None or station.position.longitude is None): # TODO: Just emit this message once per X. log.warning( 'Incomplete station position, skipping geospatial enrichment. Station: {}' .format(station)) return # Compute geohash. station.position.geohash = geohash_encode(station.position.latitude, station.position.longitude) # Compute human readable location name. if self.reverse_geocode: try: # Reverse-geocode position. station.location = resolve_location( latitude=station.position.latitude, longitude=station.position.longitude, geohash=station.position.geohash, country_code=station.position.country, ) # Improve location information. improve_location(station.location) # Format address into single label. station.name = format_address(station.location) try: if station.name.lower() == station.position.country.lower( ): del station['name'] except: pass except Exception as ex: log.error( u'Problem with reverse geocoder for station {}: {}\n{}'. format(station, ex, exception_traceback())) if 'name' not in station: station.name = u'Station #{}'.format(station.station_id) try: station.name += ', ' + station.position.country except: pass
def test_stadtteil(): """ Test heuristic OSM improvements re. `suburb` vs. `residential` attribute. """ location = resolve_location(latitude=48.482, longitude=9.204) improve_location(location) assert location.address.suburb == 'Ringelbach' assert location.address.city == 'Reutlingen' assert location.address.state == 'Baden-Württemberg' name = format_address(location) assert name == 'Paul-Pfizer-Straße, Ringelbach, Reutlingen, Baden-Württemberg, DE'
def test_road_missing(): """ These addresses originally lack the `road` attribute. """ # From `pedestrian` attribute location = resolve_location(latitude=48.774, longitude=9.174) improve_location(location) assert location.address.road == 'Königstraße' name = format_address(location) assert name == 'Königstraße, Stuttgart-Mitte, Stuttgart, Baden-Württemberg, DE' # From `cycleway` attribute location = resolve_location(latitude=48.194, longitude=11.548) improve_location(location) assert location.address.road == 'Lerchenauer Straße' name = format_address(location) assert name == 'Lerchenauer Straße, Hasenbergl-Lerchenau Ost, Feldmoching-Hasenbergl, München, Bayern, DE' # From `path` attribute location = resolve_location(latitude=49.2, longitude=9.242) improve_location(location) assert location.address.road == 'Reutlinger Straße' name = format_address(location) assert name == 'Reutlinger Straße, Amorbach, Heilbronn, Baden-Württemberg, DE' # From `footway` attribute location = resolve_location(latitude=48.702, longitude=9.126) improve_location(location) assert location.address.road == 'Hans-Holbein-Straße' name = format_address(location) assert name == 'Hans-Holbein-Straße, Leinfelden-Echterdingen, Esslingen, Baden-Württemberg, DE' # From `house_number` attribute location = resolve_location(latitude=42.734, longitude=23.308) improve_location(location) assert location.address.road == "\u0431\u043b.402" name = format_address(location) assert name == "бл.402, ж.к. Надежда 4, София, София-град, BG"
def enrich_station(self, station): # Sanity checks. if ('latitude' not in station.position or 'longitude' not in station.position) or \ (station.position.latitude is None or station.position.longitude is None): # Just emit this message once per station. StationGeocodingFailed.emit_warning(station.station_id) return # Compute geohash. station.position.geohash = geohash_encode(station.position.latitude, station.position.longitude) # Compute human readable location name. if self.reverse_geocode: try: # Reverse-geocode position. station.location = resolve_location( latitude=station.position.latitude, longitude=station.position.longitude, geohash=station.position.geohash, country_code=station.position.get('country'), ) # Improve location information. improve_location(station.location) # Format address into single label. station.name = format_address(station.location) # Apply some fixups. try: if station.name.lower() == station.position.country.lower( ): del station['name'] except: pass except Exception: log.exception( f'Failed computing humanized name for station {station}') if 'name' not in station: station.name = f'Station #{station.station_id}' try: station.name += ', ' + station.position.country except: pass
def test_road_missing(): """ These addresses originally lack the `road` attribute. """ # From `pedestrian` attribute location = resolve_location(latitude=48.774, longitude=9.174) improve_location(location) assert location.address.road == 'Königstraße' name = format_address(location) assert name == 'Königstraße, Stuttgart-Mitte, Stuttgart, Baden-Württemberg, DE' # From `cycleway` attribute location = resolve_location(latitude=48.194, longitude=11.548) improve_location(location) assert location.address.road == 'Lerchenauer Straße' name = format_address(location) assert name == 'Lerchenauer Straße, Hasenbergl-Lerchenau Ost, München, Bayern, DE' # From `path` attribute location = resolve_location(latitude=49.2, longitude=9.242) improve_location(location) assert location.address.road == 'Reutlinger Straße' name = format_address(location) assert name == 'Reutlinger Straße, Neckarsulm, Baden-Württemberg, DE' # From `footway` attribute location = resolve_location(latitude=48.702, longitude=9.126) improve_location(location) assert location.address.road == 'Hans-Holbein-Straße' name = format_address(location) assert name == 'Hans-Holbein-Straße, Leinfelden, Leinfelden-Echterdingen, Esslingen, Baden-Württemberg, DE' # From `neighbourhood` attribute location = resolve_location(latitude=27.222, longitude=78.01) improve_location(location) assert location.address.road == 'Balkeshwar Ghat' name = format_address(location) assert name == 'Balkeshwar Ghat, Balkeshwar, Agra, Uttar Pradesh, IN' # From `house_number` attribute location = resolve_location(latitude=42.734, longitude=23.308) improve_location(location) assert location.address.road == "\u0431\u043b.402" name = format_address(location) assert name == "\u0431\u043b.402, \u0436.\u043a. \u041d\u0430\u0434\u0435\u0436\u0434\u0430 4, \u041d\u0430\u0434\u0435\u0436\u0434\u0430, \u0421\u0442\u043e\u043b\u0438\u0447\u043d\u0430, BG" # Unknown road location = resolve_location(latitude=49.342, longitude=8.146) improve_location(location) assert location.address.road == 'unknown' name = format_address(location) assert name == 'Neustadt-Stadtmitte, Neustadt, Neustadt an der Weinstra\u00dfe, Rheinland-Pfalz, DE'