cleangeometries & round_coordinates shouldn't return duplicate coordinates

This commit is contained in:
Laura Klünder 2019-12-21 12:17:16 +01:00
parent 484f725aa6
commit 4d113da653
4 changed files with 76 additions and 14 deletions

View file

@ -0,0 +1,19 @@
from django.core.management.base import BaseCommand
from django.db import transaction
from c3nav.mapdata.models.geometry.base import GeometryMixin
from c3nav.mapdata.utils.models import get_submodels
class Command(BaseCommand):
help = 'clean-up/fix all geometries in the database'
def handle(self, *args, **options):
with transaction.atomic():
for model in get_submodels(GeometryMixin):
for instance in model.objects.all():
old_geom = instance.geometry.wrapped_geojson
instance.save()
instance.refresh_from_db()
if instance.geometry.wrapped_geojson != old_geom:
print('Fixed %s' % instance)