13#ifndef GDALALG_VECTOR_GEOM_INCLUDED
14#define GDALALG_VECTOR_GEOM_INCLUDED
16#include "gdalalg_vector_pipeline.h"
25class GDALVectorGeomAlgorithm
26 :
public GDALVectorPipelineStepAlgorithm
29 static constexpr const char *NAME =
"geom";
30 static constexpr const char *DESCRIPTION =
31 "Geometry operations on a vector dataset.";
32 static constexpr const char *HELP_URL =
"/programs/gdal_vector_geom.html";
34 explicit GDALVectorGeomAlgorithm(
bool standaloneStep =
false);
37 bool RunStep(GDALPipelineStepRunContext &ctxt)
override;
39 void WarnIfDeprecated()
override;
43 template <
class MyAlgorithm>
bool RegisterSubAlgorithm(
bool standalone)
45 GDALAlgorithmRegistry::AlgInfo info;
46 info.
m_name = MyAlgorithm::NAME;
47 info.
m_aliases = MyAlgorithm::GetAliasesStatic();
48 info.
m_creationFunc = [standalone]() -> std::unique_ptr<GDALAlgorithm>
49 {
return std::make_unique<MyAlgorithm>(standalone); };
58class GDALVectorGeomAlgorithmStandalone final :
public GDALVectorGeomAlgorithm
61 GDALVectorGeomAlgorithmStandalone()
62 : GDALVectorGeomAlgorithm( true)
66 ~GDALVectorGeomAlgorithmStandalone()
override;
73class GDALVectorGeomAbstractAlgorithm
74 :
public GDALVectorPipelineStepAlgorithm
79 std::string m_activeLayer{};
80 std::string m_geomField{};
83 virtual std::unique_ptr<OGRLayerWithTranslateFeature>
84 CreateAlgLayer(OGRLayer &srcLayer) = 0;
86 GDALVectorGeomAbstractAlgorithm(
const std::string &name,
87 const std::string &description,
88 const std::string &helpURL,
89 bool standaloneStep, OptionsBase &opts);
91 bool RunStep(GDALPipelineStepRunContext &ctxt)
override;
94 std::string &m_activeLayer;
102class GDALVectorGeomOneToOneAlgorithmLayer
103 :
public GDALVectorPipelineOutputLayer
106 const OGRFeatureDefn *GetLayerDefn()
const override
108 return m_srcLayer.GetLayerDefn();
111 GIntBig GetFeatureCount(
int bForce)
override
113 if (!m_poAttrQuery && !m_poFilterGeom)
114 return m_srcLayer.GetFeatureCount(bForce);
118 OGRErr IGetExtent(
int iGeomField, OGREnvelope *psExtent,
119 bool bForce)
override
121 return m_srcLayer.GetExtent(iGeomField, psExtent, bForce);
124 OGRFeature *GetFeature(
GIntBig nFID)
override
127 std::unique_ptr<OGRFeature>(m_srcLayer.GetFeature(nFID));
130 return TranslateFeature(std::move(poSrcFeature)).release();
133 int TestCapability(
const char *pszCap)
const override
142 return m_srcLayer.TestCapability(pszCap);
148 const typename T::Options m_opts;
150 GDALVectorGeomOneToOneAlgorithmLayer(OGRLayer &oSrcLayer,
151 const typename T::Options &opts)
152 : GDALVectorPipelineOutputLayer(oSrcLayer), m_opts(opts)
156 if (!m_opts.m_geomField.empty())
159 m_opts.m_geomField.c_str());
163 m_iGeomIdx = INT_MAX;
167 bool IsSelectedGeomField(
int idx)
const
169 return m_iGeomIdx < 0 || idx == m_iGeomIdx;
172 virtual std::unique_ptr<OGRFeature>
173 TranslateFeature(std::unique_ptr<OGRFeature> poSrcFeature)
const = 0;
175 void TranslateFeature(
176 std::unique_ptr<OGRFeature> poSrcFeature,
177 std::vector<std::unique_ptr<OGRFeature>> &apoOutFeatures)
override
179 auto poDstFeature = TranslateFeature(std::move(poSrcFeature));
181 apoOutFeatures.push_back(std::move(poDstFeature));
200class GDALGeosNonStreamingAlgorithmDataset
201 :
public GDALVectorNonStreamingAlgorithmDataset
204 GDALGeosNonStreamingAlgorithmDataset();
206 ~GDALGeosNonStreamingAlgorithmDataset()
override;
210 bool Process(OGRLayer &srcLayer, OGRLayer &dstLayer)
override;
212 virtual bool ProcessGeos() = 0;
215 virtual bool PolygonsOnly()
const = 0;
218 virtual bool SkipEmpty()
const = 0;
220 void SetSourceGeometryField(
int i)
222 m_sourceGeometryField = i;
227 std::vector<GEOSGeometry *> m_apoGeosInputs{};
228 GEOSGeometry *m_poGeosResultAsCollection{
nullptr};
229 GEOSGeometry **m_papoGeosResults{
nullptr};
232 bool ConvertInputsToGeos(OGRLayer &srcLayer, OGRLayer &dstLayer,
235 bool ConvertOutputsFromGeos(OGRLayer &dstLayer);
239 std::vector<std::unique_ptr<OGRFeature>> m_apoFeatures{};
240 unsigned int m_nGeosResultSize{0};
241 int m_sourceGeometryField{0};
std::function m_creationFunc
Creation function.
Definition gdalalgorithm_cpp.h:2150
std::string m_name
Algorithm (short) name.
Definition gdalalgorithm_cpp.h:2145
std::vector< std::string > m_aliases
Aliases.
Definition gdalalgorithm_cpp.h:2147
bool RegisterSubAlgorithm()
Register the sub-algorithm of type MyAlgorithm.
Definition gdalalgorithm_cpp.h:2635
virtual char ** GetMetadata(const char *pszDomain="")
Fetch metadata.
Definition gdalmajorobject.cpp:228
virtual const char * GetDescription() const
Fetch object description.
Definition gdalmajorobject.cpp:61
virtual int GetGeomFieldIndex(const char *) const
Find geometry field by name.
Definition ogrfeaturedefn.cpp:950
virtual GIntBig GetFeatureCount(int bForce=TRUE)
Fetch the feature count in this layer.
Definition ogrlayer.cpp:205
virtual const OGRFeatureDefn * GetLayerDefn() const =0
Fetch the schema information for this layer.
#define EQUAL(a, b)
Alias for strcasecmp() == 0.
Definition cpl_port.h:541
#define CPL_DISALLOW_COPY_ASSIGN(ClassName)
Helper to remove the copy and assignment constructors so that the compiler will not generate the defa...
Definition cpl_port.h:936
long long GIntBig
Large signed integer type (generally 64-bit integer type).
Definition cpl_port.h:205
#define OLCStringsAsUTF8
Layer capability for strings returned with UTF-8 \ encoding.
Definition ogr_core.h:998
#define OLCFastFeatureCount
Layer capability for fast feature count retrieval .
Definition ogr_core.h:965
#define OLCZGeometries
Layer capability for geometry with Z dimension support.
Definition ogr_core.h:1010
#define OLCRandomRead
Layer capability for random read.
Definition ogr_core.h:959
#define OLCFastGetExtent
Layer capability for fast extent retrieval.
Definition ogr_core.h:968
#define OLCMeasuredGeometries
Layer capability for measured geometries support .
Definition ogr_core.h:1007
int OGRErr
Type for a OGR error.
Definition ogr_core.h:370
#define OLCCurveGeometries
Layer capability for curve geometries support.
Definition ogr_core.h:1005
struct GEOSContextHandle_HS * GEOSContextHandle_t
GEOS context handle type.
Definition ogr_geometry.h:110