Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update split-by-square to avoid creating tasks with no features in it #1642

Merged
merged 3 commits into from
Jul 12, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading