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

Add polygon rendering support based on spatialpandas extension arrays #826

Merged
merged 14 commits into from
Dec 11, 2019

Conversation

jonmmease
Copy link
Collaborator

@jonmmease jonmmease commented Nov 5, 2019

Overview

This PR supersedes #819, adding Polygon rendering support. Whereas #819 included extension arrays that were subclasses of the existing RaggedArray extension array, this PR relies on a family of geometry extensions arrays in the not-yet-published spatialpandas package. To try out this branch, you'll need holoviz/spatialpandas#2 from the spatialpandas repository as well.

ExtensionArray Design

After a lot of prototyping, I ended up having the spatialpandas extension arrays depend on pyarrow, but not fletcher. Fletcher works great, but I found there was a little bit of an impedance mismatch with this usecase. The main reason I think is that for the geometry extension arrays, pyarrow is basically an implementation detail and I want the individual elements to be wrapped in custom classes when they are accessed as scalars. I got pretty far down this road using FletcherArray subclasses, but I had trouble chasing down the edge cases needed to get the pandas extension array test suite passing.

This may be something worth unifying with fletcher in the future (and doing so wouldn't be a breaking change), but I think this is the best first stage given current timeline/constraints.

Examples

I've created a new example notebook for polygon/line/points rendering at https://anaconda.org/jonmmease/datashader_spatialpandas/notebook.

texas

world

world_outline

centroids

Also includes support for rendering points and lines from geometry
extension arrays.
@jonmmease jonmmease mentioned this pull request Nov 5, 2019
@jonmmease jonmmease closed this Nov 5, 2019
@jonmmease jonmmease reopened this Nov 5, 2019
Copy link
Member

@jbednar jbednar left a comment

Choose a reason for hiding this comment

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

Looks great! Feel free to merge it once spatialpandas is available for conda installation (e.g. on the pyviz channel).

@jbednar
Copy link
Member

jbednar commented Nov 5, 2019

For the attached notebook, can you add points examples somewhere, for the same data already shown as polygons and lines? From the source code it looks like points are supported, but I don't see an example of that anymore.

@jonmmease
Copy link
Collaborator Author

This PR is now based on spatialpandas 0.1.0rc1, which has been published to PyPI. Tests won't pass until spatialpandas is available on the pyviz channel.

@jonmmease
Copy link
Collaborator Author

spatialpandas 0.1.0 has been released on PyPI and the pyviz anaconda channel, and CI tests are now passing. PR is ready for final testing/consideration @jbednar @philippjfr

Copy link
Member

@jbednar jbednar left a comment

Choose a reason for hiding this comment

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

Looks great! Happy to merge when @philippjfr is done reviewing it.

datashader/core.py Outdated Show resolved Hide resolved
@philippjfr
Copy link
Member

One comment otherwise this looks good and works great.

# Conflicts:
#	datashader/tests/test_dask.py
#	datashader/tests/test_pandas.py
@jonmmease
Copy link
Collaborator Author

Thanks @philippjfr, I'm looking forward to seeing what you can do with this in HoloViews 🙂

Docstring and merge conflict fixed, so I think this is ready to merge after we push out the release with GPU support.

@philippjfr
Copy link
Member

I'll push my HoloViews implementation later today. There's some trickiness around nested holes and detecting CW vs. CCW that I haven't solved yet and which I may ask you about.

@philippjfr
Copy link
Member

So I haven't yet worked out whether this is a quirk of the data or an issue rasterizing, but in certain scenarios you can get weird artifacts when rendering polygons:

import geopandas as gpd
import datashader as ds
from spatialpandas import GeoDataFrame

world_gp = gpd.read_file(
    gpd.datasets.get_path('naturalearth_lowres')
)
world_gp = world_gp.sort_values('name').reset_index(drop=True)
world_gp = world_gp[['pop_est', 'continent', 'name', 'geometry']]
spdf = GeoDataFrame(world_gp)

cvs = ds.Canvas(plot_height=245,plot_width=215, x_range=(-600.2587977094785, 720.6321972454359),y_range=(-330.57983377255783, 306.5487454907058))
ds.transfer_functions.shade(cvs.polygons(spdf, 'geometry'))

download

@jonmmease
Copy link
Collaborator Author

thanks for creating the example, looks like a rendering bug to me, i’ll take a look.

@jbednar jbednar mentioned this pull request Dec 8, 2019
@jonmmease
Copy link
Collaborator Author

@philippjfr, ok I tracked down the problem and fixed it in 6a3c737.

world

This PR is good-to-go from my end now.

@jbednar jbednar merged commit 5f2b608 into master Dec 11, 2019
@jbednar
Copy link
Member

jbednar commented Dec 11, 2019

Beautiful, thanks!

@saulshanabrook
Copy link

Super excited about this work! Am I right in thinking this will end up showing up at some point in the hvplot method to pandas? Does that already work?

Or if not, is there a way to use this to create interactive geo viz?

@jbednar
Copy link
Member

jbednar commented Dec 14, 2019

Yes, that's the idea. First we need the HoloViews support to be merged (holoviz/holoviews#4120), then hvplot will need a trivial extension to support spatialpandas data types (holoviz/hvplot#389). Should come together soon!

@saulshanabrook
Copy link

@jbednar Yay! Thanks for the pointers to those PRs, ill follow them. Thanks again everyone who is helping make this happen. It's awesome to have tools like this you can use for climate change research and also for finding a new house :)

Screen Shot 2019-12-14 at 3 01 25 PM

@maximlt maximlt deleted the polygon_spatialpandas branch December 25, 2021 17:22
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.

4 participants