diff options
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 |
commit | e75f66c13f976cb994e871deef13c80eb15ab388 (patch) | |
tree | 491641e16d8fe77647e09e0e7b4ad6771d14fe70 /ishtar_common/management/commands | |
parent | 6b41cd9f2b49866fbf53cf8df322ada2ea734cd2 (diff) | |
download | Ishtar-e75f66c13f976cb994e871deef13c80eb15ab388.tar.bz2 Ishtar-e75f66c13f976cb994e871deef13c80eb15ab388.zip |
import geofla: try to simplify geometry on error
Diffstat (limited to 'ishtar_common/management/commands')
-rw-r--r-- | ishtar_common/management/commands/import_geofla_csv.py | 12 |
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)) |