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

Auto basemap generation if tms url is input during project creation #2027

Merged
merged 3 commits into from
Dec 31, 2024
Merged
Show file tree
Hide file tree
Changes from 2 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
23 changes: 21 additions & 2 deletions src/backend/app/projects/project_routes.py
Original file line number Diff line number Diff line change
Expand Up @@ -843,6 +843,7 @@ async def add_additional_entity_list(
async def generate_files(
db: Annotated[Connection, Depends(db_conn)],
project_user_dict: Annotated[ProjectUserDict, Depends(project_manager)],
background_tasks: BackgroundTasks,
xlsform_upload: Annotated[
Optional[BytesIO], Depends(central_deps.read_optional_xlsform)
],
Expand All @@ -867,6 +868,7 @@ async def generate_files(
created (i.e. the project form references multiple geometries).
db (Connection): The database connection.
project_user_dict (ProjectUserDict): Project admin role.
background_tasks (BackgroundTasks): FastAPI background tasks.

Returns:
json (JSONResponse): A success message containing the project ID.
Expand Down Expand Up @@ -942,6 +944,13 @@ async def generate_files(
},
)

if project.custom_tms_url:
basemap_in = project_schemas.BasemapGenerate(
tile_source="tms", file_format="pmtiles", tms_url=project.custom_tms_url
)
org_id = project.organisation_id
await generate_basemap(project_id, org_id, basemap_in, db, background_tasks)
Anuj-Gupta4 marked this conversation as resolved.
Show resolved Hide resolved

return JSONResponse(
status_code=HTTPStatus.OK,
content={"message": "success"},
Expand All @@ -961,7 +970,19 @@ async def generate_project_basemap(
project_id = project_user.get("project").id
org_id = project_user.get("project").organisation_id

await generate_basemap(project_id, org_id, basemap_in, db, background_tasks)
# Create task in db and return uuid
return {"Message": "Tile generation started"}


async def generate_basemap(
project_id: int,
org_id: int,
basemap_in: project_schemas.BasemapGenerate,
db: Connection,
background_tasks: BackgroundTasks,
):
"""Generate basemap tiles for a project."""
log.debug(
"Creating generate_project_basemap background task "
f"for project ID: {project_id}"
Expand All @@ -985,8 +1006,6 @@ async def generate_project_basemap(
basemap_in.tms_url,
)

return {"Message": "Tile generation started"}


@router.patch("/{project_id}", response_model=project_schemas.ProjectOut)
async def update_project(
Expand Down
4 changes: 3 additions & 1 deletion src/backend/app/projects/project_schemas.py
Original file line number Diff line number Diff line change
Expand Up @@ -274,7 +274,9 @@ class ProjectUserContributions(BaseModel):
class BasemapGenerate(BaseModel):
"""Params to generate a new basemap."""

tile_source: Annotated[Literal["esri", "bing", "google"], Field(default="esri")]
tile_source: Annotated[
Literal["esri", "bing", "google", "tms"], Field(default="esri")
Anuj-Gupta4 marked this conversation as resolved.
Show resolved Hide resolved
]
file_format: Annotated[
Literal["mbtiles", "sqlitedb", "pmtiles"],
Field(default="mbtiles"),
Expand Down
Loading