From d747bb7da4800b6956194fb4ead89ec73e0c84a9 Mon Sep 17 00:00:00 2001 From: Étienne Loks Date: Mon, 30 May 2016 19:56:07 +0200 Subject: Add aggregated polygons --- chimere/models.py | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) (limited to 'chimere/models.py') diff --git a/chimere/models.py b/chimere/models.py index 48e7f4b..c38c9c2 100644 --- a/chimere/models.py +++ b/chimere/models.py @@ -1054,6 +1054,31 @@ class Polygon(GeographicItem): post_save.connect(weighted_post_save, sender=Polygon) +class AggregatedPolygon(models.Model): + ''' + Database view for aggregated polygons + ''' + polygon = models.MultiPolygonField() + subcategory = models.ForeignKey(SubCategory) + status = models.CharField(_(u"Status"), max_length=1, choices=STATUS) + + class Meta: + managed = False + db_table = 'chimere_aggregated_polygons' + + def getGeoJSON(self, color="#000"): + '''Return a GeoJSON string + ''' + if '#' not in color: + color = '#' + color + attributes = { + 'color': color, 'geometry': json.loads(self.polygon.geojson), + 'type': "Feature", "properties": { + 'key': "aggpoly-{}".format(self.pk), + "pk": self.id, "name": u'Aggregated polygon'}} + return json.dumps(attributes) + + class MultimediaType(models.Model): MEDIA_TYPES = (('A', _(u"Audio")), ('V', _(u"Video")), -- cgit v1.2.3