RegionCoverer with Polygon in Python

209 views
Skip to first unread message

Kuan Butts

unread,
Apr 20, 2020, 2:30:08 PM4/20/20
to s2geometry-io
Hello

Thanks in advance for any guidance that can be provided. I have a the coordinates of a Polygon and would like to identify the set of S2 cells that best represents it (a la what this tool provides: http://s2.sidewalklabs.com/regioncoverer/).

Right now, from the Py docs, there is guidance on how to get the S2 cells that cover a rectangle based on two LatLngs:

r = s2sphere.RegionCoverer()
p1 = s2sphere.LatLng.from_degrees(33, -122)
p2 = s2sphere.LatLng.from_degrees(33.1, -122.1)
cell_ids = r.get_covering(s2sphere.LatLngRect.from_point_pair(p1, p2))

I'd like to do something similar, but provide an array of coordinates instead, representing a Polygon and get the covering for that, from Py. Is that possible with current bindings?

Thanks again
Kuan

Jesse Rosenstock

unread,
Apr 20, 2020, 3:29:26 PM4/20/20
to s2geometry-io
On Monday, April 20, 2020 at 8:30:08 PM UTC+2, Kuan Butts wrote:
Thanks in advance for any guidance that can be provided. I have a the coordinates of a Polygon and would like to identify the set of S2 cells that best represents it (a la what this tool provides: http://s2.sidewalklabs.com/regioncoverer/).
[...] 
I'd like to do something similar, but provide an array of coordinates instead, representing a Polygon and get the covering for that, from Py. Is that possible with current bindings?

Kuan Butts

unread,
Apr 20, 2020, 11:00:48 PM4/20/20
to s2geometry-io
Thanks Jesse

This is embarrassing but I only just now realized that this repo (GH google/s2geometry) is different than S2Sphere from SWL (https://github.com/sidewalklabs/s2sphere).


Kuan Butts

unread,
Apr 20, 2020, 11:02:57 PM4/20/20
to s2geometry-io
* Different in that it only has part of the C library exposed in the SWL Py version vs using the Py extensions that the main S2Geom repo exposes w/ SWIG. Easier install though (via pip) so that's why I gravitated towards it at first.
Reply all
Reply to author
Forward
0 new messages