rio-stac-io 0.3.4__tar.gz
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.
- rio_stac_io-0.3.4/.gitignore +151 -0
- rio_stac_io-0.3.4/LICENSE +202 -0
- rio_stac_io-0.3.4/PKG-INFO +11 -0
- rio_stac_io-0.3.4/pyproject.toml +238 -0
- rio_stac_io-0.3.4/rio_stac_io/__init__.py +6 -0
- rio_stac_io-0.3.4/rio_stac_io/drivers/__init__.py +0 -0
- rio_stac_io-0.3.4/rio_stac_io/drivers/gti.py +92 -0
- rio_stac_io-0.3.4/rio_stac_io/drivers/stacit.py +137 -0
- rio_stac_io-0.3.4/rio_stac_io/drivers/stacta.py +89 -0
- rio_stac_io-0.3.4/rio_stac_io/io.py +332 -0
- rio_stac_io-0.3.4/rio_stac_io/utils.py +77 -0
|
@@ -0,0 +1,151 @@
|
|
|
1
|
+
# local testing data/results
|
|
2
|
+
*.vrt
|
|
3
|
+
scripts/*.tif
|
|
4
|
+
scripts/*.laz
|
|
5
|
+
scripts/*.tif.aux.xml
|
|
6
|
+
|
|
7
|
+
# Byte-compiled / optimized / DLL files
|
|
8
|
+
__pycache__/
|
|
9
|
+
*.py[cod]
|
|
10
|
+
*$py.class
|
|
11
|
+
|
|
12
|
+
# C extensions
|
|
13
|
+
*.so
|
|
14
|
+
|
|
15
|
+
# Distribution / packaging
|
|
16
|
+
.Python
|
|
17
|
+
build/
|
|
18
|
+
develop-eggs/
|
|
19
|
+
dist/
|
|
20
|
+
downloads/
|
|
21
|
+
eggs/
|
|
22
|
+
.eggs/
|
|
23
|
+
lib/
|
|
24
|
+
lib64/
|
|
25
|
+
parts/
|
|
26
|
+
sdist/
|
|
27
|
+
var/
|
|
28
|
+
wheels/
|
|
29
|
+
pip-wheel-metadata/
|
|
30
|
+
share/python-wheels/
|
|
31
|
+
*.egg-info/
|
|
32
|
+
.installed.cfg
|
|
33
|
+
*.egg
|
|
34
|
+
MANIFEST
|
|
35
|
+
|
|
36
|
+
# PyInstaller
|
|
37
|
+
# Usually these files are written by a python script from a template
|
|
38
|
+
# before PyInstaller builds the exe, so as to inject date/other infos into it.
|
|
39
|
+
*.manifest
|
|
40
|
+
*.spec
|
|
41
|
+
|
|
42
|
+
# Installer logs
|
|
43
|
+
pip-log.txt
|
|
44
|
+
pip-delete-this-directory.txt
|
|
45
|
+
|
|
46
|
+
# Unit test / coverage reports
|
|
47
|
+
htmlcov/
|
|
48
|
+
.tox/
|
|
49
|
+
.nox/
|
|
50
|
+
.coverage
|
|
51
|
+
.coverage.*
|
|
52
|
+
.cache
|
|
53
|
+
nosetests.xml
|
|
54
|
+
coverage.xml
|
|
55
|
+
*.cover
|
|
56
|
+
*.py,cover
|
|
57
|
+
.hypothesis/
|
|
58
|
+
.pytest_cache/
|
|
59
|
+
|
|
60
|
+
# Translations
|
|
61
|
+
*.mo
|
|
62
|
+
*.pot
|
|
63
|
+
|
|
64
|
+
# Django stuff:
|
|
65
|
+
*.log
|
|
66
|
+
local_settings.py
|
|
67
|
+
db.sqlite3
|
|
68
|
+
db.sqlite3-journal
|
|
69
|
+
|
|
70
|
+
# Flask stuff:
|
|
71
|
+
instance/
|
|
72
|
+
.webassets-cache
|
|
73
|
+
|
|
74
|
+
# Scrapy stuff:
|
|
75
|
+
.scrapy
|
|
76
|
+
|
|
77
|
+
# Sphinx documentation
|
|
78
|
+
docs/_build/
|
|
79
|
+
|
|
80
|
+
# PyBuilder
|
|
81
|
+
target/
|
|
82
|
+
|
|
83
|
+
# Jupyter Notebook
|
|
84
|
+
.ipynb_checkpoints
|
|
85
|
+
|
|
86
|
+
# IPython
|
|
87
|
+
profile_default/
|
|
88
|
+
ipython_config.py
|
|
89
|
+
|
|
90
|
+
# pyenv
|
|
91
|
+
.python-version
|
|
92
|
+
|
|
93
|
+
# pipenv
|
|
94
|
+
# According to pypa/pipenv#598, it is recommended to include Pipfile.lock in version control.
|
|
95
|
+
# However, in case of collaboration, if having platform-specific dependencies or dependencies
|
|
96
|
+
# having no cross-platform support, pipenv may install dependencies that don't work, or not
|
|
97
|
+
# install all needed dependencies.
|
|
98
|
+
#Pipfile.lock
|
|
99
|
+
|
|
100
|
+
# PEP 582; used by e.g. github.com/David-OConnor/pyflow
|
|
101
|
+
__pypackages__/
|
|
102
|
+
|
|
103
|
+
# Celery stuff
|
|
104
|
+
celerybeat-schedule
|
|
105
|
+
celerybeat.pid
|
|
106
|
+
|
|
107
|
+
# SageMath parsed files
|
|
108
|
+
*.sage.py
|
|
109
|
+
|
|
110
|
+
# Environments
|
|
111
|
+
.env
|
|
112
|
+
.venv
|
|
113
|
+
env/
|
|
114
|
+
venv/
|
|
115
|
+
ENV/
|
|
116
|
+
env.bak/
|
|
117
|
+
venv.bak/
|
|
118
|
+
|
|
119
|
+
# Spyder project settings
|
|
120
|
+
.spyderproject
|
|
121
|
+
.spyproject
|
|
122
|
+
|
|
123
|
+
# Rope project settings
|
|
124
|
+
.ropeproject
|
|
125
|
+
|
|
126
|
+
# mkdocs documentation
|
|
127
|
+
/site
|
|
128
|
+
|
|
129
|
+
# mypy
|
|
130
|
+
.mypy_cache/
|
|
131
|
+
.dmypy.json
|
|
132
|
+
dmypy.json
|
|
133
|
+
|
|
134
|
+
# Pyre type checker
|
|
135
|
+
.pyre/
|
|
136
|
+
|
|
137
|
+
# cba
|
|
138
|
+
.zedstate
|
|
139
|
+
|
|
140
|
+
# channel/package builds
|
|
141
|
+
channel/
|
|
142
|
+
package/
|
|
143
|
+
|
|
144
|
+
# lbatch ephemeral
|
|
145
|
+
jobs.json
|
|
146
|
+
nohup.out
|
|
147
|
+
results.json
|
|
148
|
+
|
|
149
|
+
# pixi environments
|
|
150
|
+
.pixi
|
|
151
|
+
*.egg-info
|
|
@@ -0,0 +1,202 @@
|
|
|
1
|
+
|
|
2
|
+
Apache License
|
|
3
|
+
Version 2.0, January 2004
|
|
4
|
+
http://www.apache.org/licenses/
|
|
5
|
+
|
|
6
|
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
|
7
|
+
|
|
8
|
+
1. Definitions.
|
|
9
|
+
|
|
10
|
+
"License" shall mean the terms and conditions for use, reproduction,
|
|
11
|
+
and distribution as defined by Sections 1 through 9 of this document.
|
|
12
|
+
|
|
13
|
+
"Licensor" shall mean the copyright owner or entity authorized by
|
|
14
|
+
the copyright owner that is granting the License.
|
|
15
|
+
|
|
16
|
+
"Legal Entity" shall mean the union of the acting entity and all
|
|
17
|
+
other entities that control, are controlled by, or are under common
|
|
18
|
+
control with that entity. For the purposes of this definition,
|
|
19
|
+
"control" means (i) the power, direct or indirect, to cause the
|
|
20
|
+
direction or management of such entity, whether by contract or
|
|
21
|
+
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
|
22
|
+
outstanding shares, or (iii) beneficial ownership of such entity.
|
|
23
|
+
|
|
24
|
+
"You" (or "Your") shall mean an individual or Legal Entity
|
|
25
|
+
exercising permissions granted by this License.
|
|
26
|
+
|
|
27
|
+
"Source" form shall mean the preferred form for making modifications,
|
|
28
|
+
including but not limited to software source code, documentation
|
|
29
|
+
source, and configuration files.
|
|
30
|
+
|
|
31
|
+
"Object" form shall mean any form resulting from mechanical
|
|
32
|
+
transformation or translation of a Source form, including but
|
|
33
|
+
not limited to compiled object code, generated documentation,
|
|
34
|
+
and conversions to other media types.
|
|
35
|
+
|
|
36
|
+
"Work" shall mean the work of authorship, whether in Source or
|
|
37
|
+
Object form, made available under the License, as indicated by a
|
|
38
|
+
copyright notice that is included in or attached to the work
|
|
39
|
+
(an example is provided in the Appendix below).
|
|
40
|
+
|
|
41
|
+
"Derivative Works" shall mean any work, whether in Source or Object
|
|
42
|
+
form, that is based on (or derived from) the Work and for which the
|
|
43
|
+
editorial revisions, annotations, elaborations, or other modifications
|
|
44
|
+
represent, as a whole, an original work of authorship. For the purposes
|
|
45
|
+
of this License, Derivative Works shall not include works that remain
|
|
46
|
+
separable from, or merely link (or bind by name) to the interfaces of,
|
|
47
|
+
the Work and Derivative Works thereof.
|
|
48
|
+
|
|
49
|
+
"Contribution" shall mean any work of authorship, including
|
|
50
|
+
the original version of the Work and any modifications or additions
|
|
51
|
+
to that Work or Derivative Works thereof, that is intentionally
|
|
52
|
+
submitted to Licensor for inclusion in the Work by the copyright owner
|
|
53
|
+
or by an individual or Legal Entity authorized to submit on behalf of
|
|
54
|
+
the copyright owner. For the purposes of this definition, "submitted"
|
|
55
|
+
means any form of electronic, verbal, or written communication sent
|
|
56
|
+
to the Licensor or its representatives, including but not limited to
|
|
57
|
+
communication on electronic mailing lists, source code control systems,
|
|
58
|
+
and issue tracking systems that are managed by, or on behalf of, the
|
|
59
|
+
Licensor for the purpose of discussing and improving the Work, but
|
|
60
|
+
excluding communication that is conspicuously marked or otherwise
|
|
61
|
+
designated in writing by the copyright owner as "Not a Contribution."
|
|
62
|
+
|
|
63
|
+
"Contributor" shall mean Licensor and any individual or Legal Entity
|
|
64
|
+
on behalf of whom a Contribution has been received by Licensor and
|
|
65
|
+
subsequently incorporated within the Work.
|
|
66
|
+
|
|
67
|
+
2. Grant of Copyright License. Subject to the terms and conditions of
|
|
68
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
69
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
70
|
+
copyright license to reproduce, prepare Derivative Works of,
|
|
71
|
+
publicly display, publicly perform, sublicense, and distribute the
|
|
72
|
+
Work and such Derivative Works in Source or Object form.
|
|
73
|
+
|
|
74
|
+
3. Grant of Patent License. Subject to the terms and conditions of
|
|
75
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
76
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
77
|
+
(except as stated in this section) patent license to make, have made,
|
|
78
|
+
use, offer to sell, sell, import, and otherwise transfer the Work,
|
|
79
|
+
where such license applies only to those patent claims licensable
|
|
80
|
+
by such Contributor that are necessarily infringed by their
|
|
81
|
+
Contribution(s) alone or by combination of their Contribution(s)
|
|
82
|
+
with the Work to which such Contribution(s) was submitted. If You
|
|
83
|
+
institute patent litigation against any entity (including a
|
|
84
|
+
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
|
85
|
+
or a Contribution incorporated within the Work constitutes direct
|
|
86
|
+
or contributory patent infringement, then any patent licenses
|
|
87
|
+
granted to You under this License for that Work shall terminate
|
|
88
|
+
as of the date such litigation is filed.
|
|
89
|
+
|
|
90
|
+
4. Redistribution. You may reproduce and distribute copies of the
|
|
91
|
+
Work or Derivative Works thereof in any medium, with or without
|
|
92
|
+
modifications, and in Source or Object form, provided that You
|
|
93
|
+
meet the following conditions:
|
|
94
|
+
|
|
95
|
+
(a) You must give any other recipients of the Work or
|
|
96
|
+
Derivative Works a copy of this License; and
|
|
97
|
+
|
|
98
|
+
(b) You must cause any modified files to carry prominent notices
|
|
99
|
+
stating that You changed the files; and
|
|
100
|
+
|
|
101
|
+
(c) You must retain, in the Source form of any Derivative Works
|
|
102
|
+
that You distribute, all copyright, patent, trademark, and
|
|
103
|
+
attribution notices from the Source form of the Work,
|
|
104
|
+
excluding those notices that do not pertain to any part of
|
|
105
|
+
the Derivative Works; and
|
|
106
|
+
|
|
107
|
+
(d) If the Work includes a "NOTICE" text file as part of its
|
|
108
|
+
distribution, then any Derivative Works that You distribute must
|
|
109
|
+
include a readable copy of the attribution notices contained
|
|
110
|
+
within such NOTICE file, excluding those notices that do not
|
|
111
|
+
pertain to any part of the Derivative Works, in at least one
|
|
112
|
+
of the following places: within a NOTICE text file distributed
|
|
113
|
+
as part of the Derivative Works; within the Source form or
|
|
114
|
+
documentation, if provided along with the Derivative Works; or,
|
|
115
|
+
within a display generated by the Derivative Works, if and
|
|
116
|
+
wherever such third-party notices normally appear. The contents
|
|
117
|
+
of the NOTICE file are for informational purposes only and
|
|
118
|
+
do not modify the License. You may add Your own attribution
|
|
119
|
+
notices within Derivative Works that You distribute, alongside
|
|
120
|
+
or as an addendum to the NOTICE text from the Work, provided
|
|
121
|
+
that such additional attribution notices cannot be construed
|
|
122
|
+
as modifying the License.
|
|
123
|
+
|
|
124
|
+
You may add Your own copyright statement to Your modifications and
|
|
125
|
+
may provide additional or different license terms and conditions
|
|
126
|
+
for use, reproduction, or distribution of Your modifications, or
|
|
127
|
+
for any such Derivative Works as a whole, provided Your use,
|
|
128
|
+
reproduction, and distribution of the Work otherwise complies with
|
|
129
|
+
the conditions stated in this License.
|
|
130
|
+
|
|
131
|
+
5. Submission of Contributions. Unless You explicitly state otherwise,
|
|
132
|
+
any Contribution intentionally submitted for inclusion in the Work
|
|
133
|
+
by You to the Licensor shall be under the terms and conditions of
|
|
134
|
+
this License, without any additional terms or conditions.
|
|
135
|
+
Notwithstanding the above, nothing herein shall supersede or modify
|
|
136
|
+
the terms of any separate license agreement you may have executed
|
|
137
|
+
with Licensor regarding such Contributions.
|
|
138
|
+
|
|
139
|
+
6. Trademarks. This License does not grant permission to use the trade
|
|
140
|
+
names, trademarks, service marks, or product names of the Licensor,
|
|
141
|
+
except as required for reasonable and customary use in describing the
|
|
142
|
+
origin of the Work and reproducing the content of the NOTICE file.
|
|
143
|
+
|
|
144
|
+
7. Disclaimer of Warranty. Unless required by applicable law or
|
|
145
|
+
agreed to in writing, Licensor provides the Work (and each
|
|
146
|
+
Contributor provides its Contributions) on an "AS IS" BASIS,
|
|
147
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
|
148
|
+
implied, including, without limitation, any warranties or conditions
|
|
149
|
+
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
|
150
|
+
PARTICULAR PURPOSE. You are solely responsible for determining the
|
|
151
|
+
appropriateness of using or redistributing the Work and assume any
|
|
152
|
+
risks associated with Your exercise of permissions under this License.
|
|
153
|
+
|
|
154
|
+
8. Limitation of Liability. In no event and under no legal theory,
|
|
155
|
+
whether in tort (including negligence), contract, or otherwise,
|
|
156
|
+
unless required by applicable law (such as deliberate and grossly
|
|
157
|
+
negligent acts) or agreed to in writing, shall any Contributor be
|
|
158
|
+
liable to You for damages, including any direct, indirect, special,
|
|
159
|
+
incidental, or consequential damages of any character arising as a
|
|
160
|
+
result of this License or out of the use or inability to use the
|
|
161
|
+
Work (including but not limited to damages for loss of goodwill,
|
|
162
|
+
work stoppage, computer failure or malfunction, or any and all
|
|
163
|
+
other commercial damages or losses), even if such Contributor
|
|
164
|
+
has been advised of the possibility of such damages.
|
|
165
|
+
|
|
166
|
+
9. Accepting Warranty or Additional Liability. While redistributing
|
|
167
|
+
the Work or Derivative Works thereof, You may choose to offer,
|
|
168
|
+
and charge a fee for, acceptance of support, warranty, indemnity,
|
|
169
|
+
or other liability obligations and/or rights consistent with this
|
|
170
|
+
License. However, in accepting such obligations, You may act only
|
|
171
|
+
on Your own behalf and on Your sole responsibility, not on behalf
|
|
172
|
+
of any other Contributor, and only if You agree to indemnify,
|
|
173
|
+
defend, and hold each Contributor harmless for any liability
|
|
174
|
+
incurred by, or claims asserted against, such Contributor by reason
|
|
175
|
+
of your accepting any such warranty or additional liability.
|
|
176
|
+
|
|
177
|
+
END OF TERMS AND CONDITIONS
|
|
178
|
+
|
|
179
|
+
APPENDIX: How to apply the Apache License to your work.
|
|
180
|
+
|
|
181
|
+
To apply the Apache License to your work, attach the following
|
|
182
|
+
boilerplate notice, with the fields enclosed by brackets "[]"
|
|
183
|
+
replaced with your own identifying information. (Don't include
|
|
184
|
+
the brackets!) The text should be enclosed in the appropriate
|
|
185
|
+
comment syntax for the file format. We also recommend that a
|
|
186
|
+
file or class name and description of purpose be included on the
|
|
187
|
+
same "printed page" as the copyright notice for easier
|
|
188
|
+
identification within third-party archives.
|
|
189
|
+
|
|
190
|
+
Copyright [yyyy] [name of copyright owner]
|
|
191
|
+
|
|
192
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
193
|
+
you may not use this file except in compliance with the License.
|
|
194
|
+
You may obtain a copy of the License at
|
|
195
|
+
|
|
196
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
197
|
+
|
|
198
|
+
Unless required by applicable law or agreed to in writing, software
|
|
199
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
200
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
201
|
+
See the License for the specific language governing permissions and
|
|
202
|
+
limitations under the License.
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: rio-stac-io
|
|
3
|
+
Version: 0.3.4
|
|
4
|
+
Author-email: Thomas Maschler <thomas.maschler@planet.com>
|
|
5
|
+
License-File: LICENSE
|
|
6
|
+
Requires-Python: >=3.10
|
|
7
|
+
Requires-Dist: pystac-client>=0.9.0
|
|
8
|
+
Requires-Dist: pystac>=1.11.0
|
|
9
|
+
Requires-Dist: rasterio>=1.4.3
|
|
10
|
+
Provides-Extra: gti
|
|
11
|
+
Requires-Dist: stac-geoparquet>=0.7.0; extra == 'gti'
|
|
@@ -0,0 +1,238 @@
|
|
|
1
|
+
[project]
|
|
2
|
+
authors = [{ name = "Thomas Maschler", email = "thomas.maschler@planet.com" }]
|
|
3
|
+
name = "rio-stac-io"
|
|
4
|
+
requires-python = ">= 3.10"
|
|
5
|
+
version = "v0.3.4"
|
|
6
|
+
dependencies = [
|
|
7
|
+
"rasterio>=1.4.3",
|
|
8
|
+
"pystac>=1.11.0",
|
|
9
|
+
"pystac-client>=0.9.0",
|
|
10
|
+
|
|
11
|
+
]
|
|
12
|
+
|
|
13
|
+
[project.optional-dependencies]
|
|
14
|
+
gti = ["stac-geoparquet>=0.7.0",]
|
|
15
|
+
|
|
16
|
+
|
|
17
|
+
[tool.pixi.workspace]
|
|
18
|
+
channels = ["conda-forge"]
|
|
19
|
+
platforms = ["osx-arm64", "linux-64"]
|
|
20
|
+
|
|
21
|
+
[tool.pixi.pypi-options]
|
|
22
|
+
no-binary = ["rasterio"]
|
|
23
|
+
|
|
24
|
+
[tool.pixi.pypi-dependencies]
|
|
25
|
+
rio_stac_io = { path = ".", editable = true }
|
|
26
|
+
|
|
27
|
+
[tool.pixi.environments]
|
|
28
|
+
default = { features = ["gti"], solve-group = "default" }
|
|
29
|
+
dev = { features = ["gti", "dev", "lint", "gdal-311"], solve-group = "gdal-311" }
|
|
30
|
+
dev-gdal38 = { features = ["gti", "dev", "lint", "gdal-38"], solve-group = "gdal-38" }
|
|
31
|
+
dev-gdal39 = { features = ["gti", "dev", "lint", "gdal-39"], solve-group = "gdal-39" }
|
|
32
|
+
dev-gdal310 = { features = ["gti", "dev", "lint", "gdal-310"], solve-group = "gdal-310" }
|
|
33
|
+
dev-gdal311 = { features = ["gti", "dev", "lint", "gdal-311"], solve-group = "gdal-311" }
|
|
34
|
+
lint = { features = ["lint"], solve-group = "lint", no-default-feature = true }
|
|
35
|
+
docs = { features = ["docs"], solve-group = "docs", no-default-feature = true }
|
|
36
|
+
build = { features = ["build"], solve-group = "build", no-default-feature = true }
|
|
37
|
+
|
|
38
|
+
######## Pixi/ GDAL 3.8
|
|
39
|
+
|
|
40
|
+
[tool.pixi.feature.gdal-38.dependencies]
|
|
41
|
+
libgdal = "==3.8.5"
|
|
42
|
+
libgdal-arrow-parquet = "*"
|
|
43
|
+
proj = ">=9"
|
|
44
|
+
libexpat = "*"
|
|
45
|
+
|
|
46
|
+
######## Pixi/ GDAL 3.9
|
|
47
|
+
|
|
48
|
+
[tool.pixi.feature.gdal-39.dependencies]
|
|
49
|
+
libgdal = "==3.9.3"
|
|
50
|
+
libgdal-arrow-parquet = "*"
|
|
51
|
+
proj = ">=9"
|
|
52
|
+
libexpat = "*"
|
|
53
|
+
|
|
54
|
+
######## Pixi/ GDAL 3.10
|
|
55
|
+
|
|
56
|
+
[tool.pixi.feature.gdal-310.dependencies]
|
|
57
|
+
libgdal = "==3.10.3"
|
|
58
|
+
libgdal-arrow-parquet = "*"
|
|
59
|
+
proj = ">=9"
|
|
60
|
+
libexpat = "*"
|
|
61
|
+
|
|
62
|
+
######## Pixi/ GDAL 3.11
|
|
63
|
+
|
|
64
|
+
[tool.pixi.feature.gdal-311.dependencies]
|
|
65
|
+
libgdal = "==3.11.4"
|
|
66
|
+
libgdal-arrow-parquet = "*"
|
|
67
|
+
proj = ">=9"
|
|
68
|
+
libexpat = "*"
|
|
69
|
+
|
|
70
|
+
######## Pixi/ DEV
|
|
71
|
+
|
|
72
|
+
[tool.pixi.feature.dev.pypi-dependencies]
|
|
73
|
+
pytest = ">=7.4.0"
|
|
74
|
+
pytest-cov = ">=4.1.0"
|
|
75
|
+
pytest-recording = ">=0.13.0"
|
|
76
|
+
rasterio = { version = "*", extras = ["s3"] }
|
|
77
|
+
rio-stac = ">=0.10.1"
|
|
78
|
+
morecantile = ">6.1.0"
|
|
79
|
+
|
|
80
|
+
|
|
81
|
+
[tool.pixi.feature.dev.tasks]
|
|
82
|
+
test = "pytest --record-mode=once"
|
|
83
|
+
test-ci = "pytest --record-mode=none"
|
|
84
|
+
|
|
85
|
+
######## Pixi Lint
|
|
86
|
+
|
|
87
|
+
[tool.pixi.feature.lint.dependencies]
|
|
88
|
+
python = ">=3.10,<=3.12"
|
|
89
|
+
|
|
90
|
+
[tool.pixi.feature.lint.pypi-dependencies]
|
|
91
|
+
ruff = ">=0.1.12"
|
|
92
|
+
mypy = ">=1.5.1"
|
|
93
|
+
pre-commit = ">=2.19.0"
|
|
94
|
+
types-python-dateutil = ">=2.9.0.20240315"
|
|
95
|
+
types-pytz = ">=2024.1.0.20240203"
|
|
96
|
+
types-requests = ">=2.26.0.20240315"
|
|
97
|
+
|
|
98
|
+
|
|
99
|
+
[tool.pixi.feature.lint.tasks]
|
|
100
|
+
_setup = "pre-commit install"
|
|
101
|
+
lint = { cmd = "pre-commit run --all-files", depends-on = ["_setup"] }
|
|
102
|
+
|
|
103
|
+
######## Pixi/ DOCS
|
|
104
|
+
|
|
105
|
+
[tool.pixi.feature.docs.dependencies]
|
|
106
|
+
python = ">=3.10"
|
|
107
|
+
|
|
108
|
+
[tool.pixi.feature.docs.pypi-dependencies]
|
|
109
|
+
mkdocs = ">=1.5.3"
|
|
110
|
+
mkdocs-jupyter = ">=0.24.6"
|
|
111
|
+
mkdocs-material = ">=9.5.3"
|
|
112
|
+
mkdocstrings-python = ">=1.7.5"
|
|
113
|
+
livereload = ">=2.6.3"
|
|
114
|
+
|
|
115
|
+
[tool.pixi.feature.docs.tasks]
|
|
116
|
+
localdocs = "mkdocs serve"
|
|
117
|
+
deploy = "mkdocs gh-deploy"
|
|
118
|
+
|
|
119
|
+
######## Pixi/ Hatch Build
|
|
120
|
+
|
|
121
|
+
[build-system]
|
|
122
|
+
build-backend = "hatchling.build"
|
|
123
|
+
requires = ["hatchling"]
|
|
124
|
+
|
|
125
|
+
[tool.hatch.build.targets.sdist]
|
|
126
|
+
include = ["rio_stac_io"]
|
|
127
|
+
|
|
128
|
+
[tool.hatch.build.targets.wheel]
|
|
129
|
+
only-include = ["rio_stac_io"]
|
|
130
|
+
|
|
131
|
+
[tool.pixi.feature.build.dependencies]
|
|
132
|
+
python = ">=3.10"
|
|
133
|
+
|
|
134
|
+
[tool.pixi.feature.build.pypi-dependencies]
|
|
135
|
+
hatch = "*"
|
|
136
|
+
twine = "*"
|
|
137
|
+
|
|
138
|
+
[tool.pixi.feature.build.tasks]
|
|
139
|
+
build = "pixi project version set $(git describe --tags) && hatch build"
|
|
140
|
+
deploy = { cmd = "twine upload -r planet dist/*", depends-on = ["build"] }
|
|
141
|
+
|
|
142
|
+
# PYTEST
|
|
143
|
+
|
|
144
|
+
[tool.pytest.ini_options]
|
|
145
|
+
addopts = "--cov=rio_stac_io --no-cov-on-fail --cov-report=term-missing:skip-covered --record-mode=rewrite"
|
|
146
|
+
|
|
147
|
+
[tool.mypy]
|
|
148
|
+
ignore_missing_imports = true
|
|
149
|
+
warn_unused_configs = true
|
|
150
|
+
disallow_incomplete_defs = true
|
|
151
|
+
disallow_untyped_defs = true
|
|
152
|
+
warn_return_any = true
|
|
153
|
+
exclude = "tests/*"
|
|
154
|
+
|
|
155
|
+
[tool.ruff]
|
|
156
|
+
exclude = [
|
|
157
|
+
".bzr",
|
|
158
|
+
".direnv",
|
|
159
|
+
".eggs",
|
|
160
|
+
".git",
|
|
161
|
+
".git-rewrite",
|
|
162
|
+
".hg",
|
|
163
|
+
".mypy_cache",
|
|
164
|
+
".nox",
|
|
165
|
+
".pants.d",
|
|
166
|
+
".pytype",
|
|
167
|
+
".ruff_cache",
|
|
168
|
+
".svn",
|
|
169
|
+
".tox",
|
|
170
|
+
".venv",
|
|
171
|
+
"__pypackages__",
|
|
172
|
+
"_build",
|
|
173
|
+
"buck-out",
|
|
174
|
+
"build",
|
|
175
|
+
"dist",
|
|
176
|
+
"node_modules",
|
|
177
|
+
"venv",
|
|
178
|
+
]
|
|
179
|
+
line-length = 88
|
|
180
|
+
target-version = "py311"
|
|
181
|
+
|
|
182
|
+
[tool.ruff.lint]
|
|
183
|
+
select = ["F", "E", "W", "I001"]
|
|
184
|
+
ignore = []
|
|
185
|
+
fixable = [
|
|
186
|
+
"A",
|
|
187
|
+
"B",
|
|
188
|
+
"C",
|
|
189
|
+
"D",
|
|
190
|
+
"E",
|
|
191
|
+
"F",
|
|
192
|
+
"G",
|
|
193
|
+
"I",
|
|
194
|
+
"N",
|
|
195
|
+
"Q",
|
|
196
|
+
"S",
|
|
197
|
+
"T",
|
|
198
|
+
"W",
|
|
199
|
+
"ANN",
|
|
200
|
+
"ARG",
|
|
201
|
+
"BLE",
|
|
202
|
+
"COM",
|
|
203
|
+
"DJ",
|
|
204
|
+
"DTZ",
|
|
205
|
+
"EM",
|
|
206
|
+
"ERA",
|
|
207
|
+
"EXE",
|
|
208
|
+
"FBT",
|
|
209
|
+
"ICN",
|
|
210
|
+
"INP",
|
|
211
|
+
"ISC",
|
|
212
|
+
"NPY",
|
|
213
|
+
"PD",
|
|
214
|
+
"PGH",
|
|
215
|
+
"PIE",
|
|
216
|
+
"PL",
|
|
217
|
+
"PT",
|
|
218
|
+
"PTH",
|
|
219
|
+
"PYI",
|
|
220
|
+
"RET",
|
|
221
|
+
"RSE",
|
|
222
|
+
"RUF",
|
|
223
|
+
"SIM",
|
|
224
|
+
"SLF",
|
|
225
|
+
"TCH",
|
|
226
|
+
"TID",
|
|
227
|
+
"TRY",
|
|
228
|
+
"UP",
|
|
229
|
+
"YTT",
|
|
230
|
+
]
|
|
231
|
+
unfixable = []
|
|
232
|
+
dummy-variable-rgx = "^(_+|(_+[a-zA-Z0-9_]*[a-zA-Z0-9]+?))$"
|
|
233
|
+
|
|
234
|
+
[tool.ruff.lint.mccabe]
|
|
235
|
+
max-complexity = 10
|
|
236
|
+
|
|
237
|
+
[tool.ruff.format]
|
|
238
|
+
quote-style = "double"
|
|
File without changes
|
|
@@ -0,0 +1,92 @@
|
|
|
1
|
+
from contextlib import ExitStack
|
|
2
|
+
from typing import Any, Iterable
|
|
3
|
+
|
|
4
|
+
import rasterio as rio
|
|
5
|
+
from pystac import Item, ItemCollection
|
|
6
|
+
from pystac_client import ItemSearch
|
|
7
|
+
from rasterio import DatasetReader
|
|
8
|
+
from rasterio.env import Env, local
|
|
9
|
+
|
|
10
|
+
from rio_stac_io.utils import require_gdal_version, vsi_href
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
class GTIDatasetReader(DatasetReader):
|
|
14
|
+
links: list[str | None]
|
|
15
|
+
|
|
16
|
+
@require_gdal_version("3.10.0")
|
|
17
|
+
def __init__(
|
|
18
|
+
self,
|
|
19
|
+
item_collection: ItemCollection | ItemSearch,
|
|
20
|
+
asset_key: str,
|
|
21
|
+
**profile: Any,
|
|
22
|
+
) -> None:
|
|
23
|
+
try:
|
|
24
|
+
from geopandas import GeoDataFrame
|
|
25
|
+
from stac_geoparquet.arrow import parse_stac_items_to_arrow
|
|
26
|
+
from stac_geoparquet.arrow._constants import DEFAULT_PARQUET_SCHEMA_VERSION
|
|
27
|
+
except ImportError as e:
|
|
28
|
+
raise ImportError(
|
|
29
|
+
"Missing extra modules. Please install package with as rio-stac-io[gti]"
|
|
30
|
+
) from e
|
|
31
|
+
|
|
32
|
+
with rio.Env() as env:
|
|
33
|
+
if not env.drivers().get("Parquet"):
|
|
34
|
+
raise SystemError(
|
|
35
|
+
"Cannot open Stac Query using GTI driver. "
|
|
36
|
+
"Make sure your GDAL library is build with GeoParquet support."
|
|
37
|
+
)
|
|
38
|
+
|
|
39
|
+
def rewrite_href(assets: dict[str, Any]) -> dict[str, Any]:
|
|
40
|
+
assets[asset_key]["href"] = vsi_href(assets[asset_key]["href"])
|
|
41
|
+
return assets
|
|
42
|
+
|
|
43
|
+
stack = ExitStack()
|
|
44
|
+
|
|
45
|
+
if isinstance(item_collection, ItemSearch):
|
|
46
|
+
_items: Iterable[Item] = item_collection.items()
|
|
47
|
+
else:
|
|
48
|
+
_items = item_collection.items
|
|
49
|
+
|
|
50
|
+
try:
|
|
51
|
+
# Write ItemCollection to a temporary in-memory Parquet file
|
|
52
|
+
# This will create a /vsimem/ path that can be used by the GTI driver
|
|
53
|
+
tmp_path = stack.enter_context(rio.MemoryFile(ext=".parquet"))
|
|
54
|
+
arrow = parse_stac_items_to_arrow(_items)
|
|
55
|
+
gdf = GeoDataFrame.from_arrow(arrow)
|
|
56
|
+
gdf["assets"] = gdf["assets"].apply(rewrite_href)
|
|
57
|
+
|
|
58
|
+
gdf.to_parquet(tmp_path, schema_version=DEFAULT_PARQUET_SCHEMA_VERSION)
|
|
59
|
+
tmp_path.seek(0)
|
|
60
|
+
|
|
61
|
+
href = f"GTI:{tmp_path.name}"
|
|
62
|
+
profile.pop("driver", None)
|
|
63
|
+
profile["LOCATION_FIELD"] = f"assets.{asset_key}.href"
|
|
64
|
+
|
|
65
|
+
self._files: list[str] = (
|
|
66
|
+
gdf["assets"].apply(lambda x: x[asset_key]["href"]).to_list()
|
|
67
|
+
)
|
|
68
|
+
self.links = [item.get_self_href() for item in _items]
|
|
69
|
+
|
|
70
|
+
if not local._env:
|
|
71
|
+
stack.enter_context(Env.from_defaults())
|
|
72
|
+
|
|
73
|
+
super().__init__(href, **profile)
|
|
74
|
+
|
|
75
|
+
self._env = stack
|
|
76
|
+
|
|
77
|
+
except TypeError as e:
|
|
78
|
+
stack.close()
|
|
79
|
+
if "got pyarrow.lib.NullArray" in str(e):
|
|
80
|
+
raise ValueError(
|
|
81
|
+
"Cannot open dataset. Got empty ItemCollection."
|
|
82
|
+
) from e
|
|
83
|
+
|
|
84
|
+
else:
|
|
85
|
+
raise
|
|
86
|
+
except Exception:
|
|
87
|
+
stack.close()
|
|
88
|
+
raise
|
|
89
|
+
|
|
90
|
+
@property
|
|
91
|
+
def files(self) -> list[str]:
|
|
92
|
+
return self._files
|
|
@@ -0,0 +1,137 @@
|
|
|
1
|
+
import json
|
|
2
|
+
import warnings
|
|
3
|
+
from contextlib import ExitStack
|
|
4
|
+
from typing import Any, Iterable, Literal
|
|
5
|
+
|
|
6
|
+
import rasterio as rio
|
|
7
|
+
from packaging.version import parse
|
|
8
|
+
from pystac import Item, ItemCollection
|
|
9
|
+
from pystac_client import ItemSearch
|
|
10
|
+
from rasterio import DatasetReader
|
|
11
|
+
from rasterio.env import Env, GDALVersion, local
|
|
12
|
+
from rasterio.errors import RasterioIOError
|
|
13
|
+
|
|
14
|
+
from rio_stac_io.utils import infer_projection_metadata, vsi_href
|
|
15
|
+
|
|
16
|
+
|
|
17
|
+
def rewrite_item(
|
|
18
|
+
item: Item,
|
|
19
|
+
asset_key: str,
|
|
20
|
+
merge_collections: bool,
|
|
21
|
+
gdal_version: str,
|
|
22
|
+
infer_projection: bool,
|
|
23
|
+
) -> Item:
|
|
24
|
+
item.assets[asset_key].href = vsi_href(item.assets[asset_key].href)
|
|
25
|
+
|
|
26
|
+
if merge_collections:
|
|
27
|
+
# STACIT keeps item from different collections in separate subdatasets
|
|
28
|
+
# We can bypass this by removing the collection reference
|
|
29
|
+
item.collection_id = None
|
|
30
|
+
|
|
31
|
+
if infer_projection:
|
|
32
|
+
# Infer projection metadata if missing
|
|
33
|
+
# This will call the file header of each asset to extract the projection info
|
|
34
|
+
item = infer_projection_metadata(item, asset_key)
|
|
35
|
+
|
|
36
|
+
# STACIT driver only starts supporting STAC v1.1.0 starting in GDAL v3.10.2
|
|
37
|
+
# For lower versions, we need to substitute the `proj:code` property
|
|
38
|
+
# with the now deprecated `proj:epsg`` property
|
|
39
|
+
if parse(gdal_version) < parse("3.10.2"):
|
|
40
|
+
if "proj:code" in item.properties:
|
|
41
|
+
item.properties["proj:epsg"] = int(
|
|
42
|
+
item.properties["proj:code"].replace("EPSG:", "")
|
|
43
|
+
)
|
|
44
|
+
|
|
45
|
+
if "proj:code" in item.assets[asset_key].extra_fields:
|
|
46
|
+
item.assets[asset_key].extra_fields["proj:epsg"] = int(
|
|
47
|
+
item.assets[asset_key].extra_fields["proj:code"].replace("EPSG:", "")
|
|
48
|
+
)
|
|
49
|
+
|
|
50
|
+
return item
|
|
51
|
+
|
|
52
|
+
|
|
53
|
+
class STACITDatasetReader(DatasetReader):
|
|
54
|
+
links: list[str | None]
|
|
55
|
+
|
|
56
|
+
def __init__(
|
|
57
|
+
self,
|
|
58
|
+
item_collection: ItemCollection | ItemSearch,
|
|
59
|
+
asset_key: str,
|
|
60
|
+
merge_collections: bool,
|
|
61
|
+
overlap_strategy: Literal["REMOVE_IF_NO_NODATA", "USE_ALL", "USE_MOST_RECENT"]
|
|
62
|
+
| None = None,
|
|
63
|
+
infer_projection: bool = False,
|
|
64
|
+
**profile: Any,
|
|
65
|
+
) -> None:
|
|
66
|
+
stack = ExitStack()
|
|
67
|
+
|
|
68
|
+
gdal_version = rio.__gdal_version__
|
|
69
|
+
|
|
70
|
+
if isinstance(item_collection, ItemSearch):
|
|
71
|
+
_items: Iterable[Item] = item_collection.items()
|
|
72
|
+
else:
|
|
73
|
+
_items = item_collection.items
|
|
74
|
+
|
|
75
|
+
item_collection = ItemCollection(
|
|
76
|
+
items=[
|
|
77
|
+
rewrite_item(
|
|
78
|
+
item,
|
|
79
|
+
asset_key,
|
|
80
|
+
merge_collections=merge_collections,
|
|
81
|
+
gdal_version=gdal_version,
|
|
82
|
+
infer_projection=infer_projection,
|
|
83
|
+
)
|
|
84
|
+
for item in _items
|
|
85
|
+
]
|
|
86
|
+
)
|
|
87
|
+
|
|
88
|
+
if not item_collection.items:
|
|
89
|
+
raise ValueError("Cannot open dataset. Got empty ItemCollection.")
|
|
90
|
+
|
|
91
|
+
try:
|
|
92
|
+
# Write ItemCollection to a temporary in-memory file
|
|
93
|
+
# this will create a /vsimem/ path that can be used by the STACIT driver
|
|
94
|
+
tmp_path = stack.enter_context(rio.MemoryFile(ext=".json"))
|
|
95
|
+
tmp_path.write(json.dumps(item_collection.to_dict()).encode("utf-8"))
|
|
96
|
+
tmp_path.seek(0)
|
|
97
|
+
|
|
98
|
+
href = f'STACIT:"{tmp_path.name}":asset={asset_key}'
|
|
99
|
+
|
|
100
|
+
if GDALVersion.runtime() < GDALVersion.parse("3.9.1") and (
|
|
101
|
+
overlap_strategy == "USE_ALL"
|
|
102
|
+
):
|
|
103
|
+
warnings.warn(
|
|
104
|
+
"USE_ALL overlap strategy is only supported "
|
|
105
|
+
"starting at GDAL Version 3.9.1. "
|
|
106
|
+
"Using USE_MOST_RECENT instead."
|
|
107
|
+
)
|
|
108
|
+
overlap_strategy = "USE_MOST_RECENT"
|
|
109
|
+
|
|
110
|
+
profile["overlap_strategy"] = overlap_strategy
|
|
111
|
+
|
|
112
|
+
if not local._env:
|
|
113
|
+
stack.enter_context(Env.from_defaults())
|
|
114
|
+
super().__init__(href, **profile)
|
|
115
|
+
|
|
116
|
+
self.links = [
|
|
117
|
+
item.get_self_href()
|
|
118
|
+
for item in item_collection.items
|
|
119
|
+
if item.assets[asset_key].href in self.files
|
|
120
|
+
]
|
|
121
|
+
self._env = stack
|
|
122
|
+
|
|
123
|
+
except RasterioIOError as e:
|
|
124
|
+
stack.close()
|
|
125
|
+
if str(e) == "No compatible asset found" and not infer_projection:
|
|
126
|
+
raise RasterioIOError(
|
|
127
|
+
"No compatible asset found. "
|
|
128
|
+
"This is likely due to missing projection information "
|
|
129
|
+
"in the STAC Item or Asset. "
|
|
130
|
+
"Consider setting the `infer_projection` parameter to `True` "
|
|
131
|
+
"to infer missing projection information."
|
|
132
|
+
) from e
|
|
133
|
+
else:
|
|
134
|
+
raise
|
|
135
|
+
except Exception:
|
|
136
|
+
stack.close()
|
|
137
|
+
raise
|
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+
import os
|
|
2
|
+
import warnings
|
|
3
|
+
from contextlib import ExitStack
|
|
4
|
+
from tempfile import TemporaryDirectory
|
|
5
|
+
from typing import Any
|
|
6
|
+
|
|
7
|
+
import rasterio as rio
|
|
8
|
+
from pystac import Item
|
|
9
|
+
from rasterio.env import Env, local
|
|
10
|
+
|
|
11
|
+
from rio_stac_io.utils import require_gdal_version
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
class STACTADatasetReader(rio.DatasetReader):
|
|
15
|
+
links: list[str | None]
|
|
16
|
+
|
|
17
|
+
@require_gdal_version("3.8.2")
|
|
18
|
+
def __init__(
|
|
19
|
+
self,
|
|
20
|
+
item: Item,
|
|
21
|
+
asset_key: str,
|
|
22
|
+
zoom_level: int | None = None,
|
|
23
|
+
skip_missing_metatile: bool | None = None,
|
|
24
|
+
**profile: Any,
|
|
25
|
+
) -> None:
|
|
26
|
+
stack = ExitStack()
|
|
27
|
+
|
|
28
|
+
if skip_missing_metatile is None:
|
|
29
|
+
skip = os.environ.get("GDAL_STACTA_SKIP_MISSING_METATILE")
|
|
30
|
+
match skip:
|
|
31
|
+
case "NO", "no":
|
|
32
|
+
skip_missing_metatile = False
|
|
33
|
+
case _:
|
|
34
|
+
skip_missing_metatile = True
|
|
35
|
+
|
|
36
|
+
profile["skip_missing_metatile"] = skip_missing_metatile
|
|
37
|
+
|
|
38
|
+
if skip_missing_metatile and not any(
|
|
39
|
+
[ext for ext in item.stac_extensions if "raster" in ext]
|
|
40
|
+
):
|
|
41
|
+
warnings.warn(
|
|
42
|
+
"SKIP_MISSING_METATILE is set to True "
|
|
43
|
+
"but STAC raster extension is not used. "
|
|
44
|
+
"This will likely cause an error.",
|
|
45
|
+
UserWarning,
|
|
46
|
+
)
|
|
47
|
+
|
|
48
|
+
if zoom_level is not None:
|
|
49
|
+
for key, matrix_set in item.properties["tiles:tile_matrix_sets"].items():
|
|
50
|
+
try:
|
|
51
|
+
matrices = matrix_set["tileMatrices"]
|
|
52
|
+
id = "id"
|
|
53
|
+
except KeyError:
|
|
54
|
+
matrices = matrix_set["tileMatrix"]
|
|
55
|
+
id = "identifier"
|
|
56
|
+
|
|
57
|
+
matrix_set["tileMatrices"] = [
|
|
58
|
+
matrix for matrix in matrices if int(matrix[id]) <= zoom_level
|
|
59
|
+
]
|
|
60
|
+
|
|
61
|
+
max_zoom = max(
|
|
62
|
+
[int(matrix[id]) for matrix in matrix_set["tileMatrices"]]
|
|
63
|
+
)
|
|
64
|
+
|
|
65
|
+
if not matrix_set["tileMatrices"] or max_zoom < zoom_level:
|
|
66
|
+
raise ValueError(
|
|
67
|
+
"Requested zoom level is not present in tile matrix set."
|
|
68
|
+
)
|
|
69
|
+
|
|
70
|
+
item.properties["tiles:tile_matrix_sets"][key] = matrix_set
|
|
71
|
+
|
|
72
|
+
try:
|
|
73
|
+
tmp_dir = stack.enter_context(TemporaryDirectory())
|
|
74
|
+
tmp_path = f"{tmp_dir}/stacta.json"
|
|
75
|
+
|
|
76
|
+
item.save_object(dest_href=tmp_path)
|
|
77
|
+
|
|
78
|
+
href = f'STACTA:"{tmp_path}":{asset_key}'
|
|
79
|
+
|
|
80
|
+
self.links = [item.get_self_href()]
|
|
81
|
+
|
|
82
|
+
if not local._env:
|
|
83
|
+
stack.enter_context(Env.from_defaults())
|
|
84
|
+
super().__init__(href, **profile)
|
|
85
|
+
self._env = stack
|
|
86
|
+
|
|
87
|
+
except Exception:
|
|
88
|
+
stack.close()
|
|
89
|
+
raise
|
|
@@ -0,0 +1,332 @@
|
|
|
1
|
+
from typing import Annotated, Any, Literal, overload
|
|
2
|
+
|
|
3
|
+
import pystac
|
|
4
|
+
import pystac_client
|
|
5
|
+
import rasterio as rio
|
|
6
|
+
from pystac import Item, ItemCollection
|
|
7
|
+
from pystac_client import ItemSearch
|
|
8
|
+
|
|
9
|
+
from rio_stac_io.drivers.gti import GTIDatasetReader
|
|
10
|
+
from rio_stac_io.drivers.stacit import STACITDatasetReader
|
|
11
|
+
from rio_stac_io.drivers.stacta import STACTADatasetReader
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
@overload
|
|
15
|
+
def open(
|
|
16
|
+
items: Annotated[
|
|
17
|
+
pystac.ItemCollection | pystac_client.ItemSearch,
|
|
18
|
+
"STAC Items must implement the Projection STAC extension",
|
|
19
|
+
],
|
|
20
|
+
mode: Literal["r"] = "r",
|
|
21
|
+
*,
|
|
22
|
+
asset_key: str,
|
|
23
|
+
use_gti: Literal[False] = False,
|
|
24
|
+
merge_collections: bool = False,
|
|
25
|
+
infer_projection: bool = False,
|
|
26
|
+
max_items: int = 1000,
|
|
27
|
+
collection: str | None = None,
|
|
28
|
+
crs: str | None = None,
|
|
29
|
+
resolution: Literal["AVERAGE", "HIGHEST", "LOWEST"] = "AVERAGE",
|
|
30
|
+
overlap_strategy: Literal[
|
|
31
|
+
"REMOVE_IF_NO_NODATA", "USE_ALL", "USE_MOST_RECENT"
|
|
32
|
+
] = "REMOVE_IF_NO_NODATA",
|
|
33
|
+
) -> STACITDatasetReader:
|
|
34
|
+
"""
|
|
35
|
+
STACIT
|
|
36
|
+
|
|
37
|
+
The [GDAL StacIT driver](https://gdal.org/en/stable/drivers/raster/stacit.html)
|
|
38
|
+
accepts pystac ItemCollections or ItemSearch as input and
|
|
39
|
+
will return a rasterio Dataset, similar to a VRT.
|
|
40
|
+
This driver is used by default when using a ItemCollection or ItemSearch as input.
|
|
41
|
+
|
|
42
|
+
STAC Items must use the [STAC Projection extension](https://github.com/stac-extensions/projection),
|
|
43
|
+
providing metadata about CRS used, projected bounds and Affine transformation.
|
|
44
|
+
Items without this metadata will be ignored.
|
|
45
|
+
|
|
46
|
+
By default, STACIT will split items from different STAC collections
|
|
47
|
+
or with different projections into subdatasets.
|
|
48
|
+
You can force the driver to return a single dataset
|
|
49
|
+
by either filtering by CRS or Collections or telling it
|
|
50
|
+
to merge all collections setting `merge_collections=True`.
|
|
51
|
+
|
|
52
|
+
If you need to merge items using different projection
|
|
53
|
+
consider using the GTI driver instead.
|
|
54
|
+
|
|
55
|
+
While the StacIT driver only fully supports STAC v1.1.0
|
|
56
|
+
Items starting with GDAL 3.10.2, `rio-stac-io` will assure
|
|
57
|
+
backwards compatibility also for earlier GDAL versions.
|
|
58
|
+
|
|
59
|
+
Parameters
|
|
60
|
+
----------
|
|
61
|
+
items : pystac.ItemCollection or pystac_client.ItemSearch
|
|
62
|
+
Input STAC Items. Items must implement the Projection STAC extension.
|
|
63
|
+
mode : Literal["r"], default "r"
|
|
64
|
+
Read-only mode.
|
|
65
|
+
asset_key : str
|
|
66
|
+
Asset to open.
|
|
67
|
+
use_gti : Literal[False], default False
|
|
68
|
+
Must be set to False to use the STACIT driver.
|
|
69
|
+
merge_collections : bool, default False
|
|
70
|
+
Combine items from multiple collections into a single dataset.
|
|
71
|
+
infer_projection : bool, default False
|
|
72
|
+
Infer projection metadata if missing.
|
|
73
|
+
This will call the file header of each asset to extract the projection metadata.
|
|
74
|
+
max_items : int, default 1000
|
|
75
|
+
Maximum number of items fetched. 0 means unlimited.
|
|
76
|
+
collection : str or None, optional
|
|
77
|
+
Name of collection to filter items.
|
|
78
|
+
crs : str or None, optional
|
|
79
|
+
Name of CRS to filter items.
|
|
80
|
+
resolution : Literal["AVERAGE", "HIGHEST", "LOWEST"], default "AVERAGE"
|
|
81
|
+
Strategy to use to determine dataset resolution.
|
|
82
|
+
overlap_strategy : Literal["REMOVE_IF_NO_NODATA", "USE_ALL", "USE_MOST_RECENT"],
|
|
83
|
+
default "REMOVE_IF_NO_NODATA"
|
|
84
|
+
Strategy to use when the ItemCollections contains overlapping items.
|
|
85
|
+
|
|
86
|
+
Returns
|
|
87
|
+
-------
|
|
88
|
+
rio.DatasetReader
|
|
89
|
+
A rasterio DatasetReader object.
|
|
90
|
+
""" # noqa: E501
|
|
91
|
+
...
|
|
92
|
+
|
|
93
|
+
|
|
94
|
+
@overload
|
|
95
|
+
def open(
|
|
96
|
+
items: Annotated[
|
|
97
|
+
pystac.ItemCollection | pystac_client.ItemSearch,
|
|
98
|
+
"STAC Items must implement the Projection STAC extension",
|
|
99
|
+
],
|
|
100
|
+
mode: Literal["r"] = "r",
|
|
101
|
+
*,
|
|
102
|
+
asset_key: str,
|
|
103
|
+
use_gti: Literal[True] = True,
|
|
104
|
+
sort_field: str | None = None,
|
|
105
|
+
sort_field_asc: bool = True,
|
|
106
|
+
filter: str | None = None,
|
|
107
|
+
resx: float | None = None,
|
|
108
|
+
resy: float | None = None,
|
|
109
|
+
srs: str | None = None,
|
|
110
|
+
minx: float | None = None,
|
|
111
|
+
miny: float | None = None,
|
|
112
|
+
maxx: float | None = None,
|
|
113
|
+
maxy: float | None = None,
|
|
114
|
+
) -> GTIDatasetReader:
|
|
115
|
+
"""
|
|
116
|
+
GTI
|
|
117
|
+
|
|
118
|
+
Similar to STACIT, the [GDAL GTI driver](https://gdal.org/en/stable/drivers/raster/gti.html)
|
|
119
|
+
accepts pystac ItemCollections or ItemSearch as input and will return a rasterio Dataset,
|
|
120
|
+
similar to a VRT.
|
|
121
|
+
|
|
122
|
+
The GTI driver requires GDAL version 3.10 or later
|
|
123
|
+
and GDAL must be built with (geo)parquet support.
|
|
124
|
+
In addition, rio-stac-io needs to be installed together with the `gti` extras.
|
|
125
|
+
|
|
126
|
+
Because of the extra dependencies, this driver is not the default and users
|
|
127
|
+
must opt into it by setting `use_gti=True`.
|
|
128
|
+
|
|
129
|
+
Unlike STACIT, GTI will always combine input items into a single rasterio Dataset.
|
|
130
|
+
Items in different projections will be reprojected into the projection of the first item.
|
|
131
|
+
The user can also set a different output projection by setting the `srs` argument.
|
|
132
|
+
|
|
133
|
+
Parameters
|
|
134
|
+
----------
|
|
135
|
+
items : pystac.ItemCollection or pystac_client.ItemSearch
|
|
136
|
+
Input STAC Items. Items must implement the Projection STAC extension.
|
|
137
|
+
mode : Literal["r"], default "r"
|
|
138
|
+
Read-only mode.
|
|
139
|
+
asset_key : str
|
|
140
|
+
Asset to open.
|
|
141
|
+
use_gti : Literal[True], default True
|
|
142
|
+
Must be set to True in order to use this driver.
|
|
143
|
+
sort_field : str or None, optional
|
|
144
|
+
Name of a field to use to control the order in which tiles are composited,
|
|
145
|
+
when they overlap (z-order).
|
|
146
|
+
That field may be of type String, Integer, Integer64, Date or DateTime.
|
|
147
|
+
By default, the higher the value in that field,
|
|
148
|
+
the last the corresponding tile will be rendered in the virtual mosaic (unless
|
|
149
|
+
SORT_FIELD_ASC=NO is set).
|
|
150
|
+
sort_field_asc : bool, default True
|
|
151
|
+
Whether the values in SORT_FIELD should be sorted in ascending or descending order.
|
|
152
|
+
filter : str or None, optional
|
|
153
|
+
Value of a SQL WHERE clause, used to select a subset of the features of the index.
|
|
154
|
+
resx : float or None, optional
|
|
155
|
+
Resolution along X axis in SRS units / pixel.
|
|
156
|
+
resy : float or None, optional
|
|
157
|
+
Resolution along Y axis in SRS units / pixel.
|
|
158
|
+
srs : str or None, optional
|
|
159
|
+
Override/sets the Spatial Reference System.
|
|
160
|
+
minx : float or None, optional
|
|
161
|
+
Minimum X value for the virtual mosaic extent.
|
|
162
|
+
miny : float or None, optional
|
|
163
|
+
Minimum Y value for the virtual mosaic extent.
|
|
164
|
+
maxx : float or None, optional
|
|
165
|
+
Maximum X value for the virtual mosaic extent.
|
|
166
|
+
maxy : float or None, optional
|
|
167
|
+
Maximum Y value for the virtual mosaic extent.
|
|
168
|
+
|
|
169
|
+
Returns
|
|
170
|
+
-------
|
|
171
|
+
rio.DatasetReader
|
|
172
|
+
A rasterio DatasetReader object.
|
|
173
|
+
""" # noqa: E501
|
|
174
|
+
...
|
|
175
|
+
|
|
176
|
+
|
|
177
|
+
@overload
|
|
178
|
+
def open( # type: ignore[overload-cannot-match] # passes on macos but not linux ¯\_(ツ)_/¯
|
|
179
|
+
items: Annotated[pystac.Item, "regular STAC Item"],
|
|
180
|
+
mode: Literal["r"] = "r",
|
|
181
|
+
*,
|
|
182
|
+
asset_key: str,
|
|
183
|
+
) -> rio.DatasetReader:
|
|
184
|
+
"""
|
|
185
|
+
STAC Item
|
|
186
|
+
|
|
187
|
+
A regular STAC Item can be opened directly with rasterio.
|
|
188
|
+
|
|
189
|
+
Parameters
|
|
190
|
+
----------
|
|
191
|
+
items : pystac.Item
|
|
192
|
+
Input STAC Item. Must implement the Tiled Asset STAC extension.
|
|
193
|
+
mode : Literal["r"], default "r"
|
|
194
|
+
Read-only mode.
|
|
195
|
+
asset_key : str
|
|
196
|
+
Asset to open.
|
|
197
|
+
|
|
198
|
+
Returns
|
|
199
|
+
-------
|
|
200
|
+
rio.DatasetReader
|
|
201
|
+
A rasterio DatasetReader object.
|
|
202
|
+
"""
|
|
203
|
+
...
|
|
204
|
+
|
|
205
|
+
|
|
206
|
+
@overload
|
|
207
|
+
def open( # type: ignore[overload-cannot-match] # passes on macos but not linux ¯\_(ツ)_/¯
|
|
208
|
+
items: Annotated[pystac.Item, "uses tiled-assets STAC extension"],
|
|
209
|
+
mode: Literal["r"] = "r",
|
|
210
|
+
*,
|
|
211
|
+
asset_key: str,
|
|
212
|
+
zoom_level: int | None = None,
|
|
213
|
+
whole_metatile: bool = True,
|
|
214
|
+
skip_missing_metatile: bool = True,
|
|
215
|
+
) -> STACTADatasetReader:
|
|
216
|
+
"""
|
|
217
|
+
STACTA
|
|
218
|
+
|
|
219
|
+
The [GDAL StacTA driver](https://gdal.org/en/stable/drivers/raster/stacta.html)
|
|
220
|
+
accepts a single STAC item that implements the
|
|
221
|
+
[tiled-assets STAC extension](https://github.com/stac-extensions/tiled-assets/tree/main).
|
|
222
|
+
The driver is designed to open gridded data that are stored following the TMS specifications
|
|
223
|
+
(i.e., Z/X/Y file path). All data will be loaded lazily.
|
|
224
|
+
|
|
225
|
+
When using GDAL versions prior to v3.8.x, the driver expects all tiles of the Tile matrix to be present.
|
|
226
|
+
Later versions will try to use the [STAC Raster extension](https://github.com/stac-extensions/raster/tree/main)
|
|
227
|
+
metadata (if present) to infer datatype and no data value.
|
|
228
|
+
When using sparse tiles you must set `skip_missing_metatile=True`.
|
|
229
|
+
|
|
230
|
+
Parameters
|
|
231
|
+
----------
|
|
232
|
+
items : pystac.Item
|
|
233
|
+
Input STAC Item. Must implement the Tiled Asset STAC extension.
|
|
234
|
+
mode : Literal["r"], default "r"
|
|
235
|
+
Read-only mode.
|
|
236
|
+
asset_key : str
|
|
237
|
+
Asset to open.
|
|
238
|
+
zoom_level : int or None, optional
|
|
239
|
+
Specific zoom level to open. Will default to the max zoom level specified in the tile matrix set.
|
|
240
|
+
whole_metatile : bool, default True
|
|
241
|
+
If set to True, metatiles will be entirely downloaded (into memory).
|
|
242
|
+
Otherwise, by default, if metatiles are bigger than a threshold,
|
|
243
|
+
they will be accessed in a piece-wise way.
|
|
244
|
+
skip_missing_metatile : bool, default True
|
|
245
|
+
If set to True, metatiles that are missing will be skipped without error,
|
|
246
|
+
and the corresponding area in the dataset will be filled with the nodata value or zero if there is no nodata value.
|
|
247
|
+
This setting will require the implementation of the STAC Raster Extension.
|
|
248
|
+
This setting can also be set with the GDAL_STACTA_SKIP_MISSING_METATILE configuration option.
|
|
249
|
+
|
|
250
|
+
Returns
|
|
251
|
+
-------
|
|
252
|
+
rio.DatasetReader
|
|
253
|
+
A rasterio DatasetReader object.
|
|
254
|
+
""" # noqa: E501
|
|
255
|
+
...
|
|
256
|
+
|
|
257
|
+
|
|
258
|
+
def open(
|
|
259
|
+
items: Item | ItemCollection | ItemSearch,
|
|
260
|
+
mode: Literal["r"] = "r",
|
|
261
|
+
*,
|
|
262
|
+
asset_key: str,
|
|
263
|
+
use_gti: bool = False,
|
|
264
|
+
merge_collections: bool = False,
|
|
265
|
+
infer_projection: bool = False,
|
|
266
|
+
zoom_level: int | None = None,
|
|
267
|
+
**kwargs: Any,
|
|
268
|
+
) -> rio.DatasetReader:
|
|
269
|
+
"""rio-stac-io accepts any pystac Item, ItemCollection or ItemSearch
|
|
270
|
+
and returns a rasterio DatasetReader.
|
|
271
|
+
Input items will be merged into a single layer,
|
|
272
|
+
similar to a VRT and served as a single rasterio Dataset.
|
|
273
|
+
If you need to read time series,
|
|
274
|
+
consider using [ODC STAC](https://github.com/opendatacube/odc-stac)
|
|
275
|
+
that will return an multi-dimensional XArray object instead.
|
|
276
|
+
|
|
277
|
+
```python
|
|
278
|
+
|
|
279
|
+
from pystac_client import Client
|
|
280
|
+
|
|
281
|
+
import rio_stac_io as stacio
|
|
282
|
+
|
|
283
|
+
client = Client.open(...)
|
|
284
|
+
search = client.search(...)
|
|
285
|
+
|
|
286
|
+
with stacio.open(search, asset_key="data") as src:
|
|
287
|
+
data = src.read()
|
|
288
|
+
|
|
289
|
+
```
|
|
290
|
+
|
|
291
|
+
# Drivers
|
|
292
|
+
|
|
293
|
+
rio-stac-io will determine which driver to use based on your input data.
|
|
294
|
+
By default, it will use the STACIT driver for all
|
|
295
|
+
ItemCollection and ItemSearch inputs.
|
|
296
|
+
If you set `use_gti=True`, it will use the GTI driver instead.
|
|
297
|
+
When provided with a single Item as input, it will use the
|
|
298
|
+
STACTA driver if the item uses the tiled-asset STAC extension
|
|
299
|
+
and rasterio when using a regular item.
|
|
300
|
+
|
|
301
|
+
See overloaded function signatures for details.
|
|
302
|
+
|
|
303
|
+
"""
|
|
304
|
+
|
|
305
|
+
if mode != "r":
|
|
306
|
+
raise ValueError(
|
|
307
|
+
f"This is a read-only dataset. Mode `{mode}` is not supported."
|
|
308
|
+
)
|
|
309
|
+
|
|
310
|
+
if isinstance(items, Item):
|
|
311
|
+
if any([ext for ext in items.stac_extensions if "tiled-assets" in ext]):
|
|
312
|
+
return STACTADatasetReader(
|
|
313
|
+
items, asset_key, zoom_level=zoom_level, **kwargs
|
|
314
|
+
)
|
|
315
|
+
else:
|
|
316
|
+
return rio.open(items.assets[asset_key].href)
|
|
317
|
+
|
|
318
|
+
elif isinstance(items, (ItemCollection, ItemSearch)):
|
|
319
|
+
if use_gti:
|
|
320
|
+
return GTIDatasetReader(items, asset_key, **kwargs)
|
|
321
|
+
|
|
322
|
+
else:
|
|
323
|
+
return STACITDatasetReader(
|
|
324
|
+
items,
|
|
325
|
+
asset_key,
|
|
326
|
+
merge_collections=merge_collections,
|
|
327
|
+
infer_projection=infer_projection,
|
|
328
|
+
**kwargs,
|
|
329
|
+
)
|
|
330
|
+
|
|
331
|
+
else:
|
|
332
|
+
return rio.open(items, **kwargs)
|
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
from functools import wraps
|
|
2
|
+
from typing import Any, Callable
|
|
3
|
+
|
|
4
|
+
import rasterio as rio
|
|
5
|
+
from packaging.version import parse
|
|
6
|
+
from pystac import Item
|
|
7
|
+
from pystac.extensions.projection import AssetProjectionExtension
|
|
8
|
+
from rasterio import __gdal_version__
|
|
9
|
+
from rasterio.errors import GDALVersionError
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
def require_gdal_version(gdal_version: str) -> Callable:
|
|
13
|
+
def decorator(function: Callable) -> Callable:
|
|
14
|
+
@wraps(function)
|
|
15
|
+
def wrapper(*args: Any, **kwargs: Any) -> Any:
|
|
16
|
+
runtime = parse(__gdal_version__)
|
|
17
|
+
required = parse(gdal_version)
|
|
18
|
+
|
|
19
|
+
if not runtime >= required:
|
|
20
|
+
raise GDALVersionError(
|
|
21
|
+
f"Selected Driver requires GDAL Version {gdal_version} or higher."
|
|
22
|
+
)
|
|
23
|
+
|
|
24
|
+
return function(*args, **kwargs)
|
|
25
|
+
|
|
26
|
+
return wrapper
|
|
27
|
+
|
|
28
|
+
return decorator
|
|
29
|
+
|
|
30
|
+
|
|
31
|
+
def vsi_href(href: str) -> str:
|
|
32
|
+
if href.startswith("http"):
|
|
33
|
+
href = f"/vsicurl/{href}"
|
|
34
|
+
elif href.startswith("s3://"):
|
|
35
|
+
href = href.replace("s3://", "/vsis3/")
|
|
36
|
+
elif href.startswith("gs://"):
|
|
37
|
+
href = href.replace("gs://", "/vsigs/")
|
|
38
|
+
return href
|
|
39
|
+
|
|
40
|
+
|
|
41
|
+
def has_projection_metadata(properties: dict[str, Any]) -> bool:
|
|
42
|
+
"""Check if all required projection metadata is present
|
|
43
|
+
GDAL requires the following fields:
|
|
44
|
+
1. proj:code or proj:wkt2 or proj:projjson (one of them filled with non-null values)
|
|
45
|
+
2. Any of the following:
|
|
46
|
+
proj:transform and proj:shape
|
|
47
|
+
proj:transform and proj:bbox
|
|
48
|
+
proj:bbox and proj:shape
|
|
49
|
+
"""
|
|
50
|
+
crs_info = ["proj:code", "proj:wkt2", "proj:projjson", "proj:epsg"]
|
|
51
|
+
proj_info = [
|
|
52
|
+
("proj:transform", "proj:shape"),
|
|
53
|
+
("proj:transform", "proj:bbox"),
|
|
54
|
+
("proj:bbox", "proj:shape"),
|
|
55
|
+
]
|
|
56
|
+
if not any(key in properties for key in crs_info) and not any(
|
|
57
|
+
all(key in properties for key in pair) for pair in proj_info
|
|
58
|
+
):
|
|
59
|
+
return False
|
|
60
|
+
return True
|
|
61
|
+
|
|
62
|
+
|
|
63
|
+
def infer_projection_metadata(item: Item, asset_key: str) -> Item:
|
|
64
|
+
"""Infer projection metadata in the asset's extra_fields if missing"""
|
|
65
|
+
|
|
66
|
+
if not has_projection_metadata(
|
|
67
|
+
item.assets[asset_key].extra_fields
|
|
68
|
+
) and not has_projection_metadata(item.properties):
|
|
69
|
+
with rio.open(item.assets[asset_key].href) as src:
|
|
70
|
+
asset = AssetProjectionExtension.ext(
|
|
71
|
+
item.assets[asset_key], add_if_missing=True
|
|
72
|
+
)
|
|
73
|
+
asset.bbox = list(src.bounds)
|
|
74
|
+
asset.transform = list(src.transform)
|
|
75
|
+
asset.shape = [src.height, src.width]
|
|
76
|
+
asset.code = src.crs.to_string()
|
|
77
|
+
return item
|