def generate_geom_filters(geometry, Pois): filters, geom = [], None if 'bbox' in geometry and 'geom' not in geometry: geom = geometry['bbox'].wkt filters.append( geo_func.ST_DWithin( geo_func.ST_Buffer(type_coerce(geom, Geography), geometry['buffer']), Pois.geom, 0)) elif 'bbox' in geometry and 'geom' in geometry: geom_bbox = geometry['bbox'].wkt geom = geometry['geom'].wkt filters.append( # in bbox geo_func.ST_DWithin( geo_func.ST_Intersection( geo_func.ST_Buffer(type_coerce(geom, Geography), geometry['buffer']), type_coerce(geom_bbox, Geography)), Pois.geom, 0)) elif 'bbox' not in geometry and 'geom' in geometry: geom = geometry['geom'].wkt filters.append( # buffer around geom geo_func.ST_DWithin( geo_func.ST_Buffer(type_coerce(geom, Geography), geometry['buffer']), Pois.geom, 0)) return filters, geom
def query_stops_info_by_path(session: Session, line_string_path: str): # Gets all stops information in path return session.query(Stop) \ .with_entities(Stop.stop_id, Stop.stop_name, Stop.geom) \ .filter( Stop.geom.intersects( functions.ST_Buffer(line_string_path, 0.000000000000063, 'endcap=flat join=round')))