Line data Source code
1 : /******************************************************************************
2 : *
3 : * Project: GDAL
4 : * Purpose: gdal "vector pipeline" subcommand
5 : * Author: Even Rouault <even dot rouault at spatialys.com>
6 : *
7 : ******************************************************************************
8 : * Copyright (c) 2024, Even Rouault <even dot rouault at spatialys.com>
9 : *
10 : * SPDX-License-Identifier: MIT
11 : ****************************************************************************/
12 :
13 : #include "gdalalg_vector_pipeline.h"
14 : #include "gdalalg_materialize.h"
15 : #include "gdalalg_vector_read.h"
16 : #include "gdalalg_vector_buffer.h"
17 : #include "gdalalg_vector_check_coverage.h"
18 : #include "gdalalg_vector_check_geometry.h"
19 : #include "gdalalg_vector_clean_coverage.h"
20 : #include "gdalalg_vector_clip.h"
21 : #include "gdalalg_vector_concat.h"
22 : #include "gdalalg_vector_edit.h"
23 : #include "gdalalg_vector_explode_collections.h"
24 : #include "gdalalg_vector_filter.h"
25 : #include "gdalalg_vector_geom.h"
26 : #include "gdalalg_vector_info.h"
27 : #include "gdalalg_vector_limit.h"
28 : #include "gdalalg_vector_make_point.h"
29 : #include "gdalalg_vector_make_valid.h"
30 : #include "gdalalg_vector_partition.h"
31 : #include "gdalalg_vector_reproject.h"
32 : #include "gdalalg_vector_segmentize.h"
33 : #include "gdalalg_vector_select.h"
34 : #include "gdalalg_vector_set_field_type.h"
35 : #include "gdalalg_vector_set_geom_type.h"
36 : #include "gdalalg_vector_simplify.h"
37 : #include "gdalalg_vector_simplify_coverage.h"
38 : #include "gdalalg_vector_sql.h"
39 : #include "gdalalg_vector_swap_xy.h"
40 : #include "gdalalg_vector_update.h"
41 : #include "gdalalg_vector_write.h"
42 : #include "gdalalg_tee.h"
43 :
44 : #include "../frmts/mem/memdataset.h"
45 :
46 : #include "cpl_conv.h"
47 : #include "cpl_string.h"
48 :
49 : #include <algorithm>
50 : #include <cassert>
51 :
52 : //! @cond Doxygen_Suppress
53 :
54 : #ifndef _
55 : #define _(x) (x)
56 : #endif
57 :
58 : GDALVectorAlgorithmStepRegistry::~GDALVectorAlgorithmStepRegistry() = default;
59 :
60 : /************************************************************************/
61 : /* GDALVectorPipelineStepAlgorithm::GDALVectorPipelineStepAlgorithm() */
62 : /************************************************************************/
63 :
64 1994 : GDALVectorPipelineStepAlgorithm::GDALVectorPipelineStepAlgorithm(
65 : const std::string &name, const std::string &description,
66 1994 : const std::string &helpURL, bool standaloneStep)
67 : : GDALVectorPipelineStepAlgorithm(
68 : name, description, helpURL,
69 1994 : ConstructorOptions().SetStandaloneStep(standaloneStep))
70 : {
71 1994 : }
72 :
73 : /************************************************************************/
74 : /* GDALVectorPipelineStepAlgorithm::GDALVectorPipelineStepAlgorithm() */
75 : /************************************************************************/
76 :
77 2482 : GDALVectorPipelineStepAlgorithm::GDALVectorPipelineStepAlgorithm(
78 : const std::string &name, const std::string &description,
79 2482 : const std::string &helpURL, const ConstructorOptions &options)
80 2482 : : GDALPipelineStepAlgorithm(name, description, helpURL, options)
81 : {
82 2482 : if (m_standaloneStep)
83 : {
84 595 : m_supportsStreamedOutput = true;
85 :
86 595 : if (m_constructorOptions.addDefaultArguments)
87 : {
88 451 : AddVectorInputArgs(false);
89 451 : AddProgressArg();
90 451 : AddVectorOutputArgs(false, false);
91 : }
92 : }
93 2482 : }
94 :
95 : GDALVectorPipelineStepAlgorithm::~GDALVectorPipelineStepAlgorithm() = default;
96 :
97 : /************************************************************************/
98 : /* GDALVectorPipelineAlgorithm::GDALVectorPipelineAlgorithm() */
99 : /************************************************************************/
100 :
101 100 : GDALVectorPipelineAlgorithm::GDALVectorPipelineAlgorithm()
102 : : GDALAbstractPipelineAlgorithm(
103 : NAME, DESCRIPTION, HELP_URL,
104 100 : ConstructorOptions().SetInputDatasetMaxCount(INT_MAX))
105 : {
106 100 : m_supportsStreamedOutput = true;
107 :
108 100 : AddVectorInputArgs(/* hiddenForCLI = */ true);
109 100 : AddProgressArg();
110 200 : AddArg("pipeline", 0, _("Pipeline string"), &m_pipeline)
111 100 : .SetHiddenForCLI()
112 100 : .SetPositional();
113 100 : AddVectorOutputArgs(/* hiddenForCLI = */ true,
114 : /* shortNameOutputLayerAllowed=*/false);
115 :
116 100 : AddOutputStringArg(&m_output).SetHiddenForCLI();
117 100 : AddStdoutArg(&m_stdout);
118 :
119 100 : RegisterAlgorithms(m_stepRegistry, false);
120 100 : }
121 :
122 : /************************************************************************/
123 : /* GDALVectorPipelineAlgorithm::RegisterAlgorithms() */
124 : /************************************************************************/
125 :
126 : /* static */
127 308 : void GDALVectorPipelineAlgorithm::RegisterAlgorithms(
128 : GDALVectorAlgorithmStepRegistry ®istry, bool forMixedPipeline)
129 : {
130 308 : GDALAlgorithmRegistry::AlgInfo algInfo;
131 :
132 : const auto addSuffixIfNeeded =
133 3080 : [forMixedPipeline](const char *name) -> std::string
134 : {
135 5160 : return forMixedPipeline ? std::string(name).append(VECTOR_SUFFIX)
136 8240 : : std::string(name);
137 308 : };
138 :
139 308 : registry.Register<GDALVectorReadAlgorithm>(
140 616 : addSuffixIfNeeded(GDALVectorReadAlgorithm::NAME));
141 :
142 308 : registry.Register<GDALVectorWriteAlgorithm>(
143 616 : addSuffixIfNeeded(GDALVectorWriteAlgorithm::NAME));
144 :
145 308 : registry.Register<GDALVectorInfoAlgorithm>(
146 616 : addSuffixIfNeeded(GDALVectorInfoAlgorithm::NAME));
147 :
148 308 : registry.Register<GDALVectorBufferAlgorithm>();
149 308 : registry.Register<GDALVectorCheckCoverageAlgorithm>();
150 308 : registry.Register<GDALVectorCheckGeometryAlgorithm>();
151 308 : registry.Register<GDALVectorConcatAlgorithm>();
152 308 : registry.Register<GDALVectorCleanCoverageAlgorithm>();
153 :
154 308 : registry.Register<GDALVectorClipAlgorithm>(
155 616 : addSuffixIfNeeded(GDALVectorClipAlgorithm::NAME));
156 :
157 308 : registry.Register<GDALVectorEditAlgorithm>(
158 616 : addSuffixIfNeeded(GDALVectorEditAlgorithm::NAME));
159 :
160 308 : registry.Register<GDALVectorExplodeCollectionsAlgorithm>();
161 :
162 308 : registry.Register<GDALMaterializeVectorAlgorithm>(
163 616 : addSuffixIfNeeded(GDALMaterializeVectorAlgorithm::NAME));
164 :
165 308 : registry.Register<GDALVectorReprojectAlgorithm>(
166 616 : addSuffixIfNeeded(GDALVectorReprojectAlgorithm::NAME));
167 :
168 308 : registry.Register<GDALVectorFilterAlgorithm>();
169 308 : registry.Register<GDALVectorGeomAlgorithm>();
170 308 : registry.Register<GDALVectorLimitAlgorithm>();
171 308 : registry.Register<GDALVectorMakePointAlgorithm>();
172 308 : registry.Register<GDALVectorMakeValidAlgorithm>();
173 308 : registry.Register<GDALVectorPartitionAlgorithm>();
174 308 : registry.Register<GDALVectorSegmentizeAlgorithm>();
175 :
176 308 : registry.Register<GDALVectorSelectAlgorithm>(
177 616 : addSuffixIfNeeded(GDALVectorSelectAlgorithm::NAME));
178 :
179 308 : registry.Register<GDALVectorSetFieldTypeAlgorithm>();
180 308 : registry.Register<GDALVectorSetGeomTypeAlgorithm>();
181 308 : registry.Register<GDALVectorSimplifyAlgorithm>();
182 308 : registry.Register<GDALVectorSimplifyCoverageAlgorithm>();
183 308 : registry.Register<GDALVectorSQLAlgorithm>();
184 308 : registry.Register<GDALVectorUpdateAlgorithm>(
185 616 : addSuffixIfNeeded(GDALVectorUpdateAlgorithm::NAME));
186 308 : registry.Register<GDALVectorSwapXYAlgorithm>();
187 :
188 308 : registry.Register<GDALTeeVectorAlgorithm>(
189 616 : addSuffixIfNeeded(GDALTeeVectorAlgorithm::NAME));
190 308 : }
191 :
192 : /************************************************************************/
193 : /* GDALVectorPipelineAlgorithm::GetUsageForCLI() */
194 : /************************************************************************/
195 :
196 8 : std::string GDALVectorPipelineAlgorithm::GetUsageForCLI(
197 : bool shortUsage, const UsageOptions &usageOptions) const
198 : {
199 8 : UsageOptions stepUsageOptions;
200 8 : stepUsageOptions.isPipelineStep = true;
201 :
202 8 : if (!m_helpDocCategory.empty() && m_helpDocCategory != "main")
203 : {
204 4 : auto alg = GetStepAlg(m_helpDocCategory);
205 2 : if (alg)
206 : {
207 2 : alg->SetCallPath({m_helpDocCategory});
208 1 : alg->GetArg("help-doc")->Set(true);
209 1 : return alg->GetUsageForCLI(shortUsage, stepUsageOptions);
210 : }
211 : else
212 : {
213 1 : fprintf(stderr, "ERROR: unknown pipeline step '%s'\n",
214 : m_helpDocCategory.c_str());
215 : return CPLSPrintf("ERROR: unknown pipeline step '%s'\n",
216 1 : m_helpDocCategory.c_str());
217 : }
218 : }
219 :
220 6 : UsageOptions usageOptionsMain(usageOptions);
221 6 : usageOptionsMain.isPipelineMain = true;
222 : std::string ret =
223 12 : GDALAlgorithm::GetUsageForCLI(shortUsage, usageOptionsMain);
224 6 : if (shortUsage)
225 2 : return ret;
226 :
227 : ret += "\n<PIPELINE> is of the form: read|concat [READ-OPTIONS] "
228 4 : "( ! <STEP-NAME> [STEP-OPTIONS] )* ! write|info [WRITE-OPTIONS]\n";
229 :
230 4 : if (m_helpDocCategory == "main")
231 : {
232 1 : return ret;
233 : }
234 :
235 3 : ret += '\n';
236 3 : ret += "Example: 'gdal vector pipeline --progress ! read in.gpkg ! \\\n";
237 3 : ret += " reproject --dst-crs=EPSG:32632 ! ";
238 3 : ret += "write out.gpkg --overwrite'\n";
239 3 : ret += '\n';
240 3 : ret += "Potential steps are:\n";
241 :
242 90 : for (const std::string &name : m_stepRegistry.GetNames())
243 : {
244 174 : auto alg = GetStepAlg(name);
245 87 : assert(alg);
246 87 : auto [options, maxOptLen] = alg->GetArgNamesForCLI();
247 87 : stepUsageOptions.maxOptLen =
248 87 : std::max(stepUsageOptions.maxOptLen, maxOptLen);
249 : }
250 :
251 : {
252 3 : const auto name = GDALVectorReadAlgorithm::NAME;
253 3 : ret += '\n';
254 6 : auto alg = GetStepAlg(name);
255 6 : alg->SetCallPath({name});
256 3 : ret += alg->GetUsageForCLI(shortUsage, stepUsageOptions);
257 : }
258 90 : for (const std::string &name : m_stepRegistry.GetNames())
259 : {
260 174 : auto alg = GetStepAlg(name);
261 87 : assert(alg);
262 93 : if (alg->CanBeFirstStep() && !alg->CanBeMiddleStep() &&
263 93 : !alg->IsHidden() && name != GDALVectorReadAlgorithm::NAME)
264 : {
265 3 : ret += '\n';
266 6 : alg->SetCallPath({name});
267 3 : ret += alg->GetUsageForCLI(shortUsage, stepUsageOptions);
268 : }
269 : }
270 90 : for (const std::string &name : m_stepRegistry.GetNames())
271 : {
272 174 : auto alg = GetStepAlg(name);
273 87 : assert(alg);
274 87 : if (alg->CanBeMiddleStep() && !alg->IsHidden())
275 : {
276 69 : ret += '\n';
277 138 : alg->SetCallPath({name});
278 69 : ret += alg->GetUsageForCLI(shortUsage, stepUsageOptions);
279 : }
280 : }
281 90 : for (const std::string &name : m_stepRegistry.GetNames())
282 : {
283 174 : auto alg = GetStepAlg(name);
284 87 : assert(alg);
285 99 : if (alg->CanBeLastStep() && !alg->CanBeMiddleStep() &&
286 99 : !alg->IsHidden() && name != GDALVectorWriteAlgorithm::NAME)
287 : {
288 6 : ret += '\n';
289 12 : alg->SetCallPath({name});
290 6 : ret += alg->GetUsageForCLI(shortUsage, stepUsageOptions);
291 : }
292 : }
293 : {
294 3 : const auto name = GDALVectorWriteAlgorithm::NAME;
295 3 : ret += '\n';
296 6 : auto alg = GetStepAlg(name);
297 6 : alg->SetCallPath({name});
298 3 : ret += alg->GetUsageForCLI(shortUsage, stepUsageOptions);
299 : }
300 :
301 3 : ret += GetUsageForCLIEnd();
302 :
303 3 : return ret;
304 : }
305 :
306 : /************************************************************************/
307 : /* GDALVectorPipelineOutputLayer */
308 : /************************************************************************/
309 :
310 : /************************************************************************/
311 : /* GDALVectorPipelineOutputLayer() */
312 : /************************************************************************/
313 :
314 183 : GDALVectorPipelineOutputLayer::GDALVectorPipelineOutputLayer(OGRLayer &srcLayer)
315 183 : : m_srcLayer(srcLayer)
316 : {
317 183 : }
318 :
319 : /************************************************************************/
320 : /* ~GDALVectorPipelineOutputLayer() */
321 : /************************************************************************/
322 :
323 : GDALVectorPipelineOutputLayer::~GDALVectorPipelineOutputLayer() = default;
324 :
325 : /************************************************************************/
326 : /* GDALVectorPipelineOutputLayer::ResetReading() */
327 : /************************************************************************/
328 :
329 579 : void GDALVectorPipelineOutputLayer::ResetReading()
330 : {
331 579 : m_srcLayer.ResetReading();
332 579 : m_pendingFeatures.clear();
333 579 : m_idxInPendingFeatures = 0;
334 579 : }
335 :
336 : /************************************************************************/
337 : /* GDALVectorPipelineOutputLayer::GetNextRawFeature() */
338 : /************************************************************************/
339 :
340 2337 : OGRFeature *GDALVectorPipelineOutputLayer::GetNextRawFeature()
341 : {
342 2337 : if (m_idxInPendingFeatures < m_pendingFeatures.size())
343 : {
344 : OGRFeature *poFeature =
345 14 : m_pendingFeatures[m_idxInPendingFeatures].release();
346 14 : ++m_idxInPendingFeatures;
347 14 : return poFeature;
348 : }
349 2323 : m_pendingFeatures.clear();
350 2323 : m_idxInPendingFeatures = 0;
351 : while (true)
352 : {
353 : auto poSrcFeature =
354 2332 : std::unique_ptr<OGRFeature>(m_srcLayer.GetNextFeature());
355 2332 : if (!poSrcFeature)
356 264 : return nullptr;
357 2068 : TranslateFeature(std::move(poSrcFeature), m_pendingFeatures);
358 2068 : if (m_translateError)
359 : {
360 7 : return nullptr;
361 : }
362 2061 : if (!m_pendingFeatures.empty())
363 2052 : break;
364 9 : }
365 2052 : OGRFeature *poFeature = m_pendingFeatures[0].release();
366 2052 : m_idxInPendingFeatures = 1;
367 2052 : return poFeature;
368 : }
369 :
370 : /************************************************************************/
371 : /* GDALVectorOutputDataset */
372 : /************************************************************************/
373 :
374 15 : int GDALVectorOutputDataset::TestCapability(const char *) const
375 : {
376 15 : return 0;
377 : }
378 :
379 : /************************************************************************/
380 : /* GDALVectorPipelineOutputDataset */
381 : /************************************************************************/
382 :
383 : /************************************************************************/
384 : /* GDALVectorPipelineOutputDataset() */
385 : /************************************************************************/
386 :
387 177 : GDALVectorPipelineOutputDataset::GDALVectorPipelineOutputDataset(
388 177 : GDALDataset &srcDS)
389 177 : : m_srcDS(srcDS)
390 : {
391 177 : SetDescription(m_srcDS.GetDescription());
392 177 : SetMetadata(m_srcDS.GetMetadata());
393 177 : }
394 :
395 : /************************************************************************/
396 : /* GDALVectorPipelineOutputDataset::AddLayer() */
397 : /************************************************************************/
398 :
399 187 : void GDALVectorPipelineOutputDataset::AddLayer(
400 : OGRLayer &oSrcLayer,
401 : std::unique_ptr<OGRLayerWithTranslateFeature> poNewLayer)
402 : {
403 187 : m_layersToDestroy.push_back(std::move(poNewLayer));
404 : OGRLayerWithTranslateFeature *poNewLayerRaw =
405 187 : m_layersToDestroy.back().get();
406 187 : m_layers.push_back(poNewLayerRaw);
407 187 : m_mapSrcLayerToNewLayer[&oSrcLayer] = poNewLayerRaw;
408 187 : }
409 :
410 : /************************************************************************/
411 : /* GDALVectorPipelineOutputDataset::GetLayerCount() */
412 : /************************************************************************/
413 :
414 580 : int GDALVectorPipelineOutputDataset::GetLayerCount() const
415 : {
416 580 : return static_cast<int>(m_layers.size());
417 : }
418 :
419 : /************************************************************************/
420 : /* GDALVectorPipelineOutputDataset::GetLayer() */
421 : /************************************************************************/
422 :
423 269 : OGRLayer *GDALVectorPipelineOutputDataset::GetLayer(int idx) const
424 : {
425 269 : return idx >= 0 && idx < GetLayerCount() ? m_layers[idx] : nullptr;
426 : }
427 :
428 : /************************************************************************/
429 : /* GDALVectorPipelineOutputDataset::TestCapability() */
430 : /************************************************************************/
431 :
432 128 : int GDALVectorPipelineOutputDataset::TestCapability(const char *pszCap) const
433 : {
434 128 : if (EQUAL(pszCap, ODsCRandomLayerRead) ||
435 31 : EQUAL(pszCap, ODsCMeasuredGeometries) || EQUAL(pszCap, ODsCZGeometries))
436 : {
437 112 : return m_srcDS.TestCapability(pszCap);
438 : }
439 16 : return false;
440 : }
441 :
442 : /************************************************************************/
443 : /* GDALVectorPipelineOutputDataset::ResetReading() */
444 : /************************************************************************/
445 :
446 3 : void GDALVectorPipelineOutputDataset::ResetReading()
447 : {
448 3 : m_srcDS.ResetReading();
449 3 : m_pendingFeatures.clear();
450 3 : m_idxInPendingFeatures = 0;
451 3 : }
452 :
453 : /************************************************************************/
454 : /* GDALVectorPipelineOutputDataset::GetNextFeature() */
455 : /************************************************************************/
456 :
457 23 : OGRFeature *GDALVectorPipelineOutputDataset::GetNextFeature(
458 : OGRLayer **ppoBelongingLayer, double *pdfProgressPct,
459 : GDALProgressFunc pfnProgress, void *pProgressData)
460 : {
461 23 : if (m_idxInPendingFeatures < m_pendingFeatures.size())
462 : {
463 : OGRFeature *poFeature =
464 3 : m_pendingFeatures[m_idxInPendingFeatures].release();
465 3 : if (ppoBelongingLayer)
466 3 : *ppoBelongingLayer = m_belongingLayer;
467 3 : ++m_idxInPendingFeatures;
468 3 : return poFeature;
469 : }
470 :
471 20 : m_pendingFeatures.clear();
472 20 : m_idxInPendingFeatures = 0;
473 :
474 : while (true)
475 : {
476 20 : OGRLayer *poSrcBelongingLayer = nullptr;
477 20 : auto poSrcFeature = std::unique_ptr<OGRFeature>(m_srcDS.GetNextFeature(
478 20 : &poSrcBelongingLayer, pdfProgressPct, pfnProgress, pProgressData));
479 20 : if (!poSrcFeature)
480 3 : return nullptr;
481 17 : auto iterToDstLayer = m_mapSrcLayerToNewLayer.find(poSrcBelongingLayer);
482 17 : if (iterToDstLayer != m_mapSrcLayerToNewLayer.end())
483 : {
484 17 : m_belongingLayer = iterToDstLayer->second;
485 17 : m_belongingLayer->TranslateFeature(std::move(poSrcFeature),
486 17 : m_pendingFeatures);
487 :
488 17 : if (!m_pendingFeatures.empty())
489 17 : break;
490 : }
491 0 : }
492 17 : OGRFeature *poFeature = m_pendingFeatures[0].release();
493 17 : if (ppoBelongingLayer)
494 17 : *ppoBelongingLayer = m_belongingLayer;
495 17 : m_idxInPendingFeatures = 1;
496 17 : return poFeature;
497 : }
498 :
499 : /************************************************************************/
500 : /* GDALVectorPipelinePassthroughLayer::GetLayerDefn() */
501 : /************************************************************************/
502 :
503 33 : const OGRFeatureDefn *GDALVectorPipelinePassthroughLayer::GetLayerDefn() const
504 : {
505 33 : return m_srcLayer.GetLayerDefn();
506 : }
507 :
508 : /************************************************************************/
509 : /* GDALVectorNonStreamingAlgorithmDataset() */
510 : /************************************************************************/
511 :
512 30 : GDALVectorNonStreamingAlgorithmDataset::GDALVectorNonStreamingAlgorithmDataset()
513 30 : : m_ds(MEMDataset::Create("", 0, 0, 0, GDT_Unknown, nullptr))
514 : {
515 30 : }
516 :
517 : /************************************************************************/
518 : /* ~GDALVectorNonStreamingAlgorithmDataset() */
519 : /************************************************************************/
520 :
521 : GDALVectorNonStreamingAlgorithmDataset::
522 : ~GDALVectorNonStreamingAlgorithmDataset() = default;
523 :
524 : /************************************************************************/
525 : /* GDALVectorNonStreamingAlgorithmDataset::AddProcessedLayer() */
526 : /************************************************************************/
527 :
528 26 : bool GDALVectorNonStreamingAlgorithmDataset::AddProcessedLayer(
529 : OGRLayer &srcLayer, OGRFeatureDefn &dstDefn)
530 : {
531 26 : CPLStringList aosOptions;
532 26 : if (srcLayer.TestCapability(OLCStringsAsUTF8))
533 : {
534 1 : aosOptions.AddNameValue("ADVERTIZE_UTF8", "TRUE");
535 : }
536 :
537 26 : OGRMemLayer *poDstLayer = m_ds->CreateLayer(dstDefn, aosOptions.List());
538 26 : m_layers.push_back(poDstLayer);
539 :
540 26 : const bool bRet = Process(srcLayer, *poDstLayer);
541 26 : poDstLayer->SetUpdatable(false);
542 52 : return bRet;
543 : }
544 :
545 20 : bool GDALVectorNonStreamingAlgorithmDataset::AddProcessedLayer(
546 : OGRLayer &srcLayer)
547 : {
548 20 : return AddProcessedLayer(srcLayer, *srcLayer.GetLayerDefn());
549 : }
550 :
551 : /************************************************************************/
552 : /* GDALVectorNonStreamingAlgorithmDataset::AddPassThroughLayer() */
553 : /************************************************************************/
554 :
555 6 : void GDALVectorNonStreamingAlgorithmDataset::AddPassThroughLayer(
556 : OGRLayer &oLayer)
557 : {
558 6 : m_passthrough_layers.push_back(
559 12 : std::make_unique<GDALVectorPipelinePassthroughLayer>(oLayer));
560 6 : m_layers.push_back(m_passthrough_layers.back().get());
561 6 : }
562 :
563 : /************************************************************************/
564 : /* GDALVectorNonStreamingAlgorithmDataset::GetLayerCount() */
565 : /************************************************************************/
566 :
567 74 : int GDALVectorNonStreamingAlgorithmDataset::GetLayerCount() const
568 : {
569 74 : return static_cast<int>(m_layers.size());
570 : }
571 :
572 : /************************************************************************/
573 : /* GDALVectorNonStreamingAlgorithmDataset::GetLayer() */
574 : /************************************************************************/
575 :
576 73 : OGRLayer *GDALVectorNonStreamingAlgorithmDataset::GetLayer(int idx) const
577 : {
578 73 : if (idx < 0 || idx >= static_cast<int>(m_layers.size()))
579 : {
580 4 : return nullptr;
581 : }
582 69 : return m_layers[idx];
583 : }
584 :
585 : /************************************************************************/
586 : /* GDALVectorNonStreamingAlgorithmDataset::TestCapability() */
587 : /************************************************************************/
588 :
589 18 : int GDALVectorNonStreamingAlgorithmDataset::TestCapability(
590 : const char *pszCap) const
591 : {
592 18 : if (EQUAL(pszCap, ODsCCreateLayer) || EQUAL(pszCap, ODsCDeleteLayer))
593 : {
594 4 : return false;
595 : }
596 :
597 14 : return m_ds->TestCapability(pszCap);
598 : }
599 :
600 : //! @endcond
|