def get_country_iso(self, place: Loc) -> str: """ Return ISO code for specified country""" lookup_target, modified = GeoKeys.country_normalize(place.country_name) if len(lookup_target) == 0: return '' # Try each query until we find a match - each query gets less exact query_list = [ Query(where="name = ? AND f_code = ? ", args=(lookup_target, 'ADM0'), result=Result.STRONG_MATCH), # Query(where="name LIKE ? AND f_code = ? ", # args=(self.create_wildcard(lookup_target), 'ADM0'), # result=Result.PARTIAL_MATCH) #, # Query(where="sdx = ? AND f_code = ? ", # args=(GeoKeys.get_soundex (lookup_target), 'ADM0'), # result=Result.PARTIAL_MATCH) ] row_list, result_code = self.db.process_query_list( from_tbl='main.admin', query_list=query_list) if len(row_list) > 0: res = row_list[0][Entry.ISO] if len(row_list) == 1: place.country_name = row_list[0][Entry.NAME] else: res = '' return res
def copy_georow_to_place(self, row, place: Loc): # Copy data from DB row into Place # self.logger.debug(row) place.admin1_id = '' place.admin2_id = '' place.city1 = '' place.country_iso = str(row[Entry.ISO]) place.country_name = str(self.get_country_name(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]) if place.feature == 'ADM0': self.place_type = Loc.PlaceType.COUNTRY pass elif place.feature == 'ADM1': place.admin1_id = row[Entry.ADM1] self.place_type = Loc.PlaceType.ADMIN1 elif place.feature == 'ADM2': place.admin1_id = row[Entry.ADM1] place.admin2_id = row[Entry.ADM2] self.place_type = Loc.PlaceType.ADMIN2 else: place.admin1_id = row[Entry.ADM1] place.admin2_id = row[Entry.ADM2] place.city1 = row[Entry.NAME] self.place_type = Loc.PlaceType.CITY place.admin1_name = str(self.get_admin1_name(place)) place.admin2_name = str(self.get_admin2_name(place)) if place.admin2_name is None: place.admin2_name = '' if place.admin1_name is None: place.admin1_name = '' place.city1 = str(place.city1) if place.city1 is None: place.city1 = ''