LCOV - code coverage report
Current view: top level - apps - gdalalg_vector_create.h (source / functions) Hit Total Coverage
Test: gdal_filtered.info Lines: 10 10 100.0 %
Date: 2026-04-03 14:38:35 Functions: 6 6 100.0 %

          Line data    Source code
       1             : /******************************************************************************
       2             :  *
       3             :  * Project:  GDAL
       4             :  * Purpose:  gdal "vector create" subcommand
       5             :  * Author:   Alessandro Pasotti <elpaso at itopen dot it>
       6             :  *
       7             :  ******************************************************************************
       8             :  * Copyright (c) 2026, Alessandro Pasotti <elpaso at itopen dot it>
       9             :  *
      10             :  * SPDX-License-Identifier: MIT
      11             :  ****************************************************************************/
      12             : 
      13             : #ifndef GDALALG_VECTOR_CREATE_INCLUDED
      14             : #define GDALALG_VECTOR_CREATE_INCLUDED
      15             : 
      16             : #include "gdalalg_vector_pipeline.h"
      17             : 
      18             : //! @cond Doxygen_Suppress
      19             : 
      20             : /************************************************************************/
      21             : /*                      GDALVectorCreateAlgorithm                       */
      22             : /************************************************************************/
      23             : 
      24             : class GDALVectorCreateAlgorithm /* non final */
      25             :     : public GDALVectorPipelineStepAlgorithm
      26             : {
      27             :   public:
      28             :     static constexpr const char *NAME = "create";
      29             :     static constexpr const char *DESCRIPTION = "Create a vector dataset.";
      30             :     static constexpr const char *HELP_URL = "/programs/gdal_vector_create.html";
      31             : 
      32             :     explicit GDALVectorCreateAlgorithm(bool /* standaloneStep */ = true);
      33             : 
      34             :   private:
      35             :     bool RunStep(GDALPipelineStepRunContext &ctxt) override;
      36             :     bool RunImpl(GDALProgressFunc pfnProgress, void *pProgressData) override;
      37             : 
      38             :     /** Get the list of fields to create in the output layer,
      39             :      * based on the given OGR_SCHEMA or the --like argument
      40             :      * and/or the --field parameters.
      41             :      * OGR_SCHEMA and --like and --field parameters are mutually exclusive
      42             :      */
      43             :     std::vector<OGRFieldDefn> GetOutputFields() const;
      44             : 
      45          18 :     bool CanBeFirstStep() const override
      46             :     {
      47          18 :         return true;
      48             :     }
      49             : 
      50          12 :     bool CanBeMiddleStep() const override
      51             :     {
      52          12 :         return true;
      53             :     }
      54             : 
      55           4 :     bool CanBeLastStep() const override
      56             :     {
      57           4 :         return true;
      58             :     }
      59             : 
      60             :     /**
      61             :      * Create a layer in the given dataset given the fields defined in fieldDefinitions
      62             :      * and geometry fields defined in geometryFieldDefinitions.
      63             :      */
      64             :     bool CreateLayer(
      65             :         GDALDataset *poDstDS, const std::string &layerName,
      66             :         const std::string &fidColumnName,
      67             :         const std::vector<OGRFieldDefn> &fieldDefinitions,
      68             :         const std::vector<OGRGeomFieldDefn> &geometryFieldDefinitions) const;
      69             : 
      70             :     std::string m_crs{};
      71             :     std::string m_fidColumnName{};
      72             :     std::string m_geometryType{};
      73             :     std::string m_geometryFieldName{"geom"};
      74             :     std::string m_schemaJsonOrPath{};
      75             :     std::vector<OGRFieldDefn> m_fieldDefinitions{};
      76             :     std::vector<std::string> m_fieldStrDefinitions{};
      77             : };
      78             : 
      79             : /************************************************************************/
      80             : /*                 GDALVectorCreateAlgorithmStandalone                  */
      81             : /************************************************************************/
      82             : 
      83         170 : class GDALVectorCreateAlgorithmStandalone final
      84             :     : public GDALVectorCreateAlgorithm
      85             : {
      86             :   public:
      87          85 :     GDALVectorCreateAlgorithmStandalone()
      88          85 :         : GDALVectorCreateAlgorithm(/* standaloneStep = */ true)
      89             :     {
      90          85 :     }
      91             : 
      92             :     ~GDALVectorCreateAlgorithmStandalone() override;
      93             : };
      94             : 
      95             : //! @endcond
      96             : 
      97             : #endif  // GDALALG_VECTOR_CREATE_INCLUDED

Generated by: LCOV version 1.14