pycontrails.core.polygon#
Algorithm support for grid to polygon conversion.
See also
pycontrails.MetDataArray.to_polygon_feature()
, pycontrails.MetDataArray.to_polygon_feature_collection()
Functions
|
Buffer and clean a contour. |
|
Determine the proper buffer size to use when converting to polygons. |
|
Compute a multipolygon from a 2d array. |
|
Convert a shapely multipolygon to a GeoJSON feature. |
- pycontrails.core.polygon.buffer_and_clean(contour, min_area, convex_hull, epsilon, precision, buffer, is_exterior)#
Buffer and clean a contour.
- Parameters:
contour (
npt.NDArray[np.float_]
) – Contour to buffer and clean. A 2d array of shape (n, 2) where n is the number of vertices in the contour.min_area (
float
) – Minimum area of the polygon. If the area of the buffered contour is less than this, return None.convex_hull (
bool
) – Whether to take the convex hull of the buffered contour.epsilon (
float
) – Epsilon value for polygon simplification. If 0, no simplification is performed.precision (
int | None
) – Precision of the output polygon. If None, no rounding is performed.buffer (
float
) – Buffer distance.is_exterior (
bool
, optional) – Whether the contour is an exterior contour. If True, the contour is buffered with a larger buffer distance. The polygon orientation is CCW iff this is True.
- Returns:
shapely.Polygon | None
– Buffered and cleaned polygon. If the area of the buffered contour is less thanmin_area
, return None.
- pycontrails.core.polygon.determine_buffer(longitude, latitude)#
Determine the proper buffer size to use when converting to polygons.
- pycontrails.core.polygon.find_multipolygon(arr, threshold, min_area, epsilon, interiors=True, convex_hull=False, longitude=None, latitude=None, precision=None)#
Compute a multipolygon from a 2d array.
- Parameters:
arr (
npt.NDArray[np.float_]
) – Array to convert to a multipolygon. The array will be converted to a binary array by comparing each element to threshold. This binary array is then passed intocv2.findContours()
to find the contours.threshold (
float
) – Threshold to use when converting arr to a binary array.min_area (
float
) – Minimum area of a polygon to be included in the output.epsilon (
float
) – Epsilon value to use when simplifying the polygons. Passed into shapely’sshapely.geometry.Polygon.simplify()
method.interiors (
bool
) – Whether to include interior polygons.convex_hull (
bool
) – Experimental. Whether to take the convex hull of each polygon.longitude, latitude (
npt.NDArray[np.float_]
, optional) – If provided, the coordinates values corresponding to the dimensions of arr. The contour coordinates will be converted to longitude-latitude values by indexing into this array. Defaults to None.precision (
int
, optional) – If provided, the precision to use when rounding the coordinates. Defaults to None.
- Returns:
shapely.MultiPolygon
– A multipolygon of the contours.
- pycontrails.core.polygon.multipolygon_to_geojson(multipolygon, altitude, properties=None)#
Convert a shapely multipolygon to a GeoJSON feature.
- Parameters:
- Returns:
dict[str
,Any]
– GeoJSON feature with geometry type “MultiPolygon”.