1 : /******************************************************************************
2 : * $Id: ogrfeaturedefn.cpp 24286 2012-04-21 19:17:26Z rouault $
3 : *
4 : * Project: OpenGIS Simple Features Reference Implementation
5 : * Purpose: The OGRFeatureDefn class implementation.
6 : * Author: Frank Warmerdam, warmerdam@pobox.com
7 : *
8 : ******************************************************************************
9 : * Copyright (c) 1999, Les Technologies SoftMap Inc.
10 : *
11 : * Permission is hereby granted, free of charge, to any person obtaining a
12 : * copy of this software and associated documentation files (the "Software"),
13 : * to deal in the Software without restriction, including without limitation
14 : * the rights to use, copy, modify, merge, publish, distribute, sublicense,
15 : * and/or sell copies of the Software, and to permit persons to whom the
16 : * Software is furnished to do so, subject to the following conditions:
17 : *
18 : * The above copyright notice and this permission notice shall be included
19 : * in all copies or substantial portions of the Software.
20 : *
21 : * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
22 : * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
23 : * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
24 : * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
25 : * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
26 : * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
27 : * DEALINGS IN THE SOFTWARE.
28 : ****************************************************************************/
29 :
30 : #include "ogr_feature.h"
31 : #include "ogr_api.h"
32 : #include "ogr_p.h"
33 :
34 : CPL_CVSID("$Id: ogrfeaturedefn.cpp 24286 2012-04-21 19:17:26Z rouault $");
35 :
36 : /************************************************************************/
37 : /* OGRFeatureDefn() */
38 : /************************************************************************/
39 :
40 : /**
41 : * \brief Constructor.
42 : *
43 : * The OGRFeatureDefn maintains a reference count, but this starts at
44 : * zero. It is mainly intended to represent a count of OGRFeature's
45 : * based on this definition.
46 : *
47 : * This method is the same as the C function OGR_FD_Create().
48 : *
49 : * @param pszName the name to be assigned to this layer/class. It does not
50 : * need to be unique.
51 : */
52 :
53 15000 : OGRFeatureDefn::OGRFeatureDefn( const char * pszName )
54 :
55 : {
56 15000 : pszFeatureClassName = CPLStrdup( pszName );
57 15000 : nRefCount = 0;
58 15000 : nFieldCount = 0;
59 15000 : papoFieldDefn = NULL;
60 15000 : eGeomType = wkbUnknown;
61 15000 : bIgnoreGeometry = FALSE;
62 15000 : bIgnoreStyle = FALSE;
63 15000 : }
64 :
65 : /************************************************************************/
66 : /* OGR_FD_Create() */
67 : /************************************************************************/
68 : /**
69 : * \brief Create a new feature definition object to hold the field definitions.
70 : *
71 : * The OGRFeatureDefn maintains a reference count, but this starts at
72 : * zero, and should normally be incremented by the owner.
73 : *
74 : * This function is the same as the C++ method
75 : * OGRFeatureDefn::OGRFeatureDefn().
76 : *
77 : * @param pszName the name to be assigned to this layer/class. It does not
78 : * need to be unique.
79 : * @return handle to the newly created feature definition.
80 : */
81 :
82 56 : OGRFeatureDefnH OGR_FD_Create( const char *pszName )
83 :
84 : {
85 56 : return (OGRFeatureDefnH) new OGRFeatureDefn( pszName );
86 : }
87 :
88 :
89 : /************************************************************************/
90 : /* ~OGRFeatureDefn() */
91 : /************************************************************************/
92 :
93 15000 : OGRFeatureDefn::~OGRFeatureDefn()
94 :
95 : {
96 15000 : if( nRefCount != 0 )
97 : {
98 : CPLDebug( "OGRFeatureDefn",
99 : "OGRFeatureDefn %s with a ref count of %d deleted!\n",
100 0 : pszFeatureClassName, nRefCount );
101 : }
102 :
103 15000 : CPLFree( pszFeatureClassName );
104 :
105 77666 : for( int i = 0; i < nFieldCount; i++ )
106 : {
107 62666 : delete papoFieldDefn[i];
108 : }
109 :
110 15000 : CPLFree( papoFieldDefn );
111 15000 : }
112 :
113 : /************************************************************************/
114 : /* OGR_FD_Destroy() */
115 : /************************************************************************/
116 : /**
117 : * \brief Destroy a feature definition object and release all memory associated with it.
118 : *
119 : * This function is the same as the C++ method
120 : * OGRFeatureDefn::~OGRFeatureDefn().
121 : *
122 : * @param hDefn handle to the feature definition to be destroyed.
123 : */
124 :
125 0 : void OGR_FD_Destroy( OGRFeatureDefnH hDefn )
126 :
127 : {
128 0 : delete (OGRFeatureDefn *) hDefn;
129 0 : }
130 :
131 : /************************************************************************/
132 : /* Release() */
133 : /************************************************************************/
134 :
135 : /**
136 : * \fn void OGRFeatureDefn::Release();
137 : *
138 : * \brief Drop a reference to this object, and destroy if no longer referenced.
139 : */
140 :
141 2858424 : void OGRFeatureDefn::Release()
142 :
143 : {
144 2858424 : CPLAssert( NULL != this );
145 :
146 2858424 : if( Dereference() <= 0 )
147 14866 : delete this;
148 2858424 : }
149 :
150 : /************************************************************************/
151 : /* OGR_FD_Release() */
152 : /************************************************************************/
153 :
154 : /**
155 : * \brief Drop a reference, and destroy if unreferenced.
156 : *
157 : * This function is the same as the C++ method OGRFeatureDefn::Release().
158 : *
159 : * @param hDefn handle to the feature definition to be released.
160 : */
161 :
162 58 : void OGR_FD_Release( OGRFeatureDefnH hDefn )
163 :
164 : {
165 58 : ((OGRFeatureDefn *) hDefn)->Release();
166 58 : }
167 :
168 : /************************************************************************/
169 : /* Clone() */
170 : /************************************************************************/
171 :
172 : /**
173 : * \fn OGRFeatureDefn *OGRFeatureDefn::Clone();
174 : *
175 : * \brief Create a copy of this feature definition.
176 : *
177 : * Creates a deep copy of the feature definition.
178 : *
179 : * @return the copy.
180 : */
181 :
182 6 : OGRFeatureDefn *OGRFeatureDefn::Clone()
183 :
184 : {
185 : OGRFeatureDefn *poCopy;
186 :
187 6 : poCopy = new OGRFeatureDefn( GetName() );
188 :
189 6 : poCopy->SetGeomType( GetGeomType() );
190 :
191 44 : for( int i = 0; i < GetFieldCount(); i++ )
192 38 : poCopy->AddFieldDefn( GetFieldDefn( i ) );
193 :
194 6 : return poCopy;
195 : }
196 :
197 : /************************************************************************/
198 : /* GetName() */
199 : /************************************************************************/
200 :
201 : /**
202 : * \fn const char *OGRFeatureDefn::GetName();
203 : *
204 : * \brief Get name of this OGRFeatureDefn.
205 : *
206 : * This method is the same as the C function OGR_FD_GetName().
207 : *
208 : * @return the name. This name is internal and should not be modified, or
209 : * freed.
210 : */
211 :
212 : /************************************************************************/
213 : /* OGR_FD_GetName() */
214 : /************************************************************************/
215 : /**
216 : * \brief Get name of the OGRFeatureDefn passed as an argument.
217 : *
218 : * This function is the same as the C++ method OGRFeatureDefn::GetName().
219 : *
220 : * @param hDefn handle to the feature definition to get the name from.
221 : * @return the name. This name is internal and should not be modified, or
222 : * freed.
223 : */
224 :
225 948 : const char *OGR_FD_GetName( OGRFeatureDefnH hDefn )
226 :
227 : {
228 948 : return ((OGRFeatureDefn *) hDefn)->GetName();
229 : }
230 :
231 : /************************************************************************/
232 : /* GetFieldCount() */
233 : /************************************************************************/
234 :
235 : /**
236 : * \fn int OGRFeatureDefn::GetFieldCount();
237 : *
238 : * \brief Fetch number of fields on this feature.
239 : *
240 : * This method is the same as the C function OGR_FD_GetFieldCount().
241 : * @return count of fields.
242 : */
243 :
244 : /************************************************************************/
245 : /* OGR_FD_GetFieldCount() */
246 : /************************************************************************/
247 :
248 : /**
249 : * \brief Fetch number of fields on the passed feature definition.
250 : *
251 : * This function is the same as the C++ OGRFeatureDefn::GetFieldCount().
252 : *
253 : * @param hDefn handle to the feature definition to get the fields count from.
254 : * @return count of fields.
255 : */
256 :
257 796 : int OGR_FD_GetFieldCount( OGRFeatureDefnH hDefn )
258 :
259 : {
260 796 : return ((OGRFeatureDefn *) hDefn)->GetFieldCount();
261 : }
262 :
263 : /************************************************************************/
264 : /* GetFieldDefn() */
265 : /************************************************************************/
266 :
267 : /**
268 : * \brief Fetch field definition.
269 : *
270 : * This method is the same as the C function OGR_FD_GetFieldDefn().
271 : *
272 : * Starting with GDAL 1.7.0, this method will also issue an error if the index
273 : * is not valid.
274 : *
275 : * @param iField the field to fetch, between 0 and GetFieldCount()-1.
276 : *
277 : * @return a pointer to an internal field definition object or NULL if invalid index.
278 : * This object should not be modified or freed by the application.
279 : */
280 :
281 82629666 : OGRFieldDefn *OGRFeatureDefn::GetFieldDefn( int iField )
282 :
283 : {
284 82629666 : if( iField < 0 || iField >= nFieldCount )
285 : {
286 4 : CPLError(CE_Failure, CPLE_AppDefined, "Invalid index : %d", iField);
287 4 : return NULL;
288 : }
289 :
290 82629662 : return papoFieldDefn[iField];
291 : }
292 :
293 : /************************************************************************/
294 : /* OGR_FD_GetFieldDefn() */
295 : /************************************************************************/
296 :
297 : /**
298 : * \brief Fetch field definition of the passed feature definition.
299 : *
300 : * This function is the same as the C++ method
301 : * OGRFeatureDefn::GetFieldDefn().
302 : *
303 : * Starting with GDAL 1.7.0, this method will also issue an error if the index
304 : * is not valid.
305 : *
306 : * @param hDefn handle to the feature definition to get the field definition
307 : * from.
308 : * @param iField the field to fetch, between 0 and GetFieldCount()-1.
309 : *
310 : * @return an handle to an internal field definition object or NULL if invalid index.
311 : * This object should not be modified or freed by the application.
312 : */
313 :
314 2502 : OGRFieldDefnH OGR_FD_GetFieldDefn( OGRFeatureDefnH hDefn, int iField )
315 :
316 : {
317 2502 : return (OGRFieldDefnH) ((OGRFeatureDefn *) hDefn)->GetFieldDefn( iField );
318 : }
319 :
320 : /************************************************************************/
321 : /* AddFieldDefn() */
322 : /************************************************************************/
323 :
324 : /**
325 : * \brief Add a new field definition.
326 : *
327 : * To add a new field definition to a layer definition, do not use this
328 : * function directly, but use OGRLayer::CreateField() instead.
329 : *
330 : * This method should only be called while there are no OGRFeature
331 : * objects in existance based on this OGRFeatureDefn. The OGRFieldDefn
332 : * passed in is copied, and remains the responsibility of the caller.
333 : *
334 : * This method is the same as the C function OGR_FD_AddFieldDefn().
335 : *
336 : * @param poNewDefn the definition of the new field.
337 : */
338 :
339 62716 : void OGRFeatureDefn::AddFieldDefn( OGRFieldDefn * poNewDefn )
340 :
341 : {
342 : papoFieldDefn = (OGRFieldDefn **)
343 62716 : CPLRealloc( papoFieldDefn, sizeof(void*)*(nFieldCount+1) );
344 :
345 62716 : papoFieldDefn[nFieldCount] = new OGRFieldDefn( poNewDefn );
346 62716 : nFieldCount++;
347 62716 : }
348 :
349 : /************************************************************************/
350 : /* OGR_FD_AddFieldDefn() */
351 : /************************************************************************/
352 :
353 : /**
354 : * \brief Add a new field definition to the passed feature definition.
355 : *
356 : * To add a new field definition to a layer definition, do not use this
357 : * function directly, but use OGR_L_CreateField() instead.
358 : *
359 : * This function should only be called while there are no OGRFeature
360 : * objects in existance based on this OGRFeatureDefn. The OGRFieldDefn
361 : * passed in is copied, and remains the responsibility of the caller.
362 : *
363 : * This function is the same as the C++ method OGRFeatureDefn::AddFieldDefn().
364 : *
365 : * @param hDefn handle to the feature definition to add the field definition
366 : * to.
367 : * @param hNewField handle to the new field definition.
368 : */
369 :
370 444 : void OGR_FD_AddFieldDefn( OGRFeatureDefnH hDefn, OGRFieldDefnH hNewField )
371 :
372 : {
373 444 : ((OGRFeatureDefn *) hDefn)->AddFieldDefn( (OGRFieldDefn *) hNewField );
374 444 : }
375 :
376 : /************************************************************************/
377 : /* DeleteFieldDefn() */
378 : /************************************************************************/
379 :
380 : /**
381 : * \brief Delete an existing field definition.
382 : *
383 : * To delete an existing field definition from a layer definition, do not use this
384 : * function directly, but use OGRLayer::DeleteField() instead.
385 : *
386 : * This method should only be called while there are no OGRFeature
387 : * objects in existance based on this OGRFeatureDefn.
388 : *
389 : * This method is the same as the C function OGR_FD_DeleteFieldDefn().
390 : *
391 : * @param iField the index of the field defintion.
392 : * @return OGRERR_NONE in case of success.
393 : * @since OGR 1.9.0
394 : */
395 :
396 50 : OGRErr OGRFeatureDefn::DeleteFieldDefn( int iField )
397 :
398 : {
399 50 : if (iField < 0 || iField >= nFieldCount)
400 0 : return OGRERR_FAILURE;
401 :
402 50 : delete papoFieldDefn[iField];
403 50 : papoFieldDefn[iField] = NULL;
404 :
405 50 : if (iField < nFieldCount - 1)
406 : {
407 : memmove(papoFieldDefn + iField,
408 : papoFieldDefn + iField + 1,
409 20 : (nFieldCount - 1 - iField) * sizeof(void*));
410 : }
411 :
412 50 : nFieldCount--;
413 :
414 50 : return OGRERR_NONE;
415 : }
416 :
417 : /************************************************************************/
418 : /* OGR_FD_DeleteFieldDefn() */
419 : /************************************************************************/
420 :
421 : /**
422 : * \brief Delete an existing field definition.
423 : *
424 : * To delete an existing field definition from a layer definition, do not use this
425 : * function directly, but use OGR_L_DeleteField() instead.
426 : *
427 : * This method should only be called while there are no OGRFeature
428 : * objects in existance based on this OGRFeatureDefn.
429 : *
430 : * This method is the same as the C++ method OGRFeatureDefn::DeleteFieldDefn().
431 : *
432 : * @param hDefn handle to the feature definition.
433 : * @param iField the index of the field defintion.
434 : * @return OGRERR_NONE in case of success.
435 : * @since OGR 1.9.0
436 : */
437 :
438 0 : OGRErr OGR_FD_DeleteFieldDefn( OGRFeatureDefnH hDefn, int iField )
439 :
440 : {
441 0 : return ((OGRFeatureDefn *) hDefn)->DeleteFieldDefn( iField );
442 : }
443 :
444 : /************************************************************************/
445 : /* ReorderFieldDefns() */
446 : /************************************************************************/
447 :
448 : /**
449 : * \brief Reorder the field definitions in the array of the feature definition
450 : *
451 : * To reorder the field definitions in a layer definition, do not use this
452 : * function directly, but use OGR_L_ReorderFields() instead.
453 : *
454 : * This method should only be called while there are no OGRFeature
455 : * objects in existance based on this OGRFeatureDefn.
456 : *
457 : * This method is the same as the C function OGR_FD_ReorderFieldDefns().
458 : *
459 : * @param panMap an array of GetFieldCount() elements which
460 : * is a permutation of [0, GetFieldCount()-1]. panMap is such that,
461 : * for each field definition at position i after reordering,
462 : * its position before reordering was panMap[i].
463 : * @return OGRERR_NONE in case of success.
464 : * @since OGR 1.9.0
465 : */
466 :
467 60 : OGRErr OGRFeatureDefn::ReorderFieldDefns( int* panMap )
468 :
469 : {
470 60 : if (nFieldCount == 0)
471 0 : return OGRERR_NONE;
472 :
473 60 : OGRErr eErr = OGRCheckPermutation(panMap, nFieldCount);
474 60 : if (eErr != OGRERR_NONE)
475 0 : return eErr;
476 :
477 : OGRFieldDefn** papoFieldDefnNew = (OGRFieldDefn**)
478 60 : CPLMalloc(sizeof(OGRFieldDefn*) * nFieldCount);
479 :
480 312 : for(int i=0;i<nFieldCount;i++)
481 : {
482 252 : papoFieldDefnNew[i] = papoFieldDefn[panMap[i]];
483 : }
484 :
485 60 : CPLFree(papoFieldDefn);
486 60 : papoFieldDefn = papoFieldDefnNew;
487 :
488 60 : return OGRERR_NONE;
489 : }
490 :
491 : /************************************************************************/
492 : /* OGR_FD_ReorderFieldDefns() */
493 : /************************************************************************/
494 :
495 : /**
496 : * \brief Reorder the field definitions in the array of the feature definition
497 : *
498 : * To reorder the field definitions in a layer definition, do not use this
499 : * function directly, but use OGR_L_ReorderFields() instead.
500 : *
501 : * This method should only be called while there are no OGRFeature
502 : * objects in existance based on this OGRFeatureDefn.
503 : *
504 : * This method is the same as the C++ method OGRFeatureDefn::ReorderFieldDefns().
505 : *
506 : * @param hDefn handle to the feature definition.
507 : * @param panMap an array of GetFieldCount() elements which
508 : * is a permutation of [0, GetFieldCount()-1]. panMap is such that,
509 : * for each field definition at position i after reordering,
510 : * its position before reordering was panMap[i].
511 : * @return OGRERR_NONE in case of success.
512 : * @since OGR 1.9.0
513 : */
514 :
515 0 : OGRErr OGR_FD_ReorderFieldDefn( OGRFeatureDefnH hDefn, int* panMap )
516 :
517 : {
518 0 : return ((OGRFeatureDefn *) hDefn)->ReorderFieldDefns( panMap );
519 : }
520 :
521 : /************************************************************************/
522 : /* GetGeomType() */
523 : /************************************************************************/
524 :
525 : /**
526 : * \fn OGRwkbGeometryType OGRFeatureDefn::GetGeomType();
527 : *
528 : * \brief Fetch the geometry base type.
529 : *
530 : * Note that some drivers are unable to determine a specific geometry
531 : * type for a layer, in which case wkbUnknown is returned. A value of
532 : * wkbNone indicates no geometry is available for the layer at all.
533 : * Many drivers do not properly mark the geometry
534 : * type as 25D even if some or all geometries are in fact 25D. A few (broken)
535 : * drivers return wkbPolygon for layers that also include wkbMultiPolygon.
536 : *
537 : * This method is the same as the C function OGR_FD_GetGeomType().
538 : *
539 : * @return the base type for all geometry related to this definition.
540 : */
541 :
542 : /************************************************************************/
543 : /* OGR_FD_GetGeomType() */
544 : /************************************************************************/
545 : /**
546 : * \brief Fetch the geometry base type of the passed feature definition.
547 : *
548 : * This function is the same as the C++ method OGRFeatureDefn::GetGeomType().
549 : *
550 : * @param hDefn handle to the feature definition to get the geometry type from.
551 : * @return the base type for all geometry related to this definition.
552 : */
553 :
554 266 : OGRwkbGeometryType OGR_FD_GetGeomType( OGRFeatureDefnH hDefn )
555 :
556 : {
557 266 : return ((OGRFeatureDefn *) hDefn)->GetGeomType();
558 : }
559 :
560 : /************************************************************************/
561 : /* SetGeomType() */
562 : /************************************************************************/
563 :
564 : /**
565 : * \brief Assign the base geometry type for this layer.
566 : *
567 : * All geometry objects using this type must be of the defined type or
568 : * a derived type. The default upon creation is wkbUnknown which allows for
569 : * any geometry type. The geometry type should generally not be changed
570 : * after any OGRFeatures have been created against this definition.
571 : *
572 : * This method is the same as the C function OGR_FD_SetGeomType().
573 : *
574 : * @param eNewType the new type to assign.
575 : */
576 :
577 14188 : void OGRFeatureDefn::SetGeomType( OGRwkbGeometryType eNewType )
578 :
579 : {
580 14188 : eGeomType = eNewType;
581 14188 : }
582 :
583 : /************************************************************************/
584 : /* OGR_FD_SetGeomType() */
585 : /************************************************************************/
586 :
587 : /**
588 : * \brief Assign the base geometry type for the passed layer (the same as the feature definition).
589 : *
590 : * All geometry objects using this type must be of the defined type or
591 : * a derived type. The default upon creation is wkbUnknown which allows for
592 : * any geometry type. The geometry type should generally not be changed
593 : * after any OGRFeatures have been created against this definition.
594 : *
595 : * This function is the same as the C++ method OGRFeatureDefn::SetGeomType().
596 : *
597 : * @param hDefn handle to the layer or feature definition to set the geometry
598 : * type to.
599 : * @param eType the new type to assign.
600 : */
601 :
602 8 : void OGR_FD_SetGeomType( OGRFeatureDefnH hDefn, OGRwkbGeometryType eType )
603 :
604 : {
605 8 : ((OGRFeatureDefn *) hDefn)->SetGeomType( eType );
606 8 : }
607 :
608 :
609 : /************************************************************************/
610 : /* Reference() */
611 : /************************************************************************/
612 :
613 : /**
614 : * \fn int OGRFeatureDefn::Reference();
615 : *
616 : * \brief Increments the reference count by one.
617 : *
618 : * The reference count is used keep track of the number of OGRFeature
619 : * objects referencing this definition.
620 : *
621 : * This method is the same as the C function OGR_FD_Reference().
622 : *
623 : * @return the updated reference count.
624 : */
625 :
626 : /************************************************************************/
627 : /* OGR_FD_Reference() */
628 : /************************************************************************/
629 : /**
630 : * \brief Increments the reference count by one.
631 : *
632 : * The reference count is used keep track of the number of OGRFeature
633 : * objects referencing this definition.
634 : *
635 : * This function is the same as the C++ method OGRFeatureDefn::Reference().
636 : *
637 : * @param hDefn handle to the feature definition on witch OGRFeature are
638 : * based on.
639 : * @return the updated reference count.
640 : */
641 :
642 56 : int OGR_FD_Reference( OGRFeatureDefnH hDefn )
643 :
644 : {
645 56 : return ((OGRFeatureDefn *) hDefn)->Reference();
646 : }
647 :
648 : /************************************************************************/
649 : /* Dereference() */
650 : /************************************************************************/
651 :
652 : /**
653 : * \fn int OGRFeatureDefn::Dereference();
654 : *
655 : * \brief Decrements the reference count by one.
656 : *
657 : * This method is the same as the C function OGR_FD_Dereference().
658 : *
659 : * @return the updated reference count.
660 : */
661 :
662 : /************************************************************************/
663 : /* OGR_FD_Dereference() */
664 : /************************************************************************/
665 :
666 : /**
667 : * \brief Decrements the reference count by one.
668 : *
669 : * This function is the same as the C++ method OGRFeatureDefn::Dereference().
670 : *
671 : * @param hDefn handle to the feature definition on witch OGRFeature are
672 : * based on.
673 : * @return the updated reference count.
674 : */
675 :
676 0 : int OGR_FD_Dereference( OGRFeatureDefnH hDefn )
677 :
678 : {
679 0 : return ((OGRFeatureDefn *) hDefn)->Dereference();
680 : }
681 :
682 : /************************************************************************/
683 : /* GetReferenceCount() */
684 : /************************************************************************/
685 :
686 : /**
687 : * \fn int OGRFeatureDefn::GetReferenceCount();
688 : *
689 : * \brief Fetch current reference count.
690 : *
691 : * This method is the same as the C function OGR_FD_GetReferenceCount().
692 : *
693 : * @return the current reference count.
694 : */
695 :
696 : /************************************************************************/
697 : /* OGR_FD_GetReferenceCount() */
698 : /************************************************************************/
699 :
700 : /**
701 : * \brief Fetch current reference count.
702 : *
703 : * This function is the same as the C++ method
704 : * OGRFeatureDefn::GetReferenceCount().
705 : *
706 : * @param hDefn hanlde to the feature definition on witch OGRFeature are
707 : * based on.
708 : * @return the current reference count.
709 : */
710 :
711 0 : int OGR_FD_GetReferenceCount( OGRFeatureDefnH hDefn )
712 :
713 : {
714 0 : return ((OGRFeatureDefn *) hDefn)->GetReferenceCount();
715 : }
716 :
717 : /************************************************************************/
718 : /* GetFieldIndex() */
719 : /************************************************************************/
720 :
721 : /**
722 : * \brief Find field by name.
723 : *
724 : * The field index of the first field matching the passed field name (case
725 : * insensitively) is returned.
726 : *
727 : * This method is the same as the C function OGR_FD_GetFieldIndex().
728 : *
729 : * @param pszFieldName the field name to search for.
730 : *
731 : * @return the field index, or -1 if no match found.
732 : */
733 :
734 :
735 20507284 : int OGRFeatureDefn::GetFieldIndex( const char * pszFieldName )
736 :
737 : {
738 350638178 : for( int i = 0; i < nFieldCount; i++ )
739 : {
740 350233236 : if( EQUAL(pszFieldName, papoFieldDefn[i]->GetNameRef() ) )
741 20102342 : return i;
742 : }
743 :
744 404942 : return -1;
745 : }
746 :
747 : /************************************************************************/
748 : /* OGR_FD_GetFieldIndex() */
749 : /************************************************************************/
750 : /**
751 : * \brief Find field by name.
752 : *
753 : * The field index of the first field matching the passed field name (case
754 : * insensitively) is returned.
755 : *
756 : * This function is the same as the C++ method OGRFeatureDefn::GetFieldIndex.
757 : *
758 : * @param hDefn handle to the feature definition to get field index from.
759 : * @param pszFieldName the field name to search for.
760 : *
761 : * @return the field index, or -1 if no match found.
762 : */
763 :
764 1658 : int OGR_FD_GetFieldIndex( OGRFeatureDefnH hDefn, const char *pszFieldName )
765 :
766 : {
767 1658 : return ((OGRFeatureDefn *)hDefn)->GetFieldIndex( pszFieldName );
768 : }
769 :
770 : /************************************************************************/
771 : /* IsGeometryIgnored() */
772 : /************************************************************************/
773 :
774 : /**
775 : * \fn int OGRFeatureDefn::IsGeometryIgnored();
776 : *
777 : * \brief Determine whether the geometry can be omitted when fetching features
778 : *
779 : * This method is the same as the C function OGR_FD_IsGeometryIgnored().
780 : *
781 : * @return ignore state
782 : */
783 :
784 : /************************************************************************/
785 : /* OGR_FD_IsGeometryIgnored() */
786 : /************************************************************************/
787 :
788 : /**
789 : * \brief Determine whether the geometry can be omitted when fetching features
790 : *
791 : * This function is the same as the C++ method
792 : * OGRFeatureDefn::IsGeometryIgnored().
793 : *
794 : * @param hDefn hanlde to the feature definition on witch OGRFeature are
795 : * based on.
796 : * @return ignore state
797 : */
798 :
799 8 : int OGR_FD_IsGeometryIgnored( OGRFeatureDefnH hDefn )
800 : {
801 8 : return ((OGRFeatureDefn *) hDefn)->IsGeometryIgnored();
802 : }
803 :
804 : /************************************************************************/
805 : /* SetGeometryIgnored() */
806 : /************************************************************************/
807 :
808 : /**
809 : * \fn void OGRFeatureDefn::SetGeometryIgnored( int bIgnore );
810 : *
811 : * \brief Set whether the geometry can be omitted when fetching features
812 : *
813 : * This method is the same as the C function OGR_FD_SetGeometryIgnored().
814 : *
815 : * @param bIgnore ignore state
816 : */
817 :
818 : /************************************************************************/
819 : /* OGR_FD_SetGeometryIgnored() */
820 : /************************************************************************/
821 :
822 : /**
823 : * \brief Set whether the geometry can be omitted when fetching features
824 : *
825 : * This function is the same as the C++ method
826 : * OGRFeatureDefn::SetGeometryIgnored().
827 : *
828 : * @param hDefn hanlde to the feature definition on witch OGRFeature are
829 : * based on.
830 : * @param bIgnore ignore state
831 : */
832 :
833 4 : void OGR_FD_SetGeometryIgnored( OGRFeatureDefnH hDefn, int bIgnore )
834 : {
835 4 : ((OGRFeatureDefn *) hDefn)->SetGeometryIgnored( bIgnore );
836 4 : }
837 :
838 : /************************************************************************/
839 : /* IsStyleIgnored() */
840 : /************************************************************************/
841 :
842 : /**
843 : * \fn int OGRFeatureDefn::IsStyleIgnored();
844 : *
845 : * \brief Determine whether the style can be omitted when fetching features
846 : *
847 : * This method is the same as the C function OGR_FD_IsStyleIgnored().
848 : *
849 : * @return ignore state
850 : */
851 :
852 : /************************************************************************/
853 : /* OGR_FD_IsStyleIgnored() */
854 : /************************************************************************/
855 :
856 : /**
857 : * \brief Determine whether the style can be omitted when fetching features
858 : *
859 : * This function is the same as the C++ method
860 : * OGRFeatureDefn::IsStyleIgnored().
861 : *
862 : * @param hDefn handle to the feature definition on which OGRFeature are
863 : * based on.
864 : * @return ignore state
865 : */
866 :
867 4 : int OGR_FD_IsStyleIgnored( OGRFeatureDefnH hDefn )
868 : {
869 4 : return ((OGRFeatureDefn *) hDefn)->IsStyleIgnored();
870 : }
871 :
872 : /************************************************************************/
873 : /* SetStyleIgnored() */
874 : /************************************************************************/
875 :
876 : /**
877 : * \fn void OGRFeatureDefn::SetStyleIgnored( int bIgnore );
878 : *
879 : * \brief Set whether the style can be omitted when fetching features
880 : *
881 : * This method is the same as the C function OGR_FD_SetStyleIgnored().
882 : *
883 : * @param bIgnore ignore state
884 : */
885 :
886 : /************************************************************************/
887 : /* OGR_FD_SetStyleIgnored() */
888 : /************************************************************************/
889 :
890 : /**
891 : * \brief Set whether the style can be omitted when fetching features
892 : *
893 : * This function is the same as the C++ method
894 : * OGRFeatureDefn::SetStyleIgnored().
895 : *
896 : * @param hDefn hanlde to the feature definition on witch OGRFeature are
897 : * based on.
898 : * @param bIgnore ignore state
899 : */
900 :
901 0 : void OGR_FD_SetStyleIgnored( OGRFeatureDefnH hDefn, int bIgnore )
902 : {
903 0 : ((OGRFeatureDefn *) hDefn)->SetStyleIgnored( bIgnore );
904 0 : }
905 :
906 : /************************************************************************/
907 : /* CreateFeatureDefn() */
908 : /************************************************************************/
909 :
910 2 : OGRFeatureDefn *OGRFeatureDefn::CreateFeatureDefn( const char *pszName )
911 :
912 : {
913 2 : return new OGRFeatureDefn( pszName );
914 : }
915 :
916 : /************************************************************************/
917 : /* DestroyFeatureDefn() */
918 : /************************************************************************/
919 :
920 4 : void OGRFeatureDefn::DestroyFeatureDefn( OGRFeatureDefn *poDefn )
921 :
922 : {
923 4 : delete poDefn;
924 4 : }
925 :
926 : /************************************************************************/
927 : /* IsSame() */
928 : /************************************************************************/
929 :
930 : /**
931 : * \brief Test if the feature definition is identical to the other one.
932 : *
933 : * @param poOtherFeatureDefn the other feature definition to compare to.
934 : * @return TRUE if the feature definition is identical to the other one.
935 : */
936 :
937 88 : int OGRFeatureDefn::IsSame( const OGRFeatureDefn * poOtherFeatureDefn ) const
938 : {
939 88 : if (strcmp(pszFeatureClassName, poOtherFeatureDefn->pszFeatureClassName) == 0 &&
940 : eGeomType == poOtherFeatureDefn->eGeomType &&
941 : nFieldCount == poOtherFeatureDefn->nFieldCount)
942 : {
943 28 : for(int i=0;i<nFieldCount;i++)
944 : {
945 20 : const OGRFieldDefn* poFldDefn = papoFieldDefn[i];
946 20 : const OGRFieldDefn* poOtherFldDefn = poOtherFeatureDefn->papoFieldDefn[i];
947 20 : if (!poFldDefn->IsSame(poOtherFldDefn))
948 : {
949 0 : return FALSE;
950 : }
951 : }
952 8 : return TRUE;
953 : }
954 80 : return FALSE;
955 : }
|