Skip to content

Commit

Permalink
feat: update split-by-square to avoid creating tasks without any feat…
Browse files Browse the repository at this point in the history
…ures in it
  • Loading branch information
Sujanadh committed Jul 11, 2024
1 parent 118dd68 commit b34ad1d
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 4 deletions.
7 changes: 6 additions & 1 deletion src/backend/app/projects/project_crud.py
Original file line number Diff line number Diff line change
Expand Up @@ -398,7 +398,11 @@ async def create_tasks_from_geojson(
raise HTTPException(e) from e


async def preview_split_by_square(boundary: str, meters: int):
async def preview_split_by_square(
boundary: str,
meters: int,
extract_geojson: Optional[FeatureCollection] = None,
):
"""Preview split by square for a project boundary.
Use a lambda function to remove the "z" dimension from each
Expand All @@ -409,6 +413,7 @@ async def preview_split_by_square(boundary: str, meters: int):
return await run_in_threadpool(
lambda: split_by_square(
boundary,
osm_extract=extract_geojson,
meters=meters,
)
)
Expand Down
17 changes: 14 additions & 3 deletions src/backend/app/projects/project_routes.py
Original file line number Diff line number Diff line change
Expand Up @@ -801,7 +801,9 @@ async def get_categories(current_user: AuthUser = Depends(login_required)):

@router.post("/preview-split-by-square/")
async def preview_split_by_square(
project_geojson: UploadFile = File(...), dimension: int = Form(100)
project_geojson: UploadFile = File(...),
extract_geojson: UploadFile = File(None),
dimension: int = Form(100),
):
"""Preview splitting by square.
Expand All @@ -820,9 +822,18 @@ async def preview_split_by_square(

# Validatiing Coordinate Reference System
await check_crs(boundary)
parsed_extract = None
if extract_geojson:
geojson_data = await extract_geojson.read()
parsed_extract = parse_and_filter_geojson(geojson_data, filter=False)
if parsed_extract:
await check_crs(parsed_extract)
else:
log.warning("Parsed geojson file contained no geometries")

result = await project_crud.preview_split_by_square(boundary, dimension)
return result
return await project_crud.preview_split_by_square(
boundary, dimension, parsed_extract
)


@router.post("/generate-data-extract/")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -171,6 +171,7 @@ const SplitTasks = ({ flag, geojsonFile, setGeojsonFile, customDataExtractUpload
dispatch(
GetDividedTaskFromGeojson(`${import.meta.env.VITE_API_URL}/projects/preview-split-by-square/`, {
geojson: drawnGeojsonFile,
extract_geojson: formValues.dataExtractWays === 'osm_data_extract' ? null : dataExtractFile,
dimension: formValues?.dimension,
}),
);
Expand Down

0 comments on commit b34ad1d

Please sign in to comment.