Fix for rectangle and square grid dimensions#2106
Merged
Conversation
Closed
Member
Author
|
Alternatively I need to look into how calculate a harversine distance going the long way around (when the bbox is >180), that seems achievable, although a bit fiddlier |
mfedderly
reviewed
Jun 21, 2021
Collaborator
mfedderly
left a comment
There was a problem hiding this comment.
It looks like this broke the tests in @turf/square-grid, they probably just need to be re-updated. Github also isn't letting me do the rich diff view for these geojsons, but I'm assuming you looked at the output and think its better?
Member
Author
|
I've checked the results of the proposed PR against QGIS and we now generate almost the exact same results. |
mfedderly
approved these changes
Aug 5, 2021
Collaborator
mfedderly
left a comment
There was a problem hiding this comment.
This looks great to me
4 tasks
2 tasks
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
So in digging into #2079 I found that we using the haversine distance formula for calculating how big to make the grid cells.
Where this falls down is where you bbox if > 180 degrees because it then finds the shortest distance, and the wider your bbox of interest the worse the effects would be.
Swapping to a flat earth earth calc we do something like
There doesn't seem to be an easy way to hack our distance calc to produce something similar (at least in my initial play) so adjusting the approach seems reasonable and gives more expected results when generating large grids (eg see https://github.com/Turfjs/turf/blob/master/packages/turf-rectangle-grid/test/out/big-bbox-500x100-miles.geojson)
Resolves #2079
Resolves #1948
Resolves #1598
The same lines of code possibly need to be ported to point-grid and triangle-grid. See #1886