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 | 4eba3ed5351d8087b3d4aa7f57d40d80d6886321 (patch) | |
| tree | 491641e16d8fe77647e09e0e7b4ad6771d14fe70 /ishtar_common/management/commands/import_geofla_csv.py | |
| parent | 920b279449315db7f0e8441f6035fb4e9fd9ffcd (diff) | |
| download | Ishtar-4eba3ed5351d8087b3d4aa7f57d40d80d6886321.tar.bz2 Ishtar-4eba3ed5351d8087b3d4aa7f57d40d80d6886321.zip | |
import geofla: try to simplify geometry on error
Diffstat (limited to 'ishtar_common/management/commands/import_geofla_csv.py')
| -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)) | 
