Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
return places_json
# join with tags
elif params['request'] == 'pois':
bbox_query = db.session \
.query(Pois) \
.filter(*geom_filters) \
.subquery()
# sortby needed here for generating features in next step
# sortby_group = [bbox_query.c.osm_id]
sortby_group = []
if 'sortby' in params:
if params['sortby'] == 'distance':
sortby_group.append(geo_func.ST_Distance(type_coerce(geom, Geography), bbox_query.c.geom))
elif params['sortby'] == 'category':
sortby_group.append(bbox_query.c.category)
# start = timer()
keys_agg = func.array_agg(Tags.key).label('keys')
values_agg = func.array_agg(Tags.value).label('values')
categories_agg = func.array_agg(Categories.category).label('categories')
pois_query = db.session \
.query(bbox_query.c.osm_id,
bbox_query.c.osm_type,
bbox_query.c.geom.ST_Distance(type_coerce(geom, Geography)),
bbox_query.c.geom,
keys_agg,
def get_dataset_field(tablename, field):
response = {'status':'success','data':{}}
if tablename in seen_classes:
cls = current_app.class_references[tablename]
else:
db.metadata.reflect(bind=db.engine)
seen_classes.add(tablename)
cls = type(str(tablename), (GeoPoly, db.Model,), {'__tablename__':tablename,
'__table_args__' : {'extend_existing': True}})
current_app.class_references[tablename] = cls
if field == config.geom_column:
vector = cls.query.with_entities(geofuncs.ST_AsGeoJSON(getattr(cls, field))).all()
response['data'] = [v[0] for v in vector]
elif field == 'geojson':
#TODO: How can this be cleaner? Do I need 2 queries go get geojson?
#rows = cls.query.all()
geoms = cls.query.with_entities(geofuncs.ST_AsGeoJSON(getattr(cls, config.geom_column))).all()
features = []
for i, row in enumerate(geoms):
#attributes = row.as_dict()
#attributes.pop('wkb_geometry', None)
#for k, v in attributes.iteritems():
#if isinstance(v, decimal.Decimal):
#attributes[k] = float(v)
current_feature = {'type':'Feature',
'geometry':ast.literal_eval(geoms[i][0])}
#'properties':attributes}
features.append(current_feature)
# Filter longitude between start and end longitudes
lon_start_filter = request.args.get('lon_start')
lon_end_filter = request.args.get('lon_end')
if lon_start_filter:
query = query.filter(Address.longitude >= lon_start_filter)
if lon_end_filter:
query = query.filter(Address.longitude <= lon_end_filter)
# -- distance from filters --
# Filter addresses by their distance from a specified latitude and longitude
dist_lat_filter = request.args.get('dist_lat')
dist_lng_filter = request.args.get('dist_lng')
dist_filter = request.args.get('dist')
if dist_lat_filter and dist_lng_filter and dist_filter:
query = query.filter(
func.ST_Distance(
func.ST_GeogFromWKB(func.ST_Point(Address.longitude, Address.latitude)),
func.ST_GeogFromWKB(func.ST_Point(dist_lng_filter, dist_lat_filter)))
< dist_filter
)
# Filter addresses by their distance from a specified address
dist_addr_lat_filter = request.args.get('dist_addr_lat')
dist_addr_lng_filter = request.args.get('dist_addr_lng')
dist_addr_filter = request.args.get('dist_addr')
if dist_addr_lat_filter and dist_addr_lng_filter and dist_addr_filter:
query = query.filter(
func.ST_Distance(
func.ST_GeogFromWKB(func.ST_Point(Address.longitude, Address.latitude)),
func.ST_GeogFromWKB(func.ST_Point(dist_addr_lng_filter, dist_addr_lat_filter)))
< dist_addr_filter
)
lon_end_filter = request.args.get('lon_end')
if lon_start_filter:
query = query.filter(Address.longitude >= lon_start_filter)
if lon_end_filter:
query = query.filter(Address.longitude <= lon_end_filter)
# -- distance from filters --
# Filter addresses by their distance from a specified latitude and longitude
dist_lat_filter = request.args.get('dist_lat')
dist_lng_filter = request.args.get('dist_lng')
dist_filter = request.args.get('dist')
if dist_lat_filter and dist_lng_filter and dist_filter:
query = query.filter(
func.ST_Distance(
func.ST_GeogFromWKB(func.ST_Point(Address.longitude, Address.latitude)),
func.ST_GeogFromWKB(func.ST_Point(dist_lng_filter, dist_lat_filter)))
< dist_filter
)
# Filter addresses by their distance from a specified address
dist_addr_lat_filter = request.args.get('dist_addr_lat')
dist_addr_lng_filter = request.args.get('dist_addr_lng')
dist_addr_filter = request.args.get('dist_addr')
if dist_addr_lat_filter and dist_addr_lng_filter and dist_addr_filter:
query = query.filter(
func.ST_Distance(
func.ST_GeogFromWKB(func.ST_Point(Address.longitude, Address.latitude)),
func.ST_GeogFromWKB(func.ST_Point(dist_addr_lng_filter, dist_addr_lat_filter)))
< dist_addr_filter
)
result = query.all()