def copy_georow_to_place(self, row, place: Loc, fast: bool): """ Copy data from DB row into place instance Country, admin1_id, admin2_id, city, lat/lon, feature, geoid are updated if available #Args: row: georow from geoname database place: Loc instance fast: Currently ignored #Returns: None. Place instance is updated with data from georow """ place.admin1_id = '' place.admin2_id = '' place.admin1_name = '' place.admin2_name = '' place.city = '' place.country_iso = str(row[Entry.ISO]) place.lat = row[Entry.LAT] place.lon = row[Entry.LON] place.feature = str(row[Entry.FEAT]) place.geoid = str(row[Entry.ID]) place.prefix = row[Entry.PREFIX] place.place_type = Loc.PlaceType.CITY if place.feature == 'ADM0': place.place_type = Loc.PlaceType.COUNTRY pass elif place.feature == 'ADM1': place.admin1_id = row[Entry.ADM1] place.place_type = Loc.PlaceType.ADMIN1 elif place.feature == 'ADM2': place.admin1_id = row[Entry.ADM1] place.admin2_id = row[Entry.ADM2] place.place_type = Loc.PlaceType.ADMIN2 else: place.admin1_id = row[Entry.ADM1] place.admin2_id = row[Entry.ADM2] place.city = row[Entry.NAME] self.s.update_names(place) if place.admin2_name is None: place.admin2_name = '' if place.admin1_name is None: place.admin1_name = '' place.city = str(place.city) if place.city is None: place.city = '' try: place.score = row[Entry.SCORE] except IndexError: pass
def lookup_place(self, place: Loc) -> []: """ **Lookup a place in geoname.org db** Lookup is based on place.place_type as follows: Loc.PlaceType.COUNTRY: does self.search_country(place) Loc.PlaceType.ADVANCED_SEARCH: does self.feature_search(place) Otherwise: do self.search_city(place) # Args: place: Loc instance. Call Loc.parse_place() before calling lookup_place() # Returns: Best score found place.georow_list contains a list of matching entries. Each entry has: Lat, Long, districtID (County or State or Province ID), and a match quality score """ place.result_type = Result.STRONG_MATCH best_score = MatchScore.Score.VERY_POOR if place.place_type == Loc.PlaceType.COUNTRY: # Country if place.georow_list: place.country_name = self.get_country_name(place.country_name) best_score = MatchScore.Score.VERY_GOOD else: # General search if place.place_type == Loc.PlaceType.ADMIN1: place.feature = "ADM1" place.georow_list.clear() best_score = self._search(place=place, georow_list=place.georow_list, name=place.city, admin1_id=place.admin1_id, admin2_id=place.admin2_id, iso=place.country_iso, feature=place.feature, sdx=get_soundex(place.city)) self.logger.debug(f'**LOOKUP PLACE score={best_score}') return best_score