8000 ENH: geometry agnostic Voronoi based on shapely by martinfleis · Pull Request #678 · pysal/libpysal · GitHub
[go: up one dir, main page]

Skip to content

ENH: geometry agnostic Voronoi based on shapely - #678

Merged
ljwolf merged 14 commits into
pysal:mainfrom
martinfleis:voronoi
Mar 1, 2024
Merged

ljwolf merged 14 commits into
pysal:mainfrom
martinfleis:voronoi

Conversation

@martinfleis
Copy link
Copy Markdown
Member

This pushes upstream code I have been refactoring for momepy. It is an implementation of Voronoi tessellation that works not only with points but also lines and polygons by discretising their boundaries into a set of points and dissolving the result back.

It also does not use scipy but shapely and avoids unnecessary bottlenecks when clipping the result to pre-defined limit.

It makes sense to me that it lives in cg rather than in momepy, where I'll just wrap it and add sensible default values that work for building footprints.

It is a bit different than existing voronoi_frames so I am not sure what is the best way forward here... I can try to mimic the API and eventually replace the scipy version with this one. Not sure what is the best way forward.

@codecov
codecov Bot commented Jan 20, 2024 •
Copy link
Copy Markdown

Codecov Report

Attention: 8 lines in your changes are missing coverage. Please review.

Comparison is base (65379ef) 85.0% compared to head (6c2b321) 85.0%.
Report is 1 commits behind head on main.

Additional details and impacted files

Impacted file tree graph

@@           Coverage Diff           @@
##            main    #678     +/-   ##
=======================================
- Coverage   85.0%   85.0%   -0.1%     
=======================================
  Files        141     141             
  Lines      15061   15187    +126     
=======================================
+ Hits       12809   12907     +98     
- Misses      2252    2280     +28     
Files Coverage Δ
libpysal/cg/tests/test_voronoi.py 100.0% <100.0%> (ø)
libpysal/graph/_triangulation.py 97.9% <100.0%> (ø)
libpysal/graph/tests/test_triangulation.py 98.8% <100.0%> (ø)
libpysal/cg/voronoi.py 72.9% <94.6%> (-15.7%) ⬇️
libpysal/weights/contiguity.py 78.6% <20.0%> (ø)

... and 1 file with indirect coverage changes

Comment thread libpysal/cg/voronoi.py
Comment on lines +413 to +415
ids_objects, ids_polygons = polygons.sindex.query(
objects, predicate="intersects"
)
Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

With shapely/shapely#1968 we may be able to avoid sindex query, though given it is mentioned that the ordered Voronoi can be up to 50% slower, I am not sure if it will be worth here. Need to test it.

@ljwolf
ljwolf commented Jan 26, 2024
Copy link
Copy Markdown
Member

I think this is great. I would just drop this in directly, and write a wrapper to intercept the old arguments and warn about the new argument names next release, with voronoi_frames() being changed fully over within 2 releases.

@martinfleis
Copy link
Copy Markdown
Member Author

I have merged this with voronoi_frames including some transition period. There are very minor differences in the output:

  • with clip=False, shapely defaults to a rectangle going significantly beyond the extent of original points but still way smaller that what libpysal is doing at the moment. See the comparison:

Screenshot 2024-02-01 at 16 54 31

I can try to expand that but I don't think it is worth it very much, so I'd just say this is a price to pay.

  • the polygons may have slightly different coordinates due to me fixing the geometry precision. So if there are some downstream tests checking exact geometries, those may fail.

Still need to update docstring and add tests.

@martinfleis
Copy link
Copy Markdown
Member Author

CI failing due to some deep dependency in GDAL causing segfaults... solution in progress elsewhere.

@martinfleis
Copy link
Copy Markdown
Member Author

The only remaining failures are caused by a geopandas regression on main geopandas/geopandas#3178.

Ready for review!

8000

@martinfleis
martinfleis marked this pull request as ready for review February 6, 2024 22:57
@jGaboardi jGaboardi left a comment
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great stuff @martinfleis

Comment thread libpysal/cg/voronoi.py Resolved
Comment thread libpysal/cg/voronoi.py Resolved
@ljwolf
ljwolf commented Mar 1, 2024
Copy link
Copy Markdown
Member

The test failure looks like geopandas#3180, which should resolve once that lands in geopandas. So, given that the rest of the tests pass, I will merge this now!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants

0