pointpats.minimum_rotated_rectangle¶
- pointpats.minimum_rotated_rectangle(points, return_angle=False)[source]¶
- pointpats.minimum_rotated_rectangle(points: ndarray, return_angle: bool = False) ndarray[tuple[Any, ...], dtype[float64]] | tuple[ndarray[tuple[Any, ...], dtype[float64]], float]
- pointpats.minimum_rotated_rectangle(points: GeoPandasBase, return_angle: bool = False) Polygon | tuple[Polygon, float]
Compute the minimum rotated rectangle for a point array.
This is the smallest enclosing rectangle (possibly rotated) for the input point set. It is computed using Shapely.
- Parameters:
- pointsarraylike
array representing a point pattern
- return_anglebool
whether to return the angle (in degrees) of the angle between the horizontal axis of the rectanle and the first side (i.e. length).
- Returns:
- rectangle | tuple(rectangle, angle)
Examples
>>> import numpy as np >>> import geopandas as gpd
Create an array of point coordinates.
>>> coords = np.array( ... [ ... [66.22, 32.54], ... [22.52, 22.39], ... [31.01, 81.21], ... [9.47, 31.02], ... [30.78, 60.10], ... [75.21, 58.93], ... [79.26, 7.68], ... [8.23, 39.93], ... [98.73, 77.17], ... [89.78, 42.53], ... [65.19, 92.08], ... [54.46, 8.48], ... ] ... )
Passing an array of coordinates returns an array capturing the corners.
>>> minimum_rotated_rectangle(coords) array([[ 75.5990843 , -0.72615725], [ 4.08727852, 30.41752523], [ 36.40164577, 104.61744544], [107.91345156, 73.47376296]])
>>> minimum_rotated_rectangle(coords, return_angle=True) (array([[ 75.5990843 , -0.72615725], [ 4.08727852, 30.41752523], [ 36.40164577, 104.61744544], [107.91345156, 73.47376296]]), 66.466678613503)
Passing a GeoPandas object returns a shapely geometry.
>>> geoms = gpd.GeoSeries.from_xy(*coords.T) >>> minimum_rotated_rectangle(geoms) <POLYGON ((107.913 73.474, 36.402 104.617, 4.087 30.418, 75.599 -0.726, 107....>
>>> minimum_rotated_rectangle(geoms, return_angle=True) (<POLYGON ((107.913 73.474, 36.402 104.617, 4.087 30.418, 75.599 -0.726, 107....>, 66.466678613503)