def get_projects_geojson(search_bbox_dto: ProjectSearchBBoxDTO) -> geojson.FeatureCollection:
""" search for projects meeting criteria provided return as a geojson feature collection"""
# make a polygon from provided bounding box
polygon = ProjectSearchService._make_4326_polygon_from_bbox(search_bbox_dto.bbox, search_bbox_dto.input_srid)
# validate the bbox area is less than or equal to the max area allowed to prevent
# abuse of the api or performance issues from large requests
if not ProjectSearchService.validate_bbox_area(polygon):
raise BBoxTooBigError('Requested bounding box is too large')
# get projects intersecting the polygon for created by the author_id
intersecting_projects = ProjectSearchService._get_intersecting_projects(polygon, search_bbox_dto.project_author)
# allow an empty feature collection to be returned if no intersecting features found, since this is primarily
# for returning data to show on a map
features = []
for project in intersecting_projects:
try:
localDTO = ProjectInfo.get_dto_for_locale(project.id, search_bbox_dto.preferred_locale,
project.default_locale)
except Exception as e:
pass
properties = {
"projectId": project.id,
"projectStatus": ProjectStatus(project.status).name,
"projectName": localDTO.name
}
feature = geojson.Feature(geometry=geojson.loads(project.geometry), properties=properties)
features.append(feature)
return geojson.FeatureCollection(features)
评论列表
文章目录