from .loading import Loading
from .meta import extension_tables, geocollections
from .validate import xtable_validator
[docs]
class ExtensionTable(Loading):
[docs]
validator = xtable_validator
[docs]
matrix = "xtable_matrix"
@property
[docs]
def filename(self):
return super(ExtensionTable, self).filename.replace(".loading", ".xtable")
[docs]
def write_to_map(self, *args, **kwargs):
raise NotImplementedError
[docs]
def import_from_map(self, mask=None):
from .utils import get_pandarus_map
geocollection = extension_tables[self.name].get("geocollection")
xt_field = extension_tables[self.name].get("xt_field")
if not geocollection:
raise ValueError("No geocollection for this extension table")
if geocollections[geocollection].get('kind') == 'raster':
raise ValueError("This function is only for vectors.")
map_obj = get_pandarus_map(geocollection)
data = []
if xt_field is None:
raise ValueError("No `xt_field` field name specified")
id_field = geocollections[geocollection].get("field")
if not id_field:
raise ValueError(
"Geocollection must specify ``field`` field name for unique feature ids"
)
for feature in map_obj:
label = feature["properties"][id_field]
value = float(feature["properties"][xt_field])
if mask is not None and value == mask:
continue
data.append((value, (geocollection, label)))
self.write(data)