Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def test_select_bindparam_WKBElement(self):
s = Lake.__table__.select().where(Lake.__table__.c.geom == bindparam('geom'))
wkbelement = from_shape(LineString([[0, 0], [1, 1]]), srid=4326)
results = self.conn.execute(s, geom=wkbelement)
rows = results.fetchall()
row = rows[0]
assert isinstance(row[1], WKBElement)
wkt = session.execute(row[1].ST_AsText()).scalar()
assert wkt == 'LINESTRING(0 0,1 1)'
srid = session.execute(row[1].ST_SRID()).scalar()
assert srid == 4326
cast(func.regexp_matches(loc_col, '\((.*),.*\)'),
ARRAY(Float)).label('lat'),
cast(func.regexp_matches(loc_col, '\(.*,(.*)\)'),
ARRAY(Float)).label('lon'))\
.subquery()
try:
xmin, ymin, xmax, ymax = session.query(func.min(subq.c.lon),
func.min(subq.c.lat),
func.max(subq.c.lon),
func.max(subq.c.lat))\
.first()
xmin, ymin, xmax, ymax = xmin[0], ymin[0], xmax[0], ymax[0]
except:
session.rollback()
xmin, ymin, xmax, ymax = 0, 0, 0, 0
bbox = from_shape(box(xmin, ymin, xmax, ymax), srid=4326)
md.bbox = bbox
try:
session.add(md)
session.commit()
except:
session.rollback()
session.add(md)
session.commit()
def geometry(self, shape):
"""Set the task geometry collection from a Shapely object"""
self.geom = from_shape(shape)
elif k == 'ref':
if 'name' not in outtags:
outtags['name'] = '[%s]' % v
elif k == 'network':
outtags['level'] = ROUTE_CONF.network_map.get(v, 35)
if 'name'not in outtags:
outtags['name'] = '(%s)' % osmid
# geometry
outtags['geom'] = self.build_geometry(osmid)
if outtags['geom'] is None:
return None
outtags['geom'] = from_shape(outtags['geom'], srid=self.data.c.geom.type.srid)
# find the country
c = self.country_table
sel = select([c.column_cc()], distinct=True)\
.where(c.column_geom().ST_Intersects(outtags['geom']))
cur = self.thread.conn.execute(sel)
if cur.rowcount == 1:
cntry = cur.scalar()
elif cur.rowcount > 1:
# XXX should be counting here
cntry = cur.scalar()
else:
cntry = None
outtags['country'] = cntry
def auto_fill(self, zoom):
self.zoom = zoom
geom_3857 = DBSession.execute(ST_Transform(self.area.geometry, 3857)) \
.scalar()
geom_3857 = shape.to_shape(geom_3857)
tasks = []
for i in get_tiles_in_geom(geom_3857, zoom):
multi = MultiPolygon([i[2]])
geometry = ST_Transform(shape.from_shape(multi, 3857), 4326)
tasks.append(Task(i[0], i[1], zoom, geometry))
self.tasks = tasks
project = Project(
_(u'Untitled project'),
user
)
DBSession.add(project)
DBSession.flush()
tile_size = int(request.params['tile_size'])
geometry = request.params['geometry']
geoms = parse_geojson(geometry)
multipolygon = convert_to_multipolygon(geoms)
geometry = shape.from_shape(multipolygon, 4326)
geom_3857 = DBSession.execute(ST_Transform(geometry, 3857)).scalar()
geom_3857 = shape.to_shape(geom_3857)
zoom = get_zoom_for_tile_size(geom_3857, tile_size)
project.area = Area(geometry)
project.auto_fill(zoom)
request.session.flash(_("Project #${project_id} created successfully",
mapping={'project_id': project.id}),
'success')
return HTTPFound(location=route_path('project_edit', request,
project=project.id))
except Exception, e:
msg = _("Sorry, could not create the project. <br>%s") % e.message
request.session.flash(msg, 'alert')
def set_location(self):
"""Set the location of a task as a cheaply calculated
representative point of the combined geometries."""
# set the location field, which is a representative point
# for the task's geometries
# first, get all individual coordinates for the geometries
coordinates = []
for geometry in self.geometries:
coordinates.extend(list(to_shape(geometry.geom).coords))
# then, set the location to a representative point
# (cheaper than centroid)
if len(coordinates) > 0:
self.location = from_shape(MultiPoint(
coordinates).representative_point(), srid=4326)