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
0fb58ef8
Commit
0fb58ef8
authored
Mar 29, 2019
by
Daniel Scheffler
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Nodata values are now properly written to ENVI header files.
parent
8d362c57
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
37 additions
and
28 deletions
+37
-28
geoarray/baseclasses.py
geoarray/baseclasses.py
+24
-20
geoarray/metadata.py
geoarray/metadata.py
+13
-8
No files found.
geoarray/baseclasses.py
View file @
0fb58ef8
...
...
@@ -354,7 +354,7 @@ class GeoArray(object):
if
not
self
.
is_inmem
:
self
.
set_gdalDataset_meta
()
if
self
.
_nodata
is
None
:
self
.
_nodata
=
self
.
find_noDataVal
()
self
.
find_noDataVal
()
if
self
.
_nodata
==
'ambiguous'
:
warnings
.
warn
(
'Nodata value could not be clearly identified. It has been set to None.'
)
self
.
_nodata
=
None
...
...
@@ -369,6 +369,9 @@ class GeoArray(object):
# type: (Union[int, None]) -> None
self
.
_nodata
=
value
if
self
.
_metadata
and
value
is
not
None
:
self
.
metadata
.
global_meta
.
update
({
'data ignore value'
:
str
(
value
)})
@
property
def
mask_nodata
(
self
):
"""
...
...
@@ -515,7 +518,7 @@ class GeoArray(object):
if
self
.
_metadata
is
not
None
:
return
self
.
_metadata
else
:
default
=
GDAL_Metadata
(
nbands
=
self
.
bands
)
default
=
GDAL_Metadata
(
nbands
=
self
.
bands
,
nodata_allbands
=
self
.
_nodata
)
self
.
_metadata
=
default
if
not
self
.
is_inmem
:
...
...
@@ -705,6 +708,7 @@ class GeoArray(object):
else
:
nodata
=
None
self
.
nodata
=
nodata
return
nodata
def
set_gdalDataset_meta
(
self
):
...
...
@@ -736,12 +740,12 @@ class GeoArray(object):
if
'nodata'
not
in
self
.
_initParams
or
self
.
_initParams
[
'nodata'
]
is
None
:
band
=
ds
.
GetRasterBand
(
1
)
# FIXME this does not support different nodata values within the same file
self
.
_
nodata
=
band
.
GetNoDataValue
()
self
.
nodata
=
band
.
GetNoDataValue
()
# set metadata attribute
if
self
.
is_inmem
or
not
self
.
filePath
:
# metadata cannot be read from disk -> set it to the default
self
.
_metadata
=
GDAL_Metadata
(
nbands
=
self
.
bands
)
self
.
_metadata
=
GDAL_Metadata
(
nbands
=
self
.
bands
,
nodata_allbands
=
self
.
_nodata
)
else
:
self
.
_metadata
=
GDAL_Metadata
(
filePath
=
self
.
filePath
)
...
...
@@ -977,27 +981,27 @@ class GeoArray(object):
gdal
.
Unlink
(
out_path
+
'.aux.xml'
)
elif
self
.
metadata
.
all_meta
:
# set global domain metadata
if
self
.
metadata
.
global_meta
:
ds_out
.
SetMetadata
(
dict
((
k
,
repr
(
v
))
for
k
,
v
in
self
.
metadata
.
global_meta
.
items
()))
# set global domain metadata
if
self
.
metadata
.
global_meta
:
ds_out
.
SetMetadata
(
dict
((
k
,
repr
(
v
))
for
k
,
v
in
self
.
metadata
.
global_meta
.
items
()))
if
'description'
in
envi_metadict
:
ds_out
.
SetDescription
(
envi_metadict
[
'description'
])
if
'description'
in
envi_metadict
:
ds_out
.
SetDescription
(
envi_metadict
[
'description'
])
# set band domain metadata
bandmeta_dict
=
self
.
metadata
.
to_DataFrame
().
astype
(
str
).
to_dict
()
# set band domain metadata
bandmeta_dict
=
self
.
metadata
.
to_DataFrame
().
astype
(
str
).
to_dict
()
for
bidx
in
range
(
self
.
bands
):
band
=
ds_out
.
GetRasterBand
(
bidx
+
1
)
bandmeta
=
bandmeta_dict
[
bidx
]
# meta2write = dict((k, repr(v)) for k, v in self.metadata.band_meta.items() if v is not np.nan)
band
.
SetMetadata
(
bandmeta
)
for
bidx
in
range
(
self
.
bands
):
band
=
ds_out
.
GetRasterBand
(
bidx
+
1
)
bandmeta
=
bandmeta_dict
[
bidx
]
# meta2write = dict((k, repr(v)) for k, v in self.metadata.band_meta.items() if v is not np.nan)
band
.
SetMetadata
(
bandmeta
)
if
'band_names'
in
envi_metadict
:
band
.
SetDescription
(
self
.
metadata
.
band_meta
[
'band_names'
][
bidx
].
strip
())
if
'band_names'
in
envi_metadict
:
band
.
SetDescription
(
self
.
metadata
.
band_meta
[
'band_names'
][
bidx
].
strip
())
band
.
FlushCache
()
del
band
band
.
FlushCache
()
del
band
ds_out
.
FlushCache
()
del
ds_out
...
...
geoarray/metadata.py
View file @
0fb58ef8
...
...
@@ -4,6 +4,7 @@ import os
from
pprint
import
pformat
from
copy
import
deepcopy
from
typing
import
Union
# noqa F401 # flake8 issue
from
collections
import
OrderedDict
from
geopandas
import
GeoDataFrame
,
GeoSeries
import
numpy
as
np
...
...
@@ -27,18 +28,22 @@ autohandled_meta = [
class
GDAL_Metadata
(
object
):
def
__init__
(
self
,
filePath
=
''
,
nbands
=
1
):
def
__init__
(
self
,
filePath
=
''
,
nbands
=
1
,
nodata_allbands
=
None
):
# privates
self
.
_global_meta
=
d
ict
()
self
.
_band_meta
=
d
ict
()
self
.
_global_meta
=
OrderedD
ict
()
self
.
_band_meta
=
OrderedD
ict
()
self
.
bands
=
nbands
self
.
filePath
=
filePath
self
.
fileFormat
=
''
self
.
nodata_allbands
=
nodata_allbands
if
filePath
:
self
.
read_from_file
(
filePath
)
if
nodata_allbands
is
not
None
:
self
.
global_meta
.
update
({
'data ignore value'
:
str
(
nodata_allbands
)})
@
classmethod
def
from_file
(
cls
,
filePath
):
return
GDAL_Metadata
(
filePath
=
filePath
)
...
...
@@ -73,8 +78,8 @@ class GDAL_Metadata(object):
@
band_meta
.
setter
def
band_meta
(
self
,
meta_dict
):
if
not
isinstance
(
meta_dict
,
dict
):
raise
TypeError
(
"Expected type 'dict', received '%s'."
%
type
(
meta_dict
))
if
not
isinstance
(
meta_dict
,
(
dict
,
OrderedDict
)
):
raise
TypeError
(
"Expected type 'dict'
/'OrderedDict'
, received '%s'."
%
type
(
meta_dict
))
for
k
,
v
in
meta_dict
.
items
():
if
not
isinstance
(
v
,
list
):
...
...
@@ -83,11 +88,11 @@ class GDAL_Metadata(object):
raise
ValueError
(
"The length of the given lists must be equal to the number of bands. "
"Received a list with %d items for '%s'."
%
(
len
(
v
),
k
))
self
.
_band_meta
=
meta_dict
# TODO convert strings to useful types
self
.
_band_meta
=
OrderedDict
(
meta_dict
)
# TODO convert strings to useful types
@
property
def
all_meta
(
self
):
all_meta
=
self
.
global_meta
.
copy
(
)
all_meta
=
OrderedDict
(
self
.
global_meta
.
copy
()
)
all_meta
.
update
(
self
.
band_meta
)
return
all_meta
...
...
@@ -190,7 +195,7 @@ class GDAL_Metadata(object):
return
'Metadata:
\n\n
'
+
pformat
(
self
.
all_meta
)
def
to_ENVI_metadict
(
self
):
return
d
ict
(
zip
(
self
.
all_meta
.
keys
(),
return
OrderedD
ict
(
zip
(
self
.
all_meta
.
keys
(),
[
self
.
_convert_param_to_ENVI_str
(
i
)
for
i
in
self
.
all_meta
.
values
()]))
def
get_subset
(
self
,
bands2extract
=
None
,
keys2extract
=
None
):
...
...
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