Skip to content
Open
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
25 changes: 25 additions & 0 deletions ohsome_quality_api/api/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
AttributeCompletenessKeyRequest,
IndicatorDataRequest,
IndicatorRequest,
LandCoverCompletenessRequest,
LandCoverThematicAccuracyRequest,
RoadsThematicAccuracyRequest,
)
Expand Down Expand Up @@ -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"],
Expand Down
21 changes: 21 additions & 0 deletions ohsome_quality_api/api/request_models.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
10 changes: 10 additions & 0 deletions tests/unittests/api/test_request_models.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
AttributeCompletenessKeyRequest,
BaseBpolys,
IndicatorRequest,
LandCoverCompletenessRequest,
LandCoverThematicAccuracyRequest,
RoadsThematicAccuracyRequest,
)
Expand Down Expand Up @@ -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")
Expand Down