Coverage Report

Created: 2026-03-30 09:00

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/gdal/ogr/ogresrijsongeometry.cpp
Line
Count
Source
1
// SPDX-License-Identifier: MIT
2
// Copyright 2024, Even Rouault <even.rouault at spatialys.com>
3
4
/*! @cond Doxygen_Suppress */
5
6
#include "ogresrijsongeometry.h"
7
8
#include "ogrlibjsonutils.h"
9
10
#include "ogr_geometry.h"
11
#include "ogr_spatialref.h"
12
13
static OGRPoint *OGRESRIJSONReadPoint(json_object *poObj);
14
static OGRGeometry *OGRESRIJSONReadLineString(json_object *poObj);
15
static OGRGeometry *OGRESRIJSONReadPolygon(json_object *poObj);
16
static OGRMultiPoint *OGRESRIJSONReadMultiPoint(json_object *poObj);
17
18
/************************************************************************/
19
/*                      OGRESRIJSONReadGeometry()                       */
20
/************************************************************************/
21
22
OGRGeometry *OGRESRIJSONReadGeometry(json_object *poObj)
23
35
{
24
35
    OGRGeometry *poGeometry = nullptr;
25
26
35
    if (OGRGeoJSONFindMemberByName(poObj, "x"))
27
1
        poGeometry = OGRESRIJSONReadPoint(poObj);
28
34
    else if (OGRGeoJSONFindMemberByName(poObj, "paths"))
29
0
        poGeometry = OGRESRIJSONReadLineString(poObj);
30
34
    else if (OGRGeoJSONFindMemberByName(poObj, "rings"))
31
33
        poGeometry = OGRESRIJSONReadPolygon(poObj);
32
1
    else if (OGRGeoJSONFindMemberByName(poObj, "points"))
33
0
        poGeometry = OGRESRIJSONReadMultiPoint(poObj);
34
35
35
    return poGeometry;
36
35
}
37
38
/************************************************************************/
39
/*                  OGR_G_CreateGeometryFromEsriJson()                  */
40
/************************************************************************/
41
42
/** Create a OGR geometry from a ESRIJson geometry object */
43
OGRGeometryH OGR_G_CreateGeometryFromEsriJson(const char *pszJson)
44
0
{
45
0
    if (nullptr == pszJson)
46
0
    {
47
        // Translation failed.
48
0
        return nullptr;
49
0
    }
50
51
0
    json_object *poObj = nullptr;
52
0
    if (!OGRJSonParse(pszJson, &poObj))
53
0
        return nullptr;
54
55
0
    OGRGeometry *poGeometry = OGRESRIJSONReadGeometry(poObj);
56
57
    // Release JSON tree.
58
0
    json_object_put(poObj);
59
60
0
    return OGRGeometry::ToHandle(poGeometry);
61
0
}
62
63
/************************************************************************/
64
/*                         OGRESRIJSONGetType()                         */
65
/************************************************************************/
66
67
OGRwkbGeometryType OGRESRIJSONGetGeometryType(json_object *poObj)
68
52
{
69
52
    if (nullptr == poObj)
70
0
        return wkbUnknown;
71
72
52
    json_object *poObjType = OGRGeoJSONFindMemberByName(poObj, "geometryType");
73
52
    if (nullptr == poObjType)
74
12
    {
75
12
        return wkbNone;
76
12
    }
77
78
40
    const char *name = json_object_get_string(poObjType);
79
40
    if (EQUAL(name, "esriGeometryPoint"))
80
3
        return wkbPoint;
81
37
    else if (EQUAL(name, "esriGeometryPolyline"))
82
0
        return wkbLineString;
83
37
    else if (EQUAL(name, "esriGeometryPolygon"))
84
19
        return wkbPolygon;
85
18
    else if (EQUAL(name, "esriGeometryMultiPoint"))
86
0
        return wkbMultiPoint;
87
18
    else
88
18
        return wkbUnknown;
89
40
}
90
91
/************************************************************************/
92
/*                  OGRESRIJSONGetCoordinateToDouble()                  */
93
/************************************************************************/
94
95
static double OGRESRIJSONGetCoordinateToDouble(json_object *poObjCoord,
96
                                               const char *pszCoordName,
97
                                               bool &bValid)
98
1.76k
{
99
1.76k
    const int iType = json_object_get_type(poObjCoord);
100
1.76k
    if (json_type_double != iType && json_type_int != iType)
101
2
    {
102
2
        CPLError(CE_Failure, CPLE_AppDefined,
103
2
                 "Invalid '%s' coordinate. "
104
2
                 "Type is not double or integer for \'%s\'.",
105
2
                 pszCoordName, json_object_to_json_string(poObjCoord));
106
2
        bValid = false;
107
2
        return 0.0;
108
2
    }
109
110
1.76k
    return json_object_get_double(poObjCoord);
111
1.76k
}
112
113
/************************************************************************/
114
/*                      OGRESRIJSONGetCoordinate()                      */
115
/************************************************************************/
116
117
static double OGRESRIJSONGetCoordinate(json_object *poObj,
118
                                       const char *pszCoordName, bool &bValid)
119
2
{
120
2
    json_object *poObjCoord = OGRGeoJSONFindMemberByName(poObj, pszCoordName);
121
2
    if (nullptr == poObjCoord)
122
0
    {
123
0
        CPLError(CE_Failure, CPLE_AppDefined,
124
0
                 "Invalid Point object. "
125
0
                 "Missing '%s' member.",
126
0
                 pszCoordName);
127
0
        bValid = false;
128
0
        return 0.0;
129
0
    }
130
131
2
    return OGRESRIJSONGetCoordinateToDouble(poObjCoord, pszCoordName, bValid);
132
2
}
133
134
/************************************************************************/
135
/*                        OGRESRIJSONReadPoint()                        */
136
/************************************************************************/
137
138
OGRPoint *OGRESRIJSONReadPoint(json_object *poObj)
139
1
{
140
1
    CPLAssert(nullptr != poObj);
141
142
1
    bool bValid = true;
143
1
    const double dfX = OGRESRIJSONGetCoordinate(poObj, "x", bValid);
144
1
    const double dfY = OGRESRIJSONGetCoordinate(poObj, "y", bValid);
145
1
    if (!bValid)
146
0
        return nullptr;
147
148
1
    json_object *poObjZ = OGRGeoJSONFindMemberByName(poObj, "z");
149
1
    if (nullptr == poObjZ)
150
1
        return new OGRPoint(dfX, dfY);
151
152
0
    const double dfZ = OGRESRIJSONGetCoordinateToDouble(poObjZ, "z", bValid);
153
0
    if (!bValid)
154
0
        return nullptr;
155
0
    return new OGRPoint(dfX, dfY, dfZ);
156
0
}
157
158
/************************************************************************/
159
/*                      OGRESRIJSONReaderParseZM()                      */
160
/************************************************************************/
161
162
static void OGRESRIJSONReaderParseZM(json_object *poObj, bool *bHasZ,
163
                                     bool *bHasM)
164
33
{
165
33
    CPLAssert(nullptr != poObj);
166
    // The ESRI geojson spec states that geometries other than point can
167
    // have the attributes hasZ and hasM.  A geometry that has a z value
168
    // implies the 3rd number in the tuple is z.  if hasM is true, but hasZ
169
    // is not, it is the M value.
170
33
    bool bZ = false;
171
33
    json_object *poObjHasZ = OGRGeoJSONFindMemberByName(poObj, "hasZ");
172
33
    if (poObjHasZ != nullptr)
173
0
    {
174
0
        if (json_object_get_type(poObjHasZ) == json_type_boolean)
175
0
        {
176
0
            bZ = CPL_TO_BOOL(json_object_get_boolean(poObjHasZ));
177
0
        }
178
0
    }
179
180
33
    bool bM = false;
181
33
    json_object *poObjHasM = OGRGeoJSONFindMemberByName(poObj, "hasM");
182
33
    if (poObjHasM != nullptr)
183
0
    {
184
0
        if (json_object_get_type(poObjHasM) == json_type_boolean)
185
0
        {
186
0
            bM = CPL_TO_BOOL(json_object_get_boolean(poObjHasM));
187
0
        }
188
0
    }
189
33
    if (bHasZ != nullptr)
190
33
        *bHasZ = bZ;
191
33
    if (bHasM != nullptr)
192
33
        *bHasM = bM;
193
33
}
194
195
/************************************************************************/
196
/*                  OGRESRIJSONReaderParseXYZMArray()                   */
197
/************************************************************************/
198
199
static bool OGRESRIJSONReaderParseXYZMArray(json_object *poObjCoords,
200
                                            bool /*bHasZ*/, bool bHasM,
201
                                            double *pdfX, double *pdfY,
202
                                            double *pdfZ, double *pdfM,
203
                                            int *pnNumCoords)
204
763
{
205
763
    if (poObjCoords == nullptr)
206
0
    {
207
0
        CPLDebug("ESRIJSON",
208
0
                 "OGRESRIJSONReaderParseXYZMArray: got null object.");
209
0
        return false;
210
0
    }
211
212
763
    if (json_type_array != json_object_get_type(poObjCoords))
213
1
    {
214
1
        CPLDebug("ESRIJSON",
215
1
                 "OGRESRIJSONReaderParseXYZMArray: got non-array object.");
216
1
        return false;
217
1
    }
218
219
762
    const auto coordDimension = json_object_array_length(poObjCoords);
220
221
    // Allow 4 coordinates if M is present, but it is eventually ignored.
222
762
    if (coordDimension < 2 || coordDimension > 4)
223
6
    {
224
6
        CPLDebug("ESRIJSON",
225
6
                 "OGRESRIJSONReaderParseXYZMArray: got an unexpected "
226
6
                 "array object.");
227
6
        return false;
228
6
    }
229
230
    // Read X coordinate.
231
756
    json_object *poObjCoord = json_object_array_get_idx(poObjCoords, 0);
232
756
    if (poObjCoord == nullptr)
233
0
    {
234
0
        CPLDebug("ESRIJSON",
235
0
                 "OGRESRIJSONReaderParseXYZMArray: got null object.");
236
0
        return false;
237
0
    }
238
239
756
    bool bValid = true;
240
756
    const double dfX =
241
756
        OGRESRIJSONGetCoordinateToDouble(poObjCoord, "x", bValid);
242
243
    // Read Y coordinate.
244
756
    poObjCoord = json_object_array_get_idx(poObjCoords, 1);
245
756
    if (poObjCoord == nullptr)
246
0
    {
247
0
        CPLDebug("ESRIJSON",
248
0
                 "OGRESRIJSONReaderParseXYZMArray: got null object.");
249
0
        return false;
250
0
    }
251
252
756
    const double dfY =
253
756
        OGRESRIJSONGetCoordinateToDouble(poObjCoord, "y", bValid);
254
756
    if (!bValid)
255
1
        return false;
256
257
    // Read Z or M or Z and M coordinates.
258
755
    if (coordDimension > 2)
259
194
    {
260
194
        poObjCoord = json_object_array_get_idx(poObjCoords, 2);
261
194
        if (poObjCoord == nullptr)
262
0
        {
263
0
            CPLDebug("ESRIJSON",
264
0
                     "OGRESRIJSONReaderParseXYZMArray: got null object.");
265
0
            return false;
266
0
        }
267
268
194
        const double dfZorM = OGRESRIJSONGetCoordinateToDouble(
269
194
            poObjCoord, (coordDimension > 3 || !bHasM) ? "z" : "m", bValid);
270
194
        if (!bValid)
271
0
            return false;
272
194
        if (pdfZ != nullptr)
273
194
        {
274
194
            if (coordDimension > 3 || !bHasM)
275
194
                *pdfZ = dfZorM;
276
0
            else
277
0
                *pdfZ = 0.0;
278
194
        }
279
194
        if (pdfM != nullptr && coordDimension == 3)
280
137
        {
281
137
            if (bHasM)
282
0
                *pdfM = dfZorM;
283
137
            else
284
137
                *pdfM = 0.0;
285
137
        }
286
194
        if (coordDimension == 4)
287
57
        {
288
57
            poObjCoord = json_object_array_get_idx(poObjCoords, 3);
289
57
            if (poObjCoord == nullptr)
290
0
            {
291
0
                CPLDebug("ESRIJSON",
292
0
                         "OGRESRIJSONReaderParseXYZMArray: got null object.");
293
0
                return false;
294
0
            }
295
296
57
            const double dfM =
297
57
                OGRESRIJSONGetCoordinateToDouble(poObjCoord, "m", bValid);
298
57
            if (!bValid)
299
0
                return false;
300
57
            if (pdfM != nullptr)
301
57
                *pdfM = dfM;
302
57
        }
303
194
    }
304
561
    else
305
561
    {
306
561
        if (pdfZ != nullptr)
307
561
            *pdfZ = 0.0;
308
561
        if (pdfM != nullptr)
309
561
            *pdfM = 0.0;
310
561
    }
311
312
755
    if (pnNumCoords != nullptr)
313
755
        *pnNumCoords = static_cast<int>(coordDimension);
314
755
    if (pdfX != nullptr)
315
755
        *pdfX = dfX;
316
755
    if (pdfY != nullptr)
317
755
        *pdfY = dfY;
318
319
755
    return true;
320
755
}
321
322
/************************************************************************/
323
/*                     OGRESRIJSONReadLineString()                      */
324
/************************************************************************/
325
326
OGRGeometry *OGRESRIJSONReadLineString(json_object *poObj)
327
0
{
328
0
    CPLAssert(nullptr != poObj);
329
330
0
    bool bHasZ = false;
331
0
    bool bHasM = false;
332
333
0
    OGRESRIJSONReaderParseZM(poObj, &bHasZ, &bHasM);
334
335
0
    json_object *poObjPaths = OGRGeoJSONFindMemberByName(poObj, "paths");
336
0
    if (nullptr == poObjPaths)
337
0
    {
338
0
        CPLError(CE_Failure, CPLE_AppDefined,
339
0
                 "Invalid LineString object. "
340
0
                 "Missing \'paths\' member.");
341
0
        return nullptr;
342
0
    }
343
344
0
    if (json_type_array != json_object_get_type(poObjPaths))
345
0
    {
346
0
        CPLError(CE_Failure, CPLE_AppDefined,
347
0
                 "Invalid LineString object. "
348
0
                 "Invalid \'paths\' member.");
349
0
        return nullptr;
350
0
    }
351
352
0
    OGRMultiLineString *poMLS = nullptr;
353
0
    OGRGeometry *poRet = nullptr;
354
0
    const auto nPaths = json_object_array_length(poObjPaths);
355
0
    for (auto iPath = decltype(nPaths){0}; iPath < nPaths; iPath++)
356
0
    {
357
0
        json_object *poObjPath = json_object_array_get_idx(poObjPaths, iPath);
358
0
        if (poObjPath == nullptr ||
359
0
            json_type_array != json_object_get_type(poObjPath))
360
0
        {
361
0
            delete poRet;
362
0
            CPLDebug("ESRIJSON", "LineString: got non-array object.");
363
0
            return nullptr;
364
0
        }
365
366
0
        OGRLineString *poLine = new OGRLineString();
367
0
        if (nPaths > 1)
368
0
        {
369
0
            if (iPath == 0)
370
0
            {
371
0
                poMLS = new OGRMultiLineString();
372
0
                poRet = poMLS;
373
0
            }
374
0
            poMLS->addGeometryDirectly(poLine);
375
0
        }
376
0
        else
377
0
        {
378
0
            poRet = poLine;
379
0
        }
380
0
        const auto nPoints = json_object_array_length(poObjPath);
381
0
        for (auto i = decltype(nPoints){0}; i < nPoints; i++)
382
0
        {
383
0
            int nNumCoords = 2;
384
0
            json_object *poObjCoords = json_object_array_get_idx(poObjPath, i);
385
0
            double dfX = 0.0;
386
0
            double dfY = 0.0;
387
0
            double dfZ = 0.0;
388
0
            double dfM = 0.0;
389
0
            if (!OGRESRIJSONReaderParseXYZMArray(poObjCoords, bHasZ, bHasM,
390
0
                                                 &dfX, &dfY, &dfZ, &dfM,
391
0
                                                 &nNumCoords))
392
0
            {
393
0
                delete poRet;
394
0
                return nullptr;
395
0
            }
396
397
0
            if (nNumCoords == 3 && !bHasM)
398
0
            {
399
0
                poLine->addPoint(dfX, dfY, dfZ);
400
0
            }
401
0
            else if (nNumCoords == 3)
402
0
            {
403
0
                poLine->addPointM(dfX, dfY, dfM);
404
0
            }
405
0
            else if (nNumCoords == 4)
406
0
            {
407
0
                poLine->addPoint(dfX, dfY, dfZ, dfM);
408
0
            }
409
0
            else
410
0
            {
411
0
                poLine->addPoint(dfX, dfY);
412
0
            }
413
0
        }
414
0
    }
415
416
0
    if (poRet == nullptr)
417
0
        poRet = new OGRLineString();
418
419
0
    return poRet;
420
0
}
421
422
/************************************************************************/
423
/*                       OGRESRIJSONReadPolygon()                       */
424
/************************************************************************/
425
426
OGRGeometry *OGRESRIJSONReadPolygon(json_object *poObj)
427
33
{
428
33
    CPLAssert(nullptr != poObj);
429
430
33
    bool bHasZ = false;
431
33
    bool bHasM = false;
432
433
33
    OGRESRIJSONReaderParseZM(poObj, &bHasZ, &bHasM);
434
435
33
    json_object *poObjRings = OGRGeoJSONFindMemberByName(poObj, "rings");
436
33
    if (nullptr == poObjRings)
437
0
    {
438
0
        CPLError(CE_Failure, CPLE_AppDefined,
439
0
                 "Invalid Polygon object. "
440
0
                 "Missing \'rings\' member.");
441
0
        return nullptr;
442
0
    }
443
444
33
    if (json_type_array != json_object_get_type(poObjRings))
445
0
    {
446
0
        CPLError(CE_Failure, CPLE_AppDefined,
447
0
                 "Invalid Polygon object. "
448
0
                 "Invalid \'rings\' member.");
449
0
        return nullptr;
450
0
    }
451
452
33
    const auto nRings = json_object_array_length(poObjRings);
453
33
    std::vector<std::unique_ptr<OGRGeometry>> apoGeoms;
454
33
    apoGeoms.reserve(nRings);
455
1.09k
    for (auto iRing = decltype(nRings){0}; iRing < nRings; iRing++)
456
1.07k
    {
457
1.07k
        json_object *poObjRing = json_object_array_get_idx(poObjRings, iRing);
458
1.07k
        if (poObjRing == nullptr ||
459
1.07k
            json_type_array != json_object_get_type(poObjRing))
460
1
        {
461
1
            CPLDebug("ESRIJSON", "Polygon: got non-array object.");
462
1
            return nullptr;
463
1
        }
464
465
1.07k
        auto poLine = std::make_unique<OGRLinearRing>();
466
467
1.07k
        const auto nPoints = json_object_array_length(poObjRing);
468
1.82k
        for (auto i = decltype(nPoints){0}; i < nPoints; i++)
469
763
        {
470
763
            int nNumCoords = 2;
471
763
            json_object *poObjCoords = json_object_array_get_idx(poObjRing, i);
472
763
            double dfX = 0.0;
473
763
            double dfY = 0.0;
474
763
            double dfZ = 0.0;
475
763
            double dfM = 0.0;
476
763
            if (!OGRESRIJSONReaderParseXYZMArray(poObjCoords, bHasZ, bHasM,
477
763
                                                 &dfX, &dfY, &dfZ, &dfM,
478
763
                                                 &nNumCoords))
479
8
            {
480
8
                return nullptr;
481
8
            }
482
483
755
            if (nNumCoords == 3 && !bHasM)
484
137
            {
485
137
                poLine->addPoint(dfX, dfY, dfZ);
486
137
            }
487
618
            else if (nNumCoords == 3)
488
0
            {
489
0
                poLine->addPointM(dfX, dfY, dfM);
490
0
            }
491
618
            else if (nNumCoords == 4)
492
57
            {
493
57
                poLine->addPoint(dfX, dfY, dfZ, dfM);
494
57
            }
495
561
            else
496
561
            {
497
561
                poLine->addPoint(dfX, dfY);
498
561
            }
499
755
        }
500
501
1.06k
        auto poPoly = std::make_unique<OGRPolygon>();
502
1.06k
        poPoly->addRing(std::move(poLine));
503
1.06k
        apoGeoms.push_back(std::move(poPoly));
504
1.06k
    }
505
506
24
    return OGRGeometryFactory::organizePolygons(apoGeoms).release();
507
33
}
508
509
/************************************************************************/
510
/*                     OGRESRIJSONReadMultiPoint()                      */
511
/************************************************************************/
512
513
OGRMultiPoint *OGRESRIJSONReadMultiPoint(json_object *poObj)
514
0
{
515
0
    CPLAssert(nullptr != poObj);
516
517
0
    bool bHasZ = false;
518
0
    bool bHasM = false;
519
520
0
    OGRESRIJSONReaderParseZM(poObj, &bHasZ, &bHasM);
521
522
0
    json_object *poObjPoints = OGRGeoJSONFindMemberByName(poObj, "points");
523
0
    if (nullptr == poObjPoints)
524
0
    {
525
0
        CPLError(CE_Failure, CPLE_AppDefined,
526
0
                 "Invalid MultiPoint object. "
527
0
                 "Missing \'points\' member.");
528
0
        return nullptr;
529
0
    }
530
531
0
    if (json_type_array != json_object_get_type(poObjPoints))
532
0
    {
533
0
        CPLError(CE_Failure, CPLE_AppDefined,
534
0
                 "Invalid MultiPoint object. "
535
0
                 "Invalid \'points\' member.");
536
0
        return nullptr;
537
0
    }
538
539
0
    OGRMultiPoint *poMulti = new OGRMultiPoint();
540
541
0
    const auto nPoints = json_object_array_length(poObjPoints);
542
0
    for (auto i = decltype(nPoints){0}; i < nPoints; i++)
543
0
    {
544
0
        int nNumCoords = 2;
545
0
        json_object *poObjCoords = json_object_array_get_idx(poObjPoints, i);
546
0
        double dfX = 0.0;
547
0
        double dfY = 0.0;
548
0
        double dfZ = 0.0;
549
0
        double dfM = 0.0;
550
0
        if (!OGRESRIJSONReaderParseXYZMArray(poObjCoords, bHasZ, bHasM, &dfX,
551
0
                                             &dfY, &dfZ, &dfM, &nNumCoords))
552
0
        {
553
0
            delete poMulti;
554
0
            return nullptr;
555
0
        }
556
557
0
        if (nNumCoords == 3 && !bHasM)
558
0
        {
559
0
            poMulti->addGeometryDirectly(new OGRPoint(dfX, dfY, dfZ));
560
0
        }
561
0
        else if (nNumCoords == 3)
562
0
        {
563
0
            OGRPoint *poPoint = new OGRPoint(dfX, dfY);
564
0
            poPoint->setM(dfM);
565
0
            poMulti->addGeometryDirectly(poPoint);
566
0
        }
567
0
        else if (nNumCoords == 4)
568
0
        {
569
0
            poMulti->addGeometryDirectly(new OGRPoint(dfX, dfY, dfZ, dfM));
570
0
        }
571
0
        else
572
0
        {
573
0
            poMulti->addGeometryDirectly(new OGRPoint(dfX, dfY));
574
0
        }
575
0
    }
576
577
0
    return poMulti;
578
0
}
579
580
/************************************************************************/
581
/*                  OGRESRIJSONReadSpatialReference()                   */
582
/************************************************************************/
583
584
OGRSpatialReference *OGRESRIJSONReadSpatialReference(json_object *poObj)
585
54
{
586
    /* -------------------------------------------------------------------- */
587
    /*      Read spatial reference definition.                              */
588
    /* -------------------------------------------------------------------- */
589
54
    OGRSpatialReference *poSRS = nullptr;
590
591
54
    json_object *poObjSrs =
592
54
        OGRGeoJSONFindMemberByName(poObj, "spatialReference");
593
54
    if (nullptr != poObjSrs)
594
6
    {
595
6
        json_object *poObjWkid =
596
6
            OGRGeoJSONFindMemberByName(poObjSrs, "latestWkid");
597
6
        if (poObjWkid == nullptr)
598
6
            poObjWkid = OGRGeoJSONFindMemberByName(poObjSrs, "wkid");
599
6
        if (poObjWkid == nullptr)
600
0
        {
601
0
            json_object *poObjWkt = OGRGeoJSONFindMemberByName(poObjSrs, "wkt");
602
0
            if (poObjWkt == nullptr)
603
0
                return nullptr;
604
605
0
            const char *pszWKT = json_object_get_string(poObjWkt);
606
0
            poSRS = new OGRSpatialReference();
607
0
            poSRS->SetAxisMappingStrategy(OAMS_TRADITIONAL_GIS_ORDER);
608
0
            if (OGRERR_NONE != poSRS->importFromWkt(pszWKT))
609
0
            {
610
0
                delete poSRS;
611
0
                poSRS = nullptr;
612
0
            }
613
0
            else
614
0
            {
615
0
                auto poSRSMatch = poSRS->FindBestMatch(70);
616
0
                if (poSRSMatch)
617
0
                {
618
0
                    poSRS->Release();
619
0
                    poSRS = poSRSMatch;
620
0
                    poSRS->SetAxisMappingStrategy(OAMS_TRADITIONAL_GIS_ORDER);
621
0
                }
622
0
            }
623
624
0
            return poSRS;
625
0
        }
626
627
6
        const int nEPSG = json_object_get_int(poObjWkid);
628
629
6
        poSRS = new OGRSpatialReference();
630
6
        poSRS->SetAxisMappingStrategy(OAMS_TRADITIONAL_GIS_ORDER);
631
6
        if (OGRERR_NONE != poSRS->importFromEPSG(nEPSG))
632
2
        {
633
2
            delete poSRS;
634
2
            poSRS = nullptr;
635
2
        }
636
6
    }
637
638
54
    return poSRS;
639
54
}
640
641
/*! @endcond */