Skip to content

Commit

Permalink
fixup! Store subdivided areas.
Browse files Browse the repository at this point in the history
  • Loading branch information
dracos committed Aug 17, 2023
1 parent 58f5ac2 commit 13486c3
Showing 1 changed file with 3 additions and 3 deletions.
6 changes: 3 additions & 3 deletions mapit/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
from django.contrib.gis.db import models
from django.conf import settings
from django.db import connection
from django.db.models import F, Func
from django.db.models.query import RawQuerySet
from django.utils.encoding import smart_str
from django.utils.functional import cached_property
Expand Down Expand Up @@ -336,9 +335,10 @@ def __str__(self):

def save(self, *args, **kwargs):
super().save(*args, **kwargs)
divided = Geometry.objects.filter(id=self.id).annotate(division=Func(F('polygon'), function='ST_Subdivide'))
GeometrySubdivided.objects.filter(geometry=self).delete()
GeometrySubdivided.objects.bulk_create(GeometrySubdivided(geometry=self, division=p.division) for p in divided)
with connection.cursor() as cursor:
cursor.execute('''INSERT INTO mapit_geometrysubdivided (geometry_id, division)
SELECT id,ST_Subdivide(polygon) FROM mapit_geometry WHERE id = %s''', [self.id])


class GeometrySubdivided(models.Model):
Expand Down

0 comments on commit 13486c3

Please sign in to comment.