Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Replace pygeos imports #315

Open
darribas opened this issue Dec 10, 2023 · 2 comments · May be fixed by #318
Open

Replace pygeos imports #315

darribas opened this issue Dec 10, 2023 · 2 comments · May be fixed by #318
Labels
keepup Changes to keep up with the evolution of the python stack

Comments

@darribas
Copy link
Member

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

@darribas darribas added the keepup Changes to keep up with the evolution of the python stack label Dec 10, 2023
@ljwolf
Copy link
Member

ljwolf commented Dec 10, 2023

Yes. Should be a straight swap to shapely!

@dfolch
Copy link

dfolch commented Jan 4, 2024

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

darribas added a commit to darribas/geographic-data-science that referenced this issue Jan 5, 2024
@darribas darribas linked a pull request Jan 5, 2024 that will close this issue
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
keepup Changes to keep up with the evolution of the python stack
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants