Coverage Report

Created: 2026-07-25 06:50

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