mirror of
https://github.com/qurator-spk/eynollah.git
synced 2025-09-06 15:59:57 +02:00
polygon2contour: avoid overflow
This commit is contained in:
parent
fd6a6495a2
commit
698f38e461
1 changed files with 2 additions and 1 deletions
|
@ -353,7 +353,8 @@ def contour2polygon(contour: Union[np.ndarray, Sequence[Sequence[Sequence[Number
|
||||||
return make_valid(polygon)
|
return make_valid(polygon)
|
||||||
|
|
||||||
def polygon2contour(polygon: Polygon) -> np.ndarray:
|
def polygon2contour(polygon: Polygon) -> np.ndarray:
|
||||||
return np.array(polygon.exterior.coords[:-1], dtype=np.uint)[:, np.newaxis]
|
polygon = np.array(polygon.exterior.coords[:-1], dtype=np.int)
|
||||||
|
return np.maximum(0, polygon).astype(np.uint)[:, np.newaxis]
|
||||||
|
|
||||||
def make_valid(polygon: Polygon) -> Polygon:
|
def make_valid(polygon: Polygon) -> Polygon:
|
||||||
"""Ensures shapely.geometry.Polygon object is valid by repeated rearrangement/simplification/enlargement."""
|
"""Ensures shapely.geometry.Polygon object is valid by repeated rearrangement/simplification/enlargement."""
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue