summaryrefslogtreecommitdiff
path: root/ishtar_common/management
diff options
context:
space:
mode:
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))