mirror of
https://github.com/ARUP-CAS/aiscr-qgis-amcr-viewer.git
synced 2026-06-19 12:22:54 +02:00
Update amcr_tools.py
Further polishing; removed obsolete bits
This commit is contained in:
+26
-20
@@ -17,7 +17,8 @@ TRANSLATIONS = {}
|
|||||||
# Download Digiarchive's vocabulary
|
# Download Digiarchive's vocabulary
|
||||||
def load_translations():
|
def load_translations():
|
||||||
global TRANSLATIONS
|
global TRANSLATIONS
|
||||||
if TRANSLATIONS: return
|
if TRANSLATIONS:
|
||||||
|
return
|
||||||
|
|
||||||
url = "https://digiarchiv.aiscr.cz/api/assets/i18n/cs.json"
|
url = "https://digiarchiv.aiscr.cz/api/assets/i18n/cs.json"
|
||||||
try:
|
try:
|
||||||
@@ -28,7 +29,8 @@ def load_translations():
|
|||||||
print(f"Chyba při stahování hesláře: {e}")
|
print(f"Chyba při stahování hesláře: {e}")
|
||||||
|
|
||||||
def tr_code(code):
|
def tr_code(code):
|
||||||
if not code: return ""
|
if not code:
|
||||||
|
return ""
|
||||||
return TRANSLATIONS.get(code, code)
|
return TRANSLATIONS.get(code, code)
|
||||||
|
|
||||||
def load_amcr_data(canvas, bb, filters=None):
|
def load_amcr_data(canvas, bb, filters=None):
|
||||||
@@ -64,7 +66,8 @@ def load_amcr_data(canvas, bb, filters=None):
|
|||||||
# Apply filters
|
# Apply filters
|
||||||
if filters:
|
if filters:
|
||||||
for key, value in filters.items():
|
for key, value in filters.items():
|
||||||
if not value: continue
|
if not value:
|
||||||
|
continue
|
||||||
if isinstance(value, list):
|
if isinstance(value, list):
|
||||||
base_params[key] = [f"{v}:or" for v in value]
|
base_params[key] = [f"{v}:or" for v in value]
|
||||||
else:
|
else:
|
||||||
@@ -127,22 +130,24 @@ def load_amcr_data(canvas, bb, filters=None):
|
|||||||
pian_lookup = {}
|
pian_lookup = {}
|
||||||
target_pian_ids = set()
|
target_pian_ids = set()
|
||||||
actions_with_geom = 0
|
actions_with_geom = 0
|
||||||
negative_dj_pian_ids = set()
|
|
||||||
|
|
||||||
for akce in docs_akce:
|
for akce in docs_akce:
|
||||||
piani = akce.get('az_dj_pian', [])
|
piani = akce.get('az_dj_pian', [])
|
||||||
if not piani: continue
|
if not piani:
|
||||||
|
continue
|
||||||
|
|
||||||
actions_with_geom += 1
|
actions_with_geom += 1
|
||||||
|
|
||||||
def g(key, default=""):
|
def g(key, default=""):
|
||||||
val = akce.get(key)
|
val = akce.get(key)
|
||||||
if isinstance(val, list): return str(val[0]) if val else default
|
if isinstance(val, list):
|
||||||
|
return str(val[0]) if val else default
|
||||||
return str(val) if val is not None else default
|
return str(val) if val is not None else default
|
||||||
|
|
||||||
def g_list(key, translate=False):
|
def g_list(key, translate=False):
|
||||||
val = akce.get(key, [])
|
val = akce.get(key, [])
|
||||||
if not isinstance(val, list): val = [val] if val else []
|
if not isinstance(val, list):
|
||||||
|
val = [val] if val else []
|
||||||
if translate:
|
if translate:
|
||||||
return ", ".join([tr_code(str(x)) for x in val if x])
|
return ", ".join([tr_code(str(x)) for x in val if x])
|
||||||
return ", ".join([str(x) for x in val if x])
|
return ", ".join([str(x) for x in val if x])
|
||||||
@@ -177,12 +182,6 @@ def load_amcr_data(canvas, bb, filters=None):
|
|||||||
"loc": g_list('loc')
|
"loc": g_list('loc')
|
||||||
}
|
}
|
||||||
|
|
||||||
# for pid in piani:
|
|
||||||
# if pid in negative_pians:
|
|
||||||
# continue
|
|
||||||
# pian_lookup[pid] = meta
|
|
||||||
# target_pian_ids.add(pid)
|
|
||||||
|
|
||||||
djs = akce.get('az_dokumentacni_jednotka', [])
|
djs = akce.get('az_dokumentacni_jednotka', [])
|
||||||
|
|
||||||
for dj in djs:
|
for dj in djs:
|
||||||
@@ -281,18 +280,22 @@ def load_amcr_data(canvas, bb, filters=None):
|
|||||||
for doc in docs_pian:
|
for doc in docs_pian:
|
||||||
try:
|
try:
|
||||||
pid = doc.get('ident_cely', '')
|
pid = doc.get('ident_cely', '')
|
||||||
if pid not in pian_lookup: continue
|
if pid not in pian_lookup:
|
||||||
|
continue
|
||||||
|
|
||||||
meta = pian_lookup[pid]
|
meta = pian_lookup[pid]
|
||||||
|
|
||||||
# Geometry processing
|
# Geometry processing
|
||||||
raw = doc.get('pian_chranene_udaje')
|
raw = doc.get('pian_chranene_udaje')
|
||||||
if isinstance(raw, list) and raw: raw = raw[0]
|
if isinstance(raw, list) and raw:
|
||||||
|
raw = raw[0]
|
||||||
jdata = json.loads(raw) if isinstance(raw, str) else (raw if isinstance(raw, dict) else {})
|
jdata = json.loads(raw) if isinstance(raw, str) else (raw if isinstance(raw, dict) else {})
|
||||||
|
|
||||||
wkt = None
|
wkt = None
|
||||||
if jdata.get('geom_sjtsk_wkt'): wkt = jdata['geom_sjtsk_wkt'].get('value')
|
if jdata.get('geom_sjtsk_wkt'):
|
||||||
elif jdata.get('geom_wkt'): wkt = jdata['geom_wkt'].get('value')
|
wkt = jdata['geom_sjtsk_wkt'].get('value')
|
||||||
|
elif jdata.get('geom_wkt'):
|
||||||
|
wkt = jdata['geom_wkt'].get('value')
|
||||||
|
|
||||||
# PIAN attributes
|
# PIAN attributes
|
||||||
pian_presnost = tr_code(str(doc.get('pian_presnost', '')))
|
pian_presnost = tr_code(str(doc.get('pian_presnost', '')))
|
||||||
@@ -328,9 +331,12 @@ def load_amcr_data(canvas, bb, filters=None):
|
|||||||
meta['pristupnost']
|
meta['pristupnost']
|
||||||
])
|
])
|
||||||
t = geom.type()
|
t = geom.type()
|
||||||
if t == QgsWkbTypes.PolygonGeometry: feats_p.append(feat)
|
if t == QgsWkbTypes.PolygonGeometry:
|
||||||
elif t == QgsWkbTypes.LineGeometry: feats_l.append(feat)
|
feats_p.append(feat)
|
||||||
elif t == QgsWkbTypes.PointGeometry: feats_pt.append(feat)
|
elif t == QgsWkbTypes.LineGeometry:
|
||||||
|
feats_l.append(feat)
|
||||||
|
elif t == QgsWkbTypes.PointGeometry:
|
||||||
|
feats_pt.append(feat)
|
||||||
except Exception as ex:
|
except Exception as ex:
|
||||||
print(f"Chyba při tvorbě feature: {ex}")
|
print(f"Chyba při tvorbě feature: {ex}")
|
||||||
pass
|
pass
|
||||||
|
|||||||
Reference in New Issue
Block a user