summaryrefslogtreecommitdiff
path: root/archaeological_operations/models.py
diff options
context:
space:
mode:
authorÉtienne Loks <etienne.loks@iggdrasil.net>2022-09-09 12:38:46 +0200
committerÉtienne Loks <etienne.loks@iggdrasil.net>2022-12-12 12:23:18 +0100
commita8d8513c6c365d09eb663722b29740d3231d2c56 (patch)
tree44dd6b9849a9bdfbfb6b1c22c78cf3ad0992d7c6 /archaeological_operations/models.py
parent16aa1615cfdfdf96104b8654bb7caa463a5c95e0 (diff)
downloadIshtar-a8d8513c6c365d09eb663722b29740d3231d2c56.tar.bz2
Ishtar-a8d8513c6c365d09eb663722b29740d3231d2c56.zip
Geo: display associated context records and associated finds on sheet map (refactor and fixes)
Diffstat (limited to 'archaeological_operations/models.py')
-rw-r--r--archaeological_operations/models.py53
1 files changed, 3 insertions, 50 deletions
diff --git a/archaeological_operations/models.py b/archaeological_operations/models.py
index 69b24fecd..370b3c9b2 100644
--- a/archaeological_operations/models.py
+++ b/archaeological_operations/models.py
@@ -75,7 +75,7 @@ from ishtar_common.models import (
MainItem,
HierarchicalType,
)
-from ishtar_common.models_common import Department, HistoricalRecords
+from ishtar_common.models_common import Department, GeoVectorData, HistoricalRecords
from ishtar_common.model_managers import UUIDModelManager
from ishtar_common.utils import (
cached_label_changed,
@@ -1732,53 +1732,6 @@ class Operation(
return None
return q.all()[0].poly, self._meta.verbose_name
-
- def _get_geo_item_list(self, q, current_geodata, url, precision, rounded):
- collection_id = []
- items_id = []
- q = q.values("main_geodata", "id")
- for item in q.distinct().all():
- geodata_id = item["main_geodata"]
- if geodata_id not in current_geodata:
- collection_id.append(geodata_id)
- items_id.append(item["id"])
- current_geodata.append(geodata_id)
-
- collection = []
- for idx in range(len(collection_id)):
- geo = json.loads(GeoVectorData.objects.get(pk=collection_id[idx]).geojson)
- geo_type = geo.get("type", None)
- url_geo = url.format(items_id[idx])
- if geo_type == "FeatureCollection":
- for feat in geo["features"]:
- if "properties" in feat:
- feat["properties"]["url"] = url_geo
- collection += geo["features"]
- elif geo_type:
- if "properties" in geo:
- geo["properties"]["url"] = url_geo
- collection.append(geo)
-
- if not precision and rounded:
- precision = 6
- r = re.compile(r"(\d+)\.(\d{6})(\d*)")
- new_collection = []
- for feat in collection:
- geom_type = feat["geometry"].get("type", None)
- if geom_type == "Point":
- if precision is not None:
- feat["geometry"]["coordinates"] = [
- round(feat["geometry"]["coordinates"][0], precision),
- round(feat["geometry"]["coordinates"][1], precision),
- ]
- if not (-90 <= feat["geometry"]["coordinates"][1] <= 90) or not (
- -180 <= feat["geometry"]["coordinates"][0] <= 180):
- # probably a bad projection
- continue
- new_collection.append(feat)
- return new_collection
-
-
def get_geo_items(self, rounded=True):
dct = super(Operation, self).get_geo_items(rounded=rounded)
site = Site.objects.get_current()
@@ -1792,7 +1745,7 @@ class Operation(
q = self.context_record.filter(main_geodata__isnull=False)
url = base_url + "/show-contextrecord/{}/"
- collection_context_records = self._get_geo_item_list(
+ collection_context_records = GeoVectorData._get_geo_item_list(
q, current_geodata, url, precision, rounded
)
@@ -1800,7 +1753,7 @@ class Operation(
q = BaseFind.objects.filter(context_record__operation_id=self.pk,
main_geodata__isnull=False)
url = base_url + "/show-basefind/{}/"
- collection_finds = self._get_geo_item_list(
+ collection_finds = GeoVectorData._get_geo_item_list(
q, current_geodata, url, precision, rounded
)