Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
G
geoarray
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
6
Issues
6
List
Boards
Labels
Service Desk
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Operations
Operations
Incidents
Environments
Packages & Registries
Packages & Registries
Container Registry
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Daniel Scheffler
geoarray
Commits
a0b2b7bc
Commit
a0b2b7bc
authored
Aug 08, 2018
by
Daniel Scheffler
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Band names and description are now correctly saved in ENVI format.
parent
e04db20b
Pipeline
#3067
failed with stages
in 1 minute and 12 seconds
Changes
1
Pipelines
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
25 additions
and
4 deletions
+25
-4
geoarray/baseclasses.py
geoarray/baseclasses.py
+25
-4
No files found.
geoarray/baseclasses.py
View file @
a0b2b7bc
...
...
@@ -884,6 +884,8 @@ class GeoArray(object):
if
not
os
.
path
.
isdir
(
os
.
path
.
dirname
(
out_path
)):
os
.
makedirs
(
os
.
path
.
dirname
(
out_path
))
envi_metadict
=
self
.
metadata
.
to_ENVI_metadict
()
if
self
.
is_inmem
:
ds_inmem
=
get_GDAL_ds_inmem
(
self
.
arr
,
self
.
geotransform
,
self
.
projection
,
self
.
nodata
)
# expects rows,columns,bands
...
...
@@ -895,12 +897,16 @@ class GeoArray(object):
# set metadata
# NOTE: The dataset has to be written BEFORE metadata are added. Otherwise, metadata are not written.
if
fmt
==
'ENVI'
:
envi_metadict
=
self
.
metadata
.
to_ENVI_metadict
()
ds_out
.
SetMetadata
(
envi_metadict
,
'ENVI'
)
if
'band_names'
in
envi_metadict
:
ds_out
.
SetMetadata
({
'Band_%s'
%
str
(
bidx
+
1
):
self
.
metadata
.
band_meta
[
'band_names'
][
bidx
]
for
bidx
in
range
(
self
.
bands
)})
for
bidx
in
range
(
self
.
bands
):
band
=
ds_out
.
GetRasterBand
(
bidx
+
1
)
band
.
SetDescription
(
self
.
metadata
.
band_meta
[
'band_names'
][
bidx
])
del
band
if
'description'
in
envi_metadict
:
ds_out
.
SetDescription
(
envi_metadict
[
'description'
])
ds_out
.
FlushCache
()
gdal
.
Unlink
(
out_path
+
'.aux.xml'
)
...
...
@@ -910,12 +916,18 @@ class GeoArray(object):
if
self
.
metadata
.
global_meta
:
ds_out
.
SetMetadata
(
self
.
metadata
.
global_meta
)
if
'description'
in
envi_metadict
:
ds_out
.
SetDescription
(
envi_metadict
[
'description'
])
# set band domain metadata
for
bidx
in
range
(
self
.
bands
):
band
=
ds_out
.
GetRasterBand
(
bidx
+
1
)
meta2write
=
dict
((
k
,
repr
(
v
))
for
k
,
v
in
self
.
metadata
.
band_meta
.
items
()
if
v
is
not
np
.
nan
)
band
.
SetMetadata
(
meta2write
)
if
'band_names'
in
envi_metadict
:
band
.
SetDescription
(
self
.
metadata
.
band_meta
[
'band_names'
][
bidx
])
band
.
FlushCache
()
del
band
...
...
@@ -935,6 +947,15 @@ class GeoArray(object):
gdal_Translate
(
out_path
,
src_ds
,
format
=
fmt
,
creationOptions
=
creationOptions
)
del
src_ds
# add band names
if
'band_names'
in
envi_metadict
:
ds_out
=
gdal
.
Open
(
out_path
)
for
bidx
in
range
(
self
.
bands
):
band
=
ds_out
.
GetRasterBand
(
bidx
+
1
)
band
.
SetDescription
(
self
.
metadata
.
band_meta
[
'band_names'
][
bidx
])
del
band
if
not
os
.
path
.
exists
(
out_path
):
raise
Exception
(
gdal
.
GetLastErrorMsg
())
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment