shapely's cascaded_union was deprecated, replace with unary_union
This commit is contained in:
parent
aebb158b12
commit
36df1fed66
4 changed files with 14 additions and 14 deletions
|
@ -12,7 +12,7 @@ from rest_framework.generics import get_object_or_404
|
||||||
from rest_framework.response import Response
|
from rest_framework.response import Response
|
||||||
from rest_framework.viewsets import ReadOnlyModelViewSet, ViewSet
|
from rest_framework.viewsets import ReadOnlyModelViewSet, ViewSet
|
||||||
from shapely import prepared
|
from shapely import prepared
|
||||||
from shapely.ops import cascaded_union
|
from shapely.ops import unary_union
|
||||||
|
|
||||||
from c3nav.api.utils import get_api_post_data
|
from c3nav.api.utils import get_api_post_data
|
||||||
from c3nav.editor.forms import ChangeSetForm, RejectForm
|
from c3nav.editor.forms import ChangeSetForm, RejectForm
|
||||||
|
@ -69,7 +69,7 @@ class EditorViewSet(EditorViewSetMixin, ViewSet):
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def _get_level_geometries(level):
|
def _get_level_geometries(level):
|
||||||
buildings = level.buildings.all()
|
buildings = level.buildings.all()
|
||||||
buildings_geom = cascaded_union([building.geometry for building in buildings])
|
buildings_geom = unary_union([building.geometry for building in buildings])
|
||||||
spaces = {space.pk: space for space in level.spaces.all()}
|
spaces = {space.pk: space for space in level.spaces.all()}
|
||||||
holes_geom = []
|
holes_geom = []
|
||||||
for space in spaces.values():
|
for space in spaces.values():
|
||||||
|
@ -77,11 +77,11 @@ class EditorViewSet(EditorViewSetMixin, ViewSet):
|
||||||
space.geometry = space.geometry.difference(buildings_geom)
|
space.geometry = space.geometry.difference(buildings_geom)
|
||||||
columns = [column.geometry for column in space.columns.all()]
|
columns = [column.geometry for column in space.columns.all()]
|
||||||
if columns:
|
if columns:
|
||||||
columns_geom = cascaded_union([column.geometry for column in space.columns.all()])
|
columns_geom = unary_union([column.geometry for column in space.columns.all()])
|
||||||
space.geometry = space.geometry.difference(columns_geom)
|
space.geometry = space.geometry.difference(columns_geom)
|
||||||
holes = [hole.geometry for hole in space.holes.all()]
|
holes = [hole.geometry for hole in space.holes.all()]
|
||||||
if holes:
|
if holes:
|
||||||
space_holes_geom = cascaded_union(holes)
|
space_holes_geom = unary_union(holes)
|
||||||
holes_geom.append(space_holes_geom.intersection(space.geometry))
|
holes_geom.append(space_holes_geom.intersection(space.geometry))
|
||||||
space.geometry = space.geometry.difference(space_holes_geom)
|
space.geometry = space.geometry.difference(space_holes_geom)
|
||||||
|
|
||||||
|
@ -89,7 +89,7 @@ class EditorViewSet(EditorViewSetMixin, ViewSet):
|
||||||
building.original_geometry = building.geometry
|
building.original_geometry = building.geometry
|
||||||
|
|
||||||
if holes_geom:
|
if holes_geom:
|
||||||
holes_geom = cascaded_union(holes_geom)
|
holes_geom = unary_union(holes_geom)
|
||||||
holes_geom_prep = prepared.prep(holes_geom)
|
holes_geom_prep = prepared.prep(holes_geom)
|
||||||
for obj in buildings:
|
for obj in buildings:
|
||||||
if holes_geom_prep.intersects(obj.geometry):
|
if holes_geom_prep.intersects(obj.geometry):
|
||||||
|
@ -221,7 +221,7 @@ class EditorViewSet(EditorViewSetMixin, ViewSet):
|
||||||
if request.user_permissions.can_access_base_mapdata:
|
if request.user_permissions.can_access_base_mapdata:
|
||||||
doors = [door for door in level.doors.filter(Door.q_for_request(request)).all()
|
doors = [door for door in level.doors.filter(Door.q_for_request(request)).all()
|
||||||
if door.geometry.intersects(space.geometry)]
|
if door.geometry.intersects(space.geometry)]
|
||||||
doors_space_geom = cascaded_union([door.geometry for door in doors]+[space.geometry])
|
doors_space_geom = unary_union([door.geometry for door in doors]+[space.geometry])
|
||||||
|
|
||||||
levels, levels_on_top, levels_under = self._get_levels_pk(request, level.primary_level)
|
levels, levels_on_top, levels_under = self._get_levels_pk(request, level.primary_level)
|
||||||
if level.on_top_of_id is not None:
|
if level.on_top_of_id is not None:
|
||||||
|
@ -251,7 +251,7 @@ class EditorViewSet(EditorViewSetMixin, ViewSet):
|
||||||
|
|
||||||
# deactivated for performance reasons
|
# deactivated for performance reasons
|
||||||
buildings = level.buildings.all()
|
buildings = level.buildings.all()
|
||||||
# buildings_geom = cascaded_union([building.geometry for building in buildings])
|
# buildings_geom = unary_union([building.geometry for building in buildings])
|
||||||
# for other_space in other_spaces:
|
# for other_space in other_spaces:
|
||||||
# if other_space.outside:
|
# if other_space.outside:
|
||||||
# other_space.geometry = other_space.geometry.difference(buildings_geom)
|
# other_space.geometry = other_space.geometry.difference(buildings_geom)
|
||||||
|
|
|
@ -3,13 +3,13 @@
|
||||||
from __future__ import unicode_literals
|
from __future__ import unicode_literals
|
||||||
|
|
||||||
from django.db import migrations, models
|
from django.db import migrations, models
|
||||||
from shapely.ops import cascaded_union
|
from shapely.ops import unary_union
|
||||||
|
|
||||||
|
|
||||||
def set_space_outside(apps, schema_editor):
|
def set_space_outside(apps, schema_editor):
|
||||||
Section = apps.get_model('mapdata', 'Section')
|
Section = apps.get_model('mapdata', 'Section')
|
||||||
for section in Section.objects.all():
|
for section in Section.objects.all():
|
||||||
building_geometries = cascaded_union(tuple(building.geometry for building in section.buildings.all()))
|
building_geometries = unary_union(tuple(building.geometry for building in section.buildings.all()))
|
||||||
for space in section.spaces.all():
|
for space in section.spaces.all():
|
||||||
if space.geometry.intersection(building_geometries).area / space.geometry.area < 0.5:
|
if space.geometry.intersection(building_geometries).area / space.geometry.area < 0.5:
|
||||||
space.outside = True
|
space.outside = True
|
||||||
|
|
|
@ -7,7 +7,7 @@ from django.db import models
|
||||||
from django.urls import reverse
|
from django.urls import reverse
|
||||||
from django.utils.functional import cached_property
|
from django.utils.functional import cached_property
|
||||||
from django.utils.translation import gettext_lazy as _
|
from django.utils.translation import gettext_lazy as _
|
||||||
from shapely.ops import cascaded_union
|
from shapely.ops import unary_union
|
||||||
|
|
||||||
from c3nav.mapdata.models.locations import SpecificLocation
|
from c3nav.mapdata.models.locations import SpecificLocation
|
||||||
|
|
||||||
|
@ -94,8 +94,8 @@ class Level(SpecificLocation, models.Model):
|
||||||
|
|
||||||
@cached_property
|
@cached_property
|
||||||
def bounds(self):
|
def bounds(self):
|
||||||
return cascaded_union(tuple(item.geometry.buffer(0)
|
return unary_union(tuple(item.geometry.buffer(0)
|
||||||
for item in chain(self.altitudeareas.all(), self.buildings.all()))).bounds
|
for item in chain(self.altitudeareas.all(), self.buildings.all()))).bounds
|
||||||
|
|
||||||
def get_icon(self):
|
def get_icon(self):
|
||||||
return super().get_icon() or 'layers'
|
return super().get_icon() or 'layers'
|
||||||
|
|
|
@ -10,7 +10,7 @@ from django.apps import apps
|
||||||
from django.db.models import Prefetch, Q
|
from django.db.models import Prefetch, Q
|
||||||
from django.utils.functional import cached_property
|
from django.utils.functional import cached_property
|
||||||
from django.utils.translation import gettext_lazy as _
|
from django.utils.translation import gettext_lazy as _
|
||||||
from shapely.ops import cascaded_union
|
from shapely.ops import unary_union
|
||||||
|
|
||||||
from c3nav.mapdata.grid import grid
|
from c3nav.mapdata.grid import grid
|
||||||
from c3nav.mapdata.models import Level, Location, LocationGroup, MapUpdate
|
from c3nav.mapdata.models import Level, Location, LocationGroup, MapUpdate
|
||||||
|
@ -137,7 +137,7 @@ def get_better_space_geometries():
|
||||||
result = {}
|
result = {}
|
||||||
for space in Space.objects.prefetch_related('columns', 'holes'):
|
for space in Space.objects.prefetch_related('columns', 'holes'):
|
||||||
geometry = space.geometry.difference(
|
geometry = space.geometry.difference(
|
||||||
cascaded_union(tuple(obj.geometry for obj in chain(space.columns.all(), space.holes.all())))
|
unary_union(tuple(obj.geometry for obj in chain(space.columns.all(), space.holes.all())))
|
||||||
)
|
)
|
||||||
if not geometry.is_empty:
|
if not geometry.is_empty:
|
||||||
result[space.pk] = geometry
|
result[space.pk] = geometry
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue