Skip to content

Commit

Permalink
[UK] Try and fix invalid geometry on import.
Browse files Browse the repository at this point in the history
  • Loading branch information
dracos committed Dec 5, 2014
1 parent 7f0c5a5 commit e20425b
Showing 1 changed file with 14 additions and 2 deletions.
16 changes: 14 additions & 2 deletions mapit_gb/management/commands/mapit_UK_import_boundary_line.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
from django.utils import six

from mapit.models import Area, Name, Generation, Country, Type, CodeType, NameType
from mapit.management.command_utils import save_polygons
from mapit.management.command_utils import save_polygons, fix_invalid_geos_geometry


class Command(LabelCommand):
Expand Down Expand Up @@ -150,7 +150,19 @@ def handle_label(self, filename, **options):
if options['commit']:
m.save()

poly = [feat.geom]
# Make a GEOS geometry only to check for validity:
g = feat.geom
geos_g = g.geos
if not geos_g.valid:
print(" Geometry of %s %s not valid" % (ons_code, m))
geos_g = fix_invalid_geos_geometry(geos_g)
if geos_g is None:
raise Exception("The geometry for area %s was invalid and couldn't be fixed" % name)
g = None
else:
g = geos_g.ogr

poly = [g]

if options['commit']:
m.names.update_or_create(type=name_type, defaults={'name': name})
Expand Down

0 comments on commit e20425b

Please sign in to comment.