add Space.outside (for correct rendering)
This commit is contained in:
parent
56eb1e9b13
commit
d644ac614e
2 changed files with 33 additions and 0 deletions
32
src/c3nav/mapdata/migrations/0003_space_outside.py
Normal file
32
src/c3nav/mapdata/migrations/0003_space_outside.py
Normal file
|
@ -0,0 +1,32 @@
|
|||
# -*- coding: utf-8 -*-
|
||||
# Generated by Django 1.10.7 on 2017-05-12 20:59
|
||||
from __future__ import unicode_literals
|
||||
|
||||
from django.db import migrations, models
|
||||
from shapely.ops import cascaded_union
|
||||
|
||||
|
||||
def set_space_outside(apps, schema_editor):
|
||||
Section = apps.get_model('mapdata', 'Section')
|
||||
for section in Section.objects.all():
|
||||
building_geometries = cascaded_union(tuple(building.geometry for building in section.buildings.all()))
|
||||
for space in section.spaces.all():
|
||||
if space.geometry.intersection(building_geometries).area / space.geometry.area < 0.5:
|
||||
space.outside = True
|
||||
space.save()
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
dependencies = [
|
||||
('mapdata', '0002_locationredirect'),
|
||||
]
|
||||
|
||||
operations = [
|
||||
migrations.AddField(
|
||||
model_name='space',
|
||||
name='outside',
|
||||
field=models.BooleanField(default=False, verbose_name='is outside of building'),
|
||||
),
|
||||
migrations.RunPython(set_space_outside),
|
||||
]
|
|
@ -62,6 +62,7 @@ class Space(SpecificLocation, LevelSectionGeometryMixin, models.Model):
|
|||
)
|
||||
geometry = GeometryField('polygon')
|
||||
category = models.CharField(verbose_name=_('category'), choices=CATEGORIES, default='', max_length=16)
|
||||
outside = models.BooleanField(default=False, verbose_name=_('is outside of building'))
|
||||
|
||||
class Meta:
|
||||
verbose_name = _('Space')
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue