summaryrefslogtreecommitdiff
path: root/ishtar_common/management
diff options
context:
space:
mode:
authorÉtienne Loks <etienne.loks@iggdrasil.net>2018-02-17 22:50:58 +0100
committerÉtienne Loks <etienne.loks@iggdrasil.net>2018-02-17 22:50:58 +0100
commite75f66c13f976cb994e871deef13c80eb15ab388 (patch)
tree491641e16d8fe77647e09e0e7b4ad6771d14fe70 /ishtar_common/management
parent6b41cd9f2b49866fbf53cf8df322ada2ea734cd2 (diff)
downloadIshtar-e75f66c13f976cb994e871deef13c80eb15ab388.tar.bz2
Ishtar-e75f66c13f976cb994e871deef13c80eb15ab388.zip
import geofla: try to simplify geometry on error
Diffstat (limited to 'ishtar_common/management')
-rw-r--r--ishtar_common/management/commands/import_geofla_csv.py12
1 files changed, 11 insertions, 1 deletions
diff --git a/ishtar_common/management/commands/import_geofla_csv.py b/ishtar_common/management/commands/import_geofla_csv.py
index f60296e2f..642d59a5f 100644
--- a/ishtar_common/management/commands/import_geofla_csv.py
+++ b/ishtar_common/management/commands/import_geofla_csv.py
@@ -22,6 +22,7 @@ import sys
from django.core.management.base import BaseCommand
from django.contrib.gis.geos import GEOSGeometry, Point
+from django.db.utils import DataError
from ishtar_common.models import Town
@@ -89,7 +90,16 @@ class Command(BaseCommand):
town.surface = None
if not created:
nb_changed += 1
- town.save()
+ try:
+ town.save()
+ except DataError:
+ new_limit = str(GEOSGeometry(geom, srid=srid).simplify(
+ preserve_topology=True))
+ if 'MULTI' not in new_limit:
+ new_limit = new_limit.replace(
+ 'POLYGON', 'MULTIPOLYGON(') + ')'
+ town.limit = new_limit
+ town.save()
if quiet:
return
sys.stdout.write('\n* {} town created'.format(nb_created))