from sqlalchemy import schema
from sqlalchemy.sql import select
from sqlalchemy.sql.expression import func as sqlfunc
-import geoalchemy.functions as geofunc
from osgeo import ogr
import formencode
from wrpylib import mwdb, wrmwdb, mwmarkup, wrmwmarkup
if properties['type'] in wrmwmarkup.WRMAP_POINT_TYPES:
lon, lat = coordinates
label = properties.get('name')
- point_types = {u'gasthaus': u'hut', u'haltestelle': u'busstop', u'parkplatz': u'carpark', u'achtung': u'warning', u'punkt': u'point'}
+ point_types = {u'gasthaus': u'hut', u'haltestelle': u'busstop', u'parkplatz': u'carpark', u'achtung': u'warning', u'foto': u'photo', u'verleih': u'rental', u'punkt': u'point'}
point_type = point_types[properties['type']]
sql = u'insert into wrmappointcache (page_id, type, point, label) values (%s, %s, POINT(%s, %s), %s)'
connection.execute(sql, (sledrun_page.page_id, point_type, lon, lat, label))
connection.execute(wrregioncache.delete())
# Query all combinations of sledruns and regions
- sel = select([wrregion.c.id.label('wrregion_id'), wrregion.c.border.label('border'), wrsledruncache.c.page_id, wrsledruncache.c.position_longitude, wrsledruncache.c.position_latitude], geofunc.gcontains(wrregion.c.border, sqlfunc.point(wrsledruncache.c.position_longitude, wrsledruncache.c.position_latitude)))
+ sel = select([wrregion.c.id.label('region_id'), sqlfunc.AsWKB(wrregion.c.border).label('border'), wrsledruncache.c.page_id, wrsledruncache.c.position_longitude, wrsledruncache.c.position_latitude], sqlfunc.contains(wrregion.c.border, sqlfunc.point(wrsledruncache.c.position_longitude, wrsledruncache.c.position_latitude)))
ins = wrregioncache.insert()
# Refill wrregioncache
result = connection.execute(sel)
for row in result:
point.SetPoint(0, row.position_longitude, row.position_latitude)
- if point.Within(ogr.CreateGeometryFromWkb(row.border.geom_wkb)):
- connection.execute(ins.values(wrregion_id=row.wrregion_id, page_id=row.page_id))
+ if point.Within(ogr.CreateGeometryFromWkb(row.border)):
+ connection.execute(ins.values(region_id=row.region_id, page_id=row.page_id))
# commit
transaction.commit()