Skip to content

Commit 9a0f442

Browse files
authored
Merge pull request #13404 from rouault/raster_pipeline_info_tile_compare_fixes
gdal raster compare/info/tile: make them work properly in a pipeline …
2 parents e416ffb + 464bf8b commit 9a0f442

8 files changed

+78
-9
lines changed

apps/gdalalg_pipeline.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,10 @@ void GDALPipelineStepAlgorithm::AddRasterHiddenInputDatasetArg()
6565
// GDALAlgorithm must be able to retrieve the input dataset
6666
AddInputDatasetArg(&m_inputDataset, GDAL_OF_RASTER,
6767
/* positionalAndRequired = */ false)
68+
.SetMinCount(1)
69+
.SetMaxCount(m_constructorOptions.inputDatasetMaxCount)
70+
.SetAutoOpenDataset(m_constructorOptions.autoOpenInputDatasets)
71+
.SetMetaVar(m_constructorOptions.inputDatasetMetaVar)
6872
.SetHidden();
6973
}
7074

apps/gdalalg_raster_compare.cpp

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,15 @@ GDALRasterCompareAlgorithm::GDALRasterCompareAlgorithm(bool standaloneStep)
4949

5050
SetAutoCompleteFunctionForFilename(referenceDatasetArg, GDAL_OF_RASTER);
5151

52-
AddRasterInputArgs(false, !standaloneStep);
52+
if (standaloneStep)
53+
{
54+
AddRasterInputArgs(/* openForMixedRasterVector = */ false,
55+
/* hiddenForCLI = */ false);
56+
}
57+
else
58+
{
59+
AddRasterHiddenInputDatasetArg();
60+
}
5361

5462
AddArg("skip-all-optional", 0, _("Skip all optional comparisons"),
5563
&m_skipAllOptional);

apps/gdalalg_raster_info.cpp

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,15 @@ GDALRasterInfoAlgorithm::GDALRasterInfoAlgorithm(bool standaloneStep,
3737
.SetInputDatasetHelpMsg(_("Input raster dataset"))
3838
.SetInputDatasetAlias("dataset"))
3939
{
40-
AddRasterInputArgs(openForMixedRasterVector, !standaloneStep);
40+
if (standaloneStep)
41+
{
42+
AddRasterInputArgs(openForMixedRasterVector,
43+
/* hiddenForCLI = */ false);
44+
}
45+
else
46+
{
47+
AddRasterHiddenInputDatasetArg();
48+
}
4149

4250
AddOutputFormatArg(&m_format).SetChoices("json", "text");
4351
AddArg("min-max", 0, _("Compute minimum and maximum value"), &m_minMax)

apps/gdalalg_raster_mosaic_stack_common.cpp

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -272,11 +272,14 @@ bool GDALRasterMosaicStackCommonAlgorithm::RunImpl(GDALProgressFunc pfnProgress,
272272
GDALRasterWriteAlgorithm writeAlg;
273273
for (auto &arg : writeAlg.GetArgs())
274274
{
275-
auto stepArg = GetArg(arg->GetName());
276-
if (stepArg && stepArg->IsExplicitlySet())
275+
if (!arg->IsHidden())
277276
{
278-
arg->SetSkipIfAlreadySet(true);
279-
arg->SetFrom(*stepArg);
277+
auto stepArg = GetArg(arg->GetName());
278+
if (stepArg && stepArg->IsExplicitlySet())
279+
{
280+
arg->SetSkipIfAlreadySet(true);
281+
arg->SetFrom(*stepArg);
282+
}
280283
}
281284
}
282285

apps/gdalalg_raster_tile.cpp

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -161,7 +161,15 @@ GDALRasterTileAlgorithm::GDALRasterTileAlgorithm(bool standaloneStep)
161161
.SetMinValueIncluded(0)
162162
.SetHidden(); // Used in spawn mode
163163

164-
AddRasterInputArgs(false, !standaloneStep);
164+
if (standaloneStep)
165+
{
166+
AddRasterInputArgs(/* openForMixedRasterVector = */ false,
167+
/* hiddenForCLI = */ false);
168+
}
169+
else
170+
{
171+
AddRasterHiddenInputDatasetArg();
172+
}
165173

166174
m_format = "PNG";
167175
AddOutputFormatArg(&m_format)
@@ -3878,13 +3886,14 @@ static int GenerateTilesForkMethod(CPL_FILE_HANDLE in, CPL_FILE_HANDLE out)
38783886
CPLSetConfigOption("GDAL_NUM_THREADS", "1");
38793887
GDALSetCacheMax64(pWorkStructure->nCacheMaxPerProcess);
38803888

3881-
GDALRasterTileAlgorithm alg;
3889+
GDALRasterTileAlgorithmStandalone alg;
38823890
if (pWorkStructure->poMemSrcDS)
38833891
{
38843892
auto *inputArg = alg.GetArg(GDAL_ARG_NAME_INPUT);
3885-
auto &val = inputArg->Get<std::vector<GDALArgDatasetValue>>();
3893+
std::vector<GDALArgDatasetValue> val;
38863894
val.resize(1);
38873895
val[0].Set(pWorkStructure->poMemSrcDS);
3896+
inputArg->Set(std::move(val));
38883897
}
38893898
return alg.ParseCommandLineArguments(pWorkStructure->aosArgv) && alg.Run()
38903899
? 0

autotest/utilities/test_gdalalg_raster_compare.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1155,3 +1155,12 @@ def my_progress(pct, msg, user_data):
11551155
assert alg["output-string"] == ""
11561156

11571157
assert tab_pct[0] == 1.0
1158+
1159+
1160+
def test_gdalalg_raster_compare_same_file_pipeline():
1161+
1162+
with gdal.alg.raster.pipeline(
1163+
input="../gcore/data/byte.tif",
1164+
pipeline="read ! compare --reference ../gcore/data/byte.tif",
1165+
) as alg:
1166+
assert alg["output-string"] == ""

autotest/utilities/test_gdalalg_raster_info.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -175,3 +175,13 @@ def test_gdalalg_raster_info_read_gdalg_with_input_format():
175175
info["input"] = "../gdrivers/data/gdalg/read_byte.gdalg.json"
176176
info["input-format"] = "GDALG"
177177
assert info.Run()
178+
179+
180+
def test_gdalalg_raster_info_pipeline():
181+
182+
with gdal.alg.raster.pipeline(
183+
input="../gdrivers/data/small_world.tif",
184+
pipeline="read ! info",
185+
) as alg:
186+
j = alg.Output()
187+
assert len(j["bands"]) == 3

autotest/utilities/test_gdalalg_raster_tile.py

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2251,6 +2251,24 @@ def test_gdalalg_raster_tile_pipeline(tmp_path):
22512251
assert len(gdal.ReadDirRecursive(out_dirname)) == 108
22522252

22532253

2254+
def test_gdalalg_raster_tile_pipeline_input_ds(tmp_path):
2255+
2256+
out_dirname = tmp_path / "subdir"
2257+
with gdaltest.config_options(
2258+
{
2259+
"GDAL_THRESHOLD_MIN_THREADS_FOR_SPAWN": "1",
2260+
"GDAL_THRESHOLD_MIN_TILES_PER_JOB": "1",
2261+
}
2262+
):
2263+
gdal.Run(
2264+
"raster pipeline",
2265+
input="../gdrivers/data/small_world.tif",
2266+
pipeline=f"read ! tile {out_dirname} --min-zoom=0 --max-zoom=3",
2267+
)
2268+
2269+
assert len(gdal.ReadDirRecursive(out_dirname)) == 108
2270+
2271+
22542272
@pytest.mark.skipif(_get_effective_cpus() <= 2, reason="needs more than 2 CPUs")
22552273
def test_gdalalg_raster_tile_pipeline_error(tmp_path):
22562274

0 commit comments

Comments
 (0)