35 lines
1.1 KiB
Python
35 lines
1.1 KiB
Python
# -*- 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
|
|
|
|
|
|
class Migration(migrations.Migration):
|
|
|
|
dependencies = [
|
|
('mapdata', '0044_auto_20170504_1023'),
|
|
]
|
|
|
|
operations = [
|
|
migrations.RunPython(merge_areas),
|
|
]
|