add geometry bounds for easier querying
This commit is contained in:
parent
025eb0dfae
commit
99f9aac0c3
2 changed files with 356 additions and 0 deletions
343
src/c3nav/mapdata/migrations/0036_geometry_bounds.py
Normal file
343
src/c3nav/mapdata/migrations/0036_geometry_bounds.py
Normal file
|
@ -0,0 +1,343 @@
|
||||||
|
# -*- coding: utf-8 -*-
|
||||||
|
# Generated by Django 1.11.6 on 2017-10-10 11:20
|
||||||
|
from __future__ import unicode_literals
|
||||||
|
|
||||||
|
from django.db import migrations, models
|
||||||
|
|
||||||
|
|
||||||
|
def add_geometry_bounds(apps, schema_editor):
|
||||||
|
from c3nav.mapdata.models.geometry.base import GeometryMixin
|
||||||
|
|
||||||
|
models = ('AltitudeArea', 'AltitudeMarker', 'Area', 'Building', 'Column', 'Door', 'GraphNode', 'Hole',
|
||||||
|
'LineObstacle', 'Obstacle', 'POI', 'Space', 'Stair')
|
||||||
|
for model in models:
|
||||||
|
model_cls = apps.get_model('mapdata', model)
|
||||||
|
for obj in model_cls.objects.all():
|
||||||
|
GeometryMixin.recalculate_bounds(obj)
|
||||||
|
obj.save()
|
||||||
|
|
||||||
|
def remove_geometry_bounds(apps, schema_editor):
|
||||||
|
pass
|
||||||
|
|
||||||
|
|
||||||
|
class Migration(migrations.Migration):
|
||||||
|
|
||||||
|
dependencies = [
|
||||||
|
('mapdata', '0035_auto_20170916_1216'),
|
||||||
|
]
|
||||||
|
|
||||||
|
operations = [
|
||||||
|
migrations.AddField(
|
||||||
|
model_name='altitudearea',
|
||||||
|
name='maxx',
|
||||||
|
field=models.DecimalField(db_index=True, decimal_places=2, default=0, max_digits=6, verbose_name='max x coordinate'),
|
||||||
|
preserve_default=False,
|
||||||
|
),
|
||||||
|
migrations.AddField(
|
||||||
|
model_name='altitudearea',
|
||||||
|
name='maxy',
|
||||||
|
field=models.DecimalField(db_index=True, decimal_places=2, default=0, max_digits=6, verbose_name='max y coordinate'),
|
||||||
|
preserve_default=False,
|
||||||
|
),
|
||||||
|
migrations.AddField(
|
||||||
|
model_name='altitudearea',
|
||||||
|
name='minx',
|
||||||
|
field=models.DecimalField(db_index=True, decimal_places=2, default=0, max_digits=6, verbose_name='min x coordinate'),
|
||||||
|
preserve_default=False,
|
||||||
|
),
|
||||||
|
migrations.AddField(
|
||||||
|
model_name='altitudearea',
|
||||||
|
name='miny',
|
||||||
|
field=models.DecimalField(db_index=True, decimal_places=2, default=0, max_digits=6, verbose_name='min y coordinate'),
|
||||||
|
preserve_default=False,
|
||||||
|
),
|
||||||
|
migrations.AddField(
|
||||||
|
model_name='altitudemarker',
|
||||||
|
name='maxx',
|
||||||
|
field=models.DecimalField(db_index=True, decimal_places=2, default=0, max_digits=6, verbose_name='max x coordinate'),
|
||||||
|
preserve_default=False,
|
||||||
|
),
|
||||||
|
migrations.AddField(
|
||||||
|
model_name='altitudemarker',
|
||||||
|
name='maxy',
|
||||||
|
field=models.DecimalField(db_index=True, decimal_places=2, default=0, max_digits=6, verbose_name='max y coordinate'),
|
||||||
|
preserve_default=False,
|
||||||
|
),
|
||||||
|
migrations.AddField(
|
||||||
|
model_name='altitudemarker',
|
||||||
|
name='minx',
|
||||||
|
field=models.DecimalField(db_index=True, decimal_places=2, default=0, max_digits=6, verbose_name='min x coordinate'),
|
||||||
|
preserve_default=False,
|
||||||
|
),
|
||||||
|
migrations.AddField(
|
||||||
|
model_name='altitudemarker',
|
||||||
|
name='miny',
|
||||||
|
field=models.DecimalField(db_index=True, decimal_places=2, default=0, max_digits=6, verbose_name='min y coordinate'),
|
||||||
|
preserve_default=False,
|
||||||
|
),
|
||||||
|
migrations.AddField(
|
||||||
|
model_name='area',
|
||||||
|
name='maxx',
|
||||||
|
field=models.DecimalField(db_index=True, decimal_places=2, default=0, max_digits=6, verbose_name='max x coordinate'),
|
||||||
|
preserve_default=False,
|
||||||
|
),
|
||||||
|
migrations.AddField(
|
||||||
|
model_name='area',
|
||||||
|
name='maxy',
|
||||||
|
field=models.DecimalField(db_index=True, decimal_places=2, default=0, max_digits=6, verbose_name='max y coordinate'),
|
||||||
|
preserve_default=False,
|
||||||
|
),
|
||||||
|
migrations.AddField(
|
||||||
|
model_name='area',
|
||||||
|
name='minx',
|
||||||
|
field=models.DecimalField(db_index=True, decimal_places=2, default=0, max_digits=6, verbose_name='min x coordinate'),
|
||||||
|
preserve_default=False,
|
||||||
|
),
|
||||||
|
migrations.AddField(
|
||||||
|
model_name='area',
|
||||||
|
name='miny',
|
||||||
|
field=models.DecimalField(db_index=True, decimal_places=2, default=0, max_digits=6, verbose_name='min y coordinate'),
|
||||||
|
preserve_default=False,
|
||||||
|
),
|
||||||
|
migrations.AddField(
|
||||||
|
model_name='building',
|
||||||
|
name='maxx',
|
||||||
|
field=models.DecimalField(db_index=True, decimal_places=2, default=0, max_digits=6, verbose_name='max x coordinate'),
|
||||||
|
preserve_default=False,
|
||||||
|
),
|
||||||
|
migrations.AddField(
|
||||||
|
model_name='building',
|
||||||
|
name='maxy',
|
||||||
|
field=models.DecimalField(db_index=True, decimal_places=2, default=0, max_digits=6, verbose_name='max y coordinate'),
|
||||||
|
preserve_default=False,
|
||||||
|
),
|
||||||
|
migrations.AddField(
|
||||||
|
model_name='building',
|
||||||
|
name='minx',
|
||||||
|
field=models.DecimalField(db_index=True, decimal_places=2, default=0, max_digits=6, verbose_name='min x coordinate'),
|
||||||
|
preserve_default=False,
|
||||||
|
),
|
||||||
|
migrations.AddField(
|
||||||
|
model_name='building',
|
||||||
|
name='miny',
|
||||||
|
field=models.DecimalField(db_index=True, decimal_places=2, default=0, max_digits=6, verbose_name='min y coordinate'),
|
||||||
|
preserve_default=False,
|
||||||
|
),
|
||||||
|
migrations.AddField(
|
||||||
|
model_name='column',
|
||||||
|
name='maxx',
|
||||||
|
field=models.DecimalField(db_index=True, decimal_places=2, default=0, max_digits=6, verbose_name='max x coordinate'),
|
||||||
|
preserve_default=False,
|
||||||
|
),
|
||||||
|
migrations.AddField(
|
||||||
|
model_name='column',
|
||||||
|
name='maxy',
|
||||||
|
field=models.DecimalField(db_index=True, decimal_places=2, default=0, max_digits=6, verbose_name='max y coordinate'),
|
||||||
|
preserve_default=False,
|
||||||
|
),
|
||||||
|
migrations.AddField(
|
||||||
|
model_name='column',
|
||||||
|
name='minx',
|
||||||
|
field=models.DecimalField(db_index=True, decimal_places=2, default=0, max_digits=6, verbose_name='min x coordinate'),
|
||||||
|
preserve_default=False,
|
||||||
|
),
|
||||||
|
migrations.AddField(
|
||||||
|
model_name='column',
|
||||||
|
name='miny',
|
||||||
|
field=models.DecimalField(db_index=True, decimal_places=2, default=0, max_digits=6, verbose_name='min y coordinate'),
|
||||||
|
preserve_default=False,
|
||||||
|
),
|
||||||
|
migrations.AddField(
|
||||||
|
model_name='door',
|
||||||
|
name='maxx',
|
||||||
|
field=models.DecimalField(db_index=True, decimal_places=2, default=0, max_digits=6, verbose_name='max x coordinate'),
|
||||||
|
preserve_default=False,
|
||||||
|
),
|
||||||
|
migrations.AddField(
|
||||||
|
model_name='door',
|
||||||
|
name='maxy',
|
||||||
|
field=models.DecimalField(db_index=True, decimal_places=2, default=0, max_digits=6, verbose_name='max y coordinate'),
|
||||||
|
preserve_default=False,
|
||||||
|
),
|
||||||
|
migrations.AddField(
|
||||||
|
model_name='door',
|
||||||
|
name='minx',
|
||||||
|
field=models.DecimalField(db_index=True, decimal_places=2, default=0, max_digits=6, verbose_name='min x coordinate'),
|
||||||
|
preserve_default=False,
|
||||||
|
),
|
||||||
|
migrations.AddField(
|
||||||
|
model_name='door',
|
||||||
|
name='miny',
|
||||||
|
field=models.DecimalField(db_index=True, decimal_places=2, default=0, max_digits=6, verbose_name='min y coordinate'),
|
||||||
|
preserve_default=False,
|
||||||
|
),
|
||||||
|
migrations.AddField(
|
||||||
|
model_name='graphnode',
|
||||||
|
name='maxx',
|
||||||
|
field=models.DecimalField(db_index=True, decimal_places=2, default=0, max_digits=6, verbose_name='max x coordinate'),
|
||||||
|
preserve_default=False,
|
||||||
|
),
|
||||||
|
migrations.AddField(
|
||||||
|
model_name='graphnode',
|
||||||
|
name='maxy',
|
||||||
|
field=models.DecimalField(db_index=True, decimal_places=2, default=0, max_digits=6, verbose_name='max y coordinate'),
|
||||||
|
preserve_default=False,
|
||||||
|
),
|
||||||
|
migrations.AddField(
|
||||||
|
model_name='graphnode',
|
||||||
|
name='minx',
|
||||||
|
field=models.DecimalField(db_index=True, decimal_places=2, default=0, max_digits=6, verbose_name='min x coordinate'),
|
||||||
|
preserve_default=False,
|
||||||
|
),
|
||||||
|
migrations.AddField(
|
||||||
|
model_name='graphnode',
|
||||||
|
name='miny',
|
||||||
|
field=models.DecimalField(db_index=True, decimal_places=2, default=0, max_digits=6, verbose_name='min y coordinate'),
|
||||||
|
preserve_default=False,
|
||||||
|
),
|
||||||
|
migrations.AddField(
|
||||||
|
model_name='hole',
|
||||||
|
name='maxx',
|
||||||
|
field=models.DecimalField(db_index=True, decimal_places=2, default=0, max_digits=6, verbose_name='max x coordinate'),
|
||||||
|
preserve_default=False,
|
||||||
|
),
|
||||||
|
migrations.AddField(
|
||||||
|
model_name='hole',
|
||||||
|
name='maxy',
|
||||||
|
field=models.DecimalField(db_index=True, decimal_places=2, default=0, max_digits=6, verbose_name='max y coordinate'),
|
||||||
|
preserve_default=False,
|
||||||
|
),
|
||||||
|
migrations.AddField(
|
||||||
|
model_name='hole',
|
||||||
|
name='minx',
|
||||||
|
field=models.DecimalField(db_index=True, decimal_places=2, default=0, max_digits=6, verbose_name='min x coordinate'),
|
||||||
|
preserve_default=False,
|
||||||
|
),
|
||||||
|
migrations.AddField(
|
||||||
|
model_name='hole',
|
||||||
|
name='miny',
|
||||||
|
field=models.DecimalField(db_index=True, decimal_places=2, default=0, max_digits=6, verbose_name='min y coordinate'),
|
||||||
|
preserve_default=False,
|
||||||
|
),
|
||||||
|
migrations.AddField(
|
||||||
|
model_name='lineobstacle',
|
||||||
|
name='maxx',
|
||||||
|
field=models.DecimalField(db_index=True, decimal_places=2, default=0, max_digits=6, verbose_name='max x coordinate'),
|
||||||
|
preserve_default=False,
|
||||||
|
),
|
||||||
|
migrations.AddField(
|
||||||
|
model_name='lineobstacle',
|
||||||
|
name='maxy',
|
||||||
|
field=models.DecimalField(db_index=True, decimal_places=2, default=0, max_digits=6, verbose_name='max y coordinate'),
|
||||||
|
preserve_default=False,
|
||||||
|
),
|
||||||
|
migrations.AddField(
|
||||||
|
model_name='lineobstacle',
|
||||||
|
name='minx',
|
||||||
|
field=models.DecimalField(db_index=True, decimal_places=2, default=0, max_digits=6, verbose_name='min x coordinate'),
|
||||||
|
preserve_default=False,
|
||||||
|
),
|
||||||
|
migrations.AddField(
|
||||||
|
model_name='lineobstacle',
|
||||||
|
name='miny',
|
||||||
|
field=models.DecimalField(db_index=True, decimal_places=2, default=0, max_digits=6, verbose_name='min y coordinate'),
|
||||||
|
preserve_default=False,
|
||||||
|
),
|
||||||
|
migrations.AddField(
|
||||||
|
model_name='obstacle',
|
||||||
|
name='maxx',
|
||||||
|
field=models.DecimalField(db_index=True, decimal_places=2, default=0, max_digits=6, verbose_name='max x coordinate'),
|
||||||
|
preserve_default=False,
|
||||||
|
),
|
||||||
|
migrations.AddField(
|
||||||
|
model_name='obstacle',
|
||||||
|
name='maxy',
|
||||||
|
field=models.DecimalField(db_index=True, decimal_places=2, default=0, max_digits=6, verbose_name='max y coordinate'),
|
||||||
|
preserve_default=False,
|
||||||
|
),
|
||||||
|
migrations.AddField(
|
||||||
|
model_name='obstacle',
|
||||||
|
name='minx',
|
||||||
|
field=models.DecimalField(db_index=True, decimal_places=2, default=0, max_digits=6, verbose_name='min x coordinate'),
|
||||||
|
preserve_default=False,
|
||||||
|
),
|
||||||
|
migrations.AddField(
|
||||||
|
model_name='obstacle',
|
||||||
|
name='miny',
|
||||||
|
field=models.DecimalField(db_index=True, decimal_places=2, default=0, max_digits=6, verbose_name='min y coordinate'),
|
||||||
|
preserve_default=False,
|
||||||
|
),
|
||||||
|
migrations.AddField(
|
||||||
|
model_name='poi',
|
||||||
|
name='maxx',
|
||||||
|
field=models.DecimalField(db_index=True, decimal_places=2, default=0, max_digits=6, verbose_name='max x coordinate'),
|
||||||
|
preserve_default=False,
|
||||||
|
),
|
||||||
|
migrations.AddField(
|
||||||
|
model_name='poi',
|
||||||
|
name='maxy',
|
||||||
|
field=models.DecimalField(db_index=True, decimal_places=2, default=0, max_digits=6, verbose_name='max y coordinate'),
|
||||||
|
preserve_default=False,
|
||||||
|
),
|
||||||
|
migrations.AddField(
|
||||||
|
model_name='poi',
|
||||||
|
name='minx',
|
||||||
|
field=models.DecimalField(db_index=True, decimal_places=2, default=0, max_digits=6, verbose_name='min x coordinate'),
|
||||||
|
preserve_default=False,
|
||||||
|
),
|
||||||
|
migrations.AddField(
|
||||||
|
model_name='poi',
|
||||||
|
name='miny',
|
||||||
|
field=models.DecimalField(db_index=True, decimal_places=2, default=0, max_digits=6, verbose_name='min y coordinate'),
|
||||||
|
preserve_default=False,
|
||||||
|
),
|
||||||
|
migrations.AddField(
|
||||||
|
model_name='space',
|
||||||
|
name='maxx',
|
||||||
|
field=models.DecimalField(db_index=True, decimal_places=2, default=0, max_digits=6, verbose_name='max x coordinate'),
|
||||||
|
preserve_default=False,
|
||||||
|
),
|
||||||
|
migrations.AddField(
|
||||||
|
model_name='space',
|
||||||
|
name='maxy',
|
||||||
|
field=models.DecimalField(db_index=True, decimal_places=2, default=0, max_digits=6, verbose_name='max y coordinate'),
|
||||||
|
preserve_default=False,
|
||||||
|
),
|
||||||
|
migrations.AddField(
|
||||||
|
model_name='space',
|
||||||
|
name='minx',
|
||||||
|
field=models.DecimalField(db_index=True, decimal_places=2, default=0, max_digits=6, verbose_name='min x coordinate'),
|
||||||
|
preserve_default=False,
|
||||||
|
),
|
||||||
|
migrations.AddField(
|
||||||
|
model_name='space',
|
||||||
|
name='miny',
|
||||||
|
field=models.DecimalField(db_index=True, decimal_places=2, default=0, max_digits=6, verbose_name='min y coordinate'),
|
||||||
|
preserve_default=False,
|
||||||
|
),
|
||||||
|
migrations.AddField(
|
||||||
|
model_name='stair',
|
||||||
|
name='maxx',
|
||||||
|
field=models.DecimalField(db_index=True, decimal_places=2, default=0, max_digits=6, verbose_name='max x coordinate'),
|
||||||
|
preserve_default=False,
|
||||||
|
),
|
||||||
|
migrations.AddField(
|
||||||
|
model_name='stair',
|
||||||
|
name='maxy',
|
||||||
|
field=models.DecimalField(db_index=True, decimal_places=2, default=0, max_digits=6, verbose_name='max y coordinate'),
|
||||||
|
preserve_default=False,
|
||||||
|
),
|
||||||
|
migrations.AddField(
|
||||||
|
model_name='stair',
|
||||||
|
name='minx',
|
||||||
|
field=models.DecimalField(db_index=True, decimal_places=2, default=0, max_digits=6, verbose_name='min x coordinate'),
|
||||||
|
preserve_default=False,
|
||||||
|
),
|
||||||
|
migrations.AddField(
|
||||||
|
model_name='stair',
|
||||||
|
name='miny',
|
||||||
|
field=models.DecimalField(db_index=True, decimal_places=2, default=0, max_digits=6, verbose_name='min y coordinate'),
|
||||||
|
preserve_default=False,
|
||||||
|
),
|
||||||
|
migrations.RunPython(add_geometry_bounds, remove_geometry_bounds),
|
||||||
|
]
|
|
@ -1,5 +1,7 @@
|
||||||
from collections import OrderedDict
|
from collections import OrderedDict
|
||||||
|
|
||||||
|
from django.db import models
|
||||||
|
from django.utils.translation import ugettext_lazy as _
|
||||||
from shapely.geometry import Point, mapping
|
from shapely.geometry import Point, mapping
|
||||||
|
|
||||||
from c3nav.mapdata.models.base import SerializableMixin
|
from c3nav.mapdata.models.base import SerializableMixin
|
||||||
|
@ -11,6 +13,10 @@ class GeometryMixin(SerializableMixin):
|
||||||
A map feature with a geometry
|
A map feature with a geometry
|
||||||
"""
|
"""
|
||||||
geometry = None
|
geometry = None
|
||||||
|
minx = models.DecimalField(_('min x coordinate'), max_digits=6, decimal_places=2, db_index=True)
|
||||||
|
miny = models.DecimalField(_('min y coordinate'), max_digits=6, decimal_places=2, db_index=True)
|
||||||
|
maxx = models.DecimalField(_('max x coordinate'), max_digits=6, decimal_places=2, db_index=True)
|
||||||
|
maxy = models.DecimalField(_('max y coordinate'), max_digits=6, decimal_places=2, db_index=True)
|
||||||
|
|
||||||
class Meta:
|
class Meta:
|
||||||
abstract = True
|
abstract = True
|
||||||
|
@ -59,3 +65,10 @@ class GeometryMixin(SerializableMixin):
|
||||||
|
|
||||||
def contains(self, x, y) -> bool:
|
def contains(self, x, y) -> bool:
|
||||||
return self.geometry.contains(Point(x, y))
|
return self.geometry.contains(Point(x, y))
|
||||||
|
|
||||||
|
def recalculate_bounds(self):
|
||||||
|
self.minx, self.miny, self.maxx, self.maxy = self.geometry.bounds
|
||||||
|
|
||||||
|
def save(self, *args, **kwargs):
|
||||||
|
self.recalculate_bounds()
|
||||||
|
super().save(*args, **kwargs)
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue