mirror of
https://git.ianrenton.com/ian/spothole.git
synced 2026-08-06 10:31:42 +00:00
42 lines
1.6 KiB
Python
42 lines
1.6 KiB
Python
import csv
|
|
|
|
from pyhamtools.locator import latlong_to_locator
|
|
|
|
from data.sig_ref import SIGRef
|
|
from sigrefdataproviders.local_file_sig_ref_data_provider import LocalFileSIGRefDataProvider
|
|
|
|
|
|
class DME(LocalFileSIGRefDataProvider):
|
|
"""SIG ref data provider for Diploma Municipios de Espana"""
|
|
|
|
SIG = "DME"
|
|
PATH = "datafiles/MUNICIPIOS.csv"
|
|
|
|
def __init__(self, provider_config):
|
|
super().__init__(self.SIG, provider_config, self.PATH)
|
|
|
|
def _file_to_data(self, path):
|
|
new_data = []
|
|
with open(path, encoding="latin-1") as _f:
|
|
for row in csv.DictReader(_f, delimiter=";"):
|
|
ref_id = row["COD_INE"][:5]
|
|
latitude = float(row["LATITUD_ETRS89_REGCAN95"].replace(",", ".")) if row.get(
|
|
"LATITUD_ETRS89_REGCAN95") else None
|
|
longitude = float(row["LONGITUD_ETRS89_REGCAN95"].replace(",", ".")) if row.get(
|
|
"LONGITUD_ETRS89_REGCAN95") else None
|
|
|
|
ref = SIGRef(sig=self.SIG, id=ref_id,
|
|
name=row["NOMBRE_ACTUAL"] + ", " + row["PROVINCIA"],
|
|
latitude=latitude,
|
|
longitude=longitude)
|
|
if latitude and longitude:
|
|
ref.grid = latlong_to_locator(latitude, longitude, 6)
|
|
new_data.append(ref)
|
|
|
|
# Bail out if a stop has been requested, i.e. the program is shutting down - no need to parse the rest
|
|
# of the data in this case
|
|
if self._stop:
|
|
break
|
|
|
|
return new_data
|