question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Add polygon support

See original GitHub issue

Add support for Canvas.polygon. Something like:

endangered_agg = cvs.polygon(df, 'my_polygon_field', how='sum', field='endangered_species_list_score')

Issue Analytics

  • State:closed
  • Created 7 years ago
  • Comments:10 (4 by maintainers)

github_iconTop GitHub Comments

2reactions
jbednarcommented, Dec 11, 2019

Now in master.

1reaction
jonmmeasecommented, Aug 21, 2019

I think I have a pretty clear understanding of what this might look like now that I’ve finished the following PRs:

Here’s what I’m thinking…

Polygon representation

I think the easiest thing to do here is to represent a polygon set as a pair of arrays, one for each the x and y coordinate. nan values are then used to indicate the end of one polygon and the start of the next.

Polygon fill rendering

In the quadmesh PR (https://github.com/pyviz/datashader/pull/779) I implemented filling using the “crossing number” point-in-polygon test (http://geomalgorithms.com/a03-_inclusion.html). If we use this same algorithm for these sets of polygons then we naturally get the following behavior.

  • The first polygon is filled in if it’s the only one
  • The second (and third, forth, …) polygon acts as a hole if it is enclosed in the first polygon, or it is filled in as a separate polygon if it is outside of the first polygon.

Polygon API

I propose that the Canvas.polygon method have the same API as Canvas.line. We don’t need to cover the full API right away, but in principle every combination of the axis and column arguments supported by Canvas.line could also be supported by Canvas.poly. Here are the two API uses that I expect to be most common:

Variable sized polygons, one per row. In this case, the x and y coordinates would be stored as RaggedArray columns in the DataFrame.

canvas.polygon(df, 'x', 'y', axis=1)

A collection of fixed-size polygons. This would be useful for displaying a large collection of polygons that all have the same number of vertices. In this case, the data frame would have a column for each x and y coordinate. For example, rendering a collection of pentagons would look something like this

canvas.polygon(df, ['x0', 'x1', 'x2', 'x3', 'x4'], ['y0', 'y1', 'y2', 'y3', 'y4'], axis=1)

Polygon outlines

A nice consequence of using this polygon representation and this API is that we get polygon outline rendering for free. Just change canvas.polygon to canvas.line. The line method already uses nan values to separate lines, and as long as the polygons are closed, the line method would automatically be able to draw the polygon outlines.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Add Polygon Network
Navigate to polygonscan.com · Scroll down to the bottom of the page and click on the button Add Polygon Network.
Read more >
How to Connect MetaMask to the Polygon Network - CoinDesk
1. Open and log in to your MetaMask wallet · 2. From the account options, which is a circle icon, go to “Settings.”...
Read more >
Setting up Metamask for Polygon (Matic Network) - Medium
Connecting MetaMask to Polygon. Switch the connected blockchain by clicking on the tab saying Main Ethereum Network, we need to add Polygon.
Read more >
How to Add Polygon to MetaMask? - Binance Academy
1. Adding Polygon support to your wallet involves adding some network details to the extension. First, open MetaMask and click the network ...
Read more >
Adding Polygon To Supported Wallets - The Sandbox - GitBook
Adding Polygon To Supported Wallets · Open your Metamask extension and click on your network dropdown · Select “Add a network” · Type...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found