Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
ESPACE-DEV
pyrasta
Commits
cea984bf
Commit
cea984bf
authored
Jul 10, 2021
by
Benjamin Pillot
Browse files
Add new arithmetic operations (right side operators) in available operations
parent
dc254fe7
Changes
1
Hide whitespace changes
Inline
Side-by-side
pyrasta/tools/calculator.py
View file @
cea984bf
...
...
@@ -32,22 +32,37 @@ def _op(raster1, out_file, raster2, op_type):
for
band
in
range
(
1
,
raster1
.
nb_band
+
1
):
for
window
in
get_block_windows
(
OP_WINDOW_SIZE
,
raster1
.
x_size
,
raster1
.
y_size
):
array1
=
raster1
.
_gdal_dataset
.
GetRasterBand
(
band
).
ReadAsArray
(
*
window
).
astype
(
"float32"
)
try
:
array2
=
raster2
.
_gdal_dataset
.
GetRasterBand
(
band
).
ReadAsArray
(
*
window
).
astype
(
"float32"
)
except
AttributeError
:
array2
=
raster2
# If second input is not a raster but a scalar
arrays
=
[]
for
src
in
[
raster1
,
raster2
]:
try
:
arrays
.
append
(
src
.
_gdal_dataset
.
GetRasterBand
(
band
).
ReadAsArray
(
*
window
).
astype
(
"float32"
))
except
AttributeError
:
arrays
.
append
(
src
)
# array1 = raster1._gdal_dataset.GetRasterBand(
# band).ReadAsArray(*window).astype("float32")
# try:
# array2 = raster2._gdal_dataset.GetRasterBand(
# band).ReadAsArray(*window).astype("float32")
# except AttributeError:
# array2 = raster2 # If second input is not a raster but a scalar
if
op_type
==
"add"
:
result
=
array
1
+
array
2
result
=
array
s
[
0
]
+
array
s
[
1
]
elif
op_type
==
"sub"
:
result
=
array1
-
array2
result
=
arrays
[
0
]
-
arrays
[
1
]
elif
op_type
==
"rsub"
:
result
=
arrays
[
1
]
-
arrays
[
0
]
elif
op_type
==
"mul"
:
result
=
array1
*
array2
result
=
arrays
[
0
]
*
arrays
[
1
]
elif
op_type
==
"pow"
:
result
=
arrays
[
0
]
**
arrays
[
1
]
elif
op_type
==
"rpow"
:
result
=
arrays
[
1
]
**
arrays
[
0
]
elif
op_type
==
"truediv"
:
result
=
array1
/
array2
result
=
arrays
[
0
]
/
arrays
[
1
]
elif
op_type
==
"rtruediv"
:
return
arrays
[
1
]
/
arrays
[
0
]
else
:
result
=
None
...
...
Write
Preview
Supports
Markdown
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