Line data Source code
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 108834 : OGRGeomFieldDefn::OGRGeomFieldDefn(const char *pszNameIn,
41 108834 : OGRwkbGeometryType eGeomTypeIn)
42 :
43 : {
44 108834 : Initialize(pszNameIn, eGeomTypeIn);
45 108834 : }
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 15276 : OGRGeomFieldDefn::OGRGeomFieldDefn(const OGRGeomFieldDefn *poPrototype)
62 :
63 : {
64 15276 : Initialize(poPrototype->GetNameRef(), poPrototype->GetType());
65 15276 : const OGRSpatialReference *poSRSSrc = poPrototype->GetSpatialRef();
66 15276 : if (poSRSSrc)
67 : {
68 3591 : OGRSpatialReference *l_poSRS = poSRSSrc->Clone();
69 3591 : SetSpatialRef(l_poSRS);
70 3591 : l_poSRS->Release();
71 : }
72 15276 : SetNullable(poPrototype->IsNullable());
73 15276 : SetCoordinatePrecision(poPrototype->GetCoordinatePrecision());
74 15276 : }
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 171 : OGRGeomFieldDefnH OGR_GFld_Create(const char *pszName, OGRwkbGeometryType eType)
93 :
94 : {
95 171 : return OGRGeomFieldDefn::ToHandle(new OGRGeomFieldDefn(pszName, eType));
96 : }
97 :
98 : /************************************************************************/
99 : /* Initialize() */
100 : /************************************************************************/
101 :
102 : //! @cond Doxygen_Suppress
103 124110 : void OGRGeomFieldDefn::Initialize(const char *pszNameIn,
104 : OGRwkbGeometryType eTypeIn)
105 :
106 : {
107 124110 : pszName = CPLStrdup(pszNameIn);
108 124110 : eGeomType = eTypeIn;
109 124110 : }
110 :
111 : //! @endcond
112 :
113 : /************************************************************************/
114 : /* ~OGRGeomFieldDefn() */
115 : /************************************************************************/
116 :
117 199594 : OGRGeomFieldDefn::~OGRGeomFieldDefn()
118 :
119 : {
120 124090 : CPLFree(pszName);
121 :
122 124090 : if (nullptr != poSRS)
123 26590 : const_cast<OGRSpatialReference *>(poSRS)->Release();
124 199594 : }
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 7 : OGRGeomFieldDefn::OGRGeomFieldDefn(const OGRGeomFieldDefn &oOther)
136 14 : : pszName(CPLStrdup(oOther.pszName)), eGeomType(oOther.eGeomType),
137 7 : poSRS(nullptr), bIgnore(oOther.bIgnore), bNullable(oOther.bNullable),
138 7 : m_bSealed(oOther.m_bSealed), m_oCoordPrecision(oOther.m_oCoordPrecision)
139 : {
140 7 : if (oOther.poSRS)
141 : {
142 2 : poSRS = oOther.poSRS->Clone();
143 : }
144 7 : }
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 3 : OGRGeomFieldDefn &OGRGeomFieldDefn::operator=(const OGRGeomFieldDefn &oOther)
157 : {
158 3 : if (&oOther != this)
159 : {
160 3 : CPLFree(pszName);
161 3 : pszName = CPLStrdup(oOther.pszName);
162 3 : eGeomType = oOther.eGeomType;
163 3 : if (oOther.poSRS)
164 2 : const_cast<OGRSpatialReference *>(oOther.poSRS)->Reference();
165 3 : if (poSRS)
166 1 : const_cast<OGRSpatialReference *>(poSRS)->Dereference();
167 3 : poSRS = oOther.poSRS;
168 3 : bNullable = oOther.bNullable;
169 3 : m_oCoordPrecision = oOther.m_oCoordPrecision;
170 3 : m_bSealed = oOther.m_bSealed;
171 3 : bIgnore = oOther.bIgnore;
172 : }
173 3 : return *this;
174 : }
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 171 : void OGR_GFld_Destroy(OGRGeomFieldDefnH hDefn)
188 :
189 : {
190 171 : VALIDATE_POINTER0(hDefn, "OGR_GFld_Destroy");
191 :
192 171 : delete OGRGeomFieldDefn::FromHandle(hDefn);
193 : }
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 3292 : void OGRGeomFieldDefn::SetName(const char *pszNameIn)
216 :
217 : {
218 3292 : if (m_bSealed)
219 : {
220 5 : CPLError(CE_Failure, CPLE_AppDefined,
221 : "OGRGeomFieldDefn::SetName() not allowed on a sealed object");
222 5 : return;
223 : }
224 3287 : if (pszName != pszNameIn)
225 : {
226 3287 : CPLFree(pszName);
227 3287 : pszName = CPLStrdup(pszNameIn);
228 : }
229 : }
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 4 : void OGR_GFld_SetName(OGRGeomFieldDefnH hDefn, const char *pszName)
253 :
254 : {
255 4 : VALIDATE_POINTER0(hDefn, "OGR_GFld_SetName");
256 :
257 4 : OGRGeomFieldDefn::FromHandle(hDefn)->SetName(pszName);
258 : }
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 311 : const char *OGR_GFld_GetNameRef(OGRGeomFieldDefnH hDefn)
292 :
293 : {
294 311 : VALIDATE_POINTER1(hDefn, "OGR_GFld_GetNameRef", "");
295 :
296 : #ifdef OGRAPISPY_ENABLED
297 311 : if (bOGRAPISpyEnabled)
298 2 : OGRAPISpy_GFld_GetXXXX(hDefn, "GetNameRef");
299 : #endif
300 :
301 311 : return OGRGeomFieldDefn::FromHandle(hDefn)->GetNameRef();
302 : }
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 85 : OGRwkbGeometryType OGR_GFld_GetType(OGRGeomFieldDefnH hDefn)
335 :
336 : {
337 85 : VALIDATE_POINTER1(hDefn, "OGR_GFld_GetType", wkbUnknown);
338 :
339 : #ifdef OGRAPISPY_ENABLED
340 85 : if (bOGRAPISpyEnabled)
341 2 : OGRAPISpy_GFld_GetXXXX(hDefn, "GetType");
342 : #endif
343 :
344 85 : OGRwkbGeometryType eType = OGRGeomFieldDefn::FromHandle(hDefn)->GetType();
345 85 : if (OGR_GT_IsNonLinear(eType) && !OGRGetNonLinearGeometriesEnabledFlag())
346 : {
347 1 : eType = OGR_GT_GetLinear(eType);
348 : }
349 85 : return eType;
350 : }
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 21460 : void OGRGeomFieldDefn::SetType(OGRwkbGeometryType eTypeIn)
375 :
376 : {
377 21460 : if (m_bSealed)
378 : {
379 1 : CPLError(CE_Failure, CPLE_AppDefined,
380 : "OGRGeomFieldDefn::SetType() not allowed on a sealed object");
381 1 : return;
382 : }
383 21459 : eGeomType = eTypeIn;
384 : }
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 1 : void OGR_GFld_SetType(OGRGeomFieldDefnH hDefn, OGRwkbGeometryType eType)
409 :
410 : {
411 1 : VALIDATE_POINTER0(hDefn, "OGR_GFld_SetType");
412 :
413 1 : OGRGeomFieldDefn::FromHandle(hDefn)->SetType(eType);
414 : }
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 6 : int OGR_GFld_IsIgnored(OGRGeomFieldDefnH hDefn)
448 : {
449 6 : VALIDATE_POINTER1(hDefn, "OGR_GFld_IsIgnored", FALSE);
450 :
451 6 : return OGRGeomFieldDefn::FromHandle(hDefn)->IsIgnored();
452 : }
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 1 : void OGR_GFld_SetIgnored(OGRGeomFieldDefnH hDefn, int ignore)
494 : {
495 1 : VALIDATE_POINTER0(hDefn, "OGR_GFld_SetIgnored");
496 :
497 1 : OGRGeomFieldDefn::FromHandle(hDefn)->SetIgnored(ignore);
498 : }
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 425722 : const OGRSpatialReference *OGRGeomFieldDefn::GetSpatialRef() const
514 : {
515 425722 : return poSRS;
516 : }
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 81 : OGRSpatialReferenceH OGR_GFld_GetSpatialRef(OGRGeomFieldDefnH hDefn)
537 : {
538 81 : VALIDATE_POINTER1(hDefn, "OGR_GFld_GetSpatialRef", nullptr);
539 :
540 : #ifdef OGRAPISPY_ENABLED
541 81 : if (bOGRAPISpyEnabled)
542 2 : OGRAPISpy_GFld_GetXXXX(hDefn, "GetSpatialRef");
543 : #endif
544 :
545 81 : return OGRSpatialReference::ToHandle(const_cast<OGRSpatialReference *>(
546 81 : OGRGeomFieldDefn::FromHandle(hDefn)->GetSpatialRef()));
547 : }
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 39443 : void OGRGeomFieldDefn::SetSpatialRef(const OGRSpatialReference *poSRSIn)
572 : {
573 :
574 39443 : if (m_bSealed)
575 : {
576 1 : CPLError(
577 : CE_Failure, CPLE_AppDefined,
578 : "OGRGeomFieldDefn::SetSpatialRef() not allowed on a sealed object");
579 1 : return;
580 : }
581 :
582 39442 : if (poSRS == poSRSIn)
583 : {
584 13677 : return;
585 : }
586 :
587 25765 : if (poSRS != nullptr)
588 98 : const_cast<OGRSpatialReference *>(poSRS)->Release();
589 :
590 25765 : poSRS = poSRSIn;
591 :
592 25765 : if (poSRS != nullptr)
593 25755 : const_cast<OGRSpatialReference *>(poSRS)->Reference();
594 : }
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 48 : void OGR_GFld_SetSpatialRef(OGRGeomFieldDefnH hDefn, OGRSpatialReferenceH hSRS)
622 : {
623 48 : VALIDATE_POINTER0(hDefn, "OGR_GFld_SetSpatialRef");
624 :
625 48 : OGRGeomFieldDefn::FromHandle(hDefn)->SetSpatialRef(
626 : reinterpret_cast<OGRSpatialReference *>(hSRS));
627 : }
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 342 : int OGRGeomFieldDefn::IsSame(const OGRGeomFieldDefn *poOtherFieldDefn) const
643 : {
644 1008 : if (!(strcmp(GetNameRef(), poOtherFieldDefn->GetNameRef()) == 0 &&
645 666 : GetType() == poOtherFieldDefn->GetType() &&
646 324 : IsNullable() == poOtherFieldDefn->IsNullable() &&
647 324 : m_oCoordPrecision.dfXYResolution ==
648 324 : poOtherFieldDefn->m_oCoordPrecision.dfXYResolution &&
649 322 : m_oCoordPrecision.dfZResolution ==
650 322 : poOtherFieldDefn->m_oCoordPrecision.dfZResolution &&
651 321 : m_oCoordPrecision.dfMResolution ==
652 321 : poOtherFieldDefn->m_oCoordPrecision.dfMResolution))
653 22 : return FALSE;
654 320 : const OGRSpatialReference *poMySRS = GetSpatialRef();
655 320 : const OGRSpatialReference *poOtherSRS = poOtherFieldDefn->GetSpatialRef();
656 588 : return ((poMySRS == poOtherSRS) ||
657 268 : (poMySRS != nullptr && poOtherSRS != nullptr &&
658 587 : poMySRS->IsSame(poOtherSRS)));
659 : }
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 85 : int OGR_GFld_IsNullable(OGRGeomFieldDefnH hDefn)
715 : {
716 85 : return OGRGeomFieldDefn::FromHandle(hDefn)->IsNullable();
717 : }
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 23747 : void OGRGeomFieldDefn::SetNullable(int bNullableIn)
746 : {
747 23747 : if (m_bSealed)
748 : {
749 1 : CPLError(
750 : CE_Failure, CPLE_AppDefined,
751 : "OGRGeomFieldDefn::SetNullable() not allowed on a sealed object");
752 1 : return;
753 : }
754 23746 : bNullable = bNullableIn;
755 : }
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 23 : void OGR_GFld_SetNullable(OGRGeomFieldDefnH hDefn, int bNullableIn)
778 : {
779 23 : OGRGeomFieldDefn::FromHandle(hDefn)->SetNullable(bNullableIn);
780 23 : }
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 42 : OGR_GFld_GetCoordinatePrecision(OGRGeomFieldDefnH hDefn)
813 : {
814 : return const_cast<OGRGeomCoordinatePrecision *>(
815 42 : &(OGRGeomFieldDefn::FromHandle(hDefn)->GetCoordinatePrecision()));
816 : }
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 21244 : void OGRGeomFieldDefn::SetCoordinatePrecision(
835 : const OGRGeomCoordinatePrecision &prec)
836 : {
837 21244 : if (m_bSealed)
838 : {
839 0 : CPLError(CE_Failure, CPLE_AppDefined,
840 : "OGRGeomFieldDefn::SetCoordinatePrecision() not allowed on a "
841 : "sealed object");
842 0 : return;
843 : }
844 21244 : m_oCoordPrecision = prec;
845 : }
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 18 : void OGR_GFld_SetCoordinatePrecision(OGRGeomFieldDefnH hDefn,
865 : OGRGeomCoordinatePrecisionH hGeomCoordPrec)
866 : {
867 18 : VALIDATE_POINTER0(hGeomCoordPrec, "OGR_GFld_SetCoordinatePrecision");
868 18 : OGRGeomFieldDefn::FromHandle(hDefn)->SetCoordinatePrecision(
869 : *hGeomCoordPrec);
870 : }
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 31424 : void OGRGeomFieldDefn::Seal()
885 : {
886 31424 : m_bSealed = true;
887 31424 : }
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 19259 : void OGRGeomFieldDefn::Unseal()
904 : {
905 19259 : m_bSealed = false;
906 19259 : }
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 603 : OGRGeomFieldDefn::TemporaryUnsealer OGRGeomFieldDefn::GetTemporaryUnsealer()
925 : {
926 603 : return TemporaryUnsealer(this);
927 : }
|