introducing column model
This commit is contained in:
parent
22cd575de4
commit
b19a8b7356
7 changed files with 79 additions and 11 deletions
|
@ -8,9 +8,9 @@ from rest_framework.response import Response
|
|||
from rest_framework.routers import SimpleRouter
|
||||
|
||||
from c3nav.editor.api import EditorViewSet
|
||||
from c3nav.mapdata.api import (AreaViewSet, BuildingViewSet, DoorViewSet, HoleViewSet, LineObstacleViewSet,
|
||||
LocationGroupViewSet, LocationViewSet, ObstacleViewSet, PointViewSet, SectionViewSet,
|
||||
SourceViewSet, SpaceViewSet, StairViewSet)
|
||||
from c3nav.mapdata.api import (AreaViewSet, BuildingViewSet, ColumnViewSet, DoorViewSet, HoleViewSet,
|
||||
LineObstacleViewSet, LocationGroupViewSet, LocationViewSet, ObstacleViewSet,
|
||||
PointViewSet, SectionViewSet, SourceViewSet, SpaceViewSet, StairViewSet)
|
||||
|
||||
router = SimpleRouter()
|
||||
router.register(r'sections', SectionViewSet)
|
||||
|
@ -22,6 +22,7 @@ router.register(r'areas', AreaViewSet)
|
|||
router.register(r'stairs', StairViewSet)
|
||||
router.register(r'obstacles', ObstacleViewSet)
|
||||
router.register(r'lineobstacles', LineObstacleViewSet)
|
||||
router.register(r'columns', ColumnViewSet)
|
||||
router.register(r'points', PointViewSet)
|
||||
router.register(r'sources', SourceViewSet)
|
||||
|
||||
|
|
|
@ -26,17 +26,20 @@ class EditorViewSet(ViewSet):
|
|||
section = get_object_or_404(Section, pk=section)
|
||||
buildings = section.buildings.all()
|
||||
buildings_geom = cascaded_union([building.geometry for building in buildings])
|
||||
spaces = {space.id: space for space in section.spaces.all().prefetch_related('groups', 'holes')}
|
||||
holes = sum((list(space.holes.all()) for space in spaces.values()), [])
|
||||
holes_geom = cascaded_union([hole.geometry for hole in holes])
|
||||
spaces = {space.id: space for space in section.spaces.all().prefetch_related('groups', 'holes', 'columns')}
|
||||
holes_geom = []
|
||||
for space in spaces.values():
|
||||
if space.outside:
|
||||
space.geometry = space.geometry.difference(buildings_geom)
|
||||
else:
|
||||
space.geometry = space.geometry.intersection(buildings_geom)
|
||||
columns_geom = cascaded_union([column.geometry for column in space.columns.all()])
|
||||
space.geometry = space.geometry.difference(columns_geom)
|
||||
space_holes_geom = cascaded_union([hole.geometry for hole in space.holes.all()])
|
||||
holes_geom.append(space_holes_geom.intersection(space.geometry))
|
||||
space.geometry = space.geometry.difference(space_holes_geom)
|
||||
holes_geom = cascaded_union(holes_geom)
|
||||
|
||||
spaces_geom = cascaded_union([space.geometry for space in spaces.values() if space.level == 'normal'])
|
||||
holes_geom = holes_geom.intersection(spaces_geom)
|
||||
for building in buildings:
|
||||
building.original_geometry = building.geometry
|
||||
for obj in chain(buildings, (s for s in spaces.values() if s.level == 'normal')):
|
||||
|
@ -76,14 +79,15 @@ class EditorViewSet(ViewSet):
|
|||
results = chain(
|
||||
section.buildings.all(),
|
||||
doors,
|
||||
spaces,
|
||||
[space],
|
||||
space.areas.all().prefetch_related('groups'),
|
||||
space.holes.all(),
|
||||
space.stairs.all(),
|
||||
space.obstacles.all(),
|
||||
space.lineobstacles.all(),
|
||||
space.columns.all(),
|
||||
space.points.all().prefetch_related('groups'),
|
||||
spaces,
|
||||
)
|
||||
return Response(sum([self._get_geojsons(obj) for obj in results], ()))
|
||||
else:
|
||||
|
@ -103,6 +107,7 @@ class EditorViewSet(ViewSet):
|
|||
'stair': 'rgba(160, 0, 160, 0.5)',
|
||||
'obstacle': '#999999',
|
||||
'lineobstacle': '#999999',
|
||||
'column': '#888888',
|
||||
'point': '#4488cc',
|
||||
'shadow': '#000000',
|
||||
})
|
||||
|
|
|
@ -44,4 +44,5 @@ urlpatterns.extend(add_editor_urls('Area', 'Space'))
|
|||
urlpatterns.extend(add_editor_urls('Stair', 'Space'))
|
||||
urlpatterns.extend(add_editor_urls('Obstacle', 'Space'))
|
||||
urlpatterns.extend(add_editor_urls('LineObstacle', 'Space'))
|
||||
urlpatterns.extend(add_editor_urls('Column', 'Space'))
|
||||
urlpatterns.extend(add_editor_urls('Point', 'Space'))
|
||||
|
|
|
@ -72,7 +72,7 @@ def space_detail(request, section, pk):
|
|||
'space': space,
|
||||
|
||||
'child_models': [child_model(model_name, kwargs={'space': pk}, parent=space)
|
||||
for model_name in ('Hole', 'Area', 'Stair', 'Obstacle', 'LineObstacle', 'Point')],
|
||||
for model_name in ('Hole', 'Area', 'Stair', 'Obstacle', 'LineObstacle', 'Column', 'Point')],
|
||||
'geometry_url': '/api/editor/geometries/?space='+pk,
|
||||
})
|
||||
|
||||
|
|
|
@ -13,7 +13,7 @@ from rest_framework.viewsets import GenericViewSet, ReadOnlyModelViewSet
|
|||
|
||||
from c3nav.mapdata.models import Building, Door, Hole, LocationGroup, Source, Space
|
||||
from c3nav.mapdata.models.geometry.section import SECTION_MODELS
|
||||
from c3nav.mapdata.models.geometry.space import SPACE_MODELS, Area, LineObstacle, Obstacle, Point, Stair
|
||||
from c3nav.mapdata.models.geometry.space import SPACE_MODELS, Area, Column, LineObstacle, Obstacle, Point, Stair
|
||||
from c3nav.mapdata.models.locations import LOCATION_MODELS, Location, LocationRedirect, LocationSlug
|
||||
from c3nav.mapdata.models.section import Section
|
||||
|
||||
|
@ -108,6 +108,11 @@ class LineObstacleViewSet(MapdataViewSet):
|
|||
queryset = LineObstacle.objects.all()
|
||||
|
||||
|
||||
class ColumnViewSet(MapdataViewSet):
|
||||
""" Add ?geometry=1 to get geometries, add ?space=<id> to filter by space. """
|
||||
queryset = Column.objects.all()
|
||||
|
||||
|
||||
class PointViewSet(MapdataViewSet):
|
||||
""" Add ?geometry=1 to get geometries, add ?space=<id> to filter by space. """
|
||||
queryset = Point.objects.all()
|
||||
|
|
44
src/c3nav/mapdata/migrations/0009_column.py
Normal file
44
src/c3nav/mapdata/migrations/0009_column.py
Normal file
|
@ -0,0 +1,44 @@
|
|||
# -*- coding: utf-8 -*-
|
||||
# Generated by Django 1.11.2 on 2017-06-09 13:00
|
||||
from __future__ import unicode_literals
|
||||
|
||||
from shapely.geometry import Polygon
|
||||
|
||||
import c3nav.mapdata.fields
|
||||
from django.db import migrations, models
|
||||
import django.db.models.deletion
|
||||
|
||||
|
||||
def create_columns(apps, schema_editor):
|
||||
Space = apps.get_model('mapdata', 'Space')
|
||||
for space in Space.objects.filter():
|
||||
if not space.geometry.interiors:
|
||||
continue
|
||||
for interior in space.geometry.interiors:
|
||||
space.columns.create(geometry=Polygon(list(interior.coords)))
|
||||
space.geometry = Polygon(list(space.geometry.exterior.coords))
|
||||
space.save()
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
dependencies = [
|
||||
('mapdata', '0008_auto_20170608_1317'),
|
||||
]
|
||||
|
||||
operations = [
|
||||
migrations.CreateModel(
|
||||
name='Column',
|
||||
fields=[
|
||||
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
|
||||
('geometry', c3nav.mapdata.fields.GeometryField(geomtype='polygon')),
|
||||
('space', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='columns', to='mapdata.Space', verbose_name='space')),
|
||||
],
|
||||
options={
|
||||
'verbose_name': 'Column',
|
||||
'verbose_name_plural': 'Columns',
|
||||
'default_related_name': 'columns',
|
||||
},
|
||||
),
|
||||
migrations.RunPython(create_columns),
|
||||
]
|
|
@ -33,6 +33,18 @@ class SpaceGeometryMixin(GeometryMixin):
|
|||
return result
|
||||
|
||||
|
||||
class Column(SpaceGeometryMixin, models.Model):
|
||||
"""
|
||||
An column in a space, also used to be able to create rooms within rooms.
|
||||
"""
|
||||
geometry = GeometryField('polygon')
|
||||
|
||||
class Meta:
|
||||
verbose_name = _('Column')
|
||||
verbose_name_plural = _('Columns')
|
||||
default_related_name = 'columns'
|
||||
|
||||
|
||||
class Area(SpecificLocation, SpaceGeometryMixin, models.Model):
|
||||
"""
|
||||
An area in a space.
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue