2017-05-06 17:24:09 +02:00
|
|
|
from collections import OrderedDict
|
2017-05-08 21:55:45 +02:00
|
|
|
|
2017-05-07 12:06:13 +02:00
|
|
|
from shapely.geometry import Point, mapping
|
2017-05-06 17:24:09 +02:00
|
|
|
|
2017-05-09 12:50:32 +02:00
|
|
|
from c3nav.mapdata.fields import GeometryField
|
2017-05-08 16:40:22 +02:00
|
|
|
from c3nav.mapdata.models.base import EditorFormMixin
|
2017-05-06 17:24:09 +02:00
|
|
|
from c3nav.mapdata.utils.json import format_geojson
|
|
|
|
|
2017-05-09 09:36:08 +02:00
|
|
|
GEOMETRY_MODELS = OrderedDict()
|
2017-05-06 17:24:09 +02:00
|
|
|
|
|
|
|
|
2017-05-08 16:40:22 +02:00
|
|
|
class GeometryMixin(EditorFormMixin):
|
2017-05-06 17:24:09 +02:00
|
|
|
"""
|
|
|
|
A map feature with a geometry
|
|
|
|
"""
|
2017-05-09 12:50:32 +02:00
|
|
|
geometry = None
|
|
|
|
|
2017-05-06 17:24:09 +02:00
|
|
|
class Meta:
|
|
|
|
abstract = True
|
|
|
|
|
|
|
|
def get_geojson_properties(self):
|
|
|
|
return OrderedDict((
|
|
|
|
('type', self.__class__.__name__.lower()),
|
|
|
|
('id', self.id),
|
|
|
|
))
|
|
|
|
|
|
|
|
def to_geojson(self):
|
|
|
|
return OrderedDict((
|
|
|
|
('type', 'Feature'),
|
|
|
|
('properties', self.get_geojson_properties()),
|
|
|
|
('geometry', format_geojson(mapping(self.geometry), round=False)),
|
|
|
|
))
|
|
|
|
|
|
|
|
def get_shadow_geojson(self):
|
2017-05-09 09:36:08 +02:00
|
|
|
pass
|
2017-05-06 17:24:09 +02:00
|
|
|
|
|
|
|
def contains(self, x, y):
|
|
|
|
return self.geometry.contains(Point(x, y))
|