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