EOX GitLab Instance
Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
V
VS
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Deploy
Releases
Container Registry
Model registry
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
ESA
PRISM
VS
Commits
37eb8d37
Commit
37eb8d37
authored
4 years ago
by
Fabian Schindler
Browse files
Options
Downloads
Patches
Plain Diff
Fixing subdataset step
parent
8207db8f
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
preprocessor/preprocessor/steps/subdataset.py
+21
-18
21 additions, 18 deletions
preprocessor/preprocessor/steps/subdataset.py
with
21 additions
and
18 deletions
preprocessor/preprocessor/steps/subdataset.py
+
21
−
18
View file @
37eb8d37
import
os
from
os.path
import
join
,
splitext
,
basename
from
os.path
import
join
,
splitext
,
basename
,
dirname
from
glob
import
glob
from
typing
import
Se
t
from
typing
import
Dic
t
from
osgeo
import
gdal
from
..util
import
replace_ext
def
extract_subdataset_step
(
source_dir
:
os
.
PathLike
,
target_dir
:
os
.
PathLike
,
data_file_glob
:
str
,
subdataset_types
:
Set
[
str
]
=
None
):
for
filename
in
glob
(
join
(
source_dir
,
data_file_glob
)):
gdal
.
UseExceptions
()
def
extract_subdataset_step
(
source_dir
:
os
.
PathLike
,
target_dir
:
os
.
PathLike
,
data_file_glob
:
str
,
subdataset_types
:
Dict
[
str
,
str
]
=
None
):
datafiles
=
glob
(
join
(
source_dir
,
data_file_glob
))
if
not
datafiles
:
raise
Exception
(
'
No datafiles were matched by the provided glob
'
)
for
filename
in
datafiles
:
extract_subdatasets
(
filename
,
join
(
target_dir
,
basename
(
replace_ext
(
filename
,
'
.tif
'
))),
target_dir
,
subdataset_types
)
def
extract_subdatasets
(
source_filename
:
os
.
PathLike
,
target_
filename
:
os
.
PathLike
,
subdataset_types
:
Set
[
str
]
=
None
):
def
extract_subdatasets
(
source_filename
:
os
.
PathLike
,
target_
dir
:
os
.
PathLike
,
subdataset_types
:
Dict
[
str
,
str
]
=
None
):
ds
=
gdal
.
Open
(
source_filename
)
sub_datasets
=
[]
for
locator
,
_
in
ds
.
GetSubDatasets
():
_
,
_
,
sd_type
=
locator
.
split
(
'
:
'
)
if
subdataset_types
is
None
or
sd_type
in
subdataset_types
:
sub_datasets
.
append
(
locator
)
# combine as VRT
out_vrt_name
=
join
(
source_dir
,
replace_ext
(
filename
,
'
.vrt
'
))
gdal
.
BuildVRT
(
out_vrt_name
,
sub_datasets
,
# TODO: options
)
# TODO: maybe just translate here?
gdal
.
Warp
(
target_filename
,
out_vrt_name
)
sub_datasets
.
append
((
locator
,
subdataset_types
[
sd_type
]))
if
not
sub_datasets
:
raise
Exception
(
'
No subdatasets were matched by the provided types
'
)
for
locator
,
suffix
in
sub_datasets
:
target_filename
=
join
(
target_dir
,
basename
(
replace_ext
(
source_filename
,
'
%s.tif
'
%
suffix
)))
gdal
.
Translate
(
target_filename
,
locator
,
format
=
'
GTiff
'
)
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment