Additional filtering to compensate lack of support by mysql 5.5
authorphilipp <philipp@7aebc617-e5e2-0310-91dc-80fb5f6d2477>
Sun, 27 Oct 2013 20:09:40 +0000 (20:09 +0000)
committerphilipp <philipp@7aebc617-e5e2-0310-91dc-80fb5f6d2477>
Sun, 27 Oct 2013 20:09:40 +0000 (20:09 +0000)
Mysql 5.5 doesn't have specification conform geospacial functions.
http://dev.mysql.com/doc/refman/5.5/en/functions-for-testing-spatial-relations-between-geometric-objects.html
therefore we have to do further filtering ourself.

git-svn-id: http://www.winterrodeln.org/svn/wrfeed/trunk@1760 7aebc617-e5e2-0310-91dc-80fb5f6d2477

wrfeed/controllers/berichte.py

index 74b7d2315f85ca52ed446ccc2d6cd5c8ce331023..41ffb63ea75e330ce429cf0e88517655040c2be3 100644 (file)
@@ -17,6 +17,7 @@ import datetime
 from xml.etree.ElementTree import Element, SubElement, tostring
 
 from sqlalchemy.engine import create_engine
+from osgeo import ogr
 
 import logging
 
@@ -71,6 +72,9 @@ def create_feed(page_title=None, page_ids=None, region_name=None):
         border_wkb = row['border_wkb'] # border as WKB
         where += ' and contains(geomfromwkb(%s), point(position_longitude, position_latitude))'
         params += [border_wkb]
+        # the following variables are needed for the additional filtering below
+        border = ogr.CreateGeometryFromWkb(border_wkb)
+        point = ogr.Geometry(ogr.wkbPoint)
     else:
         # user wants to have all reports
         pass
@@ -95,6 +99,15 @@ def create_feed(page_title=None, page_ids=None, region_name=None):
     last_updated = None
     for row in result:
         page_id, page_title, report_id, date_report, date_entry, condition, description, author_name, author_userid, author_username, lon, lat = row
+
+        if not region_name is None:
+            # mysql 5.5 doesn't have specification conform geospacial functions.
+            # http://dev.mysql.com/doc/refman/5.5/en/functions-for-testing-spatial-relations-between-geometric-objects.html
+            # therefore we have to do further filtering here.
+            point.SetPoint(0, lon, lat)
+            if not point.Within(border):
+                continue
+
         page_title_url = page_title.replace(u' ', u'_')
         entry = SubElement(feed, "entry")
         entry_title = SubElement(entry, "title")