-
Notifications
You must be signed in to change notification settings - Fork 6
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Ensure polygons are inside -180/180 range before making stac request #734
Merged
Merged
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains 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
This file contains 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
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,243 @@ | ||
import { Feature, MultiPolygon, Polygon } from 'geojson'; | ||
import { fixAntimeridian } from './antimeridian'; | ||
|
||
describe('Antimeridian', () => { | ||
it('Should move a feature in the first map east (180/540) to the -180/180 range', () => { | ||
const feature: Feature<Polygon> = { | ||
type: 'Feature', | ||
properties: {}, | ||
geometry: { | ||
coordinates: [ | ||
[ | ||
[190, 20], | ||
[190, -20], | ||
[200, -20], | ||
[200, 20], | ||
[190, 20] | ||
] | ||
], | ||
type: 'Polygon' | ||
} | ||
}; | ||
|
||
const expected: Feature<MultiPolygon> = { | ||
type: 'Feature', | ||
properties: {}, | ||
geometry: { | ||
coordinates: [ | ||
[ | ||
[ | ||
[-170, -20], | ||
[-160, -20], | ||
[-160, 20], | ||
[-170, 20], | ||
[-170, -20] | ||
] | ||
] | ||
], | ||
type: 'MultiPolygon' | ||
} | ||
}; | ||
|
||
const result = fixAntimeridian(feature); | ||
expect(result).toEqual(expected); | ||
}); | ||
|
||
it('Should split a feature crossing the 540 antimeridian into 2 that fall within the -180/180 range', () => { | ||
const feature: Feature<Polygon> = { | ||
type: 'Feature', | ||
properties: {}, | ||
geometry: { | ||
coordinates: [ | ||
[ | ||
[500, 20], | ||
[500, -20], | ||
[580, -20], | ||
[580, 20], | ||
[500, 20] | ||
] | ||
], | ||
type: 'Polygon' | ||
} | ||
}; | ||
|
||
const expected: Feature<MultiPolygon> = { | ||
type: 'Feature', | ||
properties: {}, | ||
geometry: { | ||
coordinates: [ | ||
[ | ||
[ | ||
[-180, -20], | ||
[-140, -20], | ||
[-140, 20], | ||
[-180, 20], | ||
[-180, -20] | ||
] | ||
], | ||
[ | ||
[ | ||
[140, -20], | ||
[180, -20], | ||
[180, 20], | ||
[140, 20], | ||
[140, -20] | ||
] | ||
] | ||
], | ||
type: 'MultiPolygon' | ||
} | ||
}; | ||
|
||
const result = fixAntimeridian(feature); | ||
expect(result).toEqual(expected); | ||
}); | ||
|
||
it('Should calculate the resulting feature in the -180/180 range when the input spans several maps', () => { | ||
const feature: Feature<Polygon> = { | ||
type: 'Feature', | ||
properties: {}, | ||
geometry: { | ||
coordinates: [ | ||
[ | ||
[-360, 10], | ||
[500, 10], | ||
[500, -10], | ||
[-360, -10], | ||
[-360, 10] | ||
] | ||
], | ||
type: 'Polygon' | ||
} | ||
}; | ||
|
||
const expected: Feature<MultiPolygon> = { | ||
type: 'Feature', | ||
properties: {}, | ||
geometry: { | ||
coordinates: [ | ||
[ | ||
[ | ||
[-180, -10], | ||
[180, -10], | ||
[180, 10], | ||
[-180, 10], | ||
[-180, -10] | ||
] | ||
] | ||
], | ||
type: 'MultiPolygon' | ||
} | ||
}; | ||
|
||
const result = fixAntimeridian(feature); | ||
expect(result).toEqual(expected); | ||
}); | ||
|
||
it('Should be able to process multipolygons, correctly resolving each polygon to the -180/180 range', () => { | ||
const feature: Feature<MultiPolygon> = { | ||
type: 'Feature', | ||
properties: {}, | ||
geometry: { | ||
coordinates: [ | ||
[ | ||
[ | ||
[170, 30], | ||
[190, 30], | ||
[190, 20], | ||
[170, 20], | ||
[170, 30] | ||
] | ||
], | ||
[ | ||
[ | ||
[-530, 10], | ||
[-530, 0], | ||
[-550, 0], | ||
[-550, 10], | ||
[-530, 10] | ||
] | ||
], | ||
[ | ||
[ | ||
[530, -10], | ||
[530, -20], | ||
[550, -20], | ||
[550, -10], | ||
[530, -10] | ||
] | ||
] | ||
], | ||
|
||
type: 'MultiPolygon' | ||
} | ||
}; | ||
|
||
const expected: Feature<MultiPolygon> = { | ||
type: 'Feature', | ||
properties: {}, | ||
geometry: { | ||
coordinates: [ | ||
[ | ||
[ | ||
[-180, -20], | ||
[-170, -20], | ||
[-170, -10], | ||
[-180, -10], | ||
[-180, -20] | ||
] | ||
], | ||
[ | ||
[ | ||
[-180, 0], | ||
[-170, 0], | ||
[-170, 10], | ||
[-180, 10], | ||
[-180, 0] | ||
] | ||
], | ||
[ | ||
[ | ||
[-180, 20], | ||
[-170, 20], | ||
[-170, 30], | ||
[-180, 30], | ||
[-180, 20] | ||
] | ||
], | ||
[ | ||
[ | ||
[170, -20], | ||
[180, -20], | ||
[180, -10], | ||
[170, -10], | ||
[170, -20] | ||
] | ||
], | ||
[ | ||
[ | ||
[170, 0], | ||
[180, 0], | ||
[180, 10], | ||
[170, 10], | ||
[170, 0] | ||
] | ||
], | ||
[ | ||
[ | ||
[170, 20], | ||
[180, 20], | ||
[180, 30], | ||
[170, 30], | ||
[170, 20] | ||
] | ||
] | ||
], | ||
type: 'MultiPolygon' | ||
} | ||
}; | ||
|
||
const result = fixAntimeridian(feature); | ||
expect(result).toEqual(expected); | ||
}); | ||
}); |
Oops, something went wrong.
Oops, something went wrong.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you point me where the order of the coordinates changes? I can't wrap my head around it.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That was also strange to me, but for some reason the turf.js function (intersect and difference), reorder the coordinates when cutting the polygons.