Discussion on improving grid functions #2640
Replies: 5 comments 1 reply
-
Two areas to maybe address before deciding on an approach: First is to decide what exactly are we giving someone when they ask for a rectangle? Is it the corners of a spherical rectangle like you'd see on the surface of the Earth? Or a planar rectangle on a 2D projection? Those points will differ more and more as you get further toward the poles. The former is more accurate and consistent, whereas the latter will "look nicer" on a map. I'm firmly team "spherical earth" - I'd want this to work as well in Sweden as it does in Kenya. Second is that the way we define the API seems odd. We have a bounding box, and then a cell width - which isn't guaranteed to be an exact multiple of the bbox edge, so we fudge that by re-centering which then leads to issues like #2013 . Would seem neater to choose between:
I can imagine use cases for both, so perhaps warrants splitting into two functions. |
Beta Was this translation helpful? Give feedback.
-
Here's my proposal. What do you think @twelch? As soon as possible roll back #2106. This would close #2638 but reopen #2079. Update the docs for the grid functions to warn the bounding box must span less than 180 degrees latitude. There might still be a simple enough fix for 2079? Suspect we'd need to somehow infer the winding of the bbox to figure out the user wants us to take the "long way round". Maybe the original reporter @stollc could weigh in? Then for v8 as it would be a breaking change, we simplify the behaviour of the grid functions so that the user provides either:
Overall we aim to have Turf do a couple of basic functions predictably and correctly, and push any remaining calculations and complexity back onto the user. Trying to cater to all potential use cases (rotations, centering, subgrids) is only going to lead to us doing none of them well. |
Beta Was this translation helpful? Give feedback.
-
Hello, my two cents about this topic 😄 About the "perfect fit"I feel like there can be situations where the user wants a perfect fit, and other where he wants a perfect size of cells. So ideally, the functions should allow for both (for example, if provided parameters But if we want to keep it simple, and only have one "way of working", I would keep the current one (define cells dimensions) because it is easier to do And for the "cellsWidth" scenario, I think it is important to provide a Note that for hexa grid, perfect fit to a bounding box will be hard to achieve 😛 About the degrees vs km/milesI indeed feel like most of the time what the user cares about is to have a square that looks like a square in real life. Note that we could imagine a grid where the height of the cells differ on each row so if the grid is applied on the full earth each cell is the same dimension in kilometers. But I feel like it is a lot more complex, especially for hexa grids, and I question myself if it could not be an issue for the devs to not have celles that are placed on a multiple of their dimension. On the other hand, it is because it is a lot more complex that it is interesting to have the feature out of the box. Perhaps it could be driven by a parameter? Aligning differents gridsThis would be easily solved with a "perfect fit" solution (either by pre-computing the cellWidth or with a parameter). But note that with a hexa grid I do not think you can have "sub grids" anyway... Rotating gridI do not think it should be part of the grid component considering we already have About "what is a rectangle"That is indeed a good question ! :D But I sincerely think we can keep it "simple", especially for the squarish grids. For me, the rectangle" should be equal to its bounding box, which I believe means a Indeed, I think that one of the very useful usage of the grids (at least the square / rectangular ones) is to partition the plan in smaller pieces, and the ability of defining if something is inside or outside of it by simply comparing the x1,y1, x2,y2 coordinates is extremely precious. About "bbox vs start point"My personal use case (which I imagine is not unusual) is that I have a polygon (in my case a city boundaries) that I want to divide in a grid of 500 meters cells. So my bbox is simply the bbox of my polygon, the width is 0.5km (in my specific scenario I do not really care about the exact size of the cell so I could technically do a I feel like it is less usual to have a "starting point" and a "number of cells" with a "cells width" unrelated to any other polygon. So I would prefer one of the solution described in the "About the perfect fit" section above |
Beta Was this translation helpful? Give feedback.
-
Thanks for that @Pitouli. Taking your comments and @twelch's here's what I suggest we do:
For example, this is what I believe a grid masked by a polygon should look like: And this is what a grid overlapped with the same polygon should give you: Should we drop the mask parameter too, and just get the user to use turf-mask? All this would be a breaking change. Thoughts? |
Beta Was this translation helpful? Give feedback.
-
My point of view would be at least one side of the grid lines up with the bbox, as opposed to neither. This behaviour seems unexpected to many people. An example. Another. One more.
I would say yes, I agree with that. Except because the grid has now been re-centered by Turf the user has to reset their understanding of where the grid lines run. Subgrids might not be that significant a use case to argue anyway. I'm more pushing for Turf to not recenter based on the level of surprise many users have when it happens.
Yeah, we'll almost certainly run into problems with floating point remainders.
So, if the next grid cell would be super narrow we make the current grid cell a fraction bigger? I don't actually mind that. I imagine the threshold should be quite small though. Less than 1% of the cell width maybe? Smaller even?
Understood. These are the things we need to coordinate at a higher level to make sure interdependent functionality works correctly. |
Beta Was this translation helpful? Give feedback.
-
Capturing some grid function related things I've been researching in one place for discussion and just awareness.
I noticed there's been some changes in behavior for at least the squareGrid/rectangleGrid functions in 2021 where something seems off/incorrect, or just don't do quite what the docs imply (for example that specifying units for cellSide will return cells that are equidistant in those units).
#2638
#2136
#2203
In addition, across all issues open/closed I see a call for the grid functions (hexGrid, squareGrid, rectangleGrid, triangleGrid, pointGrid?), to construct grids that meet different constraints. For example:
Possible solutions include:
methods
within each function rather than a one-size-fits-all approach that doesn't meet most needs. Or if the different options needed are too varied, create multiple functions.Beta Was this translation helpful? Give feedback.
All reactions