Пример #1
0
    def retrieve_csv_place(admin_table, geodata, place: Loc.Loc, key, idx):
        # 0Place (ID), 1Title, 2Name, 3Type, 4latitude, 5longitude, 6enclosed_by
        row = admin_table[idx].get(key)
        key_tokens = key.split("_")
        place.place_type = len(key_tokens) - 1
        # self.logger.debug(f'{row}')
        place.feature = row[CSVEntry.FEAT]

        place.original_entry = row[CSVEntry.TITLE]
        place.country_iso = row[CSVEntry.ISO]
        place.country_name = geodata.geo_files.geodb.get_country_name(
            place.country_iso)
        place.enclosed_by = row[CSVEntry.ENCLOSED_BY]

        place.lat: float = float(row[CSVEntry.LAT])
        place.lon: float = float(row[CSVEntry.LON])

        place.admin2_id = row[CSVEntry.ADMIN2_ID]
        place.admin1_id = row[CSVEntry.ADMIN1_ID]
        place.admin1_name = str(geodata.geo_files.geodb.get_admin1_name(place))
        place.admin2_name = str(geodata.geo_files.geodb.get_admin2_name(place))
        if place.admin2_name is None:
            place.admin2_name = ''
        if place.admin1_name is None:
            place.admin1_name = ''

        tokens = place.original_entry.split(',')
        if len(tokens) > 3:
            place.city1 = tokens[-4]
        if len(tokens) > 4:
            place.prefix = tokens[-5]

        place.id = row[CSVEntry.PLACE_ID]
Пример #2
0
 def find_geoid(self, geoid: str, place: Loc.Loc):
     place.target = geoid
     place.georow_list.clear()
     self.geo_files.geodb.lookup_geoid(place=place)
     if len(place.georow_list) > 0:
         # Copy geo row to Place
         self.geo_files.geodb.copy_georow_to_place(row=place.georow_list[0],
                                                   place=place)
         place.original_entry = place.format_full_nm(None)
         place.result_type = GeoKeys.Result.STRONG_MATCH
     else:
         place.result_type = GeoKeys.Result.NO_MATCH
Пример #3
0
    def write_updated_place(self, place: Loc.Loc, entry):
        # Write out updated location and lat/lon to  file
        self.geodata.geo_files.geodb.set_display_names(place)
        place.original_entry = place.format_full_nm(
            self.geodata.geo_files.output_replace_dct)
        prefix = GeoKeys.capwords(self.place.prefix)
        if self.diagnostics:
            self.in_diag_file.write(f'{entry}\n')

        if place.result_type != GeoKeys.Result.DELETE:
            # self.logger.debug(f'Write Updated - name={place.name} pref=[{place.prefix}]')

            self.ancestry_file_handler.write_updated(
                prefix + place.prefix_commas + place.original_entry, place)
            self.ancestry_file_handler.write_lat_lon(lat=place.lat,
                                                     lon=place.lon)
            text = prefix + place.prefix_commas + place.original_entry + '\n'
            text = str(text.encode('utf-8', errors='replace'))
            self.out_diag_file.write(text)
        else:
            # self.logger.debug('zero len, no output')
            if self.diagnostics:
                self.out_diag_file.write('DELETE\n')
            pass