Coverage Report

Created: 2026-04-01 06:20

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/gdal/apps/gdalalg_vector_create.h
Line
Count
Source
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
    bool CanBeFirstStep() const override
46
0
    {
47
0
        return true;
48
0
    }
49
50
    bool CanBeMiddleStep() const override
51
0
    {
52
0
        return true;
53
0
    }
54
55
    bool CanBeLastStep() const override
56
0
    {
57
0
        return true;
58
0
    }
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::vector<OGRFieldDefn> &fieldDefinitions,
67
        const std::vector<OGRGeomFieldDefn> &geometryFieldDefinitions) const;
68
69
    std::string m_crs;
70
    std::string m_geometryType;
71
    std::string m_geometryFieldName;
72
    std::string m_schemaJsonOrPath;
73
    std::vector<OGRFieldDefn> m_fieldDefinitions;
74
    std::vector<std::string> m_fieldStrDefinitions;
75
};
76
77
/************************************************************************/
78
/*                 GDALVectorCreateAlgorithmStandalone                  */
79
/************************************************************************/
80
81
class GDALVectorCreateAlgorithmStandalone final
82
    : public GDALVectorCreateAlgorithm
83
{
84
  public:
85
    GDALVectorCreateAlgorithmStandalone()
86
0
        : GDALVectorCreateAlgorithm(/* standaloneStep = */ true)
87
0
    {
88
0
    }
89
90
    ~GDALVectorCreateAlgorithmStandalone() override;
91
};
92
93
//! @endcond
94
95
#endif  // GDALALG_VECTOR_CREATE_INCLUDED