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
b9b19c2a
Commit
b9b19c2a
authored
Aug 08, 2018
by
Daniel Scheffler
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
GDAL_Metadata instances are now subscriptable.
parent
7b1ca393
Pipeline
#3072
failed with stages
in 1 minute and 21 seconds
Changes
2
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
54 additions
and
6 deletions
+54
-6
geoarray/baseclasses.py
geoarray/baseclasses.py
+1
-1
geoarray/metadata.py
geoarray/metadata.py
+53
-5
No files found.
geoarray/baseclasses.py
View file @
b9b19c2a
...
@@ -1487,7 +1487,7 @@ class GeoArray(object):
...
@@ -1487,7 +1487,7 @@ class GeoArray(object):
# apply zslice to bandnames and metadata
# apply zslice to bandnames and metadata
if
zslicing
:
if
zslicing
:
bNs_out
=
list
(
np
.
array
(
list
(
self
.
bandnames
))[
zslice
])
bNs_out
=
list
(
np
.
array
(
list
(
self
.
bandnames
))[
zslice
])
_meta_out
=
self
.
metadata
.
get_
band_subset
(
bandslice
=
zslice
)
_meta_out
=
self
.
metadata
.
get_
subset
(
bands2extract
=
zslice
)
else
:
else
:
bNs_out
=
list
(
self
.
bandnames
)
bNs_out
=
list
(
self
.
bandnames
)
_meta_out
=
self
.
meta
_meta_out
=
self
.
meta
...
...
geoarray/metadata.py
View file @
b9b19c2a
...
@@ -3,6 +3,7 @@
...
@@ -3,6 +3,7 @@
import
os
import
os
from
pprint
import
pformat
from
pprint
import
pformat
from
copy
import
deepcopy
from
copy
import
deepcopy
from
typing
import
Union
# noqa F401 # flake8 issue
from
geopandas
import
GeoDataFrame
,
GeoSeries
from
geopandas
import
GeoDataFrame
,
GeoSeries
import
numpy
as
np
import
numpy
as
np
...
@@ -204,13 +205,60 @@ class GDAL_Metadata(object):
...
@@ -204,13 +205,60 @@ class GDAL_Metadata(object):
return
dict
(
zip
(
self
.
all_meta
.
keys
(),
return
dict
(
zip
(
self
.
all_meta
.
keys
(),
[
self
.
_convert_param_to_ENVI_str
(
i
)
for
i
in
self
.
all_meta
.
values
()]))
[
self
.
_convert_param_to_ENVI_str
(
i
)
for
i
in
self
.
all_meta
.
values
()]))
def
get_
band_subset
(
self
,
bandslice
=
None
):
def
get_
subset
(
self
,
bands2extract
=
None
,
keys2extract
=
None
):
bandslice
=
bandslice
or
slice
(
None
)
# type: (Union[slice, list, np.ndarray], Union[str, list]) -> 'GDAL_Metadata'
meta_sub
=
deepcopy
(
self
)
meta_sub
=
deepcopy
(
self
)
for
k
,
v
in
meta_sub
.
band_meta
.
items
():
# subset bands
meta_sub
.
band_meta
[
k
]
=
list
(
np
.
array
(
v
)[
bandslice
])
if
bands2extract
is
not
None
:
if
isinstance
(
bands2extract
,
list
):
bands2extract
=
np
.
array
(
bands2extract
)
elif
isinstance
(
bands2extract
,
(
np
.
ndarray
,
slice
)):
pass
# all fine
else
:
raise
TypeError
(
bands2extract
)
for
k
,
v
in
meta_sub
.
band_meta
.
items
():
meta_sub
.
band_meta
[
k
]
=
list
(
np
.
array
(
v
)[
bands2extract
])
meta_sub
.
bands
=
len
(
list
(
range
(
*
bands2extract
.
indices
(
bands2extract
.
stop
))))
\
if
isinstance
(
bands2extract
,
slice
)
else
bands2extract
.
size
# subset metadata keys
if
keys2extract
:
keys2extract
=
[
keys2extract
]
if
isinstance
(
keys2extract
,
str
)
else
keys2extract
# global_meta = meta_sub.global_meta.copy()
for
k
in
meta_sub
.
global_meta
.
copy
().
keys
():
if
k
not
in
keys2extract
:
del
meta_sub
.
global_meta
[
k
]
meta_sub
.
bands
=
len
(
list
(
range
(
*
bandslice
.
indices
(
bandslice
.
stop
))))
for
k
in
meta_sub
.
band_meta
.
copy
().
keys
():
if
k
not
in
keys2extract
:
del
meta_sub
.
band_meta
[
k
]
if
not
meta_sub
.
all_meta
:
raise
ValueError
(
keys2extract
,
'The given metadata keys do not exist.'
)
return
meta_sub
return
meta_sub
def
__getitem__
(
self
,
given
):
if
isinstance
(
given
,
int
):
return
self
.
get_subset
(
bands2extract
=
slice
(
given
,
given
+
1
))
elif
isinstance
(
given
,
slice
):
return
self
.
get_subset
(
bands2extract
=
given
)
elif
isinstance
(
given
,
str
):
return
self
.
get_subset
(
keys2extract
=
given
)
elif
isinstance
(
given
,
list
):
if
isinstance
(
given
[
0
],
str
):
return
self
.
get_subset
(
keys2extract
=
given
)
elif
isinstance
(
given
[
0
],
int
):
return
self
.
get_subset
(
bands2extract
=
given
)
else
:
raise
TypeError
(
given
,
'Given list must contain string or integer items.'
)
elif
isinstance
(
given
,
np
.
ndarray
):
if
given
.
ndim
!=
1
:
raise
TypeError
(
given
,
'Given numpy array must be one-dimensional.'
)
return
self
.
get_subset
(
bands2extract
=
given
)
else
:
raise
TypeError
(
given
)
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