From e2e3e7211d4e15b3d87e804b91a420645325476e Mon Sep 17 00:00:00 2001 From: TimMcCauley Date: Tue, 31 Jul 2018 13:55:52 +0200 Subject: [PATCH] Closes #40 --- openpoiservice/server/api/query_builder.py | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/openpoiservice/server/api/query_builder.py b/openpoiservice/server/api/query_builder.py index 00e9c2b..280b2ef 100644 --- a/openpoiservice/server/api/query_builder.py +++ b/openpoiservice/server/api/query_builder.py @@ -6,6 +6,7 @@ from geoalchemy2.types import Geography, Geometry from geoalchemy2.elements import WKBElement, WKTElement from shapely import wkb +from shapely.geometry import MultiPoint from openpoiservice.server.db_import.models import Pois, Tags, Categories from sqlalchemy.sql.expression import type_coerce from sqlalchemy import func, cast, Integer, ARRAY @@ -236,10 +237,12 @@ def generate_geojson_features(cls, query, limit): """ geojson_features = [] + lat_lngs = [] for q_idx, q in enumerate(query): geometry = wkb.loads(str(q[3]), hex=True) + lat_lngs.append((geometry.x, geometry.y)) properties = dict( osm_id=int(q[0]), @@ -265,15 +268,14 @@ def generate_geojson_features(cls, query, limit): properties["osm_tags"] = key_values geojson_feature = geojson.Feature(geometry=geometry, - properties=properties - ) + properties=properties) geojson_features.append(geojson_feature) # limit reached if q_idx == limit - 2: break - feature_collection = geojson.FeatureCollection(geojson_features) + feature_collection = geojson.FeatureCollection(geojson_features, bbox=MultiPoint(lat_lngs).bounds) logger.info("Amount of features {}".format(len(geojson_features)))