-
Notifications
You must be signed in to change notification settings - Fork 3
feat: Sketching Overview dataclass
#10
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
6 commits
Select commit
Hold shift + click to select a range
e3a2d95
feat: Sketching overview dataclass
kylebarron 9fd24fb
Add `overviews` accessor to GeoTIFF class
kylebarron 343e5d4
Create overviews
kylebarron abbdca4
Test overview transform
kylebarron 738f47d
assert overviews length
kylebarron 9c5b790
Remove Overview __init__ method
kylebarron 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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,4 +1,5 @@ | ||
| from ._geotiff import GeoTIFF | ||
| from ._overview import Overview | ||
| from ._version import __version__ | ||
|
|
||
| __all__ = ["GeoTIFF", "__version__"] | ||
| __all__ = ["GeoTIFF", "Overview", "__version__"] |
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 |
|---|---|---|
| @@ -0,0 +1,71 @@ | ||
| from __future__ import annotations | ||
|
|
||
| from functools import cached_property | ||
| from typing import TYPE_CHECKING, Literal, Self | ||
|
|
||
| from affine import Affine | ||
| from async_tiff import TIFF | ||
|
|
||
| from async_geotiff.enums import Compression, Interleaving, PhotometricInterp | ||
|
|
||
| if TYPE_CHECKING: | ||
| from async_tiff import GeoKeyDirectory, ImageFileDirectory | ||
|
|
||
| from async_geotiff import GeoTIFF | ||
|
|
||
|
|
||
| class Overview: | ||
| """An overview level of a Cloud-Optimized GeoTIFF image.""" | ||
|
|
||
| _geotiff: GeoTIFF | ||
| """A reference to the parent GeoTIFF object. | ||
| """ | ||
|
|
||
| _gkd: GeoKeyDirectory | ||
| """The GeoKeyDirectory of the primary IFD. | ||
| """ | ||
|
|
||
| _ifd: ImageFileDirectory | ||
| """The IFD for this overview level. | ||
| """ | ||
|
|
||
| _mask_ifd: ImageFileDirectory | None | ||
| """The IFD for the mask associated with this overview level, if any. | ||
| """ | ||
|
|
||
| _overview_idx: int | ||
| """The overview level (0 is the full resolution image, 1 is the first overview, etc). | ||
| """ | ||
|
|
||
| def __init__( | ||
| self, | ||
| geotiff: GeoTIFF, | ||
| gkd: GeoKeyDirectory, | ||
| ifd: ImageFileDirectory, | ||
| mask_ifd: ImageFileDirectory | None, | ||
| overview_idx: int, | ||
| ) -> None: | ||
| self._geotiff = geotiff | ||
| self._gkd = gkd | ||
| self._ifd = ifd | ||
| self._mask_ifd = mask_ifd | ||
| self._overview_idx = overview_idx | ||
|
|
||
| @cached_property | ||
| def transform(self) -> Affine: | ||
| """The affine transform mapping pixel coordinates to geographic coordinates. | ||
|
|
||
| Returns: | ||
| Affine: The affine transform. | ||
| """ | ||
| full_transform = self._geotiff.transform | ||
|
|
||
| overview_width = self._ifd.image_width | ||
| full_width = self._geotiff.width | ||
| overview_height = self._ifd.image_height | ||
| full_height = self._geotiff.height | ||
|
|
||
| scale_x = full_width / overview_width | ||
| scale_y = full_height / overview_height | ||
|
|
||
| return full_transform * Affine.scale(scale_x, scale_y) | ||
kylebarron marked this conversation as resolved.
Show resolved
Hide resolved
|
||
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.