New parameter for Grid Generators + Modify behavior with masking #2822
Replies: 1 comment 3 replies
-
Thanks for doing this work @Pitouli. Appreciate the level of detail. I think I understand where you're going with cover vs contain. Seems like a worthwhile addition.
Would you mind putting together a quick example that shows this? A sandbox example, or even just a screenshot? I'm having some trouble visualising it.
The grid* packages are probably due for a breaking shakeup soon anyway. More info here, though it's likely the options and behaviour are going to change.
Let's discuss it a bit more to come up with a plan. Taking the above into account, would you be interested in fixing the basic behaviour of grid* functions first, and then looking in to your suggestion? It might be the best way to make sure you don't have to do the cover/contain work twice. If you don't that's fine though.
I would avoid using
I'm not the biggest fan of adding temporary legacy options to maintain backward behaviour. It complicates the interface, and ultimately you need to make a breaking change anyway to retire the legacy flag. Would much rather Turf decide where it wants to end up, and then waiting to make a breaking change at the appropriate time without holding up other development. Regardless of which approach we take, the project needs to find a way to track and manage breaking changes. Your idea might be an opportunity to try some different techniques. |
Beta Was this translation helpful? Give feedback.
-
Hello,
When you generate a grid, you provide a bounding box, a dimension for the cells, and an optional mask.
Today, the grid is always CONTAINED inside the bounding box.
I would like to add an optional "size" option that could be either "contain" (default) or "cover", so in the second case the grid COVERS the bounding box.
Additionally, when you provide a mask, the cells that intersect with it are kept, which means that the grids COVERS the mask.
This create a weird behavior when you define your bbox from your mask: your mask becomes partially covered with cells (near the bounding box, cells are missing, elsewhere they are present)
I would like to align the behavior such as if the user as provide the "size=cover" option we keep the cells that intersect with the mask (like today) but if he provide the "size=contain" option then we keep only the cells contained within the mask.
Of course, if we want to avoid breaking change (at least while we are in v7) in order to release these features in the next minor update without breaking anything, I can define the size options with "cover", "contain", and "legacy" (or "mixed" ?) and use the third one as default.
I made a gist to show the three behaviors and the update I propose:
https://gist.github.com/Pitouli/c6cfffde0a2d8c0f8d220420f93104be
You can execute the code here to see it in your browser: https://turf-sandbox.netlify.app/
By having a purely "contain grid" and a purely "cover grid", it allows this interesting scenario: imagine you have 100k points and you need to know if the belongs to an area with a detailed boundary, you can create those two grids to eliminate very quickly the points that are clearly inside the area and those that are clearly outside, and you finally only have to apply the precise algorithm for the few remaining points.
What do you think? Should I proceed with PRs? Do you have better ideas for naming of the options and its values? Should I keep a "legacy" option?
Beta Was this translation helpful? Give feedback.
All reactions