3535/* GDALRasterPixelInfoAlgorithm::GDALRasterPixelInfoAlgorithm() */
3636/* ***********************************************************************/
3737
38- GDALRasterPixelInfoAlgorithm::GDALRasterPixelInfoAlgorithm ()
39- : GDALAlgorithm(NAME, DESCRIPTION, HELP_URL)
38+ GDALRasterPixelInfoAlgorithm::GDALRasterPixelInfoAlgorithm (bool standaloneStep)
39+ : GDALPipelineStepAlgorithm(
40+ NAME, DESCRIPTION, HELP_URL,
41+ ConstructorOptions ()
42+ .SetStandaloneStep(standaloneStep)
43+ .SetAddAppendLayerArgument(false )
44+ .SetAddOverwriteLayerArgument(false )
45+ .SetAddUpdateArgument(false )
46+ .SetAddUpsertArgument(false )
47+ .SetAddSkipErrorsArgument(false )
48+ .SetOutputFormatCreateCapability(GDAL_DCAP_CREATE))
4049{
41- AddOutputFormatArg (&m_format, false , false ,
42- _ (" Output format (default is 'GeoJSON' if "
43- " 'position-dataset' not specified)" ))
44- .AddMetadataItem (GAAMDI_REQUIRED_CAPABILITIES,
45- {GDAL_DCAP_VECTOR, GDAL_DCAP_CREATE});
46- AddOpenOptionsArg (&m_openOptions);
47- AddInputFormatsArg (&m_inputFormats)
48- .AddMetadataItem (GAAMDI_REQUIRED_CAPABILITIES, {GDAL_DCAP_RASTER});
49- AddInputDatasetArg (&m_rasterDataset, GDAL_OF_RASTER).AddAlias (" dataset" );
50+ if (standaloneStep)
51+ {
52+ AddOutputFormatArg (&m_format, false , false ,
53+ _ (" Output format (default is 'GeoJSON' if "
54+ " 'position-dataset' not specified)" ))
55+ .AddMetadataItem (GAAMDI_REQUIRED_CAPABILITIES,
56+ {GDAL_DCAP_VECTOR, GDAL_DCAP_CREATE});
57+ AddOpenOptionsArg (&m_openOptions);
58+ AddInputFormatsArg (&m_inputFormats)
59+ .AddMetadataItem (GAAMDI_REQUIRED_CAPABILITIES, {GDAL_DCAP_RASTER});
60+ }
61+
62+ AddInputDatasetArg (&m_inputDataset, GDAL_OF_RASTER,
63+ /* positionalAndRequired = */ standaloneStep)
64+ .AddAlias (" dataset" )
65+ .SetMinCount (1 )
66+ .SetMaxCount (1 )
67+ .SetHiddenForCLI (!standaloneStep);
5068
5169 {
5270 auto &coordinateDatasetArg =
5371 AddArg (" position-dataset" , ' \0 ' ,
5472 _ (" Vector dataset with coordinates" ), &m_vectorDataset,
5573 GDAL_OF_VECTOR)
5674 .SetMutualExclusionGroup (" position-dataset-pos" );
75+ if (!standaloneStep)
76+ coordinateDatasetArg.SetPositional ().SetRequired ();
5777
5878 SetAutoCompleteFunctionForFilename (coordinateDatasetArg,
5979 GDAL_OF_VECTOR);
6080
6181 auto &layerArg = AddArg (GDAL_ARG_NAME_INPUT_LAYER, ' l' ,
62- _ (" Input layer name" ), &m_inputLayerName)
82+ _ (" Input layer name" ), &m_inputLayerNames)
83+ .SetMaxCount (1 )
6384 .AddAlias (" layer" );
6485 SetAutoCompleteFunctionForLayerName (layerArg, coordinateDatasetArg);
6586 }
6687
6788 AddOutputDatasetArg (&m_outputDataset, GDAL_OF_VECTOR,
68- /* positionalAndRequired = */ false );
69- AddCreationOptionsArg (&m_creationOptions);
70- AddLayerCreationOptionsArg (&m_layerCreationOptions);
71- AddOverwriteArg (&m_overwrite);
72-
73- AddOutputStringArg (&m_outputString);
89+ /* positionalAndRequired = */ false )
90+ .SetHiddenForCLI (!standaloneStep);
91+ if (standaloneStep)
92+ {
93+ AddCreationOptionsArg (&m_creationOptions);
94+ AddLayerCreationOptionsArg (&m_layerCreationOptions);
95+ AddOverwriteArg (&m_overwrite);
96+ AddOutputStringArg (&m_outputString).SetHiddenForCLI (!standaloneStep);
97+ }
7498
7599 AddBandArg (&m_band);
76100 AddArg (" overview" , 0 , _ (" Which overview level of source file must be used" ),
77101 &m_overview)
78102 .SetMinValueIncluded (0 );
79103
80- AddArg ( " position " , ' p ' , _ ( " Pixel position " ), &m_pos )
81- . AddAlias ( " pos " )
82- . SetMetaVar ( " <column,line> or <X,Y> " )
83- . SetPositional ( )
84- . SetMutualExclusionGroup ( " position-dataset-pos " )
85- . AddValidationAction (
86- [ this ]
87- {
88- if ((m_pos. size () % 2 ) != 0 )
104+ if (standaloneStep )
105+ {
106+ AddArg ( " position " , ' p ' , _ ( " Pixel position " ), &m_pos )
107+ . AddAlias ( " pos " )
108+ . SetMetaVar ( " <column,line> or <X,Y> " )
109+ . SetPositional ()
110+ . SetMutualExclusionGroup ( " position-dataset-pos " )
111+ . AddValidationAction (
112+ [ this ]
89113 {
90- ReportError (CE_Failure, CPLE_IllegalArg,
91- " An even number of values must be specified "
92- " for 'position' argument" );
93- return false ;
94- }
95- return true ;
96- });
114+ if ((m_pos.size () % 2 ) != 0 )
115+ {
116+ ReportError (
117+ CE_Failure, CPLE_IllegalArg,
118+ " An even number of values must be specified "
119+ " for 'position' argument" );
120+ return false ;
121+ }
122+ return true ;
123+ });
124+ }
125+
97126 AddArg (" position-crs" , 0 ,
98127 _ (" CRS of position (default is 'pixel' if 'position-dataset' not "
99128 " specified)" ),
@@ -121,30 +150,34 @@ GDALRasterPixelInfoAlgorithm::GDALRasterPixelInfoAlgorithm()
121150 AddValidationAction (
122151 [this ]
123152 {
124- if (auto poSrcDS = m_rasterDataset. GetDatasetRef () )
153+ if (m_inputDataset. size () == 1 )
125154 {
126- const int nOvrCount =
127- poSrcDS->GetRasterBand (1 )->GetOverviewCount ();
128- if (m_overview >= 0 && poSrcDS->GetRasterCount () > 0 &&
129- m_overview >= nOvrCount)
155+ if (auto poSrcDS = m_inputDataset[0 ].GetDatasetRef ())
130156 {
131- if (nOvrCount == 0 )
132- {
133- ReportError (
134- CE_Failure, CPLE_IllegalArg,
135- " Source dataset has no overviews. "
136- " Argument 'overview' must not be specified." );
137- }
138- else
157+ const int nOvrCount =
158+ poSrcDS->GetRasterBand (1 )->GetOverviewCount ();
159+ if (m_overview >= 0 && poSrcDS->GetRasterCount () > 0 &&
160+ m_overview >= nOvrCount)
139161 {
140- ReportError (
141- CE_Failure, CPLE_IllegalArg,
142- " Source dataset has only %d overview level%s. "
143- " 'overview' "
144- " value must be strictly lower than this number." ,
145- nOvrCount, nOvrCount > 1 ? " s" : " " );
162+ if (nOvrCount == 0 )
163+ {
164+ ReportError (
165+ CE_Failure, CPLE_IllegalArg,
166+ " Source dataset has no overviews. "
167+ " Argument 'overview' must not be specified." );
168+ }
169+ else
170+ {
171+ ReportError (
172+ CE_Failure, CPLE_IllegalArg,
173+ " Source dataset has only %d overview level%s. "
174+ " 'overview' "
175+ " value must be strictly lower than this "
176+ " number." ,
177+ nOvrCount, nOvrCount > 1 ? " s" : " " );
178+ }
179+ return false ;
146180 }
147- return false ;
148181 }
149182 }
150183 return true ;
@@ -168,9 +201,22 @@ GDALRasterPixelInfoAlgorithm::~GDALRasterPixelInfoAlgorithm()
168201/* GDALRasterPixelInfoAlgorithm::RunImpl() */
169202/* ***********************************************************************/
170203
171- bool GDALRasterPixelInfoAlgorithm::RunImpl (GDALProgressFunc, void *)
204+ bool GDALRasterPixelInfoAlgorithm::RunImpl (GDALProgressFunc pfnProgress,
205+ void *pProgressData)
172206{
173- auto poSrcDS = m_rasterDataset.GetDatasetRef ();
207+ GDALPipelineStepRunContext stepCtxt;
208+ stepCtxt.m_pfnProgress = pfnProgress;
209+ stepCtxt.m_pProgressData = pProgressData;
210+ return RunPreStepPipelineValidations () && RunStep (stepCtxt);
211+ }
212+
213+ /* ***********************************************************************/
214+ /* GDALRasterPixelInfoAlgorithm::RunStep() */
215+ /* ***********************************************************************/
216+
217+ bool GDALRasterPixelInfoAlgorithm::RunStep (GDALPipelineStepRunContext &)
218+ {
219+ auto poSrcDS = m_inputDataset[0 ].GetDatasetRef ();
174220 CPLAssert (poSrcDS);
175221
176222 auto poVectorSrcDS = m_vectorDataset.GetDatasetRef ();
@@ -183,7 +229,11 @@ bool GDALRasterPixelInfoAlgorithm::RunImpl(GDALProgressFunc, void *)
183229 return false ;
184230 }
185231
186- if (m_outputDataset.GetName ().empty ())
232+ if (!m_standaloneStep)
233+ {
234+ m_format = " MEM" ;
235+ }
236+ else if (m_outputDataset.GetName ().empty ())
187237 {
188238 if (m_format.empty ())
189239 {
@@ -217,7 +267,7 @@ bool GDALRasterPixelInfoAlgorithm::RunImpl(GDALProgressFunc, void *)
217267
218268 if (poVectorSrcDS)
219269 {
220- if (m_inputLayerName .empty ())
270+ if (m_inputLayerNames .empty ())
221271 {
222272 const int nLayerCount = poVectorSrcDS->GetLayerCount ();
223273 if (nLayerCount == 0 )
@@ -240,20 +290,20 @@ bool GDALRasterPixelInfoAlgorithm::RunImpl(GDALProgressFunc, void *)
240290 else
241291 {
242292 poSrcLayer =
243- poVectorSrcDS->GetLayerByName (m_inputLayerName .c_str ());
293+ poVectorSrcDS->GetLayerByName (m_inputLayerNames[ 0 ] .c_str ());
244294 }
245295 if (!poSrcLayer)
246296 {
247297 ReportError (
248298 CE_Failure, CPLE_AppDefined, " Cannot find layer '%s' in '%s'" ,
249- m_inputLayerName .c_str (), poVectorSrcDS->GetDescription ());
299+ m_inputLayerNames[ 0 ] .c_str (), poVectorSrcDS->GetDescription ());
250300 return false ;
251301 }
252302 if (poSrcLayer->GetGeomType () == wkbNone)
253303 {
254304 ReportError (CE_Failure, CPLE_AppDefined,
255305 " Layer '%s' of '%s' has no geometry column" ,
256- m_inputLayerName .c_str (),
306+ m_inputLayerNames[ 0 ] .c_str (),
257307 poVectorSrcDS->GetDescription ());
258308 return false ;
259309 }
@@ -370,7 +420,7 @@ bool GDALRasterPixelInfoAlgorithm::RunImpl(GDALProgressFunc, void *)
370420 }
371421 }
372422
373- if (!osOutFilename.empty ())
423+ if (!osOutFilename.empty () || !m_standaloneStep )
374424 {
375425 if (bIsGeoJSON)
376426 {
@@ -1038,7 +1088,7 @@ bool GDALRasterPixelInfoAlgorithm::RunImpl(GDALProgressFunc, void *)
10381088 }
10391089 else if (poOutDS)
10401090 {
1041- if (m_outputDataset.GetName ().empty ())
1091+ if (m_outputDataset.GetName ().empty () && m_standaloneStep )
10421092 {
10431093 poOutDS.reset ();
10441094 if (!isInteractive)
@@ -1073,4 +1123,7 @@ bool GDALRasterPixelInfoAlgorithm::RunImpl(GDALProgressFunc, void *)
10731123 return bRet;
10741124}
10751125
1126+ GDALRasterPixelInfoAlgorithmStandalone::
1127+ ~GDALRasterPixelInfoAlgorithmStandalone () = default ;
1128+
10761129// ! @endcond
0 commit comments