• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

OSGeo / gdal / 15885686134

25 Jun 2025 07:44PM UTC coverage: 71.084%. Remained the same
15885686134

push

github

rouault
gdal_priv.h: fix C++11 compatibility

573814 of 807237 relevant lines covered (71.08%)

250621.56 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

62.6
/frmts/raw/ace2dataset.cpp
1
/******************************************************************************
2
 *
3
 * Project:  ACE2 Driver
4
 * Purpose:  Implementation of ACE2 elevation format read support.
5
 *           http://tethys.eaprs.cse.dmu.ac.uk/ACE2/shared/documentation
6
 * Author:   Even Rouault, <even dot rouault at spatialys.com>
7
 *
8
 ******************************************************************************
9
 * Copyright (c) 2011-2012, Even Rouault <even dot rouault at spatialys.com>
10
 *
11
 * SPDX-License-Identifier: MIT
12
 ****************************************************************************/
13

14
#include "gdal_frmts.h"
15
#include "ogr_spatialref.h"
16
#include "rawdataset.h"
17

18
static const char *const apszCategorySource[] = {
19
    "Pure SRTM (above 60deg N pure GLOBE data, below 60S pure ACE [original] "
20
    "data)",
21
    "SRTM voids filled by interpolation and/or altimeter data",
22
    "SRTM data warped using the ERS-1 Geodetic Mission",
23
    "SRTM data warped using EnviSat & ERS-2 data",
24
    "Mean lake level data derived from Altimetry",
25
    "GLOBE/ACE data warped using combined altimetry (only above 60deg N)",
26
    "Pure altimetry data (derived from ERS-1 Geodetic Mission, ERS-2 and "
27
    "EnviSat data using Delaunay Triangulation",
28
    nullptr};
29

30
static const char *const apszCategoryQuality[] = {
31
    "Generic - use base datasets",
32
    "Accuracy of greater than +/- 16m",
33
    "Accuracy between +/- 16m - +/- 10m",
34
    "Accuracy between +/-10m - +/-5m",
35
    "Accuracy between +/-5m - +/-1m",
36
    "Accuracy between +/-1m",
37
    nullptr};
38

39
static const char *const apszCategoryConfidence[] = {
40
    "No confidence could be derived due to lack of data",
41
    "Heights generated by interpolation",
42
    "Low confidence",
43
    "Low confidence",
44
    "Low confidence",
45
    "Medium confidence",
46
    "Medium confidence",
47
    "Medium confidence",
48
    "Medium confidence",
49
    "Medium confidence",
50
    "Medium confidence",
51
    "Medium confidence",
52
    "Medium confidence",
53
    "High confidence",
54
    "High confidence",
55
    "High confidence",
56
    "High confidence",
57
    "Inland water confidence",
58
    "Inland water confidence",
59
    "Inland water confidence",
60
    "Inland water confidence",
61
    "Inland water confidence",
62
    nullptr};
63

64
/************************************************************************/
65
/* ==================================================================== */
66
/*                             ACE2Dataset                              */
67
/* ==================================================================== */
68
/************************************************************************/
69

70
class ACE2Dataset final : public GDALPamDataset
71
{
72
    friend class ACE2RasterBand;
73

74
    OGRSpatialReference m_oSRS{};
75
    GDALGeoTransform m_gt{};
76

77
  public:
78
    ACE2Dataset();
79

80
    const OGRSpatialReference *GetSpatialRef() const override
1✔
81
    {
82
        return &m_oSRS;
1✔
83
    }
84

85
    CPLErr GetGeoTransform(GDALGeoTransform &gt) const override;
86

87
    static GDALDataset *Open(GDALOpenInfo *);
88
    static int Identify(GDALOpenInfo *);
89
};
90

91
/************************************************************************/
92
/* ==================================================================== */
93
/*                            ACE2RasterBand                            */
94
/* ==================================================================== */
95
/************************************************************************/
96

97
class ACE2RasterBand final : public RawRasterBand
98
{
99
  public:
100
    ACE2RasterBand(VSILFILE *fpRaw, GDALDataType eDataType, int nXSize,
101
                   int nYSize);
102

103
    const char *GetUnitType() override;
104
    char **GetCategoryNames() override;
105
};
106

107
/************************************************************************/
108
/* ==================================================================== */
109
/*                             ACE2Dataset                              */
110
/* ==================================================================== */
111
/************************************************************************/
112

113
/************************************************************************/
114
/*                            ACE2Dataset()                             */
115
/************************************************************************/
116

117
ACE2Dataset::ACE2Dataset()
2✔
118
{
119
    m_oSRS.SetFromUserInput(SRS_WKT_WGS84_LAT_LONG);
2✔
120
    m_oSRS.SetAxisMappingStrategy(OAMS_TRADITIONAL_GIS_ORDER);
2✔
121
}
2✔
122

123
/************************************************************************/
124
/*                          GetGeoTransform()                           */
125
/************************************************************************/
126

127
CPLErr ACE2Dataset::GetGeoTransform(GDALGeoTransform &gt) const
1✔
128

129
{
130
    gt = m_gt;
1✔
131
    return CE_None;
1✔
132
}
133

134
/************************************************************************/
135
/*                          ACE2RasterBand()                            */
136
/************************************************************************/
137

138
ACE2RasterBand::ACE2RasterBand(VSILFILE *fpRawIn, GDALDataType eDataTypeIn,
2✔
139
                               int nXSize, int nYSize)
2✔
140
    : RawRasterBand(fpRawIn, 0, GDALGetDataTypeSizeBytes(eDataTypeIn),
141
                    nXSize * GDALGetDataTypeSizeBytes(eDataTypeIn), eDataTypeIn,
4✔
142
                    CPL_IS_LSB, nXSize, nYSize, RawRasterBand::OwnFP::YES)
2✔
143
{
144
}
2✔
145

146
/************************************************************************/
147
/*                             GetUnitType()                            */
148
/************************************************************************/
149

150
const char *ACE2RasterBand::GetUnitType()
×
151
{
152
    if (eDataType == GDT_Float32)
×
153
        return "m";
×
154

155
    return "";
×
156
}
157

158
/************************************************************************/
159
/*                         GetCategoryNames()                           */
160
/************************************************************************/
161

162
char **ACE2RasterBand::GetCategoryNames()
×
163
{
164
    if (eDataType != GDT_Int16)
×
165
        return nullptr;
×
166

167
    const char *pszName = poDS->GetDescription();
×
168

169
    if (strstr(pszName, "_SOURCE_"))
×
170
        return const_cast<char **>(apszCategorySource);
×
171
    if (strstr(pszName, "_QUALITY_"))
×
172
        return const_cast<char **>(apszCategoryQuality);
×
173
    if (strstr(pszName, "_CONF_"))
×
174
        return const_cast<char **>(apszCategoryConfidence);
×
175

176
    return nullptr;
×
177
}
178

179
/************************************************************************/
180
/*                             Identify()                               */
181
/************************************************************************/
182

183
int ACE2Dataset::Identify(GDALOpenInfo *poOpenInfo)
57,074✔
184

185
{
186
    if (!(poOpenInfo->IsExtensionEqualToCI("ACE2") ||
114,143✔
187
          strstr(poOpenInfo->pszFilename, ".ACE2.gz") ||
57,069✔
188
          strstr(poOpenInfo->pszFilename, ".ace2.gz")))
57,069✔
189
        return FALSE;
57,069✔
190

191
    return TRUE;
4✔
192
}
193

194
/************************************************************************/
195
/*                                Open()                                */
196
/************************************************************************/
197

198
GDALDataset *ACE2Dataset::Open(GDALOpenInfo *poOpenInfo)
2✔
199

200
{
201
    if (!Identify(poOpenInfo))
2✔
202
        return nullptr;
×
203

204
    const std::string osBasename = CPLGetBasenameSafe(poOpenInfo->pszFilename);
4✔
205
    const char *pszBasename = osBasename.c_str();
2✔
206

207
    if (strlen(pszBasename) < 7)
2✔
208
        return nullptr;
×
209

210
    /* Determine southwest coordinates from filename */
211

212
    /* e.g. 30S120W_5M.ACE2 */
213
    char pszLatLonValueString[4] = {'\0'};
2✔
214
    memset(pszLatLonValueString, 0, 4);
2✔
215
    // cppcheck-suppress redundantCopy
216
    strncpy(pszLatLonValueString, &pszBasename[0], 2);
2✔
217
    int southWestLat = atoi(pszLatLonValueString);
2✔
218
    memset(pszLatLonValueString, 0, 4);
2✔
219
    // cppcheck-suppress redundantCopy
220
    strncpy(pszLatLonValueString, &pszBasename[3], 3);
2✔
221
    int southWestLon = atoi(pszLatLonValueString);
2✔
222

223
    if (pszBasename[2] == 'N' || pszBasename[2] == 'n')
2✔
224
        /*southWestLat = southWestLat*/;
225
    else if (pszBasename[2] == 'S' || pszBasename[2] == 's')
×
226
        southWestLat = southWestLat * -1;
×
227
    else
228
        return nullptr;
×
229

230
    if (pszBasename[6] == 'E' || pszBasename[6] == 'e')
2✔
231
        /*southWestLon = southWestLon*/;
232
    else if (pszBasename[6] == 'W' || pszBasename[6] == 'w')
×
233
        southWestLon = southWestLon * -1;
×
234
    else
235
        return nullptr;
×
236

237
    GDALDataType eDT = GDT_Unknown;
2✔
238
    if (strstr(pszBasename, "_CONF_") || strstr(pszBasename, "_QUALITY_") ||
2✔
239
        strstr(pszBasename, "_SOURCE_"))
2✔
240
        eDT = GDT_Int16;
×
241
    else
242
        eDT = GDT_Float32;
2✔
243
    const int nWordSize = GDALGetDataTypeSizeBytes(eDT);
2✔
244

245
    VSIStatBufL sStat;
246
    if (strstr(pszBasename, "_5M"))
2✔
247
        sStat.st_size = 180 * 180 * nWordSize;
2✔
248
    else if (strstr(pszBasename, "_30S"))
×
249
        sStat.st_size = 1800 * 1800 * nWordSize;
×
250
    else if (strstr(pszBasename, "_9S"))
×
251
        sStat.st_size = 6000 * 6000 * nWordSize;
×
252
    else if (strstr(pszBasename, "_3S"))
×
253
        sStat.st_size = 18000 * 18000 * nWordSize;
×
254
    /* Check file size otherwise */
255
    else if (VSIStatL(poOpenInfo->pszFilename, &sStat) != 0)
×
256
    {
257
        return nullptr;
×
258
    }
259

260
    int nXSize = 0;
2✔
261
    int nYSize = 0;
2✔
262

263
    double dfPixelSize = 0;
2✔
264
    if (sStat.st_size == 180 * 180 * nWordSize)
2✔
265
    {
266
        /* 5 minute */
267
        nXSize = 180;
2✔
268
        nYSize = 180;
2✔
269
        dfPixelSize = 5.0 / 60;
2✔
270
    }
271
    else if (sStat.st_size == 1800 * 1800 * nWordSize)
×
272
    {
273
        /* 30 s */
274
        nXSize = 1800;
×
275
        nYSize = 1800;
×
276
        dfPixelSize = 30.0 / 3600;
×
277
    }
278
    else if (sStat.st_size == 6000 * 6000 * nWordSize)
×
279
    {
280
        /* 9 s */
281
        nXSize = 6000;
×
282
        nYSize = 6000;
×
283
        dfPixelSize = 9.0 / 3600;
×
284
    }
285
    else if (sStat.st_size == 18000 * 18000 * nWordSize)
×
286
    {
287
        /* 3 s */
288
        nXSize = 18000;
×
289
        nYSize = 18000;
×
290
        dfPixelSize = 3.0 / 3600;
×
291
    }
292
    else
293
        return nullptr;
×
294

295
    /* -------------------------------------------------------------------- */
296
    /*      Open file.                                                      */
297
    /* -------------------------------------------------------------------- */
298

299
    CPLString osFilename = poOpenInfo->pszFilename;
4✔
300
    if ((strstr(poOpenInfo->pszFilename, ".ACE2.gz") ||
2✔
301
         strstr(poOpenInfo->pszFilename, ".ace2.gz")) &&
2✔
302
        !STARTS_WITH(poOpenInfo->pszFilename, "/vsigzip/"))
×
303
        osFilename = "/vsigzip/" + osFilename;
×
304

305
    VSILFILE *fpImage = VSIFOpenL(osFilename, "rb+");
2✔
306
    if (fpImage == nullptr)
2✔
307
        return nullptr;
×
308

309
    /* -------------------------------------------------------------------- */
310
    /*      Create the dataset.                                             */
311
    /* -------------------------------------------------------------------- */
312
    auto poDS = std::make_unique<ACE2Dataset>();
4✔
313

314
    poDS->nRasterXSize = nXSize;
2✔
315
    poDS->nRasterYSize = nYSize;
2✔
316

317
    poDS->m_gt[0] = southWestLon;
2✔
318
    poDS->m_gt[1] = dfPixelSize;
2✔
319
    poDS->m_gt[2] = 0.0;
2✔
320
    poDS->m_gt[3] = southWestLat + nYSize * dfPixelSize;
2✔
321
    poDS->m_gt[4] = 0.0;
2✔
322
    poDS->m_gt[5] = -dfPixelSize;
2✔
323

324
    /* -------------------------------------------------------------------- */
325
    /*      Create band information objects                                 */
326
    /* -------------------------------------------------------------------- */
327
    auto poBand =
328
        std::make_unique<ACE2RasterBand>(fpImage, eDT, nXSize, nYSize);
4✔
329
    if (!poBand->IsValid())
2✔
330
        return nullptr;
×
331
    poDS->SetBand(1, std::move(poBand));
2✔
332

333
    /* -------------------------------------------------------------------- */
334
    /*      Initialize any PAM information.                                 */
335
    /* -------------------------------------------------------------------- */
336
    poDS->SetDescription(poOpenInfo->pszFilename);
2✔
337
    poDS->TryLoadXML();
2✔
338

339
    /* -------------------------------------------------------------------- */
340
    /*      Check for overviews.                                            */
341
    /* -------------------------------------------------------------------- */
342
    poDS->oOvManager.Initialize(poDS.get(), poOpenInfo->pszFilename);
2✔
343

344
    return poDS.release();
2✔
345
}
346

347
/************************************************************************/
348
/*                          GDALRegister_ACE2()                         */
349
/************************************************************************/
350

351
void GDALRegister_ACE2()
1,911✔
352

353
{
354
    if (GDALGetDriverByName("ACE2") != nullptr)
1,911✔
355
        return;
282✔
356

357
    GDALDriver *poDriver = new GDALDriver();
1,629✔
358

359
    poDriver->SetDescription("ACE2");
1,629✔
360
    poDriver->SetMetadataItem(GDAL_DCAP_RASTER, "YES");
1,629✔
361
    poDriver->SetMetadataItem(GDAL_DMD_LONGNAME, "ACE2");
1,629✔
362
    poDriver->SetMetadataItem(GDAL_DMD_HELPTOPIC, "drivers/raster/ace2.html");
1,629✔
363
    poDriver->SetMetadataItem(GDAL_DMD_EXTENSION, "ACE2");
1,629✔
364
    poDriver->SetMetadataItem(GDAL_DCAP_VIRTUALIO, "YES");
1,629✔
365

366
    poDriver->pfnOpen = ACE2Dataset::Open;
1,629✔
367
    poDriver->pfnIdentify = ACE2Dataset::Identify;
1,629✔
368

369
    GetGDALDriverManager()->RegisterDriver(poDriver);
1,629✔
370
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2025 Coveralls, Inc