Skip to content

Commit

Permalink
feat(backend): update split-by-square to avoid creating tasks with no…
Browse files Browse the repository at this point in the history
… features in it (#1642)

* feat: update split-by-square to avoid creating tasks without any features in it

* build: update fmtm-splitter to v1.3.0 for latest fixies

* build: relock backend deps after rebase

---------

Co-authored-by: spwoodcock <[email protected]>
  • Loading branch information
Sujanadh and spwoodcock authored Jul 12, 2024
1 parent 5925424 commit a1665f2
Show file tree
Hide file tree
Showing 5 changed files with 26 additions and 9 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(HTTPStatus.UNPROCESSABLE_ENTITY, detail=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
8 changes: 4 additions & 4 deletions src/backend/pdm.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion src/backend/pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ dependencies = [
"osm-login-python==1.0.3",
"osm-fieldwork==0.12.4",
"osm-rawdata==0.3.0",
"fmtm-splitter==1.2.2",
"fmtm-splitter==1.3.0",
]
requires-python = ">=3.10"
readme = "../../README.md"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -172,6 +172,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 a1665f2

Please sign in to comment.