summaryrefslogtreecommitdiff
path: root/ishtar_common/utils.py
diff options
context:
space:
mode:
authorÉtienne Loks <etienne.loks@iggdrasil.net>2022-12-20 18:20:31 +0100
committerÉtienne Loks <etienne.loks@iggdrasil.net>2022-12-20 18:20:31 +0100
commite5c56a7060c8962e167d24eba0ec7b19b36c4af6 (patch)
tree9ae8673d5bfb6ff3de826b197fc3be1a547616af /ishtar_common/utils.py
parentb8813f0575b3ea441a9687010d9abe01851cbf28 (diff)
downloadIshtar-e5c56a7060c8962e167d24eba0ec7b19b36c4af6.tar.bz2
Ishtar-e5c56a7060c8962e167d24eba0ec7b19b36c4af6.zip
Utils: adapt to v4 OSM relations importer
Diffstat (limited to 'ishtar_common/utils.py')
-rw-r--r--ishtar_common/utils.py23
1 files changed, 21 insertions, 2 deletions
diff --git a/ishtar_common/utils.py b/ishtar_common/utils.py
index 6ffda0eb6..1d3c4d143 100644
--- a/ishtar_common/utils.py
+++ b/ishtar_common/utils.py
@@ -2141,8 +2141,27 @@ def create_osm_town(rel_id, name, numero_insee=None):
geom = GEOSGeometry(str(geojson))
if geom.geom_type == "GeometryCollection":
geom = geom[0]
- town.limit = geom
- town.center = town.limit.centroid
+
+ GeoVectorData = apps.get_model("ishtar_common", "GeoVectorData")
+ GeoDataType = apps.get_model("ishtar_common", "GeoDataType")
+ GeoProviderType = apps.get_model("ishtar_common", "GeoProviderType")
+ town_content_type = ContentType.objects.get(app_label="ishtar_common", model="town")
+ data_type, __ = GeoDataType.objects.get_or_create(
+ txt_idx="town-limit", defaults={"label": "Limites commune"}
+ )
+ provider, __ = GeoProviderType.objects.get_or_create(
+ txt_idx="openstreetmap", defaults={"label": "OpenStreetMap"}
+ )
+ data = GeoVectorData.objects.create(
+ name="Limite de " + town.name,
+ source_content_type=town_content_type,
+ multi_polygon=geom,
+ source_id=town.pk,
+ data_type=data_type,
+ provider=provider
+ )
+ town.main_geodata = data
+ town._post_save_geo_ok = False
town.save()
return town