1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104
|
/******************************************************************************
*
* Project: GDAL
* Purpose: "gdal vector segmentize"
* Author: Even Rouault <even dot rouault at spatialys.com>
*
******************************************************************************
* Copyright (c) 2025, Even Rouault <even dot rouault at spatialys.com>
*
* SPDX-License-Identifier: MIT
****************************************************************************/
#include "gdalalg_vector_segmentize.h"
#include "gdal_priv.h"
#include "ogrsf_frmts.h"
//! @cond Doxygen_Suppress
#ifndef _
#define _(x) (x)
#endif
/************************************************************************/
/* GDALVectorSegmentizeAlgorithm() */
/************************************************************************/
GDALVectorSegmentizeAlgorithm::GDALVectorSegmentizeAlgorithm(
bool standaloneStep)
: GDALVectorGeomAbstractAlgorithm(NAME, DESCRIPTION, HELP_URL,
standaloneStep, m_opts)
{
AddArg("max-length", 0, _("Maximum length of a segment"),
&m_opts.m_maxLength)
.SetPositional()
.SetRequired()
.SetMinValueExcluded(0);
}
namespace
{
/************************************************************************/
/* GDALVectorSegmentizeAlgorithmLayer */
/************************************************************************/
class GDALVectorSegmentizeAlgorithmLayer final
: public GDALVectorGeomOneToOneAlgorithmLayer<GDALVectorSegmentizeAlgorithm>
{
protected:
using GDALVectorGeomOneToOneAlgorithmLayer::TranslateFeature;
std::unique_ptr<OGRFeature>
TranslateFeature(std::unique_ptr<OGRFeature> poSrcFeature) const override;
public:
GDALVectorSegmentizeAlgorithmLayer(
OGRLayer &oSrcLayer, const GDALVectorSegmentizeAlgorithm::Options &opts)
: GDALVectorGeomOneToOneAlgorithmLayer<GDALVectorSegmentizeAlgorithm>(
oSrcLayer, opts)
{
}
};
/************************************************************************/
/* TranslateFeature() */
/************************************************************************/
std::unique_ptr<OGRFeature>
GDALVectorSegmentizeAlgorithmLayer::TranslateFeature(
std::unique_ptr<OGRFeature> poSrcFeature) const
{
const int nGeomFieldCount = poSrcFeature->GetGeomFieldCount();
for (int i = 0; i < nGeomFieldCount; ++i)
{
if (IsSelectedGeomField(i))
{
if (auto poGeom = poSrcFeature->GetGeomFieldRef(i))
{
poGeom->segmentize(m_opts.m_maxLength);
}
}
}
return poSrcFeature;
}
} // namespace
/************************************************************************/
/* GDALVectorSegmentizeAlgorithm::CreateAlgLayer() */
/************************************************************************/
std::unique_ptr<OGRLayerWithTranslateFeature>
GDALVectorSegmentizeAlgorithm::CreateAlgLayer(OGRLayer &srcLayer)
{
return std::make_unique<GDALVectorSegmentizeAlgorithmLayer>(srcLayer,
m_opts);
}
GDALVectorSegmentizeAlgorithmStandalone::
~GDALVectorSegmentizeAlgorithmStandalone() = default;
//! @endcond
|