cleangeometries should delete objects with empty geometries

This commit is contained in:
Laura Klünder 2019-12-24 00:51:35 +01:00
parent 735ad498ed
commit 9664b22a0c
2 changed files with 5 additions and 0 deletions

View file

@ -80,6 +80,7 @@ class GeometryField(models.TextField):
def _validate_geomtype(self, value, exception: typing.Type[Exception] = ValidationError):
if not isinstance(value, self.classes):
# if you get this error with wrappedgeometry, looked into wrapped_geom
raise exception('Expected %s instance, got %s instead.' % (' or '.join(c.__name__ for c in self.classes),
repr(value)))

View file

@ -13,6 +13,10 @@ class Command(BaseCommand):
for model in get_submodels(GeometryMixin):
for instance in model.objects.all():
old_geom = instance.geometry.wrapped_geojson
if instance.geometry.is_empty:
print('Deleted %s' % instance)
instance.delete()
continue
instance.save()
instance.refresh_from_db()
if instance.geometry.wrapped_geojson != old_geom: