Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
What's new
10
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Open sidebar
Daniel Scheffler
geoarray
Commits
85db94cb
Commit
85db94cb
authored
Aug 06, 2018
by
Daniel Scheffler
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Added GDAL cache flushing.
parent
93cd35d6
Pipeline
#3066
failed with stages
in 1 minute and 18 seconds
Changes
2
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
18 additions
and
17 deletions
+18
-17
geoarray/baseclasses.py
geoarray/baseclasses.py
+12
-9
tests/test_geoarray.py
tests/test_geoarray.py
+6
-8
No files found.
geoarray/baseclasses.py
View file @
85db94cb
...
...
@@ -900,16 +900,21 @@ class GeoArray(object):
os
.
makedirs
(
os
.
path
.
dirname
(
out_path
))
if
self
.
is_inmem
:
ds
=
get_GDAL_ds_inmem
(
self
.
arr
,
self
.
geotransform
,
self
.
projection
,
self
.
nodata
)
# expects rows,columns,bands
ds_inmem
=
get_GDAL_ds_inmem
(
self
.
arr
,
self
.
geotransform
,
self
.
projection
,
self
.
nodata
)
# expects rows,columns,bands
# write dataset
ds_out
=
driver
.
CreateCopy
(
out_path
,
ds_inmem
,
options
=
creationOptions
if
creationOptions
else
[])
del
ds_inmem
# set metadata
# NOTE: The dataset has to be written BEFORE metadata are added. Otherwise, metadata are not written.
if
not
self
.
metadata
.
empty
:
global_meta
=
{}
# set band domain metadata
for
bidx
in
range
(
self
.
bands
):
band
=
ds
.
GetRasterBand
(
bidx
+
1
)
band
=
ds
_out
.
GetRasterBand
(
bidx
+
1
)
meta2write
=
self
.
metadata
[
bidx
].
to_dict
()
meta2write
=
dict
((
k
,
repr
(
v
))
for
k
,
v
in
meta2write
.
items
()
if
v
is
not
np
.
nan
)
...
...
@@ -923,7 +928,7 @@ class GeoArray(object):
# set global domain metadata
if
global_meta
:
ds
.
SetMetadata
(
global_meta
)
ds
_out
.
SetMetadata
(
global_meta
)
# get ENVI metadata domain
# ds_orig = gdal.Open(self.filePath)
...
...
@@ -931,14 +936,12 @@ class GeoArray(object):
# ds.SetMetadata(envi_meta_domain, 'ENVI')
# ds_orig = None
ds
.
FlushCache
()
driver
.
CreateCopy
(
out_path
,
ds
,
options
=
creationOptions
if
creationOptions
else
[])
ds_out
.
FlushCache
()
# rows, columns, bands => bands, rows, columns
# out_arr = self.arr if self.ndim == 2 else np.swapaxes(np.swapaxes(self.arr, 0, 2), 1, 2)
# gdalnumeric.SaveArray(out_arr, out_path, format=fmt, prototype=ds) # expects bands,rows,columns
del
ds
del
ds
_out
else
:
src_ds
=
gdal
.
Open
(
self
.
filePath
)
...
...
@@ -1310,7 +1313,7 @@ class GeoArray(object):
image2plot
=
data
plt
.
figure
(
figsize
=
figsize
)
plt
.
hist
(
list
(
image2plot
.
flat
),
normed
=
normed
,
bins
=
bins
,
color
=
'gray'
,
range
=
[
vmin
,
vmax
])
plt
.
hist
(
list
(
image2plot
.
flat
),
density
=
normed
,
bins
=
bins
,
color
=
'gray'
,
range
=
[
vmin
,
vmax
])
plt
.
xlabel
(
'Pixel value'
)
plt
.
ylabel
(
'Probabilty'
if
normed
else
'Count'
)
plt
.
show
()
...
...
tests/test_geoarray.py
View file @
85db94cb
...
...
@@ -384,13 +384,11 @@ class Test_GeoarrayFunctions(unittest.TestCase):
# Opening the temporary serialized variables (see setUpClass of test case 1) to re-use in the new test case
# without the need to inherit the variables from test case 1.
if
cls
.
k
==
0
:
with
open
(
os
.
path
.
join
(
tests_path
,
"tests"
,
"data"
,
"output"
,
"testtiff_path.tmp"
),
"rb"
)
as
f
:
cls
.
testtiff
=
dill
.
load
(
f
)
assert
cls
.
k
in
[
0
,
1
]
fN
=
"testtiff_path.tmp"
if
cls
.
k
==
0
else
"testtiff_array.tmp"
if
cls
.
k
==
1
:
with
open
(
os
.
path
.
join
(
tests_path
,
"tests"
,
"data"
,
"output"
,
"testtiff_array.tmp"
),
"rb"
)
as
f
:
cls
.
testtiff
=
dill
.
load
(
f
)
with
open
(
os
.
path
.
join
(
tests_path
,
"tests"
,
"data"
,
"output"
,
fN
),
"rb"
)
as
f
:
cls
.
testtiff
=
dill
.
load
(
f
)
@
classmethod
def
tearDownClass
(
cls
):
...
...
@@ -601,7 +599,7 @@ if __name__ == '__main__':
# Creating a test suite for the first test case
suite
=
unittest
.
TestSuite
()
loader
=
TestLoader
()
test
=
None
test
=
Test_GeoarrayAppliedOnPathArray
test
.
k
=
k
...
...
@@ -630,7 +628,7 @@ if __name__ == '__main__':
# will be removed in the else-statement.
if
testResult
.
wasSuccessful
()
and
testResult
.
skipped
==
[]:
other_suite
=
unittest
.
TestSuite
()
more_test
=
None
more_test
=
Test_GeoarrayFunctions
more_test
.
k
=
k
...
...
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