Skip to content

Commit

Permalink
return error when negative buffering results in empty geometry #164
Browse files Browse the repository at this point in the history
  • Loading branch information
bossie committed Feb 3, 2023
1 parent 2552290 commit 9468bdd
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 0 deletions.
8 changes: 8 additions & 0 deletions openeo_driver/ProcessGraphDeserializer.py
Original file line number Diff line number Diff line change
Expand Up @@ -627,6 +627,14 @@ def vector_buffer(args: Dict, env: EvalEnv) -> dict:
epsg_utmzone = auto_utm_epsg_for_geometry(geoms.geometry[0])

poly_buff_latlon = geoms.to_crs(epsg_utmzone).buffer(distance, resolution=buffer_resolution).to_crs(output_crs)

# TODO: give more context as to which geometries ended up empty?
if poly_buff_latlon.is_empty.any():
raise ProcessParameterInvalidException(
parameter="geometry", process="vector_buffer",
reason=f"Buffering with distance {distance} {unit} resulted in empty geometries"
)

return mapping(poly_buff_latlon[0]) if len(poly_buff_latlon) == 1 else mapping(poly_buff_latlon)


Expand Down
40 changes: 40 additions & 0 deletions tests/test_views_execute.py
Original file line number Diff line number Diff line change
Expand Up @@ -3124,3 +3124,43 @@ def test_to_vector_cube(api100, geojson, expected):
"type": "FeatureCollection",
"features": expected,
})


def test_vector_buffer_returns_error_on_empty_result_geometry(api):
geojson = {
"type": "FeatureCollection",
"features": [{
"id": "52",
"type": "Feature",
"geometry": {
"type": "Polygon",
"coordinates": [[[5.17540782, 51.2721762], [5.17541833, 51.27226422], [5.17332007, 51.27209092],
[5.17331899, 51.27206998], [5.17331584, 51.27200861], [5.17540782, 51.2721762]]]
}
}, {
"id": "53",
"type": "Feature",
"geometry": {
"type": "Polygon",
"coordinates": [[[5.21184352, 51.16855893], [5.21189095, 51.16861253], [5.21162038, 51.16887065],
[5.21141722, 51.16910133], [5.21117999, 51.16902886], [5.21103991, 51.16899166],
[5.21143081, 51.16848752], [5.21155978, 51.16848455], [5.21184352, 51.16855893]]]
}
}]
}

resp = api.result({
'vectorbuffer1': {
'process_id': 'vector_buffer',
'arguments': {
'geometry': geojson,
'distance': -10,
'unit': 'meter'
},
'result': True
}
})

resp.assert_error(400, "ProcessParameterInvalid",
message="The value passed for parameter 'geometry' in process 'vector_buffer' is invalid:"
" Buffering with distance -10 meter resulted in empty geometries")

0 comments on commit 9468bdd

Please sign in to comment.