-
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 2 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,89 @@ | |
| TInterval = conlist(StartEndTime, min_length=1) | ||
|
|
||
|
|
||
| def validate_bbox_interval(v: List[BBox]) -> List[BBox]: | ||
| 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: | ||
| _ = 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 ValueError( | ||
| f"`BBOX` {bbox} not fully contained in `Overall BBOX` {overall_bbox}" | ||
| ) | ||
|
|
||
| sub_crossing_antimeridian = xmin_sub > xmax_sub | ||
| if not crossing_antimeridian and sub_crossing_antimeridian: | ||
| raise ValueError( | ||
| f"`BBOX` {bbox} not fully contained in `Overall BBOX` {overall_bbox}" | ||
| ) | ||
|
|
||
| elif crossing_antimeridian: | ||
| # TODO: | ||
| # here we need to check for 4 cases | ||
| # 1. sub-sequent within the right part of the overall bbox | ||
| # 2. sub-sequent within the left part of the overall bbox | ||
| # 3. if sub-sequent also cross the antimeridian we need to check both part with both overall part | ||
| # | ||
| # │ | ||
| # │ | ||
| # [176,1,179,3] │ | ||
| # │ │ | ||
| # │ │ [1,1,3,3] | ||
| # │ │ | ||
| # │ ┌─────────────────────────────────────────┐ │ | ||
| # │ │ │ │ │ | ||
| # │ │ ┌──────┐ │ ┌─────────┐ │ │ | ||
| # └──│──► 2 │ │ │ 1 │ │ │ | ||
| # │ │ │ │ │ │◄────│────────┘ | ||
| # │ └──────┘ │ └─────────┘ │ | ||
|
||
| # │ │ │ | ||
| # ────────────│────────────────┼────────────────────────│──────────────── | ||
| # │ │ │ | ||
| # │ ┌──────────────┐ │ | ||
| # │ │ │ │ │ | ||
| # │ │ │ 3 │ │ | ||
| # │ │ │ │◄────────┐ │◄──────────── [5,-3,-174,5] | ||
vincentsarago marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| # │ │ │ │ │ │ | ||
| # │ └──────────────┘ │ │ | ||
| # │ │ │ │ | ||
| # └──────────────────────────────────┼──────┘ | ||
| # │ │ | ||
| # │ │ | ||
| # │ │ | ||
| # │ │ | ||
| # │ [1,-2,-179,-1] | ||
vincentsarago marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| # │ | ||
|
|
||
| pass | ||
|
|
||
| else: | ||
| if not ((xmin_sub >= xmin) and (xmax_sub <= xmax)): | ||
| raise ValueError( | ||
| f"`BBOX` {bbox} not fully contained in `Overall BBOX` {overall_bbox}" | ||
| ) | ||
|
|
||
| return v | ||
|
|
||
|
|
||
| def validate_time_interval(v: TInterval) -> TInterval: # noqa: C901 | ||
| ivalues = iter(v) | ||
|
|
||
|
|
@@ -61,7 +145,7 @@ class SpatialExtent(StacBaseModel): | |
| https://github.com/radiantearth/stac-spec/blob/v1.0.0/collection-spec/collection-spec.md#spatial-extent-object | ||
| """ | ||
|
|
||
| bbox: List[BBox] | ||
| bbox: Annotated[List[BBox], AfterValidator(validate_bbox_interval)] | ||
|
|
||
|
|
||
| class TimeInterval(StacBaseModel): | ||
|
|
||
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
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.
Uh oh!
There was an error while loading. Please reload this page.