Coverage Report

Created: 2025-12-31 08:30

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/gdal/ogr/ogrsf_frmts/edigeo/ogredigeolayer.cpp
Line
Count
Source
1
/******************************************************************************
2
 *
3
 * Project:  EDIGEO Translator
4
 * Purpose:  Implements OGREDIGEOLayer class.
5
 * Author:   Even Rouault, <even dot rouault at spatialys.com>
6
 *
7
 ******************************************************************************
8
 * Copyright (c) 2011-2013, Even Rouault <even dot rouault at spatialys.com>
9
 *
10
 * SPDX-License-Identifier: MIT
11
 ****************************************************************************/
12
13
#include "ogr_edigeo.h"
14
#include "cpl_conv.h"
15
#include "cpl_string.h"
16
#include "ogr_p.h"
17
#include "ogr_srs_api.h"
18
19
/************************************************************************/
20
/*                          OGREDIGEOLayer()                            */
21
/************************************************************************/
22
23
OGREDIGEOLayer::OGREDIGEOLayer(OGREDIGEODataSource *poDSIn, const char *pszName,
24
                               OGRwkbGeometryType eType,
25
                               OGRSpatialReference *poSRSIn)
26
0
    : poDS(poDSIn), poFeatureDefn(new OGRFeatureDefn(pszName)), poSRS(poSRSIn),
27
0
      nNextFID(0)
28
0
{
29
0
    if (poSRS)
30
0
        poSRS->Reference();
31
32
0
    poFeatureDefn->Reference();
33
0
    poFeatureDefn->SetGeomType(eType);
34
0
    if (poFeatureDefn->GetGeomFieldCount() != 0)
35
0
        poFeatureDefn->GetGeomFieldDefn(0)->SetSpatialRef(poSRS);
36
0
    SetDescription(poFeatureDefn->GetName());
37
0
}
38
39
/************************************************************************/
40
/*                          ~OGREDIGEOLayer()                           */
41
/************************************************************************/
42
43
OGREDIGEOLayer::~OGREDIGEOLayer()
44
45
0
{
46
0
    for (int i = 0; i < (int)aosFeatures.size(); i++)
47
0
        delete aosFeatures[i];
48
49
0
    poFeatureDefn->Release();
50
51
0
    if (poSRS)
52
0
        poSRS->Release();
53
0
}
54
55
/************************************************************************/
56
/*                            ResetReading()                            */
57
/************************************************************************/
58
59
void OGREDIGEOLayer::ResetReading()
60
61
0
{
62
0
    nNextFID = 0;
63
0
}
64
65
/************************************************************************/
66
/*                         GetNextRawFeature()                          */
67
/************************************************************************/
68
69
OGRFeature *OGREDIGEOLayer::GetNextRawFeature()
70
0
{
71
0
    if (nNextFID < (int)aosFeatures.size())
72
0
    {
73
0
        OGRFeature *poFeature = aosFeatures[nNextFID]->Clone();
74
0
        nNextFID++;
75
0
        return poFeature;
76
0
    }
77
0
    else
78
0
        return nullptr;
79
0
}
80
81
/************************************************************************/
82
/*                            GetFeature()                              */
83
/************************************************************************/
84
85
OGRFeature *OGREDIGEOLayer::GetFeature(GIntBig nFID)
86
0
{
87
0
    if (nFID >= 0 && nFID < (int)aosFeatures.size())
88
0
        return aosFeatures[(int)nFID]->Clone();
89
0
    else
90
0
        return nullptr;
91
0
}
92
93
/************************************************************************/
94
/*                           TestCapability()                           */
95
/************************************************************************/
96
97
int OGREDIGEOLayer::TestCapability(const char *pszCap) const
98
99
0
{
100
0
    if (EQUAL(pszCap, OLCFastFeatureCount))
101
0
        return m_poFilterGeom == nullptr && m_poAttrQuery == nullptr;
102
103
0
    else if (EQUAL(pszCap, OLCRandomRead))
104
0
        return TRUE;
105
106
0
    else if (EQUAL(pszCap, OLCStringsAsUTF8))
107
0
        return poDS->HasUTF8ContentOnly();
108
109
0
    return FALSE;
110
0
}
111
112
/************************************************************************/
113
/*                          GetFeatureCount()                           */
114
/************************************************************************/
115
116
GIntBig OGREDIGEOLayer::GetFeatureCount(int bForce)
117
0
{
118
0
    if (m_poFilterGeom != nullptr || m_poAttrQuery != nullptr)
119
0
        return OGRLayer::GetFeatureCount(bForce);
120
121
0
    return (int)aosFeatures.size();
122
0
}
123
124
/************************************************************************/
125
/*                             AddFeature()                             */
126
/************************************************************************/
127
128
void OGREDIGEOLayer::AddFeature(OGRFeature *poFeature)
129
0
{
130
0
    poFeature->SetFID(aosFeatures.size());
131
0
    aosFeatures.push_back(poFeature);
132
0
}
133
134
/************************************************************************/
135
/*                         GetAttributeIndex()                          */
136
/************************************************************************/
137
138
int OGREDIGEOLayer::GetAttributeIndex(const CPLString &osRID)
139
0
{
140
0
    std::map<CPLString, int>::iterator itAttrIndex =
141
0
        mapAttributeToIndex.find(osRID);
142
0
    if (itAttrIndex != mapAttributeToIndex.end())
143
0
        return itAttrIndex->second;
144
0
    else
145
0
        return -1;
146
0
}
147
148
/************************************************************************/
149
/*                           AddFieldDefn()                             */
150
/************************************************************************/
151
152
void OGREDIGEOLayer::AddFieldDefn(const CPLString &osName, OGRFieldType eType,
153
                                  const CPLString &osRID)
154
0
{
155
0
    if (!osRID.empty())
156
0
        mapAttributeToIndex[osRID] = poFeatureDefn->GetFieldCount();
157
158
0
    OGRFieldDefn oFieldDefn(osName, eType);
159
0
    poFeatureDefn->AddFieldDefn(&oFieldDefn);
160
0
}