def __find_places(ctx: ServiceContext, place_group_id: str, base_url: str, query_geometry: shapely.geometry.base.BaseGeometry = None, query_expr: Any = None, comb_op: str = "and") -> GeoJsonFeatureCollection: if comb_op is not None and comb_op != "and": raise NotImplementedError("comb_op not yet supported") if place_group_id == ALL_PLACES: place_groups = ctx.get_global_place_groups(base_url, load_features=True) features = [] for place_group in place_groups: features.extend(place_group['features']) feature_collection = dict(type="FeatureCollection", features=features) else: feature_collection = ctx.get_global_place_group(place_group_id, base_url, load_features=True) feature_collection = dict(type="FeatureCollection", features=feature_collection['features']) if query_geometry is None: if query_expr is None: return feature_collection else: raise NotImplementedError() else: matching_places = [] if query_expr is None: for feature in feature_collection['features']: geometry = shapely.geometry.shape(feature['geometry']) if geometry.intersects(query_geometry): matching_places.append(feature) else: raise NotImplementedError() return dict(type="FeatureCollection", features=matching_places)
def find_features(features, query_geometry): matching_features = dict() for feature_id, feature in features.items(): geometry = shapely.geometry.shape(feature["geometry"]) if geometry.intersects(query_geometry): matching_features[feature_id] = feature return matching_features
def __find_places(ctx: ServiceContext, collection_name: str, query_geometry: shapely.geometry.base.BaseGeometry = None, query_expr: Any = None, comb_op: str = "and") -> GeoJsonFeatureCollection: place_group = ctx.get_place_group(collection_name) if query_geometry is None: if query_expr is None: return place_group else: raise NotImplementedError() else: matching_places = [] if query_expr is None: for place in place_group["features"]: geometry = shapely.geometry.shape(place["geometry"]) if geometry.intersects(query_geometry): matching_places.append(place) else: raise NotImplementedError() return dict(type="FeatureCollection", features=matching_places)