google / s2geometry

Computational geometry and spatial indexing on the sphere
http://s2geometry.io/
Apache License 2.0
2.3k stars 303 forks source link

S2RegionIterator #125

Open r-barnes opened 4 years ago

r-barnes commented 4 years ago

I have a need to iterate over every cell within a region using GetInteriorCovering and GetCovering. I don't need the minimal cell set.

Using the existing GetInteriorCovering and GetCovering functions doesn't work because they calculate and store all of the cells. In my use case, this requires gigabytes of memory and leads to a crash. As an alternative, I've altered these functions to take a functor/lambda as an argument which performs the needed processing. The result is fast and has limited memory requirements.

I wonder if it is worth trying to upstream this?

jmr commented 4 years ago

It sounds like you're setting min_level = max_level or otherwise forcing a lot of cells to be generated, which is not the way it's intended to be used. What's the higher level problem you're trying to solve?

r-barnes commented 4 years ago

Ultimately, I want to the set of uint64 cell ranges at a given level which cover a polygon, but at high resolution.

To get that, I'm using max_level=24 or greater over very large areas and then merging sequential ranges.

jmr commented 4 years ago

But why are you trying to do this? S2RegionCoverer is designed so you work with a small number of cells at different levels.