Coverage Report

Created: 2026-02-14 06:52

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/gdal/apps/gdalalg_vector_swap_xy.cpp
Line
Count
Source
1
/******************************************************************************
2
 *
3
 * Project:  GDAL
4
 * Purpose:  "gdal vector swap-xy"
5
 * Author:   Even Rouault <even dot rouault at spatialys.com>
6
 *
7
 ******************************************************************************
8
 * Copyright (c) 2025, Even Rouault <even dot rouault at spatialys.com>
9
 *
10
 * SPDX-License-Identifier: MIT
11
 ****************************************************************************/
12
13
#include "gdalalg_vector_swap_xy.h"
14
15
#include "gdal_priv.h"
16
#include "ogrsf_frmts.h"
17
18
//! @cond Doxygen_Suppress
19
20
#ifndef _
21
#define _(x) (x)
22
#endif
23
24
/************************************************************************/
25
/*                     GDALVectorSwapXYAlgorithm()                      */
26
/************************************************************************/
27
28
GDALVectorSwapXYAlgorithm::GDALVectorSwapXYAlgorithm(bool standaloneStep)
29
0
    : GDALVectorGeomAbstractAlgorithm(NAME, DESCRIPTION, HELP_URL,
30
0
                                      standaloneStep, m_opts)
31
0
{
32
0
}
33
34
namespace
35
{
36
37
/************************************************************************/
38
/*                    GDALVectorSwapXYAlgorithmLayer                    */
39
/************************************************************************/
40
41
class GDALVectorSwapXYAlgorithmLayer final
42
    : public GDALVectorGeomOneToOneAlgorithmLayer<GDALVectorSwapXYAlgorithm>
43
{
44
  public:
45
    GDALVectorSwapXYAlgorithmLayer(
46
        OGRLayer &oSrcLayer, const GDALVectorSwapXYAlgorithm::Options &opts)
47
0
        : GDALVectorGeomOneToOneAlgorithmLayer<GDALVectorSwapXYAlgorithm>(
48
0
              oSrcLayer, opts)
49
0
    {
50
0
    }
51
52
    OGRErr IGetExtent(int iGeomField, OGREnvelope *psExtent,
53
                      bool bForce) override
54
0
    {
55
0
        OGRErr eErr = m_srcLayer.GetExtent(iGeomField, psExtent, bForce);
56
0
        if (eErr == CE_None)
57
0
        {
58
0
            std::swap(psExtent->MinX, psExtent->MinY);
59
0
            std::swap(psExtent->MaxX, psExtent->MaxY);
60
0
        }
61
0
        return eErr;
62
0
    }
63
64
  protected:
65
    using GDALVectorGeomOneToOneAlgorithmLayer::TranslateFeature;
66
67
    std::unique_ptr<OGRFeature>
68
    TranslateFeature(std::unique_ptr<OGRFeature> poSrcFeature) const override;
69
};
70
71
/************************************************************************/
72
/*                          TranslateFeature()                          */
73
/************************************************************************/
74
75
std::unique_ptr<OGRFeature> GDALVectorSwapXYAlgorithmLayer::TranslateFeature(
76
    std::unique_ptr<OGRFeature> poSrcFeature) const
77
0
{
78
0
    const int nGeomFieldCount = poSrcFeature->GetGeomFieldCount();
79
0
    for (int i = 0; i < nGeomFieldCount; ++i)
80
0
    {
81
0
        if (IsSelectedGeomField(i))
82
0
        {
83
0
            if (auto poGeom = poSrcFeature->GetGeomFieldRef(i))
84
0
            {
85
0
                poGeom->swapXY();
86
0
            }
87
0
        }
88
0
    }
89
90
0
    return poSrcFeature;
91
0
}
92
93
}  // namespace
94
95
/************************************************************************/
96
/*             GDALVectorSwapXYAlgorithm::CreateAlgLayer()              */
97
/************************************************************************/
98
99
std::unique_ptr<OGRLayerWithTranslateFeature>
100
GDALVectorSwapXYAlgorithm::CreateAlgLayer(OGRLayer &srcLayer)
101
0
{
102
0
    return std::make_unique<GDALVectorSwapXYAlgorithmLayer>(srcLayer, m_opts);
103
0
}
104
105
0
GDALVectorSwapXYAlgorithmStandalone::~GDALVectorSwapXYAlgorithmStandalone() =
106
    default;
107
108
//! @endcond