add LineObstacle and various improvements
This commit is contained in:
parent
06aec21669
commit
0f81d1e49a
9 changed files with 150 additions and 5 deletions
|
@ -103,7 +103,7 @@ class GeometryMapItemWithLevel(GeometryMapItem):
|
|||
return result
|
||||
|
||||
|
||||
class LineGeometryMapItemWithLevel(GeometryMapItemWithLevel):
|
||||
class DirectedLineGeometryMapItemWithLevel(GeometryMapItemWithLevel):
|
||||
geomtype = 'polyline'
|
||||
|
||||
class Meta:
|
||||
|
@ -168,7 +168,7 @@ class Outside(GeometryMapItemWithLevel):
|
|||
default_related_name = 'outsides'
|
||||
|
||||
|
||||
class Stair(LineGeometryMapItemWithLevel):
|
||||
class Stair(DirectedLineGeometryMapItemWithLevel):
|
||||
"""
|
||||
A stair
|
||||
"""
|
||||
|
@ -178,6 +178,48 @@ class Stair(LineGeometryMapItemWithLevel):
|
|||
default_related_name = 'stairs'
|
||||
|
||||
|
||||
class LineObstacle(GeometryMapItemWithLevel):
|
||||
"""
|
||||
An obstacle that is a line with a specific width
|
||||
"""
|
||||
width = models.DecimalField(_('obstacle width'), max_digits=4, decimal_places=2, default=0.15)
|
||||
|
||||
geomtype = 'polyline'
|
||||
|
||||
class Meta:
|
||||
verbose_name = _('Line Obstacle')
|
||||
verbose_name_plural = _('Line Obstacles')
|
||||
default_related_name = 'lineobstacles'
|
||||
|
||||
def to_geojson(self):
|
||||
result = super().to_geojson()
|
||||
original_geometry = result['geometry']
|
||||
draw = self.geometry.buffer(self.width/2, join_style=JOIN_STYLE.mitre, cap_style=CAP_STYLE.flat)
|
||||
result['geometry'] = format_geojson(mapping(draw))
|
||||
result['original_geometry'] = original_geometry
|
||||
return result
|
||||
|
||||
@classmethod
|
||||
def fromfile(cls, data, file_path):
|
||||
kwargs = super().fromfile(data, file_path)
|
||||
|
||||
if 'width' not in data:
|
||||
raise ValueError('missing width.')
|
||||
kwargs['width'] = data['width']
|
||||
|
||||
return kwargs
|
||||
|
||||
def get_geojson_properties(self):
|
||||
result = super().get_geojson_properties()
|
||||
result['width'] = float(self.width)
|
||||
return result
|
||||
|
||||
def tofile(self):
|
||||
result = super().tofile()
|
||||
result['width'] = float(self.width)
|
||||
return result
|
||||
|
||||
|
||||
class Obstacle(GeometryMapItemWithLevel):
|
||||
"""
|
||||
An obstacle
|
||||
|
|
|
@ -104,6 +104,14 @@ class LevelGeometries():
|
|||
def mapped(self):
|
||||
return cascaded_union([self.buildings, self.outsides])
|
||||
|
||||
@cached_property
|
||||
def lineobstacles(self):
|
||||
lineobstacles = []
|
||||
for obstacle in self.level.lineobstacles.all():
|
||||
lineobstacles.append(obstacle.geometry.buffer(obstacle.width/2,
|
||||
join_style=JOIN_STYLE.mitre, cap_style=CAP_STYLE.flat))
|
||||
return cascaded_union(lineobstacles)
|
||||
|
||||
@cached_property
|
||||
def obstacles(self):
|
||||
levels_by_name = {}
|
||||
|
@ -119,6 +127,7 @@ class LevelGeometries():
|
|||
if level_name is not None:
|
||||
obstacles = obstacles.intersection(levels_by_name[level_name].geometries.mapped)
|
||||
all_obstacles.append(obstacles)
|
||||
all_obstacles.extend(self.lineobstacles)
|
||||
|
||||
return cascaded_union(all_obstacles).intersection(self.mapped)
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue