diff --git a/ohsome_quality_api/api/api.py b/ohsome_quality_api/api/api.py index bda809439..490947c35 100644 --- a/ohsome_quality_api/api/api.py +++ b/ohsome_quality_api/api/api.py @@ -33,6 +33,7 @@ AttributeCompletenessKeyRequest, IndicatorDataRequest, IndicatorRequest, + LandCoverCompletenessRequest, LandCoverThematicAccuracyRequest, RoadsThematicAccuracyRequest, ) @@ -313,6 +314,30 @@ async def post_land_cover_thematic_accuracy( return await _post_indicator(request, "land-cover-thematic-accuracy", parameters) +@app.post( + "/indicators/land-cover-completeness", + tags=["indicator"], + response_model=Union[IndicatorJSONResponse, IndicatorGeoJSONResponse], + responses={ + 200: { + "content": { + "application/json": { + "schema": {"$ref": "#/components/schemas/IndicatorJSONResponse"} + }, + "application/geo+json": { + "schema": {"$ref": "#/components/schemas/IndicatorGeoJSONResponse"} + }, + }, + }, + }, +) +async def post_land_cover_completeness( + request: Request, parameters: LandCoverCompletenessRequest +) -> Any: + """Request the Land Cover Completeness indicator for your area of interest.""" + return await _post_indicator(request, "land-cover-completeness", parameters) + + @app.post( "/indicators/roads-thematic-accuracy", tags=["indicator"], diff --git a/ohsome_quality_api/api/request_models.py b/ohsome_quality_api/api/request_models.py index bbb6821ae..7024bfe5e 100644 --- a/ohsome_quality_api/api/request_models.py +++ b/ohsome_quality_api/api/request_models.py @@ -302,6 +302,27 @@ def indicator(self) -> str: return "land-cover-thematic-accuracy" +class LandCoverCompletenessRequest(IndicatorRequest): + model_config = ConfigDict( + json_schema_extra={ + "examples": [ + # NOTE: json.dumps avoids that keys are ordered by pydantic + json.dumps( + { + "topic": "land-cover", + "bpolys": BPOLYS_EXAMPLE, + } + ), + ] + } + ) + + @computed_field + @property + def indicator(self) -> str: + return "land-cover-completeness" + + class RoadsThematicAccuracyRequest(IndicatorRequest): attribute: Literal["surface", "oneway", "lanes", "name", "width"] | None = Field( default=None, diff --git a/tests/unittests/api/test_request_models.py b/tests/unittests/api/test_request_models.py index a7def3259..43aa44381 100644 --- a/tests/unittests/api/test_request_models.py +++ b/tests/unittests/api/test_request_models.py @@ -9,6 +9,7 @@ AttributeCompletenessKeyRequest, BaseBpolys, IndicatorRequest, + LandCoverCompletenessRequest, LandCoverThematicAccuracyRequest, RoadsThematicAccuracyRequest, ) @@ -173,6 +174,15 @@ def test_land_cover_thematic_accuracy_request_corine_class(bpolys): ) +def test_land_cover_completeness_request(bpolys): + LandCoverCompletenessRequest(bpolys=bpolys, topic="land-cover") + + +def test_land_cover_completeness_request_invalid_topic(bpolys): + with pytest.raises(ValidationError): + LandCoverCompletenessRequest(bpolys=bpolys, topic="building-count") + + def test_roads_thematic_accuracy_request_all_attributes(bpolys): # attribute parameter is optional (default all attributes) RoadsThematicAccuracyRequest(bpolys=bpolys, topic="roads")