Coverage Report

Created: 2025-06-13 06:18

/src/gdal/ogr/ogrgeomfielddefn.cpp
Line
Count
Source (jump to first uncovered line)
1
/******************************************************************************
2
 *
3
 * Project:  OpenGIS Simple Features Reference Implementation
4
 * Purpose:  The OGRGeomFieldDefn class implementation.
5
 * Author:   Even Rouault, <even dot rouault at spatialys.com>
6
 *
7
 ******************************************************************************
8
 * Copyright (c) 2013, Even Rouault <even dot rouault at spatialys.com>
9
 *
10
 * SPDX-License-Identifier: MIT
11
 ****************************************************************************/
12
13
#include "cpl_port.h"
14
#include "ogr_api.h"
15
16
#include <cstring>
17
18
#include "cpl_conv.h"
19
#include "cpl_error.h"
20
#include "ogr_core.h"
21
#include "ogr_feature.h"
22
#include "ogr_p.h"
23
#include "ogr_spatialref.h"
24
#include "ogr_srs_api.h"
25
#include "ograpispy.h"
26
27
/************************************************************************/
28
/*                         OGRGeomFieldDefn()                           */
29
/************************************************************************/
30
31
/**
32
 * \brief Constructor.
33
 *
34
 * @param pszNameIn the name of the new field.
35
 * @param eGeomTypeIn the type of the new field.
36
 *
37
 * @since GDAL 1.11
38
 */
39
40
OGRGeomFieldDefn::OGRGeomFieldDefn(const char *pszNameIn,
41
                                   OGRwkbGeometryType eGeomTypeIn)
42
43
0
{
44
0
    Initialize(pszNameIn, eGeomTypeIn);
45
0
}
46
47
/************************************************************************/
48
/*                          OGRGeomFieldDefn()                          */
49
/************************************************************************/
50
51
/**
52
 * \brief Constructor.
53
 *
54
 * Create by cloning an existing geometry field definition.
55
 *
56
 * @param poPrototype the geometry field definition to clone.
57
 *
58
 * @since GDAL 1.11
59
 */
60
61
OGRGeomFieldDefn::OGRGeomFieldDefn(const OGRGeomFieldDefn *poPrototype)
62
63
0
{
64
0
    Initialize(poPrototype->GetNameRef(), poPrototype->GetType());
65
0
    const OGRSpatialReference *poSRSSrc = poPrototype->GetSpatialRef();
66
0
    if (poSRSSrc)
67
0
    {
68
0
        OGRSpatialReference *l_poSRS = poSRSSrc->Clone();
69
0
        SetSpatialRef(l_poSRS);
70
0
        l_poSRS->Release();
71
0
    }
72
0
    SetNullable(poPrototype->IsNullable());
73
0
    SetCoordinatePrecision(poPrototype->GetCoordinatePrecision());
74
0
}
75
76
/************************************************************************/
77
/*                           OGR_GFld_Create()                          */
78
/************************************************************************/
79
/**
80
 * \brief Create a new field geometry definition.
81
 *
82
 * This function is the same as the CPP method
83
 * OGRGeomFieldDefn::OGRGeomFieldDefn().
84
 *
85
 * @param pszName the name of the new field definition.
86
 * @param eType the type of the new field definition.
87
 * @return handle to the new field definition.
88
 *
89
 * @since GDAL 1.11
90
 */
91
92
OGRGeomFieldDefnH OGR_GFld_Create(const char *pszName, OGRwkbGeometryType eType)
93
94
0
{
95
0
    return OGRGeomFieldDefn::ToHandle(new OGRGeomFieldDefn(pszName, eType));
96
0
}
97
98
/************************************************************************/
99
/*                             Initialize()                             */
100
/************************************************************************/
101
102
//! @cond Doxygen_Suppress
103
void OGRGeomFieldDefn::Initialize(const char *pszNameIn,
104
                                  OGRwkbGeometryType eTypeIn)
105
106
0
{
107
0
    pszName = CPLStrdup(pszNameIn);
108
0
    eGeomType = eTypeIn;
109
0
}
110
111
//! @endcond
112
113
/************************************************************************/
114
/*                         ~OGRGeomFieldDefn()                          */
115
/************************************************************************/
116
117
OGRGeomFieldDefn::~OGRGeomFieldDefn()
118
119
0
{
120
0
    CPLFree(pszName);
121
122
0
    if (nullptr != poSRS)
123
0
        const_cast<OGRSpatialReference *>(poSRS)->Release();
124
0
}
125
126
/************************************************************************/
127
/*                          OGRGeomFieldDefn::OGRGeomFieldDefn()        */
128
/************************************************************************/
129
130
/**
131
 * @brief OGRGeomFieldDefn::OGRGeomFieldDefn Copy constructor
132
 * @param oOther the OGRGeomFieldDefn to copy.
133
 * @since GDAL 3.11
134
 */
135
OGRGeomFieldDefn::OGRGeomFieldDefn(const OGRGeomFieldDefn &oOther)
136
0
    : pszName(CPLStrdup(oOther.pszName)), eGeomType(oOther.eGeomType),
137
0
      poSRS(nullptr), bIgnore(oOther.bIgnore), bNullable(oOther.bNullable),
138
0
      m_bSealed(oOther.m_bSealed), m_oCoordPrecision(oOther.m_oCoordPrecision)
139
0
{
140
0
    if (oOther.poSRS)
141
0
    {
142
0
        poSRS = oOther.poSRS->Clone();
143
0
    }
144
0
}
145
146
/************************************************************************/
147
/*                          OGRGeomFieldDefn::operator=()               */
148
/************************************************************************/
149
150
/**
151
 * Copy assignment operator
152
 * @param oOther the OGRGeomFieldDefn to copy.
153
 * @return a reference to the current object.
154
 * @since GDAL 3.11
155
 */
156
OGRGeomFieldDefn &OGRGeomFieldDefn::operator=(const OGRGeomFieldDefn &oOther)
157
0
{
158
0
    if (&oOther != this)
159
0
    {
160
0
        CPLFree(pszName);
161
0
        pszName = CPLStrdup(oOther.pszName);
162
0
        eGeomType = oOther.eGeomType;
163
0
        if (oOther.poSRS)
164
0
            const_cast<OGRSpatialReference *>(oOther.poSRS)->Reference();
165
0
        if (poSRS)
166
0
            const_cast<OGRSpatialReference *>(poSRS)->Dereference();
167
0
        poSRS = oOther.poSRS;
168
0
        bNullable = oOther.bNullable;
169
0
        m_oCoordPrecision = oOther.m_oCoordPrecision;
170
0
        m_bSealed = oOther.m_bSealed;
171
0
        bIgnore = oOther.bIgnore;
172
0
    }
173
0
    return *this;
174
0
}
175
176
/************************************************************************/
177
/*                         OGR_GFld_Destroy()                           */
178
/************************************************************************/
179
/**
180
 * \brief Destroy a geometry field definition.
181
 *
182
 * @param hDefn handle to the geometry field definition to destroy.
183
 *
184
 * @since GDAL 1.11
185
 */
186
187
void OGR_GFld_Destroy(OGRGeomFieldDefnH hDefn)
188
189
0
{
190
0
    VALIDATE_POINTER0(hDefn, "OGR_GFld_Destroy");
191
192
0
    delete OGRGeomFieldDefn::FromHandle(hDefn);
193
0
}
194
195
/************************************************************************/
196
/*                              SetName()                               */
197
/************************************************************************/
198
199
/**
200
 * \brief Reset the name of this field.
201
 *
202
 * This method is the same as the C function OGR_GFld_SetName().
203
 *
204
 * Note that once a OGRGeomFieldDefn has been added to a layer definition with
205
 * OGRLayer::AddGeomFieldDefn(), its setter methods should not be called on the
206
 * object returned with OGRLayer::GetLayerDefn()->GetGeomFieldDefn(). Instead,
207
 * OGRLayer::AlterGeomFieldDefn() should be called on a new instance of
208
 * OGRFieldDefn, for drivers that support AlterFieldDefn().
209
 *
210
 * @param pszNameIn the new name to apply.
211
 *
212
 * @since GDAL 1.11
213
 */
214
215
void OGRGeomFieldDefn::SetName(const char *pszNameIn)
216
217
0
{
218
0
    if (m_bSealed)
219
0
    {
220
0
        CPLError(CE_Failure, CPLE_AppDefined,
221
0
                 "OGRGeomFieldDefn::SetName() not allowed on a sealed object");
222
0
        return;
223
0
    }
224
0
    if (pszName != pszNameIn)
225
0
    {
226
0
        CPLFree(pszName);
227
0
        pszName = CPLStrdup(pszNameIn);
228
0
    }
229
0
}
230
231
/************************************************************************/
232
/*                         OGR_GFld_SetName()                           */
233
/************************************************************************/
234
/**
235
 * \brief Reset the name of this field.
236
 *
237
 * This function is the same as the CPP method OGRGeomFieldDefn::SetName().
238
 *
239
 * Note that once a OGRGeomFieldDefn has been added to a layer definition with
240
 * OGRLayer::AddGeomFieldDefn(), its setter methods should not be called on the
241
 * object returned with OGRLayer::GetLayerDefn()->GetGeomFieldDefn(). Instead,
242
 * OGRLayer::AlterGeomFieldDefn() should be called on a new instance of
243
 * OGRFieldDefn, for drivers that support AlterFieldDefn().
244
 *
245
 * @param hDefn handle to the geometry field definition to apply the
246
 * new name to.
247
 * @param pszName the new name to apply.
248
 *
249
 * @since GDAL 1.11
250
 */
251
252
void OGR_GFld_SetName(OGRGeomFieldDefnH hDefn, const char *pszName)
253
254
0
{
255
0
    VALIDATE_POINTER0(hDefn, "OGR_GFld_SetName");
256
257
0
    OGRGeomFieldDefn::FromHandle(hDefn)->SetName(pszName);
258
0
}
259
260
/************************************************************************/
261
/*                             GetNameRef()                             */
262
/************************************************************************/
263
264
/**
265
 * \fn const char *OGRGeomFieldDefn::GetNameRef();
266
 *
267
 * \brief Fetch name of this field.
268
 *
269
 * This method is the same as the C function OGR_GFld_GetNameRef().
270
 *
271
 * @return pointer to an internal name string that should not be freed or
272
 * modified.
273
 *
274
 * @since GDAL 1.11
275
 */
276
277
/************************************************************************/
278
/*                        OGR_GFld_GetNameRef()                         */
279
/************************************************************************/
280
/**
281
 * \brief Fetch name of this field.
282
 *
283
 * This function is the same as the CPP method OGRGeomFieldDefn::GetNameRef().
284
 *
285
 * @param hDefn handle to the geometry field definition.
286
 * @return the name of the geometry field definition.
287
 *
288
 * @since GDAL 1.11
289
 */
290
291
const char *OGR_GFld_GetNameRef(OGRGeomFieldDefnH hDefn)
292
293
0
{
294
0
    VALIDATE_POINTER1(hDefn, "OGR_GFld_GetNameRef", "");
295
296
0
#ifdef OGRAPISPY_ENABLED
297
0
    if (bOGRAPISpyEnabled)
298
0
        OGRAPISpy_GFld_GetXXXX(hDefn, "GetNameRef");
299
0
#endif
300
301
0
    return OGRGeomFieldDefn::FromHandle(hDefn)->GetNameRef();
302
0
}
303
304
/************************************************************************/
305
/*                              GetType()                               */
306
/************************************************************************/
307
308
/**
309
 * \fn OGRwkbGeometryType OGRGeomFieldDefn::GetType() const;
310
 *
311
 * \brief Fetch geometry type of this field.
312
 *
313
 * This method is the same as the C function OGR_GFld_GetType().
314
 *
315
 * @return field geometry type.
316
 *
317
 * @since GDAL 1.11
318
 */
319
320
/************************************************************************/
321
/*                          OGR_GFld_GetType()                          */
322
/************************************************************************/
323
/**
324
 * \brief Fetch geometry type of this field.
325
 *
326
 * This function is the same as the CPP method OGRGeomFieldDefn::GetType().
327
 *
328
 * @param hDefn handle to the geometry field definition to get type from.
329
 * @return field geometry type.
330
 *
331
 * @since GDAL 1.11
332
 */
333
334
OGRwkbGeometryType OGR_GFld_GetType(OGRGeomFieldDefnH hDefn)
335
336
0
{
337
0
    VALIDATE_POINTER1(hDefn, "OGR_GFld_GetType", wkbUnknown);
338
339
0
#ifdef OGRAPISPY_ENABLED
340
0
    if (bOGRAPISpyEnabled)
341
0
        OGRAPISpy_GFld_GetXXXX(hDefn, "GetType");
342
0
#endif
343
344
0
    OGRwkbGeometryType eType = OGRGeomFieldDefn::FromHandle(hDefn)->GetType();
345
0
    if (OGR_GT_IsNonLinear(eType) && !OGRGetNonLinearGeometriesEnabledFlag())
346
0
    {
347
0
        eType = OGR_GT_GetLinear(eType);
348
0
    }
349
0
    return eType;
350
0
}
351
352
/************************************************************************/
353
/*                              SetType()                               */
354
/************************************************************************/
355
356
/**
357
 * \brief Set the geometry type of this field.
358
 * This should never be done to an OGRGeomFieldDefn
359
 * that is already part of an OGRFeatureDefn.
360
 *
361
 * This method is the same as the C function OGR_GFld_SetType().
362
 *
363
 * Note that once a OGRGeomFieldDefn has been added to a layer definition with
364
 * OGRLayer::AddGeomFieldDefn(), its setter methods should not be called on the
365
 * object returned with OGRLayer::GetLayerDefn()->GetGeomFieldDefn(). Instead,
366
 * OGRLayer::AlterGeomFieldDefn() should be called on a new instance of
367
 * OGRFieldDefn, for drivers that support AlterFieldDefn().
368
 *
369
 * @param eTypeIn the new field geometry type.
370
 *
371
 * @since GDAL 1.11
372
 */
373
374
void OGRGeomFieldDefn::SetType(OGRwkbGeometryType eTypeIn)
375
376
0
{
377
0
    if (m_bSealed)
378
0
    {
379
0
        CPLError(CE_Failure, CPLE_AppDefined,
380
0
                 "OGRGeomFieldDefn::SetType() not allowed on a sealed object");
381
0
        return;
382
0
    }
383
0
    eGeomType = eTypeIn;
384
0
}
385
386
/************************************************************************/
387
/*                          OGR_GFld_SetType()                          */
388
/************************************************************************/
389
/**
390
 * \brief Set the geometry type of this field.
391
 * This should never be done to an OGRGeomFieldDefn
392
 * that is already part of an OGRFeatureDefn.
393
 *
394
 * This function is the same as the CPP method OGRGeomFieldDefn::SetType().
395
 *
396
 * Note that once a OGRGeomFieldDefn has been added to a layer definition with
397
 * OGRLayer::AddGeomFieldDefn(), its setter methods should not be called on the
398
 * object returned with OGRLayer::GetLayerDefn()->GetGeomFieldDefn(). Instead,
399
 * OGRLayer::AlterGeomFieldDefn() should be called on a new instance of
400
 * OGRFieldDefn, for drivers that support AlterFieldDefn().
401
 *
402
 * @param hDefn handle to the geometry field definition to set type to.
403
 * @param eType the new field geometry type.
404
 *
405
 * @since GDAL 1.11
406
 */
407
408
void OGR_GFld_SetType(OGRGeomFieldDefnH hDefn, OGRwkbGeometryType eType)
409
410
0
{
411
0
    VALIDATE_POINTER0(hDefn, "OGR_GFld_SetType");
412
413
0
    OGRGeomFieldDefn::FromHandle(hDefn)->SetType(eType);
414
0
}
415
416
/************************************************************************/
417
/*                             IsIgnored()                              */
418
/************************************************************************/
419
420
/**
421
 * \fn int OGRGeomFieldDefn::IsIgnored() const;
422
 *
423
 * \brief Return whether this field should be omitted when fetching features
424
 *
425
 * This method is the same as the C function OGR_GFld_IsIgnored().
426
 *
427
 * @return ignore state
428
 *
429
 * @since GDAL 1.11
430
 */
431
432
/************************************************************************/
433
/*                         OGR_GFld_IsIgnored()                         */
434
/************************************************************************/
435
436
/**
437
 * \brief Return whether this field should be omitted when fetching features
438
 *
439
 * This method is the same as the C++ method OGRGeomFieldDefn::IsIgnored().
440
 *
441
 * @param hDefn handle to the geometry field definition
442
 * @return ignore state
443
 *
444
 * @since GDAL 1.11
445
 */
446
447
int OGR_GFld_IsIgnored(OGRGeomFieldDefnH hDefn)
448
0
{
449
0
    VALIDATE_POINTER1(hDefn, "OGR_GFld_IsIgnored", FALSE);
450
451
0
    return OGRGeomFieldDefn::FromHandle(hDefn)->IsIgnored();
452
0
}
453
454
/************************************************************************/
455
/*                            SetIgnored()                              */
456
/************************************************************************/
457
458
/**
459
 * \fn void OGRGeomFieldDefn::SetIgnored( int ignore );
460
 *
461
 * \brief Set whether this field should be omitted when fetching features
462
 *
463
 * This method is the same as the C function OGR_GFld_SetIgnored().
464
 *
465
 * This method should not be called on a object returned with
466
 * OGRLayer::GetLayerDefn()->GetGeomFieldDefn(). Instead, the
467
 * OGRLayer::SetIgnoredFields() method should be called.
468
 *
469
 * @param ignore ignore state
470
 *
471
 * @since GDAL 1.11
472
 */
473
474
/************************************************************************/
475
/*                        OGR_GFld_SetIgnored()                         */
476
/************************************************************************/
477
478
/**
479
 * \brief Set whether this field should be omitted when fetching features
480
 *
481
 * This method is the same as the C++ method OGRGeomFieldDefn::SetIgnored().
482
 *
483
 * This method should not be called on a object returned with
484
 * OGRLayer::GetLayerDefn()->GetGeomFieldDefn(). Instead, the
485
 * OGRLayer::SetIgnoredFields() method should be called.
486
 *
487
 * @param hDefn handle to the geometry field definition
488
 * @param ignore ignore state
489
 *
490
 * @since GDAL 1.11
491
 */
492
493
void OGR_GFld_SetIgnored(OGRGeomFieldDefnH hDefn, int ignore)
494
0
{
495
0
    VALIDATE_POINTER0(hDefn, "OGR_GFld_SetIgnored");
496
497
0
    OGRGeomFieldDefn::FromHandle(hDefn)->SetIgnored(ignore);
498
0
}
499
500
/************************************************************************/
501
/*                           GetSpatialRef()                            */
502
/************************************************************************/
503
/**
504
 * \brief Fetch spatial reference system of this field.
505
 *
506
 * This method is the same as the C function OGR_GFld_GetSpatialRef().
507
 *
508
 * @return field spatial reference system.
509
 *
510
 * @since GDAL 1.11
511
 */
512
513
const OGRSpatialReference *OGRGeomFieldDefn::GetSpatialRef() const
514
0
{
515
0
    return poSRS;
516
0
}
517
518
/************************************************************************/
519
/*                       OGR_GFld_GetSpatialRef()                       */
520
/************************************************************************/
521
522
/**
523
 * \brief Fetch spatial reference system of this field.
524
 *
525
 * This function is the same as the C++ method
526
 * OGRGeomFieldDefn::GetSpatialRef().
527
 *
528
 * @param hDefn handle to the geometry field definition
529
 *
530
 * @return a reference to the field spatial reference system.
531
 * It should not be modified.
532
 *
533
 * @since GDAL 1.11
534
 */
535
536
OGRSpatialReferenceH OGR_GFld_GetSpatialRef(OGRGeomFieldDefnH hDefn)
537
0
{
538
0
    VALIDATE_POINTER1(hDefn, "OGR_GFld_GetSpatialRef", nullptr);
539
540
0
#ifdef OGRAPISPY_ENABLED
541
0
    if (bOGRAPISpyEnabled)
542
0
        OGRAPISpy_GFld_GetXXXX(hDefn, "GetSpatialRef");
543
0
#endif
544
545
0
    return OGRSpatialReference::ToHandle(const_cast<OGRSpatialReference *>(
546
0
        OGRGeomFieldDefn::FromHandle(hDefn)->GetSpatialRef()));
547
0
}
548
549
/************************************************************************/
550
/*                           SetSpatialRef()                            */
551
/************************************************************************/
552
553
/**
554
 * \brief Set the spatial reference of this field.
555
 *
556
 * This method is the same as the C function OGR_GFld_SetSpatialRef().
557
 *
558
 * This method drops the reference of the previously set SRS object and
559
 * acquires a new reference on the passed object (if non-NULL).
560
 *
561
 * Note that once a OGRGeomFieldDefn has been added to a layer definition with
562
 * OGRLayer::AddGeomFieldDefn(), its setter methods should not be called on the
563
 * object returned with OGRLayer::GetLayerDefn()->GetGeomFieldDefn(). Instead,
564
 * OGRLayer::AlterGeomFieldDefn() should be called on a new instance of
565
 * OGRFieldDefn, for drivers that support AlterFieldDefn().
566
 *
567
 * @param poSRSIn the new SRS to apply.
568
 *
569
 * @since GDAL 1.11
570
 */
571
void OGRGeomFieldDefn::SetSpatialRef(const OGRSpatialReference *poSRSIn)
572
0
{
573
574
0
    if (m_bSealed)
575
0
    {
576
0
        CPLError(
577
0
            CE_Failure, CPLE_AppDefined,
578
0
            "OGRGeomFieldDefn::SetSpatialRef() not allowed on a sealed object");
579
0
        return;
580
0
    }
581
582
0
    if (poSRS == poSRSIn)
583
0
    {
584
0
        return;
585
0
    }
586
587
0
    if (poSRS != nullptr)
588
0
        const_cast<OGRSpatialReference *>(poSRS)->Release();
589
590
0
    poSRS = poSRSIn;
591
592
0
    if (poSRS != nullptr)
593
0
        const_cast<OGRSpatialReference *>(poSRS)->Reference();
594
0
}
595
596
/************************************************************************/
597
/*                       OGR_GFld_SetSpatialRef()                       */
598
/************************************************************************/
599
600
/**
601
 * \brief Set the spatial reference of this field.
602
 *
603
 * This function is the same as the C++ method
604
 * OGRGeomFieldDefn::SetSpatialRef().
605
 *
606
 * This function drops the reference of the previously set SRS object and
607
 * acquires a new reference on the passed object (if non-NULL).
608
 *
609
 * Note that once a OGRGeomFieldDefn has been added to a layer definition with
610
 * OGRLayer::AddGeomFieldDefn(), its setter methods should not be called on the
611
 * object returned with OGRLayer::GetLayerDefn()->GetGeomFieldDefn(). Instead,
612
 * OGRLayer::AlterGeomFieldDefn() should be called on a new instance of
613
 * OGRFieldDefn, for drivers that support AlterFieldDefn().
614
 *
615
 * @param hDefn handle to the geometry field definition
616
 * @param hSRS the new SRS to apply.
617
 *
618
 * @since GDAL 1.11
619
 */
620
621
void OGR_GFld_SetSpatialRef(OGRGeomFieldDefnH hDefn, OGRSpatialReferenceH hSRS)
622
0
{
623
0
    VALIDATE_POINTER0(hDefn, "OGR_GFld_SetSpatialRef");
624
625
0
    OGRGeomFieldDefn::FromHandle(hDefn)->SetSpatialRef(
626
0
        reinterpret_cast<OGRSpatialReference *>(hSRS));
627
0
}
628
629
/************************************************************************/
630
/*                             IsSame()                                 */
631
/************************************************************************/
632
633
/**
634
 * \brief Test if the geometry field definition is identical to the other one.
635
 *
636
 * @param poOtherFieldDefn the other field definition to compare to.
637
 * @return TRUE if the geometry field definition is identical to the other one.
638
 *
639
 * @since GDAL 1.11
640
 */
641
642
int OGRGeomFieldDefn::IsSame(const OGRGeomFieldDefn *poOtherFieldDefn) const
643
0
{
644
0
    if (!(strcmp(GetNameRef(), poOtherFieldDefn->GetNameRef()) == 0 &&
645
0
          GetType() == poOtherFieldDefn->GetType() &&
646
0
          IsNullable() == poOtherFieldDefn->IsNullable() &&
647
0
          m_oCoordPrecision.dfXYResolution ==
648
0
              poOtherFieldDefn->m_oCoordPrecision.dfXYResolution &&
649
0
          m_oCoordPrecision.dfZResolution ==
650
0
              poOtherFieldDefn->m_oCoordPrecision.dfZResolution &&
651
0
          m_oCoordPrecision.dfMResolution ==
652
0
              poOtherFieldDefn->m_oCoordPrecision.dfMResolution))
653
0
        return FALSE;
654
0
    const OGRSpatialReference *poMySRS = GetSpatialRef();
655
0
    const OGRSpatialReference *poOtherSRS = poOtherFieldDefn->GetSpatialRef();
656
0
    return ((poMySRS == poOtherSRS) ||
657
0
            (poMySRS != nullptr && poOtherSRS != nullptr &&
658
0
             poMySRS->IsSame(poOtherSRS)));
659
0
}
660
661
/************************************************************************/
662
/*                             IsNullable()                             */
663
/************************************************************************/
664
665
/**
666
 * \fn int OGRGeomFieldDefn::IsNullable() const
667
 *
668
 * \brief Return whether this geometry field can receive null values.
669
 *
670
 * By default, fields are nullable.
671
 *
672
 * Even if this method returns FALSE (i.e not-nullable field), it doesn't mean
673
 * that OGRFeature::IsFieldSet() will necessary return TRUE, as fields can be
674
 * temporary unset and null/not-null validation is usually done when
675
 * OGRLayer::CreateFeature()/SetFeature() is called.
676
 *
677
 * Note that not-nullable geometry fields might also contain 'empty' geometries.
678
 *
679
 * This method is the same as the C function OGR_GFld_IsNullable().
680
 *
681
 * @return TRUE if the field is authorized to be null.
682
 * @since GDAL 2.0
683
 */
684
685
/************************************************************************/
686
/*                         OGR_GFld_IsNullable()                        */
687
/************************************************************************/
688
689
/**
690
 * \brief Return whether this geometry field can receive null values.
691
 *
692
 * By default, fields are nullable.
693
 *
694
 * Even if this method returns FALSE (i.e not-nullable field), it doesn't mean
695
 * that OGRFeature::IsFieldSet() will necessary return TRUE, as fields can be
696
 * temporary unset and null/not-null validation is usually done when
697
 * OGRLayer::CreateFeature()/SetFeature() is called.
698
 *
699
 * Note that not-nullable geometry fields might also contain 'empty' geometries.
700
 *
701
 * This method is the same as the C++ method OGRGeomFieldDefn::IsNullable().
702
 *
703
 * Note that once a OGRGeomFieldDefn has been added to a layer definition with
704
 * OGRLayer::AddGeomFieldDefn(), its setter methods should not be called on the
705
 * object returned with OGRLayer::GetLayerDefn()->GetGeomFieldDefn(). Instead,
706
 * OGRLayer::AlterGeomFieldDefn() should be called on a new instance of
707
 * OGRFieldDefn, for drivers that support AlterFieldDefn().
708
 *
709
 * @param hDefn handle to the field definition
710
 * @return TRUE if the field is authorized to be null.
711
 * @since GDAL 2.0
712
 */
713
714
int OGR_GFld_IsNullable(OGRGeomFieldDefnH hDefn)
715
0
{
716
0
    return OGRGeomFieldDefn::FromHandle(hDefn)->IsNullable();
717
0
}
718
719
/************************************************************************/
720
/*                            SetNullable()                             */
721
/************************************************************************/
722
723
/**
724
 * \fn void OGRGeomFieldDefn::SetNullable( int bNullableIn );
725
 *
726
 * \brief Set whether this geometry field can receive null values.
727
 *
728
 * By default, fields are nullable, so this method is generally called with
729
 * FALSE to set a not-null constraint.
730
 *
731
 * Drivers that support writing not-null constraint will advertise the
732
 * GDAL_DCAP_NOTNULL_GEOMFIELDS driver metadata item.
733
 *
734
 * This method is the same as the C function OGR_GFld_SetNullable().
735
 *
736
 * Note that once a OGRGeomFieldDefn has been added to a layer definition with
737
 * OGRLayer::AddGeomFieldDefn(), its setter methods should not be called on the
738
 * object returned with OGRLayer::GetLayerDefn()->GetGeomFieldDefn(). Instead,
739
 * OGRLayer::AlterGeomFieldDefn() should be called on a new instance of
740
 * OGRFieldDefn, for drivers that support AlterFieldDefn().
741
 *
742
 * @param bNullableIn FALSE if the field must have a not-null constraint.
743
 * @since GDAL 2.0
744
 */
745
void OGRGeomFieldDefn::SetNullable(int bNullableIn)
746
0
{
747
0
    if (m_bSealed)
748
0
    {
749
0
        CPLError(
750
0
            CE_Failure, CPLE_AppDefined,
751
0
            "OGRGeomFieldDefn::SetNullable() not allowed on a sealed object");
752
0
        return;
753
0
    }
754
0
    bNullable = bNullableIn;
755
0
}
756
757
/************************************************************************/
758
/*                        OGR_GFld_SetNullable()                        */
759
/************************************************************************/
760
761
/**
762
 * \brief Set whether this geometry field can receive null values.
763
 *
764
 * By default, fields are nullable, so this method is generally called with
765
 * FALSE to set a not-null constraint.
766
 *
767
 * Drivers that support writing not-null constraint will advertise the
768
 * GDAL_DCAP_NOTNULL_GEOMFIELDS driver metadata item.
769
 *
770
 * This method is the same as the C++ method OGRGeomFieldDefn::SetNullable().
771
 *
772
 * @param hDefn handle to the field definition
773
 * @param bNullableIn FALSE if the field must have a not-null constraint.
774
 * @since GDAL 2.0
775
 */
776
777
void OGR_GFld_SetNullable(OGRGeomFieldDefnH hDefn, int bNullableIn)
778
0
{
779
0
    OGRGeomFieldDefn::FromHandle(hDefn)->SetNullable(bNullableIn);
780
0
}
781
782
/************************************************************************/
783
/*                        GetCoordinatePrecision()                      */
784
/************************************************************************/
785
786
/**
787
 * \fn int OGRGeomFieldDefn::GetCoordinatePrecision() const
788
 *
789
 * \brief Return the coordinate precision associated to this geometry field.
790
 *
791
 * This method is the same as the C function OGR_GFld_GetCoordinatePrecision().
792
 *
793
 * @return the coordinate precision
794
 * @since GDAL 3.9
795
 */
796
797
/************************************************************************/
798
/*                     OGR_GFld_GetCoordinatePrecision()                */
799
/************************************************************************/
800
801
/**
802
 * \brief Return the coordinate precision associated to this geometry field.
803
 *
804
 * This method is the same as the C++ method OGRGeomFieldDefn::GetCoordinatePrecision()
805
 *
806
 * @param hDefn handle to the field definition
807
 * @return the coordinate precision
808
 * @since GDAL 3.9
809
 */
810
811
OGRGeomCoordinatePrecisionH
812
OGR_GFld_GetCoordinatePrecision(OGRGeomFieldDefnH hDefn)
813
0
{
814
0
    return const_cast<OGRGeomCoordinatePrecision *>(
815
0
        &(OGRGeomFieldDefn::FromHandle(hDefn)->GetCoordinatePrecision()));
816
0
}
817
818
/************************************************************************/
819
/*                        SetCoordinatePrecision()                      */
820
/************************************************************************/
821
822
/**
823
 * \brief Set coordinate precision associated to this geometry field.
824
 *
825
 * This method is the same as the C function OGR_GFld_SetCoordinatePrecision().
826
 *
827
 * Note that once a OGRGeomFieldDefn has been added to a layer definition with
828
 * OGRLayer::AddGeomFieldDefn(), its setter methods should not be called on the
829
 * object returned with OGRLayer::GetLayerDefn()->GetGeomFieldDefn().
830
 *
831
 * @param prec Coordinate precision
832
 * @since GDAL 3.9
833
 */
834
void OGRGeomFieldDefn::SetCoordinatePrecision(
835
    const OGRGeomCoordinatePrecision &prec)
836
0
{
837
0
    if (m_bSealed)
838
0
    {
839
0
        CPLError(CE_Failure, CPLE_AppDefined,
840
0
                 "OGRGeomFieldDefn::SetCoordinatePrecision() not allowed on a "
841
0
                 "sealed object");
842
0
        return;
843
0
    }
844
0
    m_oCoordPrecision = prec;
845
0
}
846
847
/************************************************************************/
848
/*                     OGR_GFld_SetCoordinatePrecision()                */
849
/************************************************************************/
850
851
/**
852
 * \brief Set coordinate precision associated to this geometry field.
853
 *
854
 * This method is the same as the C++ method OGRGeomFieldDefn::SetCoordinatePrecision()
855
 *
856
 * Note that once a OGRGeomFieldDefn has been added to a layer definition with
857
 * OGRLayer::AddGeomFieldDefn(), its setter methods should not be called on the
858
 * object returned with OGRLayer::GetLayerDefn()->GetGeomFieldDefn().
859
 *
860
 * @param hDefn handle to the field definition.  Must not be NULL.
861
 * @param hGeomCoordPrec Coordinate precision. Must not be NULL.
862
 * @since GDAL 3.9
863
 */
864
void OGR_GFld_SetCoordinatePrecision(OGRGeomFieldDefnH hDefn,
865
                                     OGRGeomCoordinatePrecisionH hGeomCoordPrec)
866
0
{
867
0
    VALIDATE_POINTER0(hGeomCoordPrec, "OGR_GFld_SetCoordinatePrecision");
868
0
    OGRGeomFieldDefn::FromHandle(hDefn)->SetCoordinatePrecision(
869
0
        *hGeomCoordPrec);
870
0
}
871
872
/************************************************************************/
873
/*                       OGRGeomFieldDefn::Seal()                       */
874
/************************************************************************/
875
876
/** Seal a OGRGeomFieldDefn.
877
 *
878
 * A sealed OGRGeomFieldDefn can not be modified while it is sealed.
879
 *
880
 * This method should only be called by driver implementations.
881
 *
882
 * @since GDAL 3.9
883
 */
884
void OGRGeomFieldDefn::Seal()
885
0
{
886
0
    m_bSealed = true;
887
0
}
888
889
/************************************************************************/
890
/*                       OGRGeomFieldDefn::Unseal()                     */
891
/************************************************************************/
892
893
/** Unseal a OGRGeomFieldDefn.
894
 *
895
 * Undo OGRGeomFieldDefn::Seal()
896
 *
897
 * Using GetTemporaryUnsealer() is recommended for most use cases.
898
 *
899
 * This method should only be called by driver implementations.
900
 *
901
 * @since GDAL 3.9
902
 */
903
void OGRGeomFieldDefn::Unseal()
904
0
{
905
0
    m_bSealed = false;
906
0
}
907
908
/************************************************************************/
909
/*                  OGRGeomFieldDefn::GetTemporaryUnsealer()            */
910
/************************************************************************/
911
912
/** Return an object that temporary unseals the OGRGeomFieldDefn
913
 *
914
 * The returned object calls Unseal() initially, and when it is destroyed
915
 * it calls Seal().
916
 *
917
 * This method should only be called by driver implementations.
918
 *
919
 * It is also possible to use the helper method whileUnsealing(). Example:
920
 * whileUnsealing(poGeomFieldDefn)->some_method()
921
 *
922
 * @since GDAL 3.9
923
 */
924
OGRGeomFieldDefn::TemporaryUnsealer OGRGeomFieldDefn::GetTemporaryUnsealer()
925
0
{
926
0
    return TemporaryUnsealer(this);
927
0
}