From dbd3eab4521574badd01868489b46be53b10524e Mon Sep 17 00:00:00 2001 From: sujanadh Date: Mon, 25 Dec 2023 17:18:35 +0545 Subject: [PATCH 1/2] feat: created separate api to check the coordinate system --- src/backend/app/projects/project_routes.py | 29 +++++++++++++++++++++- 1 file changed, 28 insertions(+), 1 deletion(-) diff --git a/src/backend/app/projects/project_routes.py b/src/backend/app/projects/project_routes.py index 11fb9d9146..d6d0789d22 100644 --- a/src/backend/app/projects/project_routes.py +++ b/src/backend/app/projects/project_routes.py @@ -1233,4 +1233,31 @@ async def project_dashboard( ProjectDashboard: The project dashboard details. """ - return await project_crud.get_dashboard_detail(project_id, db) \ No newline at end of file + return await project_crud.get_dashboard_detail(project_id, db) + + +@router.post("/check_crs") +async def check_coordinate_system(boundary: UploadFile = File(...)): + """Check coordinate system of uploaded file. + + Args: + boundary (UploadFile): File containing the boundary. + + Returns: + dict: Dictionary containing the result of the check. + """ + + boundary_type = boundary.content_type.split("/") + if len(boundary_type) != 2 or boundary_type[0] != "application" or boundary_type[1] != "geo+json": + raise HTTPException( + status_code=400, detail="Invalid boundary file. Must be GeoJSON." + ) + content = await boundary.read() + boundary = json.loads(content) + + # Validating Coordinate Reference System + if check_crs(boundary): + return {"message": "Valid boundary file"} + else: + return {"message":"Unsupported coordinate system, it is recommended to use a " + "GeoJSON file in WGS84(EPSG 4326) standard."} \ No newline at end of file From 8d79d028dbf0b1d414554c83f24af7bd34d90861 Mon Sep 17 00:00:00 2001 From: sujanadh Date: Tue, 26 Dec 2023 10:01:01 +0545 Subject: [PATCH 2/2] feat: added new api to check coordinate system --- src/backend/app/projects/project_routes.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/backend/app/projects/project_routes.py b/src/backend/app/projects/project_routes.py index d6d0789d22..cc4340d274 100644 --- a/src/backend/app/projects/project_routes.py +++ b/src/backend/app/projects/project_routes.py @@ -1256,8 +1256,9 @@ async def check_coordinate_system(boundary: UploadFile = File(...)): boundary = json.loads(content) # Validating Coordinate Reference System - if check_crs(boundary): + try: + check_crs(boundary) return {"message": "Valid boundary file"} - else: + except Exception as e: return {"message":"Unsupported coordinate system, it is recommended to use a " "GeoJSON file in WGS84(EPSG 4326) standard."} \ No newline at end of file