rasterix 0.1a3__py3-none-any.whl → 0.1.1__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- rasterix/_version.py +16 -3
- rasterix/lib.py +106 -0
- rasterix/raster_index.py +491 -167
- rasterix/rasterize/rasterio.py +4 -3
- rasterix/strategies.py +165 -0
- rasterix/utils.py +108 -0
- {rasterix-0.1a3.dist-info → rasterix-0.1.1.dist-info}/METADATA +7 -42
- rasterix-0.1.1.dist-info/RECORD +16 -0
- {rasterix-0.1a3.dist-info → rasterix-0.1.1.dist-info}/WHEEL +1 -1
- rasterix-0.1a3.dist-info/RECORD +0 -13
- {rasterix-0.1a3.dist-info → rasterix-0.1.1.dist-info}/licenses/LICENSE +0 -0
rasterix/_version.py
CHANGED
|
@@ -1,7 +1,14 @@
|
|
|
1
1
|
# file generated by setuptools-scm
|
|
2
2
|
# don't change, don't track in version control
|
|
3
3
|
|
|
4
|
-
__all__ = [
|
|
4
|
+
__all__ = [
|
|
5
|
+
"__version__",
|
|
6
|
+
"__version_tuple__",
|
|
7
|
+
"version",
|
|
8
|
+
"version_tuple",
|
|
9
|
+
"__commit_id__",
|
|
10
|
+
"commit_id",
|
|
11
|
+
]
|
|
5
12
|
|
|
6
13
|
TYPE_CHECKING = False
|
|
7
14
|
if TYPE_CHECKING:
|
|
@@ -9,13 +16,19 @@ if TYPE_CHECKING:
|
|
|
9
16
|
from typing import Union
|
|
10
17
|
|
|
11
18
|
VERSION_TUPLE = Tuple[Union[int, str], ...]
|
|
19
|
+
COMMIT_ID = Union[str, None]
|
|
12
20
|
else:
|
|
13
21
|
VERSION_TUPLE = object
|
|
22
|
+
COMMIT_ID = object
|
|
14
23
|
|
|
15
24
|
version: str
|
|
16
25
|
__version__: str
|
|
17
26
|
__version_tuple__: VERSION_TUPLE
|
|
18
27
|
version_tuple: VERSION_TUPLE
|
|
28
|
+
commit_id: COMMIT_ID
|
|
29
|
+
__commit_id__: COMMIT_ID
|
|
19
30
|
|
|
20
|
-
__version__ = version = '0.
|
|
21
|
-
__version_tuple__ = version_tuple = (0, 1,
|
|
31
|
+
__version__ = version = '0.1.1'
|
|
32
|
+
__version_tuple__ = version_tuple = (0, 1, 1)
|
|
33
|
+
|
|
34
|
+
__commit_id__ = commit_id = None
|
rasterix/lib.py
ADDED
|
@@ -0,0 +1,106 @@
|
|
|
1
|
+
"""Shared library utilities for rasterix."""
|
|
2
|
+
|
|
3
|
+
import logging
|
|
4
|
+
|
|
5
|
+
from affine import Affine
|
|
6
|
+
|
|
7
|
+
# Define TRACE level (lower than DEBUG)
|
|
8
|
+
TRACE = 5
|
|
9
|
+
logging.addLevelName(TRACE, "TRACE")
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
class TraceLogger(logging.Logger):
|
|
13
|
+
"""Logger with trace level support."""
|
|
14
|
+
|
|
15
|
+
def trace(self, message, *args, **kwargs):
|
|
16
|
+
"""Log a message with severity 'TRACE'."""
|
|
17
|
+
if self.isEnabledFor(TRACE):
|
|
18
|
+
self._log(TRACE, message, args, **kwargs)
|
|
19
|
+
|
|
20
|
+
|
|
21
|
+
# Set the custom logger class
|
|
22
|
+
logging.setLoggerClass(TraceLogger)
|
|
23
|
+
|
|
24
|
+
# Create logger for the rasterix package
|
|
25
|
+
logger = logging.getLogger("rasterix")
|
|
26
|
+
|
|
27
|
+
|
|
28
|
+
def affine_from_tiepoint_and_scale(
|
|
29
|
+
tiepoint: list[float] | tuple[float, ...],
|
|
30
|
+
scale: list[float] | tuple[float, ...],
|
|
31
|
+
) -> Affine:
|
|
32
|
+
"""Create an Affine transform from GeoTIFF tiepoint and pixel scale.
|
|
33
|
+
|
|
34
|
+
Parameters
|
|
35
|
+
----------
|
|
36
|
+
tiepoint : list or tuple
|
|
37
|
+
GeoTIFF model tiepoint in format [I, J, K, X, Y, Z]
|
|
38
|
+
where (I, J, K) are pixel coords and (X, Y, Z) are world coords.
|
|
39
|
+
scale : list or tuple
|
|
40
|
+
GeoTIFF model pixel scale in format [ScaleX, ScaleY, ScaleZ].
|
|
41
|
+
|
|
42
|
+
Returns
|
|
43
|
+
-------
|
|
44
|
+
Affine
|
|
45
|
+
Affine transformation matrix.
|
|
46
|
+
|
|
47
|
+
Raises
|
|
48
|
+
------
|
|
49
|
+
AssertionError
|
|
50
|
+
If ScaleZ is not 0 (only 2D rasters are supported).
|
|
51
|
+
|
|
52
|
+
Examples
|
|
53
|
+
--------
|
|
54
|
+
>>> tiepoint = [0.0, 0.0, 0.0, 323400.0, 4265400.0, 0.0]
|
|
55
|
+
>>> scale = [30.0, 30.0, 0.0]
|
|
56
|
+
>>> affine = affine_from_tiepoint_and_scale(tiepoint, scale)
|
|
57
|
+
"""
|
|
58
|
+
if len(tiepoint) < 6:
|
|
59
|
+
raise ValueError(f"tiepoint must have at least 6 elements, got {len(tiepoint)}")
|
|
60
|
+
if len(scale) < 3:
|
|
61
|
+
raise ValueError(f"scale must have at least 3 elements, got {len(scale)}")
|
|
62
|
+
|
|
63
|
+
i, j, k, x, y, z = tiepoint[:6]
|
|
64
|
+
scale_x, scale_y, scale_z = scale[:3]
|
|
65
|
+
|
|
66
|
+
# We only support 2D rasters
|
|
67
|
+
assert scale_z == 0, f"Z pixel scale must be 0 for 2D rasters, got {scale_z}"
|
|
68
|
+
|
|
69
|
+
# The tiepoint gives us the world coordinates at pixel (I, J)
|
|
70
|
+
# Affine transform: x_world = c + i * a, y_world = f + j * e
|
|
71
|
+
# So: c = x - i * scale_x, f = y - j * scale_y
|
|
72
|
+
c = x - i * scale_x
|
|
73
|
+
f = y - j * scale_y
|
|
74
|
+
|
|
75
|
+
return Affine.translation(c, f) * Affine.scale(scale_x, scale_y)
|
|
76
|
+
|
|
77
|
+
|
|
78
|
+
def affine_from_stac_proj_metadata(metadata: dict) -> Affine | None:
|
|
79
|
+
"""Extract Affine transform from STAC projection metadata.
|
|
80
|
+
|
|
81
|
+
Parameters
|
|
82
|
+
----------
|
|
83
|
+
metadata : dict
|
|
84
|
+
Dictionary containing STAC metadata. Should contain a 'proj:transform' key.
|
|
85
|
+
|
|
86
|
+
Returns
|
|
87
|
+
-------
|
|
88
|
+
Affine or None
|
|
89
|
+
Affine transformation matrix if 'proj:transform' is found, None otherwise.
|
|
90
|
+
|
|
91
|
+
Examples
|
|
92
|
+
--------
|
|
93
|
+
>>> metadata = {"proj:transform": [30.0, 0.0, 323400.0, 0.0, 30.0, 4268400.0]}
|
|
94
|
+
>>> affine = affine_from_stac_proj_metadata(metadata)
|
|
95
|
+
"""
|
|
96
|
+
if "proj:transform" not in metadata:
|
|
97
|
+
return None
|
|
98
|
+
|
|
99
|
+
transform = metadata["proj:transform"]
|
|
100
|
+
# proj:transform is a 3x3 matrix in row-major order, but typically only 6 elements
|
|
101
|
+
# [a, b, c, d, e, f, 0, 0, 1] where the affine is constructed from first 6 elements
|
|
102
|
+
if len(transform) < 6:
|
|
103
|
+
raise ValueError(f"proj:transform must have at least 6 elements, got {len(transform)}")
|
|
104
|
+
|
|
105
|
+
a, b, c, d, e, f = transform[:6]
|
|
106
|
+
return Affine(a, b, c, d, e, f)
|