Coverage Report

Created: 2026-03-30 09:00

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/gdal/ogr/ogrsf_frmts/avc/ogravcbindatasource.cpp
Line
Count
Source
1
/******************************************************************************
2
 *
3
 * Project:  OGR
4
 * Purpose:  Implements OGRAVCBinDataSource class.
5
 * Author:   Frank Warmerdam, warmerdam@pobox.com
6
 *
7
 ******************************************************************************
8
 * Copyright (c) 2002, Frank Warmerdam <warmerdam@pobox.com>
9
 *
10
 * SPDX-License-Identifier: MIT
11
 ****************************************************************************/
12
13
#include "ogr_avc.h"
14
#include "cpl_conv.h"
15
#include "cpl_string.h"
16
17
/************************************************************************/
18
/*                        OGRAVCBinDataSource()                         */
19
/************************************************************************/
20
21
OGRAVCBinDataSource::OGRAVCBinDataSource()
22
20.7k
    : papoLayers(nullptr), nLayers(0), psAVC(nullptr)
23
20.7k
{
24
20.7k
    poSRS = nullptr;
25
20.7k
}
26
27
/************************************************************************/
28
/*                        ~OGRAVCBinDataSource()                        */
29
/************************************************************************/
30
31
OGRAVCBinDataSource::~OGRAVCBinDataSource()
32
33
20.7k
{
34
20.7k
    if (psAVC)
35
14.8k
    {
36
14.8k
        AVCE00ReadClose(psAVC);
37
14.8k
        psAVC = nullptr;
38
14.8k
    }
39
40
33.4k
    for (int i = 0; i < nLayers; i++)
41
12.6k
        delete papoLayers[i];
42
43
20.7k
    CPLFree(papoLayers);
44
20.7k
}
45
46
/************************************************************************/
47
/*                                Open()                                */
48
/************************************************************************/
49
50
int OGRAVCBinDataSource::Open(const char *pszNewName, int bTestOpen)
51
52
20.7k
{
53
    /* -------------------------------------------------------------------- */
54
    /*      Open the source file.  Suppress error reporting if we are in    */
55
    /*      TestOpen mode.                                                  */
56
    /* -------------------------------------------------------------------- */
57
20.7k
    if (bTestOpen)
58
20.7k
        CPLPushErrorHandler(CPLQuietErrorHandler);
59
60
20.7k
    psAVC = AVCE00ReadOpen(pszNewName);
61
62
20.7k
    if (bTestOpen)
63
20.7k
    {
64
20.7k
        CPLPopErrorHandler();
65
20.7k
        CPLErrorReset();
66
20.7k
    }
67
68
20.7k
    if (psAVC == nullptr)
69
5.96k
        return FALSE;
70
71
14.8k
    pszCoverageName = CPLStrdup(psAVC->pszCoverName);
72
73
    // Read SRS first
74
112k
    for (int iSection = 0; iSection < psAVC->numSections; iSection++)
75
98.1k
    {
76
98.1k
        AVCE00Section *psSec = psAVC->pasSections + iSection;
77
78
98.1k
        switch (psSec->eType)
79
98.1k
        {
80
13.0k
            case AVCFilePRJ:
81
13.0k
            {
82
13.0k
                AVCBinFile *hFile = AVCBinReadOpen(
83
13.0k
                    psAVC->pszCoverPath, psSec->pszFilename, psAVC->eCoverType,
84
13.0k
                    psSec->eType, psAVC->psDBCSInfo);
85
13.0k
                if (hFile && poSRS == nullptr)
86
12.9k
                {
87
12.9k
                    char **papszPRJ = AVCBinReadNextPrj(hFile);
88
89
12.9k
                    poSRS = new OGRSpatialReference();
90
12.9k
                    poSRS->SetAxisMappingStrategy(OAMS_TRADITIONAL_GIS_ORDER);
91
12.9k
                    if (poSRS->importFromESRI(papszPRJ) != OGRERR_NONE)
92
8.07k
                    {
93
8.07k
                        CPLError(CE_Warning, CPLE_AppDefined,
94
8.07k
                                 "Failed to parse PRJ section, ignoring.");
95
8.07k
                        delete poSRS;
96
8.07k
                        poSRS = nullptr;
97
8.07k
                    }
98
12.9k
                }
99
13.0k
                if (hFile)
100
12.9k
                {
101
12.9k
                    AVCBinReadClose(hFile);
102
12.9k
                }
103
13.0k
            }
104
13.0k
            break;
105
106
85.1k
            default:
107
85.1k
                break;
108
98.1k
        }
109
98.1k
    }
110
111
    /* -------------------------------------------------------------------- */
112
    /*      Create layers for the "interesting" sections of the coverage.   */
113
    /* -------------------------------------------------------------------- */
114
115
14.8k
    papoLayers = static_cast<OGRLayer **>(
116
14.8k
        CPLCalloc(sizeof(OGRLayer *), psAVC->numSections));
117
14.8k
    nLayers = 0;
118
119
112k
    for (int iSection = 0; iSection < psAVC->numSections; iSection++)
120
98.1k
    {
121
98.1k
        AVCE00Section *psSec = psAVC->pasSections + iSection;
122
123
98.1k
        switch (psSec->eType)
124
98.1k
        {
125
1.41k
            case AVCFileARC:
126
2.86k
            case AVCFilePAL:
127
3.08k
            case AVCFileCNT:
128
4.40k
            case AVCFileLAB:
129
9.66k
            case AVCFileRPL:
130
10.0k
            case AVCFileTXT:
131
12.6k
            case AVCFileTX6:
132
12.6k
                papoLayers[nLayers++] = new OGRAVCBinLayer(this, psSec);
133
12.6k
                break;
134
135
85.4k
            default:
136
85.4k
                break;
137
98.1k
        }
138
98.1k
    }
139
140
14.8k
    return nLayers > 0;
141
14.8k
}
142
143
/************************************************************************/
144
/*                           TestCapability()                           */
145
/************************************************************************/
146
147
int OGRAVCBinDataSource::TestCapability(const char *) const
148
0
{
149
0
    return FALSE;
150
0
}
151
152
/************************************************************************/
153
/*                              GetLayer()                              */
154
/************************************************************************/
155
156
const OGRLayer *OGRAVCBinDataSource::GetLayer(int iLayer) const
157
158
27.9k
{
159
27.9k
    if (iLayer < 0 || iLayer >= nLayers)
160
0
        return nullptr;
161
162
27.9k
    return papoLayers[iLayer];
163
27.9k
}