mirror of
https://git.ianrenton.com/ian/spothole.git
synced 2026-08-05 18:11:41 +00:00
37 lines
1.2 KiB
Python
37 lines
1.2 KiB
Python
import json
|
|
import logging
|
|
|
|
import geopandas
|
|
from shapely import prepare
|
|
|
|
from core.data_store import DATA_STORE
|
|
from providers.staticdata.local_file_static_data_provider import LocalFileStaticDataProvider
|
|
|
|
|
|
class ITUZoneData(LocalFileStaticDataProvider):
|
|
"""Static data provider for ITU zone geodata."""
|
|
|
|
PATH = "datafiles/ituzones.geojson"
|
|
|
|
def __init__(self, provider_config):
|
|
super().__init__("ITU Zone Data", provider_config, self.PATH)
|
|
|
|
def _load_data(self, path):
|
|
try:
|
|
with open(path) as f:
|
|
itu_zone_data = geopandas.GeoDataFrame.from_features(json.load(f)["features"])
|
|
for idx in itu_zone_data.index:
|
|
prepare(itu_zone_data.at[idx, 'geometry'])
|
|
|
|
# Bail out if a stop has been requested, i.e. the program is shutting down - no need to prepare the rest
|
|
# of the data in this case
|
|
if self.stop:
|
|
break
|
|
|
|
DATA_STORE.itu_zone_data = itu_zone_data
|
|
return True
|
|
|
|
except Exception as e:
|
|
logging.error("Exception when loading ITU zone data.", e, exc_info=True)
|
|
return False
|