summaryrefslogtreecommitdiff
path: root/chimere/models.py
diff options
context:
space:
mode:
authorÉtienne Loks <etienne.loks@iggdrasil.net>2016-05-13 10:31:58 +0200
committerÉtienne Loks <etienne.loks@iggdrasil.net>2016-05-13 10:31:58 +0200
commit990493bf4ceaf7aa3e9ce79635799bc1c6b20679 (patch)
tree17a6510be9de5a9106a2e63369154c1ea02ff91b /chimere/models.py
parentf8838f35d33ddb53705da4bae05f9dc2f7d139c2 (diff)
downloadChimère-990493bf4ceaf7aa3e9ce79635799bc1c6b20679.tar.bz2
Chimère-990493bf4ceaf7aa3e9ce79635799bc1c6b20679.zip
Include polygons in area detection
Diffstat (limited to 'chimere/models.py')
-rw-r--r--chimere/models.py18
1 files changed, 18 insertions, 0 deletions
diff --git a/chimere/models.py b/chimere/models.py
index 7575e1c..a68945a 100644
--- a/chimere/models.py
+++ b/chimere/models.py
@@ -1466,6 +1466,7 @@ class SimpleArea:
subcat.order as order, subcat.item_type as item_type
from chimere_subcategory subcat
inner join chimere_category cat on cat.id=subcat.category_id'''
+
sql = sql_main + '''
inner join chimere_marker mark on ST_Contains(%s, mark.point)''' % area
if equal_status:
@@ -1476,6 +1477,7 @@ class SimpleArea:
and mc.marker_id=mark.id'''
sql += where
subcats = set(SubCategory.objects.raw(sql))
+
sql = sql_main + '''
inner join chimere_route rt on (ST_Intersects(%s, rt.route) or
ST_Contains(%s, rt.route))''' % (area, area)
@@ -1490,6 +1492,22 @@ class SimpleArea:
# set union behave strangely. Doing it manualy...
for c in set(SubCategory.objects.raw(sql)):
subcats.add(c)
+
+ sql = sql_main + '''
+ inner join chimere_polygon pol on (ST_Intersects(%s, pol.polygon) or
+ ST_Contains(%s, pol.polygon))''' % (area, area)
+ if equal_status:
+ sql += ' and pol.status' + equal_status
+ sql += date_condition % {'alias': 'pol'}
+ sql += '''
+ inner join chimere_polygon_categories pc on pc.subcategory_id=subcat.id
+ and pc.polygon_id=pol.id'''
+ sql += where
+ # subcats.union(set(SubCategory.objects.raw(sql)))
+ # set union behave strangely. Doing it manualy...
+ for c in set(SubCategory.objects.raw(sql)):
+ subcats.add(c)
+
return subcats