Replace `pygeos` imports
Opened this issue · 2 comments
Chapter 8 (points) includes imports from pygeos
:
from pygeos import minimum_rotated_rectangle, from_shapely, to_shapely
My sense is, since shapely
2.0, general recommendation is to rely on shapely
rather than pygeos
directly. Should we update this? One probably more for @ljwolf
Yes. Should be a straight swap to shapely!
One fewer dependency for the book would be great. Here is a proposed update for this.
Original
For the minimum rotated rectangle, we will use the minimum_rotated_rectangle
function from the pygeos
module, which constructs the minimum rotated rectangle for an input multi-point object. This means that we will need to collect our points together into a single multi-point object and then compute the rotated rectangle for that object.
from pygeos import minimum_rotated_rectangle, from_shapely, to_shapely
point_array = geopandas.points_from_xy(x=user.x, y=user.y)
min_rot_rect = minimum_rotated_rectangle(
from_shapely(
point_array.unary_union()
)
)
min_rot_rect = to_shapely(min_rot_rect)
Update
For the minimum rotated rectangle, we will use the minimum_rotated_rectangle
property from GeoPandas, which constructs the minimum rotated rectangle for an input multi-point object. This means that we will need to collect our points together into a single multi-point object and then compute the rotated rectangle for that object.
point_array = geopandas.points_from_xy(x=user.x, y=user.y)
min_rot_rect = point_array.unary_union().minimum_rotated_rectangle