Skip to content

Commit f1d75bb

Browse files
committed
gdal raster scale: rename --[src/dst][min/max] to --[input/output][min/max]
1 parent 5d85037 commit f1d75bb

5 files changed

Lines changed: 90 additions & 79 deletions

File tree

.github/workflows/ubuntu_26.04/reference_arg_names.txt

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -70,8 +70,6 @@ dim
7070
distance
7171
distance-units
7272
drivers
73-
dst-max
74-
dst-min
7573
elevation-name
7674
enable-sozip
7775
end-angle
@@ -129,6 +127,8 @@ input-crs
129127
input-field
130128
input-format
131129
input-layer
130+
input-max
131+
input-min
132132
input-nodata
133133
input-prefix
134134
interval
@@ -230,6 +230,8 @@ output-crs
230230
output-data-type
231231
output-format
232232
output-layer
233+
output-max
234+
output-min
233235
output-nodata
234236
output-open-option
235237
output-string
@@ -313,8 +315,6 @@ spectral
313315
split-multipolygons
314316
sql
315317
src-field-type
316-
src-max
317-
src-min
318318
start-angle
319319
stat
320320
stats

apps/gdalalg_raster_scale.cpp

Lines changed: 16 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -34,19 +34,25 @@ GDALRasterScaleAlgorithm::GDALRasterScaleAlgorithm(bool standaloneStep)
3434
AddOutputDataTypeArg(&m_type);
3535
AddBandArg(&m_band,
3636
_("Select band to restrict the scaling (1-based index)"));
37-
AddArg("src-min", 0, _("Minimum value of the source range"), &m_srcMin)
38-
.SetMutualDependencyGroup("src-max-min");
39-
AddArg("src-max", 0, _("Maximum value of the source range"), &m_srcMax)
40-
.SetMutualDependencyGroup("src-max-min");
41-
AddArg("dst-min", 0, _("Minimum value of the destination range"), &m_dstMin)
42-
.SetMutualDependencyGroup("dst-max-min");
43-
AddArg("dst-max", 0, _("Maximum value of the destination range"), &m_dstMax)
44-
.SetMutualDependencyGroup("dst-max-min");
37+
AddArg("input-min", 0, _("Minimum value of the source range"), &m_srcMin)
38+
.SetMutualDependencyGroup("input-max-min")
39+
.AddHiddenAlias("src-min");
40+
AddArg("input-max", 0, _("Maximum value of the source range"), &m_srcMax)
41+
.SetMutualDependencyGroup("input-max-min")
42+
.AddHiddenAlias("src-max");
43+
AddArg("output-min", 0, _("Minimum value of the destination range"),
44+
&m_dstMin)
45+
.SetMutualDependencyGroup("output-max-min")
46+
.AddHiddenAlias("dst-min");
47+
AddArg("output-max", 0, _("Maximum value of the destination range"),
48+
&m_dstMax)
49+
.SetMutualDependencyGroup("output-max-min")
50+
.AddHiddenAlias("dst-max");
4551
AddArg("exponent", 0,
4652
_("Exponent to apply non-linear scaling with a power function"),
4753
&m_exponent);
48-
AddArg("no-clip", 0, _("Do not clip input values to [srcmin, srcmax]"),
49-
&m_noClip);
54+
AddArg("no-clip", 0,
55+
_("Do not clip input values to [innput-min, input-max]"), &m_noClip);
5056
}
5157

5258
/************************************************************************/

autotest/gcore/algorithm.py

Lines changed: 37 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -569,34 +569,39 @@ def test_algorithm_mutual_dependencies(tmp_path):
569569
):
570570
alg.Run()
571571

572+
573+
def test_algorithm_mutual_dependency_group(tmp_path):
574+
575+
reg = gdal.GetGlobalAlgorithmRegistry()
576+
572577
# Check mutual dependency group
573578
alg = reg["raster"]["scale"]
574579

575580
usage = json.loads(alg.GetUsageAsJSON())
576-
src_min = [a for a in usage["input_arguments"] if a["name"] == "src-min"][0]
577-
src_max = [a for a in usage["input_arguments"] if a["name"] == "src-max"][0]
578-
dst_min = [a for a in usage["input_arguments"] if a["name"] == "dst-min"][0]
579-
dst_max = [a for a in usage["input_arguments"] if a["name"] == "dst-max"][0]
580-
581-
assert src_min["mutual_dependency_group"] == "src-max-min"
582-
assert src_max["mutual_dependency_group"] == "src-max-min"
583-
assert dst_min["mutual_dependency_group"] == "dst-max-min"
584-
assert dst_max["mutual_dependency_group"] == "dst-max-min"
585-
586-
src_min_arg = alg.GetArg("src-min")
587-
src_max_arg = alg.GetArg("src-max")
588-
dst_min_arg = alg.GetArg("dst-min")
589-
dst_max_arg = alg.GetArg("dst-max")
590-
591-
assert src_min_arg.GetMutualDependencyGroup() == "src-max-min"
592-
assert src_max_arg.GetMutualDependencyGroup() == "src-max-min"
593-
assert dst_min_arg.GetMutualDependencyGroup() == "dst-max-min"
594-
assert dst_max_arg.GetMutualDependencyGroup() == "dst-max-min"
595-
596-
assert src_min["depends_on"] == ["src-max"]
597-
assert src_max["depends_on"] == ["src-min"]
598-
assert dst_min["depends_on"] == ["dst-max"]
599-
assert dst_max["depends_on"] == ["dst-min"]
581+
src_min = [a for a in usage["input_arguments"] if a["name"] == "input-min"][0]
582+
src_max = [a for a in usage["input_arguments"] if a["name"] == "input-max"][0]
583+
dst_min = [a for a in usage["input_arguments"] if a["name"] == "output-min"][0]
584+
dst_max = [a for a in usage["input_arguments"] if a["name"] == "output-max"][0]
585+
586+
assert src_min["mutual_dependency_group"] == "input-max-min"
587+
assert src_max["mutual_dependency_group"] == "input-max-min"
588+
assert dst_min["mutual_dependency_group"] == "output-max-min"
589+
assert dst_max["mutual_dependency_group"] == "output-max-min"
590+
591+
src_min_arg = alg.GetArg("input-min")
592+
src_max_arg = alg.GetArg("input-max")
593+
dst_min_arg = alg.GetArg("output-min")
594+
dst_max_arg = alg.GetArg("output-max")
595+
596+
assert src_min_arg.GetMutualDependencyGroup() == "input-max-min"
597+
assert src_max_arg.GetMutualDependencyGroup() == "input-max-min"
598+
assert dst_min_arg.GetMutualDependencyGroup() == "output-max-min"
599+
assert dst_max_arg.GetMutualDependencyGroup() == "output-max-min"
600+
601+
assert src_min["depends_on"] == ["input-max"]
602+
assert src_max["depends_on"] == ["input-min"]
603+
assert dst_min["depends_on"] == ["output-max"]
604+
assert dst_max["depends_on"] == ["output-min"]
600605

601606
# This does not include mutual dependencies
602607
assert src_min_arg.GetDirectDependencies() is None
@@ -605,26 +610,26 @@ def test_algorithm_mutual_dependencies(tmp_path):
605610
assert dst_max_arg.GetDirectDependencies() is None
606611

607612
# This includes both direct and mutual dependencies
608-
assert alg.GetArgDependencies("src-max") == ["src-min"]
609-
assert alg.GetArgDependencies("src-min") == ["src-max"]
610-
assert alg.GetArgDependencies("dst-min") == ["dst-max"]
611-
assert alg.GetArgDependencies("dst-max") == ["dst-min"]
613+
assert alg.GetArgDependencies("input-max") == ["input-min"]
614+
assert alg.GetArgDependencies("input-min") == ["input-max"]
615+
assert alg.GetArgDependencies("output-min") == ["output-max"]
616+
assert alg.GetArgDependencies("output-max") == ["output-min"]
612617

613-
alg["src-min"] = 1
618+
alg["input-min"] = 1
614619
alg["output"] = str(tmp_path / "out.tif")
615620
alg["input"] = "data/byte.tif"
616621
with pytest.raises(
617622
RuntimeError,
618-
match=r"Argument\(s\) 'src-min' require\(s\) that the following argument\(s\) are also specified: src-max.",
623+
match=r"Argument\(s\) 'input-min' require\(s\) that the following argument\(s\) are also specified: input-max.",
619624
):
620625
alg.Run()
621626

622627
alg = reg["raster"]["scale"]
623-
alg["src-max"] = 10
628+
alg["input-max"] = 10
624629
alg["input"] = "data/byte.tif"
625630
alg["output"] = str(tmp_path / "out.tif")
626631
with pytest.raises(
627632
RuntimeError,
628-
match=r"Argument\(s\) 'src-max' require\(s\) that the following argument\(s\) are also specified: src-min.",
633+
match=r"Argument\(s\) 'input-max' require\(s\) that the following argument\(s\) are also specified: input-min.",
629634
):
630635
alg.Run()

autotest/utilities/test_gdalalg_raster_scale.py

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -94,10 +94,10 @@ def test_gdalalg_raster_scale_missing_srcmin():
9494
alg["input"] = src_ds
9595
alg["output"] = ""
9696
alg["output-format"] = "MEM"
97-
alg["src-max"] = 0
97+
alg["output-max"] = 0
9898
with pytest.raises(
9999
Exception,
100-
match=r"Argument\(s\) 'src-max' require\(s\) that the following argument\(s\) are also specified: src-min.",
100+
match=r"Argument\(s\) 'output-max' require\(s\) that the following argument\(s\) are also specified: output-min.",
101101
):
102102
alg.Run()
103103

@@ -114,7 +114,7 @@ def test_gdalalg_raster_scale_missing_srcmax():
114114
alg["src-min"] = 0
115115
with pytest.raises(
116116
Exception,
117-
match=r"Argument\(s\) 'src-min' require\(s\) that the following argument\(s\) are also specified: src-max.",
117+
match=r"Argument\(s\) 'input-min' require\(s\) that the following argument\(s\) are also specified: input-max.",
118118
):
119119
alg.Run()
120120

@@ -128,10 +128,10 @@ def test_gdalalg_raster_scale_missing_dstmin():
128128
alg["input"] = src_ds
129129
alg["output"] = ""
130130
alg["output-format"] = "MEM"
131-
alg["dst-max"] = 0
131+
alg["output-max"] = 0
132132
with pytest.raises(
133133
Exception,
134-
match=r"Argument\(s\) 'dst-max' require\(s\) that the following argument\(s\) are also specified: dst-min.",
134+
match=r"Argument\(s\) 'output-max' require\(s\) that the following argument\(s\) are also specified: output-min.",
135135
):
136136
alg.Run()
137137

@@ -145,10 +145,10 @@ def test_gdalalg_raster_scale_missing_dstmax():
145145
alg["input"] = src_ds
146146
alg["output"] = ""
147147
alg["output-format"] = "MEM"
148-
alg["dst-min"] = 0
148+
alg["output-min"] = 0
149149
with pytest.raises(
150150
Exception,
151-
match=r"Argument\(s\) 'dst-min' require\(s\) that the following argument\(s\) are also specified: dst-max.",
151+
match=r"Argument\(s\) 'output-min' require\(s\) that the following argument\(s\) are also specified: output-max.",
152152
):
153153
alg.Run()
154154

@@ -163,10 +163,10 @@ def test_gdalalg_raster_scale_srcmin_srcmax_destmin_dstmax():
163163
alg["input"] = src_ds
164164
alg["output"] = ""
165165
alg["output-format"] = "MEM"
166-
alg["src-min"] = 10
167-
alg["src-max"] = 20
168-
alg["dst-min"] = 100
169-
alg["dst-max"] = 200
166+
alg["input-min"] = 10
167+
alg["input-max"] = 20
168+
alg["output-min"] = 100
169+
alg["output-max"] = 200
170170
assert alg.Run()
171171
out_ds = alg["output"].GetDataset()
172172
assert out_ds.GetRasterBand(1).ComputeRasterMinMax() == (150, 150)

doc/source/programs/gdal_raster_scale.rst

Lines changed: 22 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,8 @@ Description
2121
-----------
2222

2323
:program:`gdal raster scale` can be used to rescale the input pixels values
24-
from the range :option:`--src-min` to :option:`--src-max` to the range
25-
:option:`--dst-min` to :option:`--dst-max`.
24+
from the range :option:`--input-min` to :option:`--input-max` to the range
25+
:option:`--output-min` to :option:`--output-max`.
2626
It is also often necessary to reset the output datatype with the :option:`--ot` switch.
2727
If omitted the output range is from the minimum value to the maximum value allowed
2828
for integer data types (for example from 0 to 255 for Byte output) or from 0 to 1
@@ -54,19 +54,11 @@ Program-Specific Options
5454

5555
Index (starting at 1) of the band to which the scaling must be only applied.
5656

57-
.. option:: --dst-max <DSTMAX>
58-
59-
Maximum value of the output range. This option must be used together with :option:`--dst-min`.
60-
61-
.. option:: --dst-min <DSTMIN>
62-
63-
Minimum value of the output range. This option must be used together with :option:`--dst-max`.
64-
6557
.. option:: --exponent <EXPONENT>
6658

6759
Apply non-linear scaling with a power function. ``exp_val`` is the exponent
6860
of the power function (must be positive). This option must be used with the
69-
:option:`--src-min` / :option:`--src-max` / :option:`--dst-min` / :option:`--dst-max` options.
61+
:option:`--input-min` / :option:`--input-max` / :option:`--output-min` / :option:`--output-max` options.
7062

7163
The scaled value ``Dst`` is calculated from the source value ``Src`` with the following
7264
formula:
@@ -79,21 +71,29 @@ Program-Specific Options
7971
:ref:`gdal_raster_unscale` assumes linear scaling, and
8072
this cannot unscale values back to the original ones.
8173

82-
.. option:: --no-clip
83-
84-
Disable clipping input values to the source range. Note that using this option
85-
with non-linear scaling with a non-integer exponent will cause input values lower
86-
than the minimum value of the source range to be mapped to not-a-number.
87-
88-
.. option:: --src-max <SRCMAX>
74+
.. option:: --input-max <MAX>
8975

9076
Maximum value of the source range. If not specified, it will be calculated from the source dataset.
91-
This option must be used together with :option:`--src-min`.
77+
This option must be used together with :option:`--input-min`.
9278

93-
.. option:: --src-min <SRCMIN>
79+
.. option:: --input-min <MIN>
9480

9581
Minimum value of the source range. If not specified, it will be calculated from the input dataset.
96-
This option must be used together with :option:`--src-max`.
82+
This option must be used together with :option:`--input-max`.
83+
84+
.. option:: --output-max <MAX>
85+
86+
Maximum value of the output range. This option must be used together with :option:`--output-min`.
87+
88+
.. option:: --output-min <MIN>
89+
90+
Minimum value of the output range. This option must be used together with :option:`--output-max`.
91+
92+
.. option:: --no-clip
93+
94+
Disable clipping input values to the source range. Note that using this option
95+
with non-linear scaling with a non-integer exponent will cause input values lower
96+
than the minimum value of the source range to be mapped to not-a-number.
9797

9898
Standard Options
9999
----------------
@@ -127,4 +127,4 @@ Examples
127127

128128
.. code-block:: bash
129129
130-
$ gdal raster scale --datatype Byte --src-min 0 --src-max 4095 uint16.tif byte.tif --overwrite
130+
$ gdal raster scale --datatype Byte --input-min 0 --input-max 4095 uint16.tif byte.tif --overwrite

0 commit comments

Comments
 (0)