Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions apps/gdalalg_raster_calc.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -649,6 +649,17 @@ static bool ParseSourceDescriptors(const std::vector<std::string> &inputs,

std::string dsn =
(pos == std::string::npos) ? input : input.substr(pos + 1);

if (!dsn.empty() && dsn.front() == '[' && dsn.back() == ']')
{
dsn = "{\"type\":\"gdal_streamed_alg\", \"command_line\":\"gdal "
"raster pipeline " +
CPLString(dsn.substr(1, dsn.size() - 2))
.replaceAll('\\', "\\\\")
.replaceAll('"', "\\\"") +
"\"}";
}

if (datasets.find(name) != datasets.end())
{
CPLError(CE_Failure, CPLE_AppDefined,
Expand Down
12 changes: 12 additions & 0 deletions autotest/utilities/test_gdalalg_raster_calc.py
Original file line number Diff line number Diff line change
Expand Up @@ -1025,3 +1025,15 @@ def test_gdalalg_raster_calc_sum_float_input_with_nodata(calc, tmp_vsimem):

out_ds = calc["output"].GetDataset()
assert out_ds.GetRasterBand(1).Checksum() == 1


@pytest.mark.require_driver("GDALG")
def test_gdalalg_raster_calc_input_pipeline(calc):

calc["input"] = "A=[ read ../gcore/data/byte.tif ! aspect ]"
calc["output-format"] = "MEM"
calc["calc"] = "A * 10"
calc.Run()

out_ds = calc["output"].GetDataset()
assert out_ds.GetRasterBand(1).Checksum() == 4692
8 changes: 8 additions & 0 deletions doc/source/programs/gdal_raster_calc.rst
Original file line number Diff line number Diff line change
Expand Up @@ -184,3 +184,11 @@ Examples
.. code-block:: bash
gdal raster calc -i A=input1.tif -i B=input2.tif -o result.tif --flatten --calc=mean --dialect=builtin
.. example::
:title: Generate a masked aspect layer where the slope angle is greater than 2 degrees, using nested pipelines (since GDAL 3.12.1)

.. code-block:: bash
gdal raster calc -i "SLOPE=[ read dem.tif ! slope ]" -i "ASPECT=[ read dem.tif ! aspect ]" -o result.tif --calc "(SLOPE >= 2) ? ASPECT : -9999" --nodata -9999
Loading