merge areas
This commit is contained in:
parent
c7cbe277a7
commit
d1b827ef8b
1 changed files with 37 additions and 0 deletions
37
src/c3nav/mapdata/migrations/0045_merge_areas.py
Normal file
37
src/c3nav/mapdata/migrations/0045_merge_areas.py
Normal file
|
@ -0,0 +1,37 @@
|
||||||
|
# -*- coding: utf-8 -*-
|
||||||
|
# Generated by Django 1.10.4 on 2017-05-04 12:52
|
||||||
|
from __future__ import unicode_literals
|
||||||
|
|
||||||
|
from django.db import migrations
|
||||||
|
|
||||||
|
|
||||||
|
def merge_areas(apps, schema_editor):
|
||||||
|
from shapely.ops import cascaded_union
|
||||||
|
Level = apps.get_model('mapdata', 'Level')
|
||||||
|
for level in Level.objects.all():
|
||||||
|
level_areas = list(level.areas.all())
|
||||||
|
while level_areas:
|
||||||
|
current_area = level_areas.pop(0)
|
||||||
|
while True:
|
||||||
|
for area in level_areas[:]:
|
||||||
|
if area.geometry.intersects(current_area.geometry) and current_area.public == area.public:
|
||||||
|
current_area.geometry = cascaded_union([area.geometry, current_area.geometry])
|
||||||
|
current_area.save()
|
||||||
|
level_areas.remove(area)
|
||||||
|
area.delete()
|
||||||
|
break
|
||||||
|
else:
|
||||||
|
break
|
||||||
|
|
||||||
|
return
|
||||||
|
|
||||||
|
|
||||||
|
class Migration(migrations.Migration):
|
||||||
|
|
||||||
|
dependencies = [
|
||||||
|
('mapdata', '0044_auto_20170504_1023'),
|
||||||
|
]
|
||||||
|
|
||||||
|
operations = [
|
||||||
|
migrations.RunPython(merge_areas),
|
||||||
|
]
|
Loading…
Add table
Add a link
Reference in a new issue