-
Couldn't load subscription status.
- Fork 30
add spatial intervals validation #178
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
Merged
Merged
Changes from 7 commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
ddd3df4
add spatial intervals validation
vincentsarago 8dadc6f
sketch
vincentsarago 49527c2
Update tests/test_models.py
vincentsarago e29593d
Update stac_pydantic/collection.py
vincentsarago 128226e
Update stac_pydantic/collection.py
vincentsarago d11ea0e
Update stac_pydantic/collection.py
vincentsarago 5b474b5
update
vincentsarago e53e32a
improve comments
vincentsarago 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 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
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
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
|
|
@@ -11,6 +11,7 @@ | |||||
| Provider, | ||||||
| StacBaseModel, | ||||||
| UtcDatetime, | ||||||
| validate_bbox, | ||||||
| ) | ||||||
|
|
||||||
| if TYPE_CHECKING: | ||||||
|
|
@@ -21,6 +22,90 @@ | |||||
| TInterval = conlist(StartEndTime, min_length=1) | ||||||
|
|
||||||
|
|
||||||
| def validate_bbox_interval(v: List[BBox]) -> List[BBox]: # noqa: C901 | ||||||
| ivalues = iter(v) | ||||||
|
|
||||||
| # The first time interval always describes the overall spatial extent of the data. | ||||||
| overall_bbox = next(ivalues, None) | ||||||
| if not overall_bbox: | ||||||
| return v | ||||||
|
|
||||||
| assert validate_bbox(overall_bbox) | ||||||
|
|
||||||
| if len(overall_bbox) == 4: | ||||||
| xmin, ymin, xmax, ymax = overall_bbox | ||||||
| else: | ||||||
| xmin, ymin, _, xmax, ymax, _ = overall_bbox | ||||||
|
|
||||||
| crossing_antimeridian = xmin > xmax | ||||||
| for bbox in ivalues: | ||||||
| error_msg = ValueError( | ||||||
| f"`BBOX` {bbox} not fully contained in `Overall BBOX` {overall_bbox}" | ||||||
| ) | ||||||
| _ = validate_bbox(bbox) | ||||||
|
|
||||||
| if len(bbox) == 4: | ||||||
| xmin_sub, ymin_sub, xmax_sub, ymax_sub = bbox | ||||||
| else: | ||||||
| xmin_sub, ymin_sub, _, xmax_sub, ymax_sub, _ = bbox | ||||||
|
|
||||||
| if not ((ymin_sub >= ymin) and (ymax_sub <= ymax)): | ||||||
| raise error_msg | ||||||
|
|
||||||
| sub_crossing_antimeridian = xmin_sub > xmax_sub | ||||||
| if not crossing_antimeridian and sub_crossing_antimeridian: | ||||||
| raise error_msg | ||||||
|
|
||||||
| elif crossing_antimeridian: | ||||||
| # Antimeridian | ||||||
| # + 180 │ - 180 0 | ||||||
| # [176,1,179,3] │ │ | ||||||
| # │ │ │ | ||||||
| # │ │ │ | ||||||
| # │ │ │ [-178,1,-176,3] | ||||||
| # │ ┌─────────────────────────────────────────┐ │ │ | ||||||
| # │ │ │ │ │ │ | ||||||
| # │ │ ┌──────┐ │ ┌─────────┐ │ │ │ | ||||||
| # └──│──► 2 │ │ │ 1 │ │ │ │ | ||||||
| # │ │ │ │ │ │◄────│─────┼───────────┘ | ||||||
| # │ └──────┘ │ └─────────┘ │ │ | ||||||
| # │ │ │ │ 0 | ||||||
| # ────────────│────────────────┼────────────────────────│─────┼────────── | ||||||
| # │ │ │ │ | ||||||
| # │ ┌──────────────┐ │ │ | ||||||
| # │ │ │ │ │ │ | ||||||
| # │ │ │ 3 │ │ │ | ||||||
| # │ │ │ │◄────────┐ │◄────┼─────── [175,-3,-174,5] | ||||||
| # │ │ │ │ │ │ │ | ||||||
| # │ └──────────────┘ │ │ │ | ||||||
| # │ │ │ │ │ | ||||||
| # └──────────────────────────────────┼──────┘ │ | ||||||
| # │ │ │ | ||||||
| # │ │ │ | ||||||
| # │ │ │ | ||||||
| # │ │ │ | ||||||
| # │ [179,-2,-179,-1] │ | ||||||
|
|
||||||
| # Case 3 | ||||||
| if sub_crossing_antimeridian: | ||||||
| if not (xmin_sub > xmin and xmax_sub < xmax): | ||||||
| raise error_msg | ||||||
|
|
||||||
| # case 1 | ||||||
| elif xmax_sub <= 0 and xmax_sub > xmax: | ||||||
| raise error_msg | ||||||
|
|
||||||
| # case 2 | ||||||
| elif xmin_sub >= 0 and xmin_sub < xmin: | ||||||
|
||||||
| elif xmin_sub >= 0 and xmin_sub < xmin: | |
| elif xmin_sub < xmin or xmax_sub < xmin: |
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
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
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
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.