obstacle altitude
This commit is contained in:
parent
4826930bbb
commit
7734863c39
5 changed files with 37 additions and 3 deletions
25
src/c3nav/mapdata/migrations/0077_obstacle_altitude.py
Normal file
25
src/c3nav/mapdata/migrations/0077_obstacle_altitude.py
Normal file
|
@ -0,0 +1,25 @@
|
||||||
|
# Generated by Django 2.2.8 on 2019-12-22 19:55
|
||||||
|
|
||||||
|
from decimal import Decimal
|
||||||
|
import django.core.validators
|
||||||
|
from django.db import migrations, models
|
||||||
|
|
||||||
|
|
||||||
|
class Migration(migrations.Migration):
|
||||||
|
|
||||||
|
dependencies = [
|
||||||
|
('mapdata', '0076_obstacle_color'),
|
||||||
|
]
|
||||||
|
|
||||||
|
operations = [
|
||||||
|
migrations.AddField(
|
||||||
|
model_name='lineobstacle',
|
||||||
|
name='altitude',
|
||||||
|
field=models.DecimalField(decimal_places=2, default=0, max_digits=6, validators=[django.core.validators.MinValueValidator(Decimal('0'))], verbose_name='altitude above ground'),
|
||||||
|
),
|
||||||
|
migrations.AddField(
|
||||||
|
model_name='obstacle',
|
||||||
|
name='altitude',
|
||||||
|
field=models.DecimalField(decimal_places=2, default=0, max_digits=6, validators=[django.core.validators.MinValueValidator(Decimal('0'))], verbose_name='altitude above ground'),
|
||||||
|
),
|
||||||
|
]
|
|
@ -230,8 +230,8 @@ class AltitudeArea(LevelGeometryMixin, models.Model):
|
||||||
space.geometry = space.geometry.difference(buildings_geom)
|
space.geometry = space.geometry.difference(buildings_geom)
|
||||||
space_accessible = space.geometry.difference(
|
space_accessible = space.geometry.difference(
|
||||||
unary_union(tuple(c.geometry for c in space.columns.all() if c.access_restriction_id is None) +
|
unary_union(tuple(c.geometry for c in space.columns.all() if c.access_restriction_id is None) +
|
||||||
tuple(o.geometry for o in space.obstacles.all()) +
|
tuple(o.geometry for o in space.obstacles.all() if o.altitude == 0) +
|
||||||
tuple(o.buffered_geometry for o in space.lineobstacles.all()) +
|
tuple(o.buffered_geometry for o in space.lineobstacles.all() if o.altitude == 0) +
|
||||||
tuple(h.geometry for h in space.holes.all()))
|
tuple(h.geometry for h in space.holes.all()))
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
|
@ -170,6 +170,8 @@ class Obstacle(SpaceGeometryMixin, models.Model):
|
||||||
geometry = GeometryField('polygon')
|
geometry = GeometryField('polygon')
|
||||||
height = models.DecimalField(_('height'), max_digits=6, decimal_places=2, default=0.8,
|
height = models.DecimalField(_('height'), max_digits=6, decimal_places=2, default=0.8,
|
||||||
validators=[MinValueValidator(Decimal('0'))])
|
validators=[MinValueValidator(Decimal('0'))])
|
||||||
|
altitude = models.DecimalField(_('altitude above ground'), max_digits=6, decimal_places=2, default=0,
|
||||||
|
validators=[MinValueValidator(Decimal('0'))])
|
||||||
color = models.CharField(null=True, blank=True, max_length=32, verbose_name=_('color (optional)'))
|
color = models.CharField(null=True, blank=True, max_length=32, verbose_name=_('color (optional)'))
|
||||||
|
|
||||||
class Meta:
|
class Meta:
|
||||||
|
@ -186,6 +188,7 @@ class Obstacle(SpaceGeometryMixin, models.Model):
|
||||||
def _serialize(self, geometry=True, **kwargs):
|
def _serialize(self, geometry=True, **kwargs):
|
||||||
result = super()._serialize(geometry=geometry, **kwargs)
|
result = super()._serialize(geometry=geometry, **kwargs)
|
||||||
result['height'] = float(str(self.height))
|
result['height'] = float(str(self.height))
|
||||||
|
result['altitude'] = float(str(self.altitude))
|
||||||
result['color'] = self.color
|
result['color'] = self.color
|
||||||
return result
|
return result
|
||||||
|
|
||||||
|
@ -198,6 +201,8 @@ class LineObstacle(SpaceGeometryMixin, models.Model):
|
||||||
width = models.DecimalField(_('width'), max_digits=4, decimal_places=2, default=0.15)
|
width = models.DecimalField(_('width'), max_digits=4, decimal_places=2, default=0.15)
|
||||||
height = models.DecimalField(_('height'), max_digits=6, decimal_places=2, default=0.8,
|
height = models.DecimalField(_('height'), max_digits=6, decimal_places=2, default=0.8,
|
||||||
validators=[MinValueValidator(Decimal('0'))])
|
validators=[MinValueValidator(Decimal('0'))])
|
||||||
|
altitude = models.DecimalField(_('altitude above ground'), max_digits=6, decimal_places=2, default=0,
|
||||||
|
validators=[MinValueValidator(Decimal('0'))])
|
||||||
color = models.CharField(null=True, blank=True, max_length=32, verbose_name=_('color (optional)'))
|
color = models.CharField(null=True, blank=True, max_length=32, verbose_name=_('color (optional)'))
|
||||||
|
|
||||||
class Meta:
|
class Meta:
|
||||||
|
@ -215,6 +220,7 @@ class LineObstacle(SpaceGeometryMixin, models.Model):
|
||||||
result = super()._serialize(geometry=geometry, **kwargs)
|
result = super()._serialize(geometry=geometry, **kwargs)
|
||||||
result['width'] = float(str(self.width))
|
result['width'] = float(str(self.width))
|
||||||
result['height'] = float(str(self.height))
|
result['height'] = float(str(self.height))
|
||||||
|
result['altitude'] = float(str(self.altitude))
|
||||||
result['color'] = self.color
|
result['color'] = self.color
|
||||||
if geometry:
|
if geometry:
|
||||||
result['buffered_geometry'] = format_geojson(mapping(self.buffered_geometry))
|
result['buffered_geometry'] = format_geojson(mapping(self.buffered_geometry))
|
||||||
|
|
|
@ -92,6 +92,7 @@ class AltitudeAreaGeometries:
|
||||||
lower=altitudes,
|
lower=altitudes,
|
||||||
upper=altitudes + int(0.001 * 1000),
|
upper=altitudes + int(0.001 * 1000),
|
||||||
crops=crops)
|
crops=crops)
|
||||||
|
# todo: treat altitude properly
|
||||||
for height, height_geometries in self.obstacles.items():
|
for height, height_geometries in self.obstacles.items():
|
||||||
for color, color_geometries in height_geometries.items():
|
for color, color_geometries in height_geometries.items():
|
||||||
for geometry in color_geometries:
|
for geometry in color_geometries:
|
||||||
|
|
|
@ -151,7 +151,9 @@ class LevelGeometries:
|
||||||
for obstacle in space.obstacles.all():
|
for obstacle in space.obstacles.all():
|
||||||
if not obstacle.height:
|
if not obstacle.height:
|
||||||
continue
|
continue
|
||||||
obstacles.setdefault(int(obstacle.height*1000), {}).setdefault(obstacle.color, []).append(
|
obstacles.setdefault(
|
||||||
|
int((obstacle.height+obstacle.altitude)*1000), {}
|
||||||
|
).setdefault(obstacle.color, []).append(
|
||||||
obstacle.geometry.intersection(space.walkable_geom)
|
obstacle.geometry.intersection(space.walkable_geom)
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue