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

Faster polygon construction using Shapely 2.0.0 #47

Merged
merged 4 commits into from
Jan 10, 2023
Merged

Faster polygon construction using Shapely 2.0.0 #47

merged 4 commits into from
Jan 10, 2023

Conversation

mx-moth
Copy link
Contributor

@mx-moth mx-moth commented Jan 10, 2023

Shapely 2 exposes a shapely.polygons function which can create large numbers of polygons directly from numpy arrays. This gives a dramatic performance improvement, varying by dataset type. For UGRID I have seen the time taken to construct the polygons halve, for large CF grids the time has dropped from ~6 seconds to ~0.1 second.

This makes #40 irrelevant. This was found when investigating caching strategies. The slow down was always in constructing the polygons not in calculating vertices, and polygons still have to be constructed when loading them from the cache.

Shapely 2.0.0 gains the `shapely.polygons` function which can create
a large number of polygons at speed. This is perfect for making dataset
geometries.
@mx-moth mx-moth self-assigned this Jan 10, 2023
Changes to Shapely 2.0.0 mean the arguments to `shapely.geometry.box`
can no longer be `decimal.Decimal`. They must be numpy-compatible scalar
number types.
This interface is drastically quicker than constructing polygons
one-by-one. This has reduced the time taken to construct the `gbr4`
polygons from ~6 seconds to ~0.1 seconds. Similar reductions apply to
other datasets also.
@mx-moth mx-moth merged commit 3d4c767 into main Jan 10, 2023
@mx-moth mx-moth deleted the shapely-2 branch January 10, 2023 03:39
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant