1 : /******************************************************************************
2 : * $Id: ogrfeature.cpp 23414 2011-11-23 05:50:05Z warmerdam $
3 : *
4 : * Project: OpenGIS Simple Features Reference Implementation
5 : * Purpose: The OGRFeature class implementation.
6 : * Author: Frank Warmerdam, warmerda@home.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 : #include <vector>
34 :
35 : CPL_CVSID("$Id: ogrfeature.cpp 23414 2011-11-23 05:50:05Z warmerdam $");
36 :
37 : /************************************************************************/
38 : /* OGRFeature() */
39 : /************************************************************************/
40 :
41 : /**
42 : * \brief Constructor
43 : *
44 : * Note that the OGRFeature will increment the reference count of it's
45 : * defining OGRFeatureDefn. Destruction of the OGRFeatureDefn before
46 : * destruction of all OGRFeatures that depend on it is likely to result in
47 : * a crash.
48 : *
49 : * This method is the same as the C function OGR_F_Create().
50 : *
51 : * @param poDefnIn feature class (layer) definition to which the feature will
52 : * adhere.
53 : */
54 :
55 1373548 : OGRFeature::OGRFeature( OGRFeatureDefn * poDefnIn )
56 :
57 : {
58 1373548 : m_pszStyleString = NULL;
59 1373548 : m_poStyleTable = NULL;
60 1373548 : m_pszTmpFieldValue = NULL;
61 1373548 : poDefnIn->Reference();
62 1373548 : poDefn = poDefnIn;
63 :
64 1373548 : nFID = OGRNullFID;
65 :
66 1373548 : poGeometry = NULL;
67 :
68 : // we should likely be initializing from the defaults, but this will
69 : // usually be a waste.
70 : pauFields = (OGRField *) CPLCalloc( poDefn->GetFieldCount(),
71 1373548 : sizeof(OGRField) );
72 :
73 22265588 : for( int i = 0; i < poDefn->GetFieldCount(); i++ )
74 : {
75 20892040 : pauFields[i].Set.nMarker1 = OGRUnsetMarker;
76 20892040 : pauFields[i].Set.nMarker2 = OGRUnsetMarker;
77 : }
78 1373548 : }
79 :
80 : /************************************************************************/
81 : /* OGR_F_Create() */
82 : /************************************************************************/
83 : /**
84 : * \brief Feature factory.
85 : *
86 : * Note that the OGRFeature will increment the reference count of it's
87 : * defining OGRFeatureDefn. Destruction of the OGRFeatureDefn before
88 : * destruction of all OGRFeatures that depend on it is likely to result in
89 : * a crash.
90 : *
91 : * This function is the same as the C++ method OGRFeature::OGRFeature().
92 : *
93 : * @param hDefn handle to the feature class (layer) definition to
94 : * which the feature will adhere.
95 : *
96 : * @return an handle to the new feature object with null fields and
97 : * no geometry.
98 : */
99 :
100 19713 : OGRFeatureH OGR_F_Create( OGRFeatureDefnH hDefn )
101 :
102 : {
103 19713 : VALIDATE_POINTER1( hDefn, "OGR_F_Create", NULL );
104 :
105 19713 : return (OGRFeatureH) new OGRFeature( (OGRFeatureDefn *) hDefn );
106 : }
107 :
108 : /************************************************************************/
109 : /* ~OGRFeature() */
110 : /************************************************************************/
111 :
112 1373548 : OGRFeature::~OGRFeature()
113 :
114 : {
115 1373548 : if( poGeometry != NULL )
116 637142 : delete poGeometry;
117 :
118 22265595 : for( int i = 0; i < poDefn->GetFieldCount(); i++ )
119 : {
120 20892047 : OGRFieldDefn *poFDefn = poDefn->GetFieldDefn(i);
121 :
122 20892047 : if( !IsFieldSet(i) )
123 9068308 : continue;
124 :
125 11823739 : switch( poFDefn->GetType() )
126 : {
127 : case OFTString:
128 4328296 : if( pauFields[i].String != NULL )
129 4328296 : VSIFree( pauFields[i].String );
130 4328296 : break;
131 :
132 : case OFTBinary:
133 89 : if( pauFields[i].Binary.paData != NULL )
134 89 : VSIFree( pauFields[i].Binary.paData );
135 89 : break;
136 :
137 : case OFTStringList:
138 116 : CSLDestroy( pauFields[i].StringList.paList );
139 116 : break;
140 :
141 : case OFTIntegerList:
142 : case OFTRealList:
143 65618 : CPLFree( pauFields[i].IntegerList.paList );
144 : break;
145 :
146 : default:
147 : // should add support for wide strings.
148 : break;
149 : }
150 : }
151 :
152 1373548 : poDefn->Release();
153 :
154 1373548 : CPLFree( pauFields );
155 1373548 : CPLFree(m_pszStyleString);
156 1373548 : CPLFree(m_pszTmpFieldValue);
157 1373548 : }
158 :
159 : /************************************************************************/
160 : /* OGR_F_Destroy() */
161 : /************************************************************************/
162 : /**
163 : * \brief Destroy feature
164 : *
165 : * The feature is deleted, but within the context of the GDAL/OGR heap.
166 : * This is necessary when higher level applications use GDAL/OGR from a
167 : * DLL and they want to delete a feature created within the DLL. If the
168 : * delete is done in the calling application the memory will be freed onto
169 : * the application heap which is inappropriate.
170 : *
171 : * This function is the same as the C++ method OGRFeature::DestroyFeature().
172 : *
173 : * @param hFeat handle to the feature to destroy.
174 : */
175 :
176 27359 : void OGR_F_Destroy( OGRFeatureH hFeat )
177 :
178 : {
179 27359 : delete (OGRFeature *) hFeat;
180 27359 : }
181 :
182 : /************************************************************************/
183 : /* CreateFeature() */
184 : /************************************************************************/
185 :
186 : /**
187 : * \brief Feature factory.
188 : *
189 : * This is essentially a feature factory, useful for
190 : * applications creating features but wanting to ensure they
191 : * are created out of the OGR/GDAL heap.
192 : *
193 : * This method is the same as the C function OGR_F_Create().
194 : *
195 : * @param poDefn Feature definition defining schema.
196 : *
197 : * @return new feature object with null fields and no geometry. May be
198 : * deleted with delete.
199 : */
200 :
201 125291 : OGRFeature *OGRFeature::CreateFeature( OGRFeatureDefn *poDefn )
202 :
203 : {
204 125291 : return new OGRFeature( poDefn );
205 : }
206 :
207 : /************************************************************************/
208 : /* DestroyFeature() */
209 : /************************************************************************/
210 :
211 : /**
212 : * \brief Destroy feature
213 : *
214 : * The feature is deleted, but within the context of the GDAL/OGR heap.
215 : * This is necessary when higher level applications use GDAL/OGR from a
216 : * DLL and they want to delete a feature created within the DLL. If the
217 : * delete is done in the calling application the memory will be freed onto
218 : * the application heap which is inappropriate.
219 : *
220 : * This method is the same as the C function OGR_F_Destroy().
221 : *
222 : * @param poFeature the feature to delete.
223 : */
224 :
225 586509 : void OGRFeature::DestroyFeature( OGRFeature *poFeature )
226 :
227 : {
228 586509 : delete poFeature;
229 586509 : }
230 :
231 : /************************************************************************/
232 : /* GetDefnRef() */
233 : /************************************************************************/
234 :
235 : /**
236 : * \fn OGRFeatureDefn *OGRFeature::GetDefnRef();
237 : *
238 : * \brief Fetch feature definition.
239 : *
240 : * This method is the same as the C function OGR_F_GetDefnRef().
241 : *
242 : * @return a reference to the feature definition object.
243 : */
244 :
245 : /************************************************************************/
246 : /* OGR_F_GetDefnRef() */
247 : /************************************************************************/
248 :
249 : /**
250 : * \brief Fetch feature definition.
251 : *
252 : * This function is the same as the C++ method OGRFeature::GetDefnRef().
253 : *
254 : * @param hFeat handle to the feature to get the feature definition from.
255 : *
256 : * @return an handle to the feature definition object on which feature
257 : * depends.
258 : */
259 :
260 76 : OGRFeatureDefnH OGR_F_GetDefnRef( OGRFeatureH hFeat )
261 :
262 : {
263 76 : VALIDATE_POINTER1( hFeat, "OGR_F_GetDefnRef", NULL );
264 :
265 76 : return (OGRFeatureDefnH) ((OGRFeature *) hFeat)->GetDefnRef();
266 : }
267 :
268 : /************************************************************************/
269 : /* SetGeometryDirectly() */
270 : /************************************************************************/
271 :
272 : /**
273 : * \brief Set feature geometry.
274 : *
275 : * This method updates the features geometry, and operate exactly as
276 : * SetGeometry(), except that this method assumes ownership of the
277 : * passed geometry.
278 : *
279 : * This method is the same as the C function OGR_F_SetGeometryDirectly().
280 : *
281 : * @param poGeomIn new geometry to apply to feature. Passing NULL value here
282 : * is correct and it will result in deallocation of currently assigned geometry
283 : * without assigning new one.
284 : *
285 : * @return OGRERR_NONE if successful, or OGR_UNSUPPORTED_GEOMETRY_TYPE if
286 : * the geometry type is illegal for the OGRFeatureDefn (checking not yet
287 : * implemented).
288 : */
289 :
290 539988 : OGRErr OGRFeature::SetGeometryDirectly( OGRGeometry * poGeomIn )
291 :
292 : {
293 539988 : delete poGeometry;
294 539988 : poGeometry = poGeomIn;
295 :
296 : // I should be verifying that the geometry matches the defn's type.
297 :
298 539988 : return OGRERR_NONE;
299 : }
300 :
301 : /************************************************************************/
302 : /* OGR_F_SetGeometryDirectly() */
303 : /************************************************************************/
304 :
305 : /**
306 : * \brief Set feature geometry.
307 : *
308 : * This function updates the features geometry, and operate exactly as
309 : * SetGeometry(), except that this function assumes ownership of the
310 : * passed geometry.
311 : *
312 : * This function is the same as the C++ method
313 : * OGRFeature::SetGeometryDirectly.
314 : *
315 : * @param hFeat handle to the feature on which to apply the geometry.
316 : * @param hGeom handle to the new geometry to apply to feature.
317 : *
318 : * @return OGRERR_NONE if successful, or OGR_UNSUPPORTED_GEOMETRY_TYPE if
319 : * the geometry type is illegal for the OGRFeatureDefn (checking not yet
320 : * implemented).
321 : */
322 :
323 1231 : OGRErr OGR_F_SetGeometryDirectly( OGRFeatureH hFeat, OGRGeometryH hGeom )
324 :
325 : {
326 1231 : VALIDATE_POINTER1( hFeat, "OGR_F_SetGeometryDirectly", CE_Failure );
327 :
328 1231 : return ((OGRFeature *) hFeat)->SetGeometryDirectly((OGRGeometry *) hGeom);
329 : }
330 :
331 : /************************************************************************/
332 : /* SetGeometry() */
333 : /************************************************************************/
334 :
335 : /**
336 : * \brief Set feature geometry.
337 : *
338 : * This method updates the features geometry, and operate exactly as
339 : * SetGeometryDirectly(), except that this method does not assume ownership
340 : * of the passed geometry, but instead makes a copy of it.
341 : *
342 : * This method is the same as the C function OGR_F_SetGeometry().
343 : *
344 : * @param poGeomIn new geometry to apply to feature. Passing NULL value here
345 : * is correct and it will result in deallocation of currently assigned geometry
346 : * without assigning new one.
347 : *
348 : * @return OGRERR_NONE if successful, or OGR_UNSUPPORTED_GEOMETRY_TYPE if
349 : * the geometry type is illegal for the OGRFeatureDefn (checking not yet
350 : * implemented).
351 : */
352 :
353 199820 : OGRErr OGRFeature::SetGeometry( OGRGeometry * poGeomIn )
354 :
355 : {
356 199820 : delete poGeometry;
357 :
358 199820 : if( poGeomIn != NULL )
359 98417 : poGeometry = poGeomIn->clone();
360 : else
361 101403 : poGeometry = NULL;
362 :
363 : // I should be verifying that the geometry matches the defn's type.
364 :
365 199820 : return OGRERR_NONE;
366 : }
367 :
368 : /************************************************************************/
369 : /* OGR_F_SetGeometry() */
370 : /************************************************************************/
371 :
372 : /**
373 : * \brief Set feature geometry.
374 : *
375 : * This function updates the features geometry, and operate exactly as
376 : * SetGeometryDirectly(), except that this function does not assume ownership
377 : * of the passed geometry, but instead makes a copy of it.
378 : *
379 : * This function is the same as the C++ OGRFeature::SetGeometry().
380 : *
381 : * @param hFeat handle to the feature on which new geometry is applied to.
382 : * @param hGeom handle to the new geometry to apply to feature.
383 : *
384 : * @return OGRERR_NONE if successful, or OGR_UNSUPPORTED_GEOMETRY_TYPE if
385 : * the geometry type is illegal for the OGRFeatureDefn (checking not yet
386 : * implemented).
387 : */
388 :
389 15496 : OGRErr OGR_F_SetGeometry( OGRFeatureH hFeat, OGRGeometryH hGeom )
390 :
391 : {
392 15496 : VALIDATE_POINTER1( hFeat, "OGR_F_SetGeometry", CE_Failure );
393 :
394 15496 : return ((OGRFeature *) hFeat)->SetGeometry((OGRGeometry *) hGeom);
395 : }
396 :
397 : /************************************************************************/
398 : /* StealGeometry() */
399 : /************************************************************************/
400 :
401 : /**
402 : * \brief Take away ownership of geometry.
403 : *
404 : * Fetch the geometry from this feature, and clear the reference to the
405 : * geometry on the feature. This is a mechanism for the application to
406 : * take over ownship of the geometry from the feature without copying.
407 : * Sort of an inverse to SetGeometryDirectly().
408 : *
409 : * After this call the OGRFeature will have a NULL geometry.
410 : *
411 : * @return the pointer to the geometry.
412 : */
413 :
414 251 : OGRGeometry *OGRFeature::StealGeometry()
415 :
416 : {
417 251 : OGRGeometry *poReturn = poGeometry;
418 251 : poGeometry = NULL;
419 251 : return poReturn;
420 : }
421 :
422 : /************************************************************************/
423 : /* OGR_F_StealGeometry() */
424 : /************************************************************************/
425 :
426 : /**
427 : * \brief Take away ownership of geometry.
428 : *
429 : * Fetch the geometry from this feature, and clear the reference to the
430 : * geometry on the feature. This is a mechanism for the application to
431 : * take over ownship of the geometry from the feature without copying.
432 : * Sort of an inverse to OGR_FSetGeometryDirectly().
433 : *
434 : * After this call the OGRFeature will have a NULL geometry.
435 : *
436 : * @return the pointer to the geometry.
437 : */
438 :
439 0 : OGRGeometryH OGR_F_StealGeometry( OGRFeatureH hFeat )
440 :
441 : {
442 0 : VALIDATE_POINTER1( hFeat, "OGR_F_StealGeometry", NULL );
443 :
444 0 : return (OGRGeometryH) ((OGRFeature *) hFeat)->StealGeometry();
445 : }
446 :
447 : /************************************************************************/
448 : /* GetGeometryRef() */
449 : /************************************************************************/
450 :
451 : /**
452 : * \fn OGRGeometry *OGRFeature::GetGeometryRef();
453 : *
454 : * \brief Fetch pointer to feature geometry.
455 : *
456 : * This method is the same as the C function OGR_F_GetGeometryRef().
457 : *
458 : * @return pointer to internal feature geometry. This object should
459 : * not be modified.
460 : */
461 :
462 : /************************************************************************/
463 : /* OGR_F_GetGeometryRef() */
464 : /************************************************************************/
465 :
466 : /**
467 : * \brief Fetch an handle to feature geometry.
468 : *
469 : * This function is the same as the C++ method OGRFeature::GetGeometryRef().
470 : *
471 : * @param hFeat handle to the feature to get geometry from.
472 : * @return an handle to internal feature geometry. This object should
473 : * not be modified.
474 : */
475 :
476 4974 : OGRGeometryH OGR_F_GetGeometryRef( OGRFeatureH hFeat )
477 :
478 : {
479 4974 : VALIDATE_POINTER1( hFeat, "OGR_F_GetGeometryRef", NULL );
480 :
481 4974 : return (OGRGeometryH) ((OGRFeature *) hFeat)->GetGeometryRef();
482 : }
483 :
484 : /************************************************************************/
485 : /* Clone() */
486 : /************************************************************************/
487 :
488 : /**
489 : * \brief Duplicate feature.
490 : *
491 : * The newly created feature is owned by the caller, and will have it's own
492 : * reference to the OGRFeatureDefn.
493 : *
494 : * This method is the same as the C function OGR_F_Clone().
495 : *
496 : * @return new feature, exactly matching this feature.
497 : */
498 :
499 1226 : OGRFeature *OGRFeature::Clone()
500 :
501 : {
502 1226 : OGRFeature *poNew = new OGRFeature( poDefn );
503 :
504 1226 : poNew->SetGeometry( poGeometry );
505 :
506 8519 : for( int i = 0; i < poDefn->GetFieldCount(); i++ )
507 : {
508 7293 : poNew->SetField( i, pauFields + i );
509 : }
510 :
511 1226 : if( GetStyleString() != NULL )
512 261 : poNew->SetStyleString(GetStyleString());
513 :
514 1226 : poNew->SetFID( GetFID() );
515 :
516 1226 : return poNew;
517 : }
518 :
519 : /************************************************************************/
520 : /* OGR_F_Clone() */
521 : /************************************************************************/
522 :
523 : /**
524 : * \brief Duplicate feature.
525 : *
526 : * The newly created feature is owned by the caller, and will have it's own
527 : * reference to the OGRFeatureDefn.
528 : *
529 : * This function is the same as the C++ method OGRFeature::Clone().
530 : *
531 : * @param hFeat handle to the feature to clone.
532 : * @return an handle to the new feature, exactly matching this feature.
533 : */
534 :
535 36 : OGRFeatureH OGR_F_Clone( OGRFeatureH hFeat )
536 :
537 : {
538 36 : VALIDATE_POINTER1( hFeat, "OGR_F_Clone", NULL );
539 :
540 36 : return (OGRFeatureH) ((OGRFeature *) hFeat)->Clone();
541 : }
542 :
543 : /************************************************************************/
544 : /* GetFieldCount() */
545 : /************************************************************************/
546 :
547 : /**
548 : * \fn int OGRFeature::GetFieldCount();
549 : *
550 : * \brief Fetch number of fields on this feature.
551 : * This will always be the same
552 : * as the field count for the OGRFeatureDefn.
553 : *
554 : * This method is the same as the C function OGR_F_GetFieldCount().
555 : *
556 : * @return count of fields.
557 : */
558 :
559 : /************************************************************************/
560 : /* OGR_F_GetFieldCount() */
561 : /************************************************************************/
562 :
563 : /**
564 : * \brief Fetch number of fields on this feature
565 : * This will always be the same
566 : * as the field count for the OGRFeatureDefn.
567 : *
568 : * This function is the same as the C++ method OGRFeature::GetFieldCount().
569 : *
570 : * @param hFeat handle to the feature to get the fields count from.
571 : * @return count of fields.
572 : */
573 :
574 4607 : int OGR_F_GetFieldCount( OGRFeatureH hFeat )
575 :
576 : {
577 4607 : VALIDATE_POINTER1( hFeat, "OGR_F_GetFieldCount", 0 );
578 :
579 4607 : return ((OGRFeature *) hFeat)->GetFieldCount();
580 : }
581 :
582 : /************************************************************************/
583 : /* GetFieldDefnRef() */
584 : /************************************************************************/
585 :
586 : /**
587 : * \fn OGRFieldDefn *OGRFeature::GetFieldDefnRef( int iField );
588 : *
589 : * \brief Fetch definition for this field.
590 : *
591 : * This method is the same as the C function OGR_F_GetFieldDefnRef().
592 : *
593 : * @param iField the field to fetch, from 0 to GetFieldCount()-1.
594 : *
595 : * @return the field definition (from the OGRFeatureDefn). This is an
596 : * internal reference, and should not be deleted or modified.
597 : */
598 :
599 : /************************************************************************/
600 : /* OGR_F_GetFieldDefnRef() */
601 : /************************************************************************/
602 :
603 : /**
604 : * \brief Fetch definition for this field.
605 : *
606 : * This function is the same as the C++ method OGRFeature::GetFieldDefnRef().
607 : *
608 : * @param hFeat handle to the feature on which the field is found.
609 : * @param i the field to fetch, from 0 to GetFieldCount()-1.
610 : *
611 : * @return an handle to the field definition (from the OGRFeatureDefn).
612 : * This is an internal reference, and should not be deleted or modified.
613 : */
614 :
615 3720 : OGRFieldDefnH OGR_F_GetFieldDefnRef( OGRFeatureH hFeat, int i )
616 :
617 : {
618 3720 : VALIDATE_POINTER1( hFeat, "OGR_F_GetFieldDefnRef", NULL );
619 :
620 3720 : return (OGRFieldDefnH) ((OGRFeature *) hFeat)->GetFieldDefnRef(i);
621 : }
622 :
623 : /************************************************************************/
624 : /* GetFieldIndex() */
625 : /************************************************************************/
626 :
627 : /**
628 : * \fn int OGRFeature::GetFieldIndex( const char * pszName );
629 : *
630 : * \brief Fetch the field index given field name.
631 : *
632 : * This is a cover for the OGRFeatureDefn::GetFieldIndex() method.
633 : *
634 : * This method is the same as the C function OGR_F_GetFieldIndex().
635 : *
636 : * @param pszName the name of the field to search for.
637 : *
638 : * @return the field index, or -1 if no matching field is found.
639 : */
640 :
641 : /************************************************************************/
642 : /* OGR_F_GetFieldIndex() */
643 : /************************************************************************/
644 :
645 : /**
646 : * \brief Fetch the field index given field name.
647 : *
648 : * This is a cover for the OGRFeatureDefn::GetFieldIndex() method.
649 : *
650 : * This function is the same as the C++ method OGRFeature::GetFieldIndex().
651 : *
652 : * @param hFeat handle to the feature on which the field is found.
653 : * @param pszName the name of the field to search for.
654 : *
655 : * @return the field index, or -1 if no matching field is found.
656 : */
657 :
658 2898 : int OGR_F_GetFieldIndex( OGRFeatureH hFeat, const char *pszName )
659 :
660 : {
661 2898 : VALIDATE_POINTER1( hFeat, "OGR_F_GetFieldIndex", 0 );
662 :
663 2898 : return ((OGRFeature *) hFeat)->GetFieldIndex( pszName );
664 : }
665 :
666 : /************************************************************************/
667 : /* IsFieldSet() */
668 : /************************************************************************/
669 :
670 : /**
671 : * \fn int OGRFeature::IsFieldSet( int iField ) const;
672 : *
673 : * \brief Test if a field has ever been assigned a value or not.
674 : *
675 : * This method is the same as the C function OGR_F_IsFieldSet().
676 : *
677 : * @param iField the field to test.
678 : *
679 : * @return TRUE if the field has been set, otherwise false.
680 : */
681 :
682 36556535 : int OGRFeature::IsFieldSet( int iField ) const
683 :
684 : {
685 36556535 : int iSpecialField = iField - poDefn->GetFieldCount();
686 36556535 : if (iSpecialField >= 0)
687 : {
688 : // special field value accessors
689 40 : switch (iSpecialField)
690 : {
691 : case SPF_FID:
692 22 : return ((OGRFeature *)this)->GetFID() != OGRNullFID;
693 :
694 : case SPF_OGR_GEOM_WKT:
695 : case SPF_OGR_GEOMETRY:
696 15 : return poGeometry != NULL;
697 :
698 : case SPF_OGR_STYLE:
699 0 : return ((OGRFeature *)this)->GetStyleString() != NULL;
700 :
701 : case SPF_OGR_GEOM_AREA:
702 3 : if( poGeometry == NULL )
703 0 : return FALSE;
704 :
705 3 : return OGR_G_GetArea((OGRGeometryH)poGeometry) != 0.0;
706 :
707 : default:
708 0 : return FALSE;
709 : }
710 : }
711 : else
712 : {
713 36556495 : return pauFields[iField].Set.nMarker1 != OGRUnsetMarker
714 36556495 : || pauFields[iField].Set.nMarker2 != OGRUnsetMarker;
715 : }
716 : }
717 :
718 : /************************************************************************/
719 : /* OGR_F_IsFieldSet() */
720 : /************************************************************************/
721 :
722 : /**
723 : * \brief Test if a field has ever been assigned a value or not.
724 : *
725 : * This function is the same as the C++ method OGRFeature::IsFieldSet().
726 : *
727 : * @param hFeat handle to the feature on which the field is.
728 : * @param iField the field to test.
729 : *
730 : * @return TRUE if the field has been set, otherwise false.
731 : */
732 :
733 4434 : int OGR_F_IsFieldSet( OGRFeatureH hFeat, int iField )
734 :
735 : {
736 4434 : VALIDATE_POINTER1( hFeat, "OGR_F_IsFieldSet", 0 );
737 :
738 4434 : OGRFeature* poFeature = (OGRFeature* )hFeat;
739 :
740 4434 : if (iField < 0 || iField >= poFeature->GetFieldCount())
741 : {
742 0 : CPLError(CE_Failure, CPLE_AppDefined, "Invalid index : %d", iField);
743 0 : return FALSE;
744 : }
745 :
746 4434 : return poFeature->IsFieldSet( iField );
747 : }
748 :
749 : /************************************************************************/
750 : /* UnsetField() */
751 : /************************************************************************/
752 :
753 : /**
754 : * \brief Clear a field, marking it as unset.
755 : *
756 : * This method is the same as the C function OGR_F_UnsetField().
757 : *
758 : * @param iField the field to unset.
759 : */
760 :
761 933914 : void OGRFeature::UnsetField( int iField )
762 :
763 : {
764 933914 : OGRFieldDefn *poFDefn = poDefn->GetFieldDefn( iField );
765 :
766 933914 : if( poFDefn == NULL || !IsFieldSet(iField) )
767 933888 : return;
768 :
769 26 : switch( poFDefn->GetType() )
770 : {
771 : case OFTRealList:
772 : case OFTIntegerList:
773 0 : CPLFree( pauFields[iField].IntegerList.paList );
774 0 : break;
775 :
776 : case OFTStringList:
777 0 : CSLDestroy( pauFields[iField].StringList.paList );
778 0 : break;
779 :
780 : case OFTString:
781 13 : CPLFree( pauFields[iField].String );
782 13 : break;
783 :
784 : case OFTBinary:
785 0 : CPLFree( pauFields[iField].Binary.paData );
786 : break;
787 :
788 : default:
789 : break;
790 : }
791 :
792 26 : pauFields[iField].Set.nMarker1 = OGRUnsetMarker;
793 26 : pauFields[iField].Set.nMarker2 = OGRUnsetMarker;
794 : }
795 :
796 : /************************************************************************/
797 : /* OGR_F_UnsetField() */
798 : /************************************************************************/
799 :
800 : /**
801 : * \brief Clear a field, marking it as unset.
802 : *
803 : * This function is the same as the C++ method OGRFeature::UnsetField().
804 : *
805 : * @param hFeat handle to the feature on which the field is.
806 : * @param iField the field to unset.
807 : */
808 :
809 22 : void OGR_F_UnsetField( OGRFeatureH hFeat, int iField )
810 :
811 : {
812 22 : VALIDATE_POINTER0( hFeat, "OGR_F_UnsetField" );
813 :
814 22 : ((OGRFeature *) hFeat)->UnsetField( iField );
815 : }
816 :
817 : /************************************************************************/
818 : /* GetRawFieldRef() */
819 : /************************************************************************/
820 :
821 : /**
822 : * \fn OGRField *OGRFeature::GetRawFieldRef( int iField );
823 : *
824 : * \brief Fetch a pointer to the internal field value given the index.
825 : *
826 : * This method is the same as the C function OGR_F_GetRawFieldRef().
827 : *
828 : * @param iField the field to fetch, from 0 to GetFieldCount()-1.
829 : *
830 : * @return the returned pointer is to an internal data structure, and should
831 : * not be freed, or modified.
832 : */
833 :
834 : /************************************************************************/
835 : /* OGR_F_GetRawFieldRef() */
836 : /************************************************************************/
837 :
838 : /**
839 : * \brief Fetch an handle to the internal field value given the index.
840 : *
841 : * This function is the same as the C++ method OGRFeature::GetRawFieldRef().
842 : *
843 : * @param hFeat handle to the feature on which field is found.
844 : * @param iField the field to fetch, from 0 to GetFieldCount()-1.
845 : *
846 : * @return the returned handle is to an internal data structure, and should
847 : * not be freed, or modified.
848 : */
849 :
850 0 : OGRField *OGR_F_GetRawFieldRef( OGRFeatureH hFeat, int iField )
851 :
852 : {
853 0 : VALIDATE_POINTER1( hFeat, "OGR_F_GetRawFieldRef", NULL );
854 :
855 0 : return ((OGRFeature *)hFeat)->GetRawFieldRef( iField );
856 : }
857 :
858 : /************************************************************************/
859 : /* GetFieldAsInteger() */
860 : /************************************************************************/
861 :
862 : /**
863 : * \brief Fetch field value as integer.
864 : *
865 : * OFTString features will be translated using atoi(). OFTReal fields
866 : * will be cast to integer. Other field types, or errors will result in
867 : * a return value of zero.
868 : *
869 : * This method is the same as the C function OGR_F_GetFieldAsInteger().
870 : *
871 : * @param iField the field to fetch, from 0 to GetFieldCount()-1.
872 : *
873 : * @return the field value.
874 : */
875 :
876 1812964 : int OGRFeature::GetFieldAsInteger( int iField )
877 :
878 : {
879 1812964 : int iSpecialField = iField - poDefn->GetFieldCount();
880 1812964 : if (iSpecialField >= 0)
881 : {
882 : // special field value accessors
883 26 : switch (iSpecialField)
884 : {
885 : case SPF_FID:
886 26 : return GetFID();
887 :
888 : case SPF_OGR_GEOM_AREA:
889 0 : if( poGeometry == NULL )
890 0 : return 0;
891 0 : return (int)OGR_G_GetArea((OGRGeometryH)poGeometry);
892 :
893 : default:
894 0 : return 0;
895 : }
896 : }
897 :
898 1812938 : OGRFieldDefn *poFDefn = poDefn->GetFieldDefn( iField );
899 :
900 1812938 : if( poFDefn == NULL )
901 0 : return 0;
902 :
903 1812938 : if( !IsFieldSet(iField) )
904 6 : return 0;
905 :
906 1812932 : if( poFDefn->GetType() == OFTInteger )
907 1793105 : return pauFields[iField].Integer;
908 19827 : else if( poFDefn->GetType() == OFTReal )
909 6 : return (int) pauFields[iField].Real;
910 19821 : else if( poFDefn->GetType() == OFTString )
911 : {
912 19821 : if( pauFields[iField].String == NULL )
913 0 : return 0;
914 : else
915 19821 : return atoi(pauFields[iField].String);
916 : }
917 : else
918 0 : return 0;
919 : }
920 :
921 : /************************************************************************/
922 : /* OGR_F_GetFieldAsInteger() */
923 : /************************************************************************/
924 :
925 : /**
926 : * \brief Fetch field value as integer.
927 : *
928 : * OFTString features will be translated using atoi(). OFTReal fields
929 : * will be cast to integer. Other field types, or errors will result in
930 : * a return value of zero.
931 : *
932 : * This function is the same as the C++ method OGRFeature::GetFieldAsInteger().
933 : *
934 : * @param hFeat handle to the feature that owned the field.
935 : * @param iField the field to fetch, from 0 to GetFieldCount()-1.
936 : *
937 : * @return the field value.
938 : */
939 :
940 2623 : int OGR_F_GetFieldAsInteger( OGRFeatureH hFeat, int iField )
941 :
942 : {
943 2623 : VALIDATE_POINTER1( hFeat, "OGR_F_GetFieldAsInteger", 0 );
944 :
945 2623 : return ((OGRFeature *)hFeat)->GetFieldAsInteger(iField);
946 : }
947 :
948 : /************************************************************************/
949 : /* GetFieldAsDouble() */
950 : /************************************************************************/
951 :
952 : /**
953 : * \brief Fetch field value as a double.
954 : *
955 : * OFTString features will be translated using atof(). OFTInteger fields
956 : * will be cast to double. Other field types, or errors will result in
957 : * a return value of zero.
958 : *
959 : * This method is the same as the C function OGR_F_GetFieldAsDouble().
960 : *
961 : * @param iField the field to fetch, from 0 to GetFieldCount()-1.
962 : *
963 : * @return the field value.
964 : */
965 :
966 39084 : double OGRFeature::GetFieldAsDouble( int iField )
967 :
968 : {
969 39084 : int iSpecialField = iField - poDefn->GetFieldCount();
970 39084 : if (iSpecialField >= 0)
971 : {
972 : // special field value accessors
973 4 : switch (iSpecialField)
974 : {
975 : case SPF_FID:
976 0 : return GetFID();
977 :
978 : case SPF_OGR_GEOM_AREA:
979 4 : if( poGeometry == NULL )
980 0 : return 0.0;
981 4 : return OGR_G_GetArea((OGRGeometryH)poGeometry);
982 :
983 : default:
984 0 : return 0.0;
985 : }
986 : }
987 :
988 39080 : OGRFieldDefn *poFDefn = poDefn->GetFieldDefn( iField );
989 :
990 39080 : if( poFDefn == NULL )
991 0 : return 0.0;
992 :
993 39080 : if( !IsFieldSet(iField) )
994 58 : return 0.0;
995 :
996 39022 : if( poFDefn->GetType() == OFTReal )
997 11391 : return pauFields[iField].Real;
998 27631 : else if( poFDefn->GetType() == OFTInteger )
999 0 : return pauFields[iField].Integer;
1000 27631 : else if( poFDefn->GetType() == OFTString )
1001 : {
1002 27631 : if( pauFields[iField].String == NULL )
1003 0 : return 0;
1004 : else
1005 27631 : return atof(pauFields[iField].String);
1006 : }
1007 : else
1008 0 : return 0.0;
1009 : }
1010 :
1011 : /************************************************************************/
1012 : /* OGR_F_GetFieldAsDouble() */
1013 : /************************************************************************/
1014 :
1015 : /**
1016 : * \brief Fetch field value as a double.
1017 : *
1018 : * OFTString features will be translated using atof(). OFTInteger fields
1019 : * will be cast to double. Other field types, or errors will result in
1020 : * a return value of zero.
1021 : *
1022 : * This function is the same as the C++ method OGRFeature::GetFieldAsDouble().
1023 : *
1024 : * @param hFeat handle to the feature that owned the field.
1025 : * @param iField the field to fetch, from 0 to GetFieldCount()-1.
1026 : *
1027 : * @return the field value.
1028 : */
1029 :
1030 638 : double OGR_F_GetFieldAsDouble( OGRFeatureH hFeat, int iField )
1031 :
1032 : {
1033 638 : VALIDATE_POINTER1( hFeat, "OGR_F_GetFieldAsDouble", 0 );
1034 :
1035 638 : return ((OGRFeature *)hFeat)->GetFieldAsDouble(iField);
1036 : }
1037 :
1038 : /************************************************************************/
1039 : /* GetFieldAsString() */
1040 : /************************************************************************/
1041 :
1042 : /**
1043 : * \brief Fetch field value as a string.
1044 : *
1045 : * OFTReal and OFTInteger fields will be translated to string using
1046 : * sprintf(), but not necessarily using the established formatting rules.
1047 : * Other field types, or errors will result in a return value of zero.
1048 : *
1049 : * This method is the same as the C function OGR_F_GetFieldAsString().
1050 : *
1051 : * @param iField the field to fetch, from 0 to GetFieldCount()-1.
1052 : *
1053 : * @return the field value. This string is internal, and should not be
1054 : * modified, or freed. Its lifetime may be very brief.
1055 : */
1056 :
1057 1677605 : const char *OGRFeature::GetFieldAsString( int iField )
1058 :
1059 : {
1060 : #define TEMP_BUFFER_SIZE 80
1061 : char szTempBuffer[TEMP_BUFFER_SIZE];
1062 :
1063 1677605 : CPLFree(m_pszTmpFieldValue);
1064 1677605 : m_pszTmpFieldValue = NULL;
1065 :
1066 1677605 : int iSpecialField = iField - poDefn->GetFieldCount();
1067 1677605 : if (iSpecialField >= 0)
1068 : {
1069 : // special field value accessors
1070 33 : switch (iSpecialField)
1071 : {
1072 : case SPF_FID:
1073 0 : snprintf( szTempBuffer, TEMP_BUFFER_SIZE, "%ld", GetFID() );
1074 0 : return m_pszTmpFieldValue = CPLStrdup( szTempBuffer );
1075 :
1076 : case SPF_OGR_GEOMETRY:
1077 29 : if( poGeometry )
1078 29 : return poGeometry->getGeometryName();
1079 : else
1080 0 : return "";
1081 :
1082 : case SPF_OGR_STYLE:
1083 2 : if( GetStyleString() == NULL )
1084 0 : return "";
1085 : else
1086 2 : return GetStyleString();
1087 :
1088 : case SPF_OGR_GEOM_WKT:
1089 : {
1090 2 : if( poGeometry == NULL )
1091 0 : return "";
1092 :
1093 2 : if (poGeometry->exportToWkt( &m_pszTmpFieldValue ) == OGRERR_NONE )
1094 2 : return m_pszTmpFieldValue;
1095 : else
1096 0 : return "";
1097 : }
1098 :
1099 : case SPF_OGR_GEOM_AREA:
1100 0 : if( poGeometry == NULL )
1101 0 : return "";
1102 :
1103 : snprintf( szTempBuffer, TEMP_BUFFER_SIZE, "%.16g",
1104 0 : OGR_G_GetArea((OGRGeometryH)poGeometry) );
1105 0 : return m_pszTmpFieldValue = CPLStrdup( szTempBuffer );
1106 :
1107 : default:
1108 0 : return "";
1109 : }
1110 : }
1111 :
1112 1677572 : OGRFieldDefn *poFDefn = poDefn->GetFieldDefn( iField );
1113 :
1114 1677572 : if( poFDefn == NULL )
1115 0 : return "";
1116 :
1117 1677572 : if( !IsFieldSet(iField) )
1118 200 : return "";
1119 :
1120 1677372 : if( poFDefn->GetType() == OFTString )
1121 : {
1122 1661933 : if( pauFields[iField].String == NULL )
1123 0 : return "";
1124 : else
1125 1661933 : return pauFields[iField].String;
1126 : }
1127 15439 : else if( poFDefn->GetType() == OFTInteger )
1128 : {
1129 : snprintf( szTempBuffer, TEMP_BUFFER_SIZE,
1130 14427 : "%d", pauFields[iField].Integer );
1131 14427 : return m_pszTmpFieldValue = CPLStrdup( szTempBuffer );
1132 : }
1133 1012 : else if( poFDefn->GetType() == OFTReal )
1134 : {
1135 : char szFormat[64];
1136 :
1137 716 : if( poFDefn->GetWidth() != 0 )
1138 : {
1139 : snprintf( szFormat, sizeof(szFormat), "%%%d.%df",
1140 539 : poFDefn->GetWidth(), poFDefn->GetPrecision() );
1141 : }
1142 : else
1143 177 : strcpy( szFormat, "%.15g" );
1144 :
1145 : snprintf( szTempBuffer, TEMP_BUFFER_SIZE,
1146 716 : szFormat, pauFields[iField].Real );
1147 :
1148 716 : return m_pszTmpFieldValue = CPLStrdup( szTempBuffer );
1149 : }
1150 296 : else if( poFDefn->GetType() == OFTDateTime )
1151 : {
1152 : snprintf( szTempBuffer, TEMP_BUFFER_SIZE,
1153 : "%04d/%02d/%02d %2d:%02d:%02d",
1154 149 : pauFields[iField].Date.Year,
1155 149 : pauFields[iField].Date.Month,
1156 149 : pauFields[iField].Date.Day,
1157 149 : pauFields[iField].Date.Hour,
1158 149 : pauFields[iField].Date.Minute,
1159 894 : pauFields[iField].Date.Second );
1160 :
1161 149 : if( pauFields[iField].Date.TZFlag > 1 )
1162 : {
1163 47 : int nOffset = (pauFields[iField].Date.TZFlag - 100) * 15;
1164 47 : int nHours = (int) (nOffset / 60); // round towards zero
1165 47 : int nMinutes = ABS(nOffset - nHours * 60);
1166 :
1167 47 : if( nOffset < 0 )
1168 : {
1169 6 : strcat( szTempBuffer, "-" );
1170 6 : nHours = ABS(nHours);
1171 : }
1172 : else
1173 41 : strcat( szTempBuffer, "+" );
1174 :
1175 47 : if( nMinutes == 0 )
1176 : snprintf( szTempBuffer+strlen(szTempBuffer),
1177 43 : TEMP_BUFFER_SIZE-strlen(szTempBuffer), "%02d", nHours );
1178 : else
1179 : snprintf( szTempBuffer+strlen(szTempBuffer),
1180 4 : TEMP_BUFFER_SIZE-strlen(szTempBuffer), "%02d%02d", nHours, nMinutes );
1181 : }
1182 :
1183 149 : return m_pszTmpFieldValue = CPLStrdup( szTempBuffer );
1184 : }
1185 147 : else if( poFDefn->GetType() == OFTDate )
1186 : {
1187 : snprintf( szTempBuffer, TEMP_BUFFER_SIZE, "%04d/%02d/%02d",
1188 33 : pauFields[iField].Date.Year,
1189 33 : pauFields[iField].Date.Month,
1190 99 : pauFields[iField].Date.Day );
1191 :
1192 33 : return m_pszTmpFieldValue = CPLStrdup( szTempBuffer );
1193 : }
1194 114 : else if( poFDefn->GetType() == OFTTime )
1195 : {
1196 : snprintf( szTempBuffer, TEMP_BUFFER_SIZE, "%2d:%02d:%02d",
1197 29 : pauFields[iField].Date.Hour,
1198 29 : pauFields[iField].Date.Minute,
1199 87 : pauFields[iField].Date.Second );
1200 :
1201 29 : return m_pszTmpFieldValue = CPLStrdup( szTempBuffer );
1202 : }
1203 85 : else if( poFDefn->GetType() == OFTIntegerList )
1204 : {
1205 : char szItem[32];
1206 15 : int i, nCount = pauFields[iField].IntegerList.nCount;
1207 :
1208 15 : snprintf( szTempBuffer, TEMP_BUFFER_SIZE, "(%d:", nCount );
1209 46 : for( i = 0; i < nCount; i++ )
1210 : {
1211 : snprintf( szItem, sizeof(szItem), "%d",
1212 31 : pauFields[iField].IntegerList.paList[i] );
1213 31 : if( strlen(szTempBuffer) + strlen(szItem) + 6
1214 : >= sizeof(szTempBuffer) )
1215 : {
1216 0 : break;
1217 : }
1218 :
1219 31 : if( i > 0 )
1220 16 : strcat( szTempBuffer, "," );
1221 :
1222 31 : strcat( szTempBuffer, szItem );
1223 : }
1224 :
1225 15 : if( i < nCount )
1226 0 : strcat( szTempBuffer, ",...)" );
1227 : else
1228 15 : strcat( szTempBuffer, ")" );
1229 :
1230 15 : return m_pszTmpFieldValue = CPLStrdup( szTempBuffer );
1231 : }
1232 70 : else if( poFDefn->GetType() == OFTRealList )
1233 : {
1234 : char szItem[40];
1235 : char szFormat[64];
1236 11 : int i, nCount = pauFields[iField].RealList.nCount;
1237 :
1238 11 : if( poFDefn->GetWidth() != 0 )
1239 : {
1240 : snprintf( szFormat, sizeof(szFormat), "%%%d.%df",
1241 0 : poFDefn->GetWidth(), poFDefn->GetPrecision() );
1242 : }
1243 : else
1244 11 : strcpy( szFormat, "%.16g" );
1245 :
1246 11 : snprintf( szTempBuffer, TEMP_BUFFER_SIZE, "(%d:", nCount );
1247 33 : for( i = 0; i < nCount; i++ )
1248 : {
1249 : snprintf( szItem, sizeof(szItem), szFormat,
1250 22 : pauFields[iField].RealList.paList[i] );
1251 22 : if( strlen(szTempBuffer) + strlen(szItem) + 6
1252 : >= sizeof(szTempBuffer) )
1253 : {
1254 0 : break;
1255 : }
1256 :
1257 22 : if( i > 0 )
1258 11 : strcat( szTempBuffer, "," );
1259 :
1260 22 : strcat( szTempBuffer, szItem );
1261 : }
1262 :
1263 11 : if( i < nCount )
1264 0 : strcat( szTempBuffer, ",...)" );
1265 : else
1266 11 : strcat( szTempBuffer, ")" );
1267 :
1268 11 : return m_pszTmpFieldValue = CPLStrdup( szTempBuffer );
1269 : }
1270 59 : else if( poFDefn->GetType() == OFTStringList )
1271 : {
1272 43 : int i, nCount = pauFields[iField].StringList.nCount;
1273 :
1274 43 : snprintf( szTempBuffer, TEMP_BUFFER_SIZE, "(%d:", nCount );
1275 129 : for( i = 0; i < nCount; i++ )
1276 : {
1277 86 : const char *pszItem = pauFields[iField].StringList.paList[i];
1278 :
1279 86 : if( strlen(szTempBuffer) + strlen(pszItem) + 6
1280 : >= sizeof(szTempBuffer) )
1281 : {
1282 0 : break;
1283 : }
1284 :
1285 86 : if( i > 0 )
1286 43 : strcat( szTempBuffer, "," );
1287 :
1288 86 : strcat( szTempBuffer, pszItem );
1289 : }
1290 :
1291 43 : if( i < nCount )
1292 0 : strcat( szTempBuffer, ",...)" );
1293 : else
1294 43 : strcat( szTempBuffer, ")" );
1295 :
1296 43 : return m_pszTmpFieldValue = CPLStrdup( szTempBuffer );
1297 : }
1298 16 : else if( poFDefn->GetType() == OFTBinary )
1299 : {
1300 16 : int nCount = pauFields[iField].Binary.nCount;
1301 : char *pszHex;
1302 :
1303 16 : if( nCount > (int) sizeof(szTempBuffer) / 2 - 4 )
1304 0 : nCount = sizeof(szTempBuffer) / 2 - 4;
1305 :
1306 16 : pszHex = CPLBinaryToHex( nCount, pauFields[iField].Binary.paData );
1307 :
1308 16 : memcpy( szTempBuffer, pszHex, 2 * nCount );
1309 16 : szTempBuffer[nCount*2] = '\0';
1310 16 : if( nCount < pauFields[iField].Binary.nCount )
1311 0 : strcat( szTempBuffer, "..." );
1312 :
1313 16 : CPLFree( pszHex );
1314 :
1315 16 : return m_pszTmpFieldValue = CPLStrdup( szTempBuffer );
1316 : }
1317 : else
1318 0 : return "";
1319 : #undef TEMP_BUFFER_SIZE
1320 : }
1321 :
1322 : /************************************************************************/
1323 : /* OGR_F_GetFieldAsString() */
1324 : /************************************************************************/
1325 :
1326 : /**
1327 : * \brief Fetch field value as a string.
1328 : *
1329 : * OFTReal and OFTInteger fields will be translated to string using
1330 : * sprintf(), but not necessarily using the established formatting rules.
1331 : * Other field types, or errors will result in a return value of zero.
1332 : *
1333 : * This function is the same as the C++ method OGRFeature::GetFieldAsString().
1334 : *
1335 : * @param hFeat handle to the feature that owned the field.
1336 : * @param iField the field to fetch, from 0 to GetFieldCount()-1.
1337 : *
1338 : * @return the field value. This string is internal, and should not be
1339 : * modified, or freed. Its lifetime may be very brief.
1340 : */
1341 :
1342 3426 : const char *OGR_F_GetFieldAsString( OGRFeatureH hFeat, int iField )
1343 :
1344 : {
1345 3426 : VALIDATE_POINTER1( hFeat, "OGR_F_GetFieldAsString", NULL );
1346 :
1347 3426 : return ((OGRFeature *)hFeat)->GetFieldAsString(iField);
1348 : }
1349 :
1350 : /************************************************************************/
1351 : /* GetFieldAsIntegerList() */
1352 : /************************************************************************/
1353 :
1354 : /**
1355 : * \brief Fetch field value as a list of integers.
1356 : *
1357 : * Currently this method only works for OFTIntegerList fields.
1358 : *
1359 : * This method is the same as the C function OGR_F_GetFieldAsIntegerList().
1360 : *
1361 : * @param iField the field to fetch, from 0 to GetFieldCount()-1.
1362 : * @param pnCount an integer to put the list count (number of integers) into.
1363 : *
1364 : * @return the field value. This list is internal, and should not be
1365 : * modified, or freed. Its lifetime may be very brief. If *pnCount is zero
1366 : * on return the returned pointer may be NULL or non-NULL.
1367 : */
1368 :
1369 2887 : const int *OGRFeature::GetFieldAsIntegerList( int iField, int *pnCount )
1370 :
1371 : {
1372 2887 : OGRFieldDefn *poFDefn = poDefn->GetFieldDefn( iField );
1373 :
1374 2887 : if( poFDefn != NULL && IsFieldSet(iField) &&
1375 : poFDefn->GetType() == OFTIntegerList )
1376 : {
1377 2887 : if( pnCount != NULL )
1378 2887 : *pnCount = pauFields[iField].IntegerList.nCount;
1379 :
1380 2887 : return pauFields[iField].IntegerList.paList;
1381 : }
1382 : else
1383 : {
1384 0 : if( pnCount != NULL )
1385 0 : *pnCount = 0;
1386 :
1387 0 : return NULL;
1388 : }
1389 : }
1390 :
1391 : /************************************************************************/
1392 : /* OGR_F_GetFieldAsIntegerList() */
1393 : /************************************************************************/
1394 :
1395 : /**
1396 : * \brief Fetch field value as a list of integers.
1397 : *
1398 : * Currently this function only works for OFTIntegerList fields.
1399 : *
1400 : * This function is the same as the C++ method
1401 : * OGRFeature::GetFieldAsIntegerList().
1402 : *
1403 : * @param hFeat handle to the feature that owned the field.
1404 : * @param iField the field to fetch, from 0 to GetFieldCount()-1.
1405 : * @param pnCount an integer to put the list count (number of integers) into.
1406 : *
1407 : * @return the field value. This list is internal, and should not be
1408 : * modified, or freed. Its lifetime may be very brief. If *pnCount is zero
1409 : * on return the returned pointer may be NULL or non-NULL.
1410 : */
1411 :
1412 3 : const int *OGR_F_GetFieldAsIntegerList( OGRFeatureH hFeat, int iField,
1413 : int *pnCount )
1414 :
1415 : {
1416 3 : VALIDATE_POINTER1( hFeat, "OGR_F_GetFieldAsIntegerList", NULL );
1417 :
1418 3 : return ((OGRFeature *)hFeat)->GetFieldAsIntegerList(iField, pnCount);
1419 : }
1420 :
1421 : /************************************************************************/
1422 : /* GetFieldAsDoubleList() */
1423 : /************************************************************************/
1424 :
1425 : /**
1426 : * \brief Fetch field value as a list of doubles.
1427 : *
1428 : * Currently this method only works for OFTRealList fields.
1429 : *
1430 : * This method is the same as the C function OGR_F_GetFieldAsDoubleList().
1431 : *
1432 : * @param iField the field to fetch, from 0 to GetFieldCount()-1.
1433 : * @param pnCount an integer to put the list count (number of doubles) into.
1434 : *
1435 : * @return the field value. This list is internal, and should not be
1436 : * modified, or freed. Its lifetime may be very brief. If *pnCount is zero
1437 : * on return the returned pointer may be NULL or non-NULL.
1438 : */
1439 :
1440 98 : const double *OGRFeature::GetFieldAsDoubleList( int iField, int *pnCount )
1441 :
1442 : {
1443 98 : OGRFieldDefn *poFDefn = poDefn->GetFieldDefn( iField );
1444 :
1445 98 : if( poFDefn != NULL && IsFieldSet(iField) &&
1446 : poFDefn->GetType() == OFTRealList )
1447 : {
1448 95 : if( pnCount != NULL )
1449 95 : *pnCount = pauFields[iField].RealList.nCount;
1450 :
1451 95 : return pauFields[iField].RealList.paList;
1452 : }
1453 : else
1454 : {
1455 3 : if( pnCount != NULL )
1456 3 : *pnCount = 0;
1457 :
1458 3 : return NULL;
1459 : }
1460 : }
1461 :
1462 : /************************************************************************/
1463 : /* OGR_F_GetFieldAsDoubleList() */
1464 : /************************************************************************/
1465 :
1466 : /**
1467 : * \brief Fetch field value as a list of doubles.
1468 : *
1469 : * Currently this function only works for OFTRealList fields.
1470 : *
1471 : * This function is the same as the C++ method
1472 : * OGRFeature::GetFieldAsDoubleList().
1473 : *
1474 : * @param hFeat handle to the feature that owned the field.
1475 : * @param iField the field to fetch, from 0 to GetFieldCount()-1.
1476 : * @param pnCount an integer to put the list count (number of doubles) into.
1477 : *
1478 : * @return the field value. This list is internal, and should not be
1479 : * modified, or freed. Its lifetime may be very brief. If *pnCount is zero
1480 : * on return the returned pointer may be NULL or non-NULL.
1481 : */
1482 :
1483 16 : const double *OGR_F_GetFieldAsDoubleList( OGRFeatureH hFeat, int iField,
1484 : int *pnCount )
1485 :
1486 : {
1487 16 : VALIDATE_POINTER1( hFeat, "OGR_F_GetFieldAsDoubleList", NULL );
1488 :
1489 16 : return ((OGRFeature *)hFeat)->GetFieldAsDoubleList(iField, pnCount);
1490 : }
1491 :
1492 : /************************************************************************/
1493 : /* GetFieldAsStringList() */
1494 : /************************************************************************/
1495 :
1496 : /**
1497 : * \brief Fetch field value as a list of strings.
1498 : *
1499 : * Currently this method only works for OFTStringList fields.
1500 : *
1501 : * The returned list is terminated by a NULL pointer. The number of
1502 : * elements can also be calculated using CSLCount().
1503 : *
1504 : * This method is the same as the C function OGR_F_GetFieldAsStringList().
1505 : *
1506 : * @param iField the field to fetch, from 0 to GetFieldCount()-1.
1507 : *
1508 : * @return the field value. This list is internal, and should not be
1509 : * modified, or freed. Its lifetime may be very brief.
1510 : */
1511 :
1512 69 : char **OGRFeature::GetFieldAsStringList( int iField ) const
1513 :
1514 : {
1515 69 : OGRFieldDefn *poFDefn = poDefn->GetFieldDefn( iField );
1516 :
1517 69 : if( poFDefn == NULL )
1518 0 : return NULL;
1519 :
1520 69 : if( !IsFieldSet(iField) )
1521 0 : return NULL;
1522 :
1523 69 : if( poFDefn->GetType() == OFTStringList )
1524 : {
1525 69 : return pauFields[iField].StringList.paList;
1526 : }
1527 : else
1528 : {
1529 0 : return NULL;
1530 : }
1531 : }
1532 :
1533 : /************************************************************************/
1534 : /* OGR_F_GetFieldAsStringList() */
1535 : /************************************************************************/
1536 :
1537 : /**
1538 : * \brief Fetch field value as a list of strings.
1539 : *
1540 : * Currently this method only works for OFTStringList fields.
1541 : *
1542 : * The returned list is terminated by a NULL pointer. The number of
1543 : * elements can also be calculated using CSLCount().
1544 : *
1545 : * This function is the same as the C++ method
1546 : * OGRFeature::GetFieldAsStringList().
1547 : *
1548 : * @param hFeat handle to the feature that owned the field.
1549 : * @param iField the field to fetch, from 0 to GetFieldCount()-1.
1550 : *
1551 : * @return the field value. This list is internal, and should not be
1552 : * modified, or freed. Its lifetime may be very brief.
1553 : */
1554 :
1555 3 : char **OGR_F_GetFieldAsStringList( OGRFeatureH hFeat, int iField )
1556 :
1557 : {
1558 3 : VALIDATE_POINTER1( hFeat, "OGR_F_GetFieldAsStringList", NULL );
1559 :
1560 3 : return ((OGRFeature *)hFeat)->GetFieldAsStringList(iField);
1561 : }
1562 :
1563 : /************************************************************************/
1564 : /* GetFieldAsBinary() */
1565 : /************************************************************************/
1566 :
1567 : /**
1568 : * \brief Fetch field value as binary data.
1569 : *
1570 : * Currently this method only works for OFTBinary fields.
1571 : *
1572 : * This method is the same as the C function OGR_F_GetFieldAsBinary().
1573 : *
1574 : * @param iField the field to fetch, from 0 to GetFieldCount()-1.
1575 : * @param pnBytes location to put the number of bytes returned.
1576 : *
1577 : * @return the field value. This data is internal, and should not be
1578 : * modified, or freed. Its lifetime may be very brief.
1579 : */
1580 :
1581 70 : GByte *OGRFeature::GetFieldAsBinary( int iField, int *pnBytes )
1582 :
1583 : {
1584 70 : OGRFieldDefn *poFDefn = poDefn->GetFieldDefn( iField );
1585 :
1586 70 : *pnBytes = 0;
1587 :
1588 70 : if( poFDefn == NULL )
1589 0 : return NULL;
1590 :
1591 70 : if( !IsFieldSet(iField) )
1592 0 : return NULL;
1593 :
1594 70 : if( poFDefn->GetType() == OFTBinary )
1595 : {
1596 70 : *pnBytes = pauFields[iField].Binary.nCount;
1597 70 : return pauFields[iField].Binary.paData;
1598 : }
1599 : else
1600 : {
1601 0 : return NULL;
1602 : }
1603 : }
1604 :
1605 : /************************************************************************/
1606 : /* OGR_F_GetFieldAsBinary() */
1607 : /************************************************************************/
1608 :
1609 : /**
1610 : * \brief Fetch field value as binary.
1611 : *
1612 : * Currently this method only works for OFTBinary fields.
1613 : *
1614 : * This function is the same as the C++ method
1615 : * OGRFeature::GetFieldAsBinary().
1616 : *
1617 : * @param hFeat handle to the feature that owned the field.
1618 : * @param iField the field to fetch, from 0 to GetFieldCount()-1.
1619 : * @param pnBytes location to place count of bytes returned.
1620 : *
1621 : * @return the field value. This list is internal, and should not be
1622 : * modified, or freed. Its lifetime may be very brief.
1623 : */
1624 :
1625 45 : GByte *OGR_F_GetFieldAsBinary( OGRFeatureH hFeat, int iField, int *pnBytes )
1626 :
1627 : {
1628 45 : VALIDATE_POINTER1( hFeat, "OGR_F_GetFieldAsBinary", NULL );
1629 45 : VALIDATE_POINTER1( pnBytes, "OGR_F_GetFieldAsBinary", NULL );
1630 :
1631 45 : return ((OGRFeature *)hFeat)->GetFieldAsBinary(iField,pnBytes);
1632 : }
1633 :
1634 : /************************************************************************/
1635 : /* GetFieldAsDateTime() */
1636 : /************************************************************************/
1637 :
1638 : /**
1639 : * \brief Fetch field value as date and time.
1640 : *
1641 : * Currently this method only works for OFTDate, OFTTime and OFTDateTime fields.
1642 : *
1643 : * This method is the same as the C function OGR_F_GetFieldAsDateTime().
1644 : *
1645 : * @param iField the field to fetch, from 0 to GetFieldCount()-1.
1646 : * @param pnYear (including century)
1647 : * @param pnMonth (1-12)
1648 : * @param pnDay (1-31)
1649 : * @param pnHour (0-23)
1650 : * @param pnMinute (0-59)
1651 : * @param pnSecond (0-59)
1652 : * @param pnTZFlag (0=unknown, 1=localtime, 100=GMT, see data model for details)
1653 : *
1654 : * @return TRUE on success or FALSE on failure.
1655 : */
1656 :
1657 131 : int OGRFeature::GetFieldAsDateTime( int iField,
1658 : int *pnYear, int *pnMonth, int *pnDay,
1659 : int *pnHour, int *pnMinute, int *pnSecond,
1660 : int *pnTZFlag )
1661 :
1662 : {
1663 131 : OGRFieldDefn *poFDefn = poDefn->GetFieldDefn( iField );
1664 :
1665 131 : if( poFDefn == NULL )
1666 0 : return FALSE;
1667 :
1668 131 : if( !IsFieldSet(iField) )
1669 0 : return FALSE;
1670 :
1671 131 : if( poFDefn->GetType() == OFTDate
1672 : || poFDefn->GetType() == OFTTime
1673 : || poFDefn->GetType() == OFTDateTime )
1674 :
1675 : {
1676 131 : if( pnYear )
1677 131 : *pnYear = pauFields[iField].Date.Year;
1678 131 : if( pnMonth )
1679 131 : *pnMonth = pauFields[iField].Date.Month;
1680 131 : if( pnDay )
1681 131 : *pnDay = pauFields[iField].Date.Day;
1682 131 : if( pnHour )
1683 130 : *pnHour = pauFields[iField].Date.Hour;
1684 131 : if( pnMinute )
1685 130 : *pnMinute = pauFields[iField].Date.Minute;
1686 131 : if( pnSecond )
1687 130 : *pnSecond = pauFields[iField].Date.Second;
1688 131 : if( pnTZFlag )
1689 130 : *pnTZFlag = pauFields[iField].Date.TZFlag;
1690 :
1691 131 : return TRUE;
1692 : }
1693 : else
1694 : {
1695 0 : return FALSE;
1696 : }
1697 : }
1698 :
1699 : /************************************************************************/
1700 : /* OGR_F_GetFieldAsDateTime() */
1701 : /************************************************************************/
1702 :
1703 : /**
1704 : * \brief Fetch field value as date and time.
1705 : *
1706 : * Currently this method only works for OFTDate, OFTTime and OFTDateTime fields.
1707 : *
1708 : * This function is the same as the C++ method
1709 : * OGRFeature::GetFieldAsDateTime().
1710 : *
1711 : * @param hFeat handle to the feature that owned the field.
1712 : * @param iField the field to fetch, from 0 to GetFieldCount()-1.
1713 : * @param pnYear (including century)
1714 : * @param pnMonth (1-12)
1715 : * @param pnDay (1-31)
1716 : * @param pnHour (0-23)
1717 : * @param pnMinute (0-59)
1718 : * @param pnSecond (0-59)
1719 : * @param pnTZFlag (0=unknown, 1=localtime, 100=GMT, see data model for details)
1720 : *
1721 : * @return TRUE on success or FALSE on failure.
1722 : */
1723 :
1724 1 : int OGR_F_GetFieldAsDateTime( OGRFeatureH hFeat, int iField,
1725 : int *pnYear, int *pnMonth, int *pnDay,
1726 : int *pnHour, int *pnMinute, int *pnSecond,
1727 : int *pnTZFlag )
1728 :
1729 : {
1730 1 : VALIDATE_POINTER1( hFeat, "OGR_F_GetFieldAsDateTime", 0 );
1731 :
1732 : return ((OGRFeature *)hFeat)->GetFieldAsDateTime( iField,
1733 : pnYear, pnMonth, pnDay,
1734 : pnHour, pnMinute,pnSecond,
1735 1 : pnTZFlag );
1736 : }
1737 :
1738 : /************************************************************************/
1739 : /* SetField() */
1740 : /************************************************************************/
1741 :
1742 : /**
1743 : * \brief Set field to integer value.
1744 : *
1745 : * OFTInteger and OFTReal fields will be set directly. OFTString fields
1746 : * will be assigned a string representation of the value, but not necessarily
1747 : * taking into account formatting constraints on this field. Other field
1748 : * types may be unaffected.
1749 : *
1750 : * This method is the same as the C function OGR_F_SetFieldInteger().
1751 : *
1752 : * @param iField the field to fetch, from 0 to GetFieldCount()-1.
1753 : * @param nValue the value to assign.
1754 : */
1755 :
1756 874789 : void OGRFeature::SetField( int iField, int nValue )
1757 :
1758 : {
1759 874789 : OGRFieldDefn *poFDefn = poDefn->GetFieldDefn( iField );
1760 :
1761 874789 : if( poFDefn == NULL )
1762 0 : return;
1763 :
1764 874789 : if( poFDefn->GetType() == OFTInteger )
1765 : {
1766 874752 : pauFields[iField].Integer = nValue;
1767 874752 : pauFields[iField].Set.nMarker2 = 0;
1768 : }
1769 37 : else if( poFDefn->GetType() == OFTReal )
1770 : {
1771 25 : pauFields[iField].Real = nValue;
1772 : }
1773 12 : else if( poFDefn->GetType() == OFTString )
1774 : {
1775 : char szTempBuffer[64];
1776 :
1777 5 : sprintf( szTempBuffer, "%d", nValue );
1778 :
1779 5 : if( IsFieldSet( iField) )
1780 0 : CPLFree( pauFields[iField].String );
1781 :
1782 5 : pauFields[iField].String = CPLStrdup( szTempBuffer );
1783 : }
1784 : else
1785 : /* do nothing for other field types */;
1786 : }
1787 :
1788 : /************************************************************************/
1789 : /* OGR_F_SetFieldInteger() */
1790 : /************************************************************************/
1791 :
1792 : /**
1793 : * \brief Set field to integer value.
1794 : *
1795 : * OFTInteger and OFTReal fields will be set directly. OFTString fields
1796 : * will be assigned a string representation of the value, but not necessarily
1797 : * taking into account formatting constraints on this field. Other field
1798 : * types may be unaffected.
1799 : *
1800 : * This function is the same as the C++ method OGRFeature::SetField().
1801 : *
1802 : * @param hFeat handle to the feature that owned the field.
1803 : * @param iField the field to fetch, from 0 to GetFieldCount()-1.
1804 : * @param nValue the value to assign.
1805 : */
1806 :
1807 9217 : void OGR_F_SetFieldInteger( OGRFeatureH hFeat, int iField, int nValue )
1808 :
1809 : {
1810 9217 : VALIDATE_POINTER0( hFeat, "OGR_F_SetFieldInteger" );
1811 :
1812 9217 : ((OGRFeature *)hFeat)->SetField( iField, nValue );
1813 : }
1814 :
1815 : /************************************************************************/
1816 : /* SetField() */
1817 : /************************************************************************/
1818 :
1819 : /**
1820 : * \brief Set field to double value.
1821 : *
1822 : * OFTInteger and OFTReal fields will be set directly. OFTString fields
1823 : * will be assigned a string representation of the value, but not necessarily
1824 : * taking into account formatting constraints on this field. Other field
1825 : * types may be unaffected.
1826 : *
1827 : * This method is the same as the C function OGR_F_SetFieldDouble().
1828 : *
1829 : * @param iField the field to fetch, from 0 to GetFieldCount()-1.
1830 : * @param dfValue the value to assign.
1831 : */
1832 :
1833 88326 : void OGRFeature::SetField( int iField, double dfValue )
1834 :
1835 : {
1836 88326 : OGRFieldDefn *poFDefn = poDefn->GetFieldDefn( iField );
1837 :
1838 88326 : if( poFDefn == NULL )
1839 0 : return;
1840 :
1841 88326 : if( poFDefn->GetType() == OFTReal )
1842 : {
1843 88046 : pauFields[iField].Real = dfValue;
1844 : }
1845 280 : else if( poFDefn->GetType() == OFTInteger )
1846 : {
1847 234 : pauFields[iField].Integer = (int) dfValue;
1848 234 : pauFields[iField].Set.nMarker2 = 0;
1849 : }
1850 46 : else if( poFDefn->GetType() == OFTString )
1851 : {
1852 : char szTempBuffer[128];
1853 :
1854 39 : sprintf( szTempBuffer, "%.16g", dfValue );
1855 :
1856 39 : if( IsFieldSet( iField) )
1857 0 : CPLFree( pauFields[iField].String );
1858 :
1859 39 : pauFields[iField].String = CPLStrdup( szTempBuffer );
1860 : }
1861 : else
1862 : /* do nothing for other field types */;
1863 : }
1864 :
1865 : /************************************************************************/
1866 : /* OGR_F_SetFieldDouble() */
1867 : /************************************************************************/
1868 :
1869 : /**
1870 : * \brief Set field to double value.
1871 : *
1872 : * OFTInteger and OFTReal fields will be set directly. OFTString fields
1873 : * will be assigned a string representation of the value, but not necessarily
1874 : * taking into account formatting constraints on this field. Other field
1875 : * types may be unaffected.
1876 : *
1877 : * This function is the same as the C++ method OGRFeature::SetField().
1878 : *
1879 : * @param hFeat handle to the feature that owned the field.
1880 : * @param iField the field to fetch, from 0 to GetFieldCount()-1.
1881 : * @param dfValue the value to assign.
1882 : */
1883 :
1884 226 : void OGR_F_SetFieldDouble( OGRFeatureH hFeat, int iField, double dfValue )
1885 :
1886 : {
1887 226 : VALIDATE_POINTER0( hFeat, "OGR_F_SetFieldDouble" );
1888 :
1889 226 : ((OGRFeature *)hFeat)->SetField( iField, dfValue );
1890 : }
1891 :
1892 : /************************************************************************/
1893 : /* SetField() */
1894 : /************************************************************************/
1895 :
1896 : /**
1897 : * \brief Set field to string value.
1898 : *
1899 : * OFTInteger fields will be set based on an atoi() conversion of the string.
1900 : * OFTReal fields will be set based on an atof() conversion of the string.
1901 : * Other field types may be unaffected.
1902 : *
1903 : * This method is the same as the C function OGR_F_SetFieldString().
1904 : *
1905 : * @param iField the field to fetch, from 0 to GetFieldCount()-1.
1906 : * @param pszValue the value to assign.
1907 : */
1908 :
1909 10422097 : void OGRFeature::SetField( int iField, const char * pszValue )
1910 :
1911 : {
1912 10422097 : OGRFieldDefn *poFDefn = poDefn->GetFieldDefn( iField );
1913 :
1914 10422097 : if( poFDefn == NULL )
1915 0 : return;
1916 :
1917 10422097 : if( poFDefn->GetType() == OFTString )
1918 : {
1919 4127109 : if( IsFieldSet(iField) )
1920 361 : CPLFree( pauFields[iField].String );
1921 :
1922 4127109 : pauFields[iField].String = CPLStrdup( pszValue );
1923 : }
1924 6294988 : else if( poFDefn->GetType() == OFTInteger )
1925 : {
1926 5877694 : pauFields[iField].Integer = atoi(pszValue);
1927 5877694 : pauFields[iField].Set.nMarker2 = OGRUnsetMarker;
1928 : }
1929 417294 : else if( poFDefn->GetType() == OFTReal )
1930 : {
1931 417113 : pauFields[iField].Real = atof(pszValue);
1932 : }
1933 181 : else if( poFDefn->GetType() == OFTDate
1934 : || poFDefn->GetType() == OFTTime
1935 : || poFDefn->GetType() == OFTDateTime )
1936 : {
1937 : OGRField sWrkField;
1938 :
1939 157 : if( OGRParseDate( pszValue, &sWrkField, 0 ) )
1940 153 : memcpy( pauFields+iField, &sWrkField, sizeof(sWrkField));
1941 : }
1942 24 : else if( poFDefn->GetType() == OFTIntegerList
1943 : || poFDefn->GetType() == OFTRealList )
1944 : {
1945 12 : char **papszValueList = NULL;
1946 :
1947 12 : if( pszValue[0] == '(' && strchr(pszValue,':') != NULL )
1948 : {
1949 : papszValueList = CSLTokenizeString2(
1950 10 : pszValue, ",:()", 0 );
1951 : }
1952 :
1953 22 : if( CSLCount(papszValueList) == 0
1954 10 : || atoi(papszValueList[0]) != CSLCount(papszValueList)-1 )
1955 : {
1956 : /* do nothing - the count does not match entries */
1957 : }
1958 10 : else if( poFDefn->GetType() == OFTIntegerList )
1959 : {
1960 10 : int i, nCount = atoi(papszValueList[0]);
1961 10 : std::vector<int> anValues;
1962 :
1963 40 : for( i=0; i < nCount; i++ )
1964 30 : anValues.push_back( atoi(papszValueList[i+1]) );
1965 10 : SetField( iField, nCount, &(anValues[0]) );
1966 : }
1967 0 : else if( poFDefn->GetType() == OFTRealList )
1968 : {
1969 0 : int i, nCount = atoi(papszValueList[0]);
1970 0 : std::vector<double> adfValues;
1971 :
1972 0 : for( i=0; i < nCount; i++ )
1973 0 : adfValues.push_back( atof(papszValueList[i+1]) );
1974 0 : SetField( iField, nCount, &(adfValues[0]) );
1975 : }
1976 :
1977 12 : CSLDestroy(papszValueList);
1978 : }
1979 : else
1980 : /* do nothing for other field types */;
1981 : }
1982 :
1983 : /************************************************************************/
1984 : /* OGR_F_SetFieldString() */
1985 : /************************************************************************/
1986 :
1987 : /**
1988 : * \brief Set field to string value.
1989 : *
1990 : * OFTInteger fields will be set based on an atoi() conversion of the string.
1991 : * OFTReal fields will be set based on an atof() conversion of the string.
1992 : * Other field types may be unaffected.
1993 : *
1994 : * This function is the same as the C++ method OGRFeature::SetField().
1995 : *
1996 : * @param hFeat handle to the feature that owned the field.
1997 : * @param iField the field to fetch, from 0 to GetFieldCount()-1.
1998 : * @param pszValue the value to assign.
1999 : */
2000 :
2001 3140 : void OGR_F_SetFieldString( OGRFeatureH hFeat, int iField, const char *pszValue)
2002 :
2003 : {
2004 3140 : VALIDATE_POINTER0( hFeat, "OGR_F_SetFieldString" );
2005 :
2006 3140 : ((OGRFeature *)hFeat)->SetField( iField, pszValue );
2007 : }
2008 :
2009 : /************************************************************************/
2010 : /* SetField() */
2011 : /************************************************************************/
2012 :
2013 : /**
2014 : * \brief Set field to list of integers value.
2015 : *
2016 : * This method currently on has an effect of OFTIntegerList fields.
2017 : *
2018 : * This method is the same as the C function OGR_F_SetFieldIntegerList().
2019 : *
2020 : * @param iField the field to set, from 0 to GetFieldCount()-1.
2021 : * @param nCount the number of values in the list being assigned.
2022 : * @param panValues the values to assign.
2023 : */
2024 :
2025 51086 : void OGRFeature::SetField( int iField, int nCount, int *panValues )
2026 :
2027 : {
2028 51086 : OGRFieldDefn *poFDefn = poDefn->GetFieldDefn( iField );
2029 :
2030 51086 : if( poFDefn == NULL )
2031 0 : return;
2032 :
2033 51086 : if( poFDefn->GetType() == OFTIntegerList )
2034 : {
2035 : OGRField uField;
2036 :
2037 51086 : uField.IntegerList.nCount = nCount;
2038 51086 : uField.Set.nMarker2 = 0;
2039 51086 : uField.IntegerList.paList = panValues;
2040 :
2041 51086 : SetField( iField, &uField );
2042 : }
2043 : }
2044 :
2045 : /************************************************************************/
2046 : /* OGR_F_SetFieldIntegerList() */
2047 : /************************************************************************/
2048 :
2049 : /**
2050 : * \brief Set field to list of integers value.
2051 : *
2052 : * This function currently on has an effect of OFTIntegerList fields.
2053 : *
2054 : * This function is the same as the C++ method OGRFeature::SetField().
2055 : *
2056 : * @param hFeat handle to the feature that owned the field.
2057 : * @param iField the field to set, from 0 to GetFieldCount()-1.
2058 : * @param nCount the number of values in the list being assigned.
2059 : * @param panValues the values to assign.
2060 : */
2061 :
2062 6 : void OGR_F_SetFieldIntegerList( OGRFeatureH hFeat, int iField,
2063 : int nCount, int *panValues )
2064 :
2065 : {
2066 6 : VALIDATE_POINTER0( hFeat, "OGR_F_SetFieldIntegerList" );
2067 :
2068 6 : ((OGRFeature *)hFeat)->SetField( iField, nCount, panValues );
2069 : }
2070 :
2071 : /************************************************************************/
2072 : /* SetField() */
2073 : /************************************************************************/
2074 :
2075 : /**
2076 : * \brief Set field to list of doubles value.
2077 : *
2078 : * This method currently on has an effect of OFTRealList fields.
2079 : *
2080 : * This method is the same as the C function OGR_F_SetFieldDoubleList().
2081 : *
2082 : * @param iField the field to set, from 0 to GetFieldCount()-1.
2083 : * @param nCount the number of values in the list being assigned.
2084 : * @param padfValues the values to assign.
2085 : */
2086 :
2087 11643 : void OGRFeature::SetField( int iField, int nCount, double * padfValues )
2088 :
2089 : {
2090 11643 : OGRFieldDefn *poFDefn = poDefn->GetFieldDefn( iField );
2091 :
2092 11643 : if( poFDefn == NULL )
2093 0 : return;
2094 :
2095 11643 : if( poFDefn->GetType() == OFTRealList )
2096 : {
2097 : OGRField uField;
2098 :
2099 11643 : uField.RealList.nCount = nCount;
2100 11643 : uField.Set.nMarker2 = 0;
2101 11643 : uField.RealList.paList = padfValues;
2102 :
2103 11643 : SetField( iField, &uField );
2104 : }
2105 : }
2106 :
2107 : /************************************************************************/
2108 : /* OGR_F_SetFieldDoubleList() */
2109 : /************************************************************************/
2110 :
2111 : /**
2112 : * \brief Set field to list of doubles value.
2113 : *
2114 : * This function currently on has an effect of OFTRealList fields.
2115 : *
2116 : * This function is the same as the C++ method OGRFeature::SetField().
2117 : *
2118 : * @param hFeat handle to the feature that owned the field.
2119 : * @param iField the field to set, from 0 to GetFieldCount()-1.
2120 : * @param nCount the number of values in the list being assigned.
2121 : * @param padfValues the values to assign.
2122 : */
2123 :
2124 29 : void OGR_F_SetFieldDoubleList( OGRFeatureH hFeat, int iField,
2125 : int nCount, double *padfValues )
2126 :
2127 : {
2128 29 : VALIDATE_POINTER0( hFeat, "OGR_F_SetFieldDoubleList" );
2129 :
2130 29 : ((OGRFeature *)hFeat)->SetField( iField, nCount, padfValues );
2131 : }
2132 :
2133 : /************************************************************************/
2134 : /* SetField() */
2135 : /************************************************************************/
2136 :
2137 : /**
2138 : * \brief Set field to list of strings value.
2139 : *
2140 : * This method currently on has an effect of OFTStringList fields.
2141 : *
2142 : * This method is the same as the C function OGR_F_SetFieldStringList().
2143 : *
2144 : * @param iField the field to set, from 0 to GetFieldCount()-1.
2145 : * @param papszValues the values to assign.
2146 : */
2147 :
2148 70 : void OGRFeature::SetField( int iField, char ** papszValues )
2149 :
2150 : {
2151 70 : OGRFieldDefn *poFDefn = poDefn->GetFieldDefn( iField );
2152 :
2153 70 : if( poFDefn == NULL )
2154 0 : return;
2155 :
2156 70 : if( poFDefn->GetType() == OFTStringList )
2157 : {
2158 : OGRField uField;
2159 :
2160 70 : uField.StringList.nCount = CSLCount(papszValues);
2161 70 : uField.Set.nMarker2 = 0;
2162 70 : uField.StringList.paList = papszValues;
2163 :
2164 70 : SetField( iField, &uField );
2165 : }
2166 : }
2167 :
2168 : /************************************************************************/
2169 : /* OGR_F_SetFieldStringList() */
2170 : /************************************************************************/
2171 :
2172 : /**
2173 : * \brief Set field to list of strings value.
2174 : *
2175 : * This function currently on has an effect of OFTStringList fields.
2176 : *
2177 : * This function is the same as the C++ method OGRFeature::SetField().
2178 : *
2179 : * @param hFeat handle to the feature that owned the field.
2180 : * @param iField the field to set, from 0 to GetFieldCount()-1.
2181 : * @param papszValues the values to assign.
2182 : */
2183 :
2184 14 : void OGR_F_SetFieldStringList( OGRFeatureH hFeat, int iField,
2185 : char ** papszValues )
2186 :
2187 : {
2188 14 : VALIDATE_POINTER0( hFeat, "OGR_F_SetFieldStringList" );
2189 :
2190 14 : ((OGRFeature *)hFeat)->SetField( iField, papszValues );
2191 : }
2192 :
2193 : /************************************************************************/
2194 : /* SetField() */
2195 : /************************************************************************/
2196 :
2197 : /**
2198 : * \brief Set field to binary data.
2199 : *
2200 : * This method currently on has an effect of OFTBinary fields.
2201 : *
2202 : * This method is the same as the C function OGR_F_SetFieldBinary().
2203 : *
2204 : * @param iField the field to set, from 0 to GetFieldCount()-1.
2205 : * @param nBytes bytes of data being set.
2206 : * @param pabyData the raw data being applied.
2207 : */
2208 :
2209 84 : void OGRFeature::SetField( int iField, int nBytes, GByte *pabyData )
2210 :
2211 : {
2212 84 : OGRFieldDefn *poFDefn = poDefn->GetFieldDefn( iField );
2213 :
2214 84 : if( poFDefn == NULL )
2215 0 : return;
2216 :
2217 84 : if( poFDefn->GetType() == OFTBinary )
2218 : {
2219 : OGRField uField;
2220 :
2221 84 : uField.Binary.nCount = nBytes;
2222 84 : uField.Set.nMarker2 = 0;
2223 84 : uField.Binary.paData = pabyData;
2224 :
2225 84 : SetField( iField, &uField );
2226 : }
2227 : }
2228 :
2229 : /************************************************************************/
2230 : /* OGR_F_SetFieldBinary() */
2231 : /************************************************************************/
2232 :
2233 : /**
2234 : * \brief Set field to binary data.
2235 : *
2236 : * This function currently on has an effect of OFTBinary fields.
2237 : *
2238 : * This function is the same as the C++ method OGRFeature::SetField().
2239 : *
2240 : * @param hFeat handle to the feature that owned the field.
2241 : * @param iField the field to set, from 0 to GetFieldCount()-1.
2242 : * @param nBytes the number of bytes in pabyData array.
2243 : * @param pabyData the data to apply.
2244 : */
2245 :
2246 20 : void OGR_F_SetFieldBinary( OGRFeatureH hFeat, int iField,
2247 : int nBytes, GByte *pabyData )
2248 :
2249 : {
2250 20 : VALIDATE_POINTER0( hFeat, "OGR_F_SetFieldBinary" );
2251 :
2252 20 : ((OGRFeature *)hFeat)->SetField( iField, nBytes, pabyData );
2253 : }
2254 :
2255 : /************************************************************************/
2256 : /* SetField() */
2257 : /************************************************************************/
2258 :
2259 : /**
2260 : * \brief Set field to date.
2261 : *
2262 : * This method currently only has an effect for OFTDate, OFTTime and OFTDateTime
2263 : * fields.
2264 : *
2265 : * This method is the same as the C function OGR_F_SetFieldDateTime().
2266 : *
2267 : * @param iField the field to set, from 0 to GetFieldCount()-1.
2268 : * @param nYear (including century)
2269 : * @param nMonth (1-12)
2270 : * @param nDay (1-31)
2271 : * @param nHour (0-23)
2272 : * @param nMinute (0-59)
2273 : * @param nSecond (0-59)
2274 : * @param nTZFlag (0=unknown, 1=localtime, 100=GMT, see data model for details)
2275 : */
2276 :
2277 86 : void OGRFeature::SetField( int iField, int nYear, int nMonth, int nDay,
2278 : int nHour, int nMinute, int nSecond,
2279 : int nTZFlag )
2280 :
2281 : {
2282 86 : OGRFieldDefn *poFDefn = poDefn->GetFieldDefn( iField );
2283 :
2284 86 : if( poFDefn == NULL )
2285 0 : return;
2286 :
2287 86 : if( poFDefn->GetType() == OFTDate
2288 : || poFDefn->GetType() == OFTTime
2289 : || poFDefn->GetType() == OFTDateTime )
2290 : {
2291 86 : pauFields[iField].Date.Year = (GInt16)nYear;
2292 86 : pauFields[iField].Date.Month = (GByte)nMonth;
2293 86 : pauFields[iField].Date.Day = (GByte)nDay;
2294 86 : pauFields[iField].Date.Hour = (GByte)nHour;
2295 86 : pauFields[iField].Date.Minute = (GByte)nMinute;
2296 86 : pauFields[iField].Date.Second = (GByte)nSecond;
2297 86 : pauFields[iField].Date.TZFlag = (GByte)nTZFlag;
2298 : }
2299 : }
2300 :
2301 : /************************************************************************/
2302 : /* OGR_F_SetFieldDateTime() */
2303 : /************************************************************************/
2304 :
2305 : /**
2306 : * \brief Set field to datetime.
2307 : *
2308 : * This method currently only has an effect for OFTDate, OFTTime and OFTDateTime
2309 : * fields.
2310 : *
2311 : * @param hFeat handle to the feature that owned the field.
2312 : * @param iField the field to set, from 0 to GetFieldCount()-1.
2313 : * @param nYear (including century)
2314 : * @param nMonth (1-12)
2315 : * @param nDay (1-31)
2316 : * @param nHour (0-23)
2317 : * @param nMinute (0-59)
2318 : * @param nSecond (0-59)
2319 : * @param nTZFlag (0=unknown, 1=localtime, 100=GMT, see data model for details)
2320 : */
2321 :
2322 25 : void OGR_F_SetFieldDateTime( OGRFeatureH hFeat, int iField,
2323 : int nYear, int nMonth, int nDay,
2324 : int nHour, int nMinute, int nSecond,
2325 : int nTZFlag )
2326 :
2327 :
2328 : {
2329 25 : VALIDATE_POINTER0( hFeat, "OGR_F_SetFieldDateTime" );
2330 :
2331 : ((OGRFeature *)hFeat)->SetField( iField, nYear, nMonth, nDay,
2332 25 : nHour, nMinute, nSecond, nTZFlag );
2333 : }
2334 :
2335 : /************************************************************************/
2336 : /* SetField() */
2337 : /************************************************************************/
2338 :
2339 : /**
2340 : * \brief Set field.
2341 : *
2342 : * The passed value OGRField must be of exactly the same type as the
2343 : * target field, or an application crash may occur. The passed value
2344 : * is copied, and will not be affected. It remains the responsibility of
2345 : * the caller.
2346 : *
2347 : * This method is the same as the C function OGR_F_SetFieldRaw().
2348 : *
2349 : * @param iField the field to fetch, from 0 to GetFieldCount()-1.
2350 : * @param puValue the value to assign.
2351 : */
2352 :
2353 441896 : void OGRFeature::SetField( int iField, OGRField * puValue )
2354 :
2355 : {
2356 441896 : OGRFieldDefn *poFDefn = poDefn->GetFieldDefn( iField );
2357 :
2358 441896 : if( poFDefn == NULL )
2359 0 : return;
2360 :
2361 441896 : if( poFDefn->GetType() == OFTInteger )
2362 : {
2363 57459 : pauFields[iField] = *puValue;
2364 : }
2365 384437 : else if( poFDefn->GetType() == OFTReal )
2366 : {
2367 116310 : pauFields[iField] = *puValue;
2368 : }
2369 268127 : else if( poFDefn->GetType() == OFTString )
2370 : {
2371 201969 : if( IsFieldSet( iField ) )
2372 12 : CPLFree( pauFields[iField].String );
2373 :
2374 201969 : if( puValue->String == NULL )
2375 0 : pauFields[iField].String = NULL;
2376 202411 : else if( puValue->Set.nMarker1 == OGRUnsetMarker
2377 : && puValue->Set.nMarker2 == OGRUnsetMarker )
2378 442 : pauFields[iField] = *puValue;
2379 : else
2380 201527 : pauFields[iField].String = CPLStrdup( puValue->String );
2381 : }
2382 66158 : else if( poFDefn->GetType() == OFTDate
2383 : || poFDefn->GetType() == OFTTime
2384 : || poFDefn->GetType() == OFTDateTime )
2385 : {
2386 312 : memcpy( pauFields+iField, puValue, sizeof(OGRField) );
2387 : }
2388 65846 : else if( poFDefn->GetType() == OFTIntegerList )
2389 : {
2390 53938 : int nCount = puValue->IntegerList.nCount;
2391 :
2392 53938 : if( IsFieldSet( iField ) )
2393 4 : CPLFree( pauFields[iField].IntegerList.paList );
2394 :
2395 53938 : if( puValue->Set.nMarker1 == OGRUnsetMarker
2396 : && puValue->Set.nMarker2 == OGRUnsetMarker )
2397 : {
2398 0 : pauFields[iField] = *puValue;
2399 : }
2400 : else
2401 : {
2402 53938 : pauFields[iField].IntegerList.paList =
2403 53938 : (int *) CPLMalloc(sizeof(int) * nCount);
2404 53938 : memcpy( pauFields[iField].IntegerList.paList,
2405 : puValue->IntegerList.paList,
2406 107876 : sizeof(int) * nCount );
2407 53938 : pauFields[iField].IntegerList.nCount = nCount;
2408 : }
2409 : }
2410 11908 : else if( poFDefn->GetType() == OFTRealList )
2411 : {
2412 11701 : int nCount = puValue->RealList.nCount;
2413 :
2414 11701 : if( IsFieldSet( iField ) )
2415 14 : CPLFree( pauFields[iField].RealList.paList );
2416 :
2417 11704 : if( puValue->Set.nMarker1 == OGRUnsetMarker
2418 : && puValue->Set.nMarker2 == OGRUnsetMarker )
2419 : {
2420 3 : pauFields[iField] = *puValue;
2421 : }
2422 : else
2423 : {
2424 11698 : pauFields[iField].RealList.paList =
2425 11698 : (double *) CPLMalloc(sizeof(double) * nCount);
2426 11698 : memcpy( pauFields[iField].RealList.paList,
2427 : puValue->RealList.paList,
2428 23396 : sizeof(double) * nCount );
2429 11698 : pauFields[iField].RealList.nCount = nCount;
2430 : }
2431 : }
2432 207 : else if( poFDefn->GetType() == OFTStringList )
2433 : {
2434 118 : if( IsFieldSet( iField ) )
2435 2 : CSLDestroy( pauFields[iField].StringList.paList );
2436 :
2437 118 : if( puValue->Set.nMarker1 == OGRUnsetMarker
2438 : && puValue->Set.nMarker2 == OGRUnsetMarker )
2439 : {
2440 0 : pauFields[iField] = *puValue;
2441 : }
2442 : else
2443 : {
2444 118 : pauFields[iField].StringList.paList =
2445 118 : CSLDuplicate( puValue->StringList.paList );
2446 :
2447 118 : pauFields[iField].StringList.nCount = puValue->StringList.nCount;
2448 : CPLAssert( CSLCount(puValue->StringList.paList)
2449 118 : == puValue->StringList.nCount );
2450 : }
2451 : }
2452 89 : else if( poFDefn->GetType() == OFTBinary )
2453 : {
2454 89 : if( IsFieldSet( iField ) )
2455 0 : CPLFree( pauFields[iField].Binary.paData );
2456 :
2457 89 : if( puValue->Set.nMarker1 == OGRUnsetMarker
2458 : && puValue->Set.nMarker2 == OGRUnsetMarker )
2459 : {
2460 0 : pauFields[iField] = *puValue;
2461 : }
2462 : else
2463 : {
2464 89 : pauFields[iField].Binary.nCount = puValue->Binary.nCount;
2465 89 : pauFields[iField].Binary.paData =
2466 89 : (GByte *) CPLMalloc(puValue->Binary.nCount);
2467 89 : memcpy( pauFields[iField].Binary.paData,
2468 : puValue->Binary.paData,
2469 178 : puValue->Binary.nCount );
2470 : }
2471 : }
2472 : else
2473 : /* do nothing for other field types */;
2474 : }
2475 :
2476 : /************************************************************************/
2477 : /* OGR_F_SetFieldRaw() */
2478 : /************************************************************************/
2479 :
2480 : /**
2481 : * \brief Set field.
2482 : *
2483 : * The passed value OGRField must be of exactly the same type as the
2484 : * target field, or an application crash may occur. The passed value
2485 : * is copied, and will not be affected. It remains the responsibility of
2486 : * the caller.
2487 : *
2488 : * This function is the same as the C++ method OGRFeature::SetField().
2489 : *
2490 : * @param hFeat handle to the feature that owned the field.
2491 : * @param iField the field to fetch, from 0 to GetFieldCount()-1.
2492 : * @param psValue handle on the value to assign.
2493 : */
2494 :
2495 0 : void OGR_F_SetFieldRaw( OGRFeatureH hFeat, int iField, OGRField *psValue )
2496 :
2497 : {
2498 0 : VALIDATE_POINTER0( hFeat, "OGR_F_SetFieldRaw" );
2499 :
2500 0 : ((OGRFeature *)hFeat)->SetField( iField, psValue );
2501 : }
2502 :
2503 : /************************************************************************/
2504 : /* DumpReadable() */
2505 : /************************************************************************/
2506 :
2507 : /**
2508 : * \brief Dump this feature in a human readable form.
2509 : *
2510 : * This dumps the attributes, and geometry; however, it doesn't definition
2511 : * information (other than field types and names), nor does it report the
2512 : * geometry spatial reference system.
2513 : *
2514 : * A few options can be defined to change the default dump :
2515 : * <ul>
2516 : * <li>DISPLAY_FIELDS=NO : to hide the dump of the attributes</li>
2517 : * <li>DISPLAY_STYLE=NO : to hide the dump of the style string</li>
2518 : * <li>DISPLAY_GEOMETRY=NO : to hide the dump of the geometry</li>
2519 : * <li>DISPLAY_GEOMETRY=SUMMARY : to get only a summary of the geometry</li>
2520 : * </ul>
2521 : *
2522 : * This method is the same as the C function OGR_F_DumpReadable().
2523 : *
2524 : * @param fpOut the stream to write to, such as stdout. If NULL stdout will
2525 : * be used.
2526 : * @param papszOptions NULL terminated list of options (may be NULL)
2527 : */
2528 :
2529 67 : void OGRFeature::DumpReadable( FILE * fpOut, char** papszOptions )
2530 :
2531 : {
2532 67 : if( fpOut == NULL )
2533 67 : fpOut = stdout;
2534 :
2535 67 : fprintf( fpOut, "OGRFeature(%s):%ld\n", poDefn->GetName(), GetFID() );
2536 :
2537 : const char* pszDisplayFields =
2538 67 : CSLFetchNameValue(papszOptions, "DISPLAY_FIELDS");
2539 67 : if (pszDisplayFields == NULL || CSLTestBoolean(pszDisplayFields))
2540 : {
2541 225 : for( int iField = 0; iField < GetFieldCount(); iField++ )
2542 : {
2543 168 : OGRFieldDefn *poFDefn = poDefn->GetFieldDefn(iField);
2544 :
2545 : fprintf( fpOut, " %s (%s) = ",
2546 : poFDefn->GetNameRef(),
2547 168 : OGRFieldDefn::GetFieldTypeName(poFDefn->GetType()) );
2548 :
2549 168 : if( IsFieldSet( iField ) )
2550 168 : fprintf( fpOut, "%s\n", GetFieldAsString( iField ) );
2551 : else
2552 0 : fprintf( fpOut, "(null)\n" );
2553 :
2554 : }
2555 : }
2556 :
2557 :
2558 67 : if( GetStyleString() != NULL )
2559 : {
2560 : const char* pszDisplayStyle =
2561 0 : CSLFetchNameValue(papszOptions, "DISPLAY_STYLE");
2562 0 : if (pszDisplayStyle == NULL || CSLTestBoolean(pszDisplayStyle))
2563 : {
2564 0 : fprintf( fpOut, " Style = %s\n", GetStyleString() );
2565 : }
2566 : }
2567 :
2568 67 : if( poGeometry != NULL )
2569 : {
2570 : const char* pszDisplayGeometry =
2571 67 : CSLFetchNameValue(papszOptions, "DISPLAY_GEOMETRY");
2572 67 : if ( ! (pszDisplayGeometry != NULL && EQUAL(pszDisplayGeometry, "NO") ) )
2573 57 : poGeometry->dumpReadable( fpOut, " ", papszOptions );
2574 : }
2575 :
2576 67 : fprintf( fpOut, "\n" );
2577 67 : }
2578 :
2579 : /************************************************************************/
2580 : /* OGR_F_DumpReadable() */
2581 : /************************************************************************/
2582 :
2583 : /**
2584 : * \brief Dump this feature in a human readable form.
2585 : *
2586 : * This dumps the attributes, and geometry; however, it doesn't definition
2587 : * information (other than field types and names), nor does it report the
2588 : * geometry spatial reference system.
2589 : *
2590 : * This function is the same as the C++ method OGRFeature::DumpReadable().
2591 : *
2592 : * @param hFeat handle to the feature to dump.
2593 : * @param fpOut the stream to write to, such as strout.
2594 : */
2595 :
2596 0 : void OGR_F_DumpReadable( OGRFeatureH hFeat, FILE *fpOut )
2597 :
2598 : {
2599 0 : VALIDATE_POINTER0( hFeat, "OGR_F_DumpReadable" );
2600 :
2601 0 : ((OGRFeature *) hFeat)->DumpReadable( fpOut );
2602 : }
2603 :
2604 : /************************************************************************/
2605 : /* GetFID() */
2606 : /************************************************************************/
2607 :
2608 : /**
2609 : * \fn long OGRFeature::GetFID();
2610 : *
2611 : * \brief Get feature identifier.
2612 : *
2613 : * This method is the same as the C function OGR_F_GetFID().
2614 : *
2615 : * @return feature id or OGRNullFID if none has been assigned.
2616 : */
2617 :
2618 : /************************************************************************/
2619 : /* OGR_F_GetFID() */
2620 : /************************************************************************/
2621 :
2622 : /**
2623 : * \brief Get feature identifier.
2624 : *
2625 : * This function is the same as the C++ method OGRFeature::GetFID().
2626 : *
2627 : * @param hFeat handle to the feature from which to get the feature
2628 : * identifier.
2629 : * @return feature id or OGRNullFID if none has been assigned.
2630 : */
2631 :
2632 263 : long OGR_F_GetFID( OGRFeatureH hFeat )
2633 :
2634 : {
2635 263 : VALIDATE_POINTER1( hFeat, "OGR_F_GetFID", 0 );
2636 :
2637 263 : return ((OGRFeature *) hFeat)->GetFID();
2638 : }
2639 :
2640 : /************************************************************************/
2641 : /* SetFID() */
2642 : /************************************************************************/
2643 :
2644 : /**
2645 : * \brief Set the feature identifier.
2646 : *
2647 : * For specific types of features this operation may fail on illegal
2648 : * features ids. Generally it always succeeds. Feature ids should be
2649 : * greater than or equal to zero, with the exception of OGRNullFID (-1)
2650 : * indicating that the feature id is unknown.
2651 : *
2652 : * This method is the same as the C function OGR_F_SetFID().
2653 : *
2654 : * @param nFID the new feature identifier value to assign.
2655 : *
2656 : * @return On success OGRERR_NONE, or on failure some other value.
2657 : */
2658 :
2659 1395214 : OGRErr OGRFeature::SetFID( long nFID )
2660 :
2661 : {
2662 1395214 : this->nFID = nFID;
2663 :
2664 1395214 : return OGRERR_NONE;
2665 : }
2666 :
2667 : /************************************************************************/
2668 : /* OGR_F_SetFID() */
2669 : /************************************************************************/
2670 :
2671 : /**
2672 : * \brief Set the feature identifier.
2673 : *
2674 : * For specific types of features this operation may fail on illegal
2675 : * features ids. Generally it always succeeds. Feature ids should be
2676 : * greater than or equal to zero, with the exception of OGRNullFID (-1)
2677 : * indicating that the feature id is unknown.
2678 : *
2679 : * This function is the same as the C++ method OGRFeature::SetFID().
2680 : *
2681 : * @param hFeat handle to the feature to set the feature id to.
2682 : * @param nFID the new feature identifier value to assign.
2683 : *
2684 : * @return On success OGRERR_NONE, or on failure some other value.
2685 : */
2686 :
2687 113 : OGRErr OGR_F_SetFID( OGRFeatureH hFeat, long nFID )
2688 :
2689 : {
2690 113 : VALIDATE_POINTER1( hFeat, "OGR_F_SetFID", CE_Failure );
2691 :
2692 113 : return ((OGRFeature *) hFeat)->SetFID(nFID);
2693 : }
2694 :
2695 : /************************************************************************/
2696 : /* Equal() */
2697 : /************************************************************************/
2698 :
2699 : /**
2700 : * \brief Test if two features are the same.
2701 : *
2702 : * Two features are considered equal if the share them (pointer equality)
2703 : * same OGRFeatureDefn, have the same field values, and the same geometry
2704 : * (as tested by OGRGeometry::Equal()) as well as the same feature id.
2705 : *
2706 : * This method is the same as the C function OGR_F_Equal().
2707 : *
2708 : * @param poFeature the other feature to test this one against.
2709 : *
2710 : * @return TRUE if they are equal, otherwise FALSE.
2711 : */
2712 :
2713 20857 : OGRBoolean OGRFeature::Equal( OGRFeature * poFeature )
2714 :
2715 : {
2716 20857 : if( poFeature == this )
2717 1 : return TRUE;
2718 :
2719 20856 : if( GetFID() != poFeature->GetFID() )
2720 20613 : return FALSE;
2721 :
2722 243 : if( GetDefnRef() != poFeature->GetDefnRef() )
2723 0 : return FALSE;
2724 :
2725 : int i;
2726 243 : int nFields = GetDefnRef()->GetFieldCount();
2727 2133 : for(i=0; i<nFields; i++)
2728 : {
2729 1920 : if( IsFieldSet(i) != poFeature->IsFieldSet(i) )
2730 0 : return FALSE;
2731 :
2732 1920 : if( !IsFieldSet(i) )
2733 452 : continue;
2734 :
2735 1468 : switch (GetDefnRef()->GetFieldDefn(i)->GetType() )
2736 : {
2737 : case OFTInteger:
2738 595 : if( GetFieldAsInteger(i) !=
2739 : poFeature->GetFieldAsInteger(i) )
2740 1 : return FALSE;
2741 594 : break;
2742 :
2743 : case OFTReal:
2744 235 : if( GetFieldAsDouble(i) !=
2745 : poFeature->GetFieldAsDouble(i) )
2746 1 : return FALSE;
2747 234 : break;
2748 :
2749 : case OFTString:
2750 492 : if ( strcmp(GetFieldAsString(i),
2751 : poFeature->GetFieldAsString(i)) != 0 )
2752 1 : return FALSE;
2753 491 : break;
2754 :
2755 : case OFTIntegerList:
2756 : {
2757 : int nCount1, nCount2;
2758 34 : const int* pnList1 = GetFieldAsIntegerList(i, &nCount1);
2759 : const int* pnList2 =
2760 34 : poFeature->GetFieldAsIntegerList(i, &nCount2);
2761 34 : if( nCount1 != nCount2 )
2762 1 : return FALSE;
2763 : int j;
2764 95 : for(j=0;j<nCount1;j++)
2765 : {
2766 63 : if( pnList1[j] != pnList2[j] )
2767 1 : return FALSE;
2768 : }
2769 32 : break;
2770 : }
2771 :
2772 : case OFTRealList:
2773 : {
2774 : int nCount1, nCount2;
2775 : const double* padfList1 =
2776 29 : GetFieldAsDoubleList(i, &nCount1);
2777 : const double* padfList2 =
2778 29 : poFeature->GetFieldAsDoubleList(i, &nCount2);
2779 29 : if( nCount1 != nCount2 )
2780 1 : return FALSE;
2781 : int j;
2782 83 : for(j=0;j<nCount1;j++)
2783 : {
2784 56 : if( padfList1[j] != padfList2[j] )
2785 1 : return FALSE;
2786 : }
2787 27 : break;
2788 : }
2789 :
2790 : case OFTStringList:
2791 : {
2792 : int nCount1, nCount2;
2793 27 : char** papszList1 = GetFieldAsStringList(i);
2794 27 : char** papszList2 = poFeature->GetFieldAsStringList(i);
2795 27 : nCount1 = CSLCount(papszList1);
2796 27 : nCount2 = CSLCount(papszList2);
2797 27 : if( nCount1 != nCount2 )
2798 1 : return FALSE;
2799 : int j;
2800 77 : for(j=0;j<nCount1;j++)
2801 : {
2802 52 : if( strcmp(papszList1[j], papszList2[j]) != 0 )
2803 1 : return FALSE;
2804 : }
2805 25 : break;
2806 : }
2807 :
2808 : case OFTTime:
2809 : case OFTDate:
2810 : case OFTDateTime:
2811 : {
2812 : int nYear1, nMonth1, nDay1, nHour1,
2813 : nMinute1, nSecond1, nTZFlag1;
2814 : int nYear2, nMonth2, nDay2, nHour2,
2815 : nMinute2, nSecond2, nTZFlag2;
2816 : GetFieldAsDateTime(i, &nYear1, &nMonth1, &nDay1,
2817 56 : &nHour1, &nMinute1, &nSecond1, &nTZFlag1);
2818 : poFeature->GetFieldAsDateTime(i, &nYear2, &nMonth2, &nDay2,
2819 56 : &nHour2, &nMinute2, &nSecond2, &nTZFlag2);
2820 :
2821 56 : if( !(nYear1 == nYear2 && nMonth1 == nMonth2 &&
2822 : nDay1 == nDay2 && nHour1 == nHour2 &&
2823 : nMinute1 == nMinute2 && nSecond1 == nSecond2 &&
2824 : nTZFlag1 == nTZFlag2) )
2825 21 : return FALSE;
2826 35 : break;
2827 : }
2828 :
2829 : case OFTBinary:
2830 : {
2831 : int nCount1, nCount2;
2832 0 : GByte* pabyData1 = GetFieldAsBinary(i, &nCount1);
2833 0 : GByte* pabyData2 = poFeature->GetFieldAsBinary(i, &nCount2);
2834 0 : if( nCount1 != nCount2 )
2835 0 : return FALSE;
2836 0 : if( memcmp(pabyData1, pabyData2, nCount1) != 0 )
2837 0 : return FALSE;
2838 0 : break;
2839 : }
2840 :
2841 : default:
2842 0 : if( strcmp(GetFieldAsString(i),
2843 : poFeature->GetFieldAsString(i)) != 0 )
2844 0 : return FALSE;
2845 : break;
2846 : }
2847 : }
2848 :
2849 213 : if( GetGeometryRef() == NULL && poFeature->GetGeometryRef() != NULL )
2850 1 : return FALSE;
2851 :
2852 212 : if( GetGeometryRef() != NULL && poFeature->GetGeometryRef() == NULL )
2853 1 : return FALSE;
2854 :
2855 379 : if( GetGeometryRef() != NULL && poFeature->GetGeometryRef() != NULL
2856 168 : && (!GetGeometryRef()->Equals( poFeature->GetGeometryRef() ) ) )
2857 0 : return FALSE;
2858 :
2859 211 : return TRUE;
2860 : }
2861 :
2862 : /************************************************************************/
2863 : /* OGR_F_Equal() */
2864 : /************************************************************************/
2865 :
2866 : /**
2867 : * \brief Test if two features are the same.
2868 : *
2869 : * Two features are considered equal if the share them (handle equality)
2870 : * same OGRFeatureDefn, have the same field values, and the same geometry
2871 : * (as tested by OGR_G_Equal()) as well as the same feature id.
2872 : *
2873 : * This function is the same as the C++ method OGRFeature::Equal().
2874 : *
2875 : * @param hFeat handle to one of the feature.
2876 : * @param hOtherFeat handle to the other feature to test this one against.
2877 : *
2878 : * @return TRUE if they are equal, otherwise FALSE.
2879 : */
2880 :
2881 42 : int OGR_F_Equal( OGRFeatureH hFeat, OGRFeatureH hOtherFeat )
2882 :
2883 : {
2884 42 : VALIDATE_POINTER1( hFeat, "OGR_F_Equal", 0 );
2885 42 : VALIDATE_POINTER1( hOtherFeat, "OGR_F_Equal", 0 );
2886 :
2887 42 : return ((OGRFeature *) hFeat)->Equal( (OGRFeature *) hOtherFeat );
2888 : }
2889 :
2890 :
2891 : /************************************************************************/
2892 : /* SetFrom() */
2893 : /************************************************************************/
2894 :
2895 : /**
2896 : * \brief Set one feature from another.
2897 : *
2898 : * Overwrite the contents of this feature from the geometry and attributes
2899 : * of another. The poSrcFeature does not need to have the same
2900 : * OGRFeatureDefn. Field values are copied by corresponding field names.
2901 : * Field types do not have to exactly match. SetField() method conversion
2902 : * rules will be applied as needed.
2903 : *
2904 : * This method is the same as the C function OGR_F_SetFrom().
2905 : *
2906 : * @param poSrcFeature the feature from which geometry, and field values will
2907 : * be copied.
2908 : *
2909 : * @param bForgiving TRUE if the operation should continue despite lacking
2910 : * output fields matching some of the source fields.
2911 : *
2912 : * @return OGRERR_NONE if the operation succeeds, even if some values are
2913 : * not transferred, otherwise an error code.
2914 : */
2915 :
2916 543 : OGRErr OGRFeature::SetFrom( OGRFeature * poSrcFeature, int bForgiving )
2917 :
2918 : {
2919 : /* -------------------------------------------------------------------- */
2920 : /* Retrieve the field ids by name. */
2921 : /* -------------------------------------------------------------------- */
2922 : int iField, *panMap;
2923 : OGRErr eErr;
2924 :
2925 543 : panMap = (int *) VSIMalloc( sizeof(int) * poSrcFeature->GetFieldCount() );
2926 6579 : for( iField = 0; iField < poSrcFeature->GetFieldCount(); iField++ )
2927 : {
2928 6036 : panMap[iField] = GetFieldIndex(
2929 6036 : poSrcFeature->GetFieldDefnRef(iField)->GetNameRef() );
2930 :
2931 6036 : if( panMap[iField] == -1 )
2932 : {
2933 103 : if( bForgiving )
2934 103 : continue;
2935 : else
2936 : {
2937 0 : VSIFree(panMap);
2938 0 : return OGRERR_FAILURE;
2939 : }
2940 : }
2941 : }
2942 :
2943 543 : eErr = SetFrom( poSrcFeature, panMap, bForgiving );
2944 :
2945 543 : VSIFree(panMap);
2946 :
2947 543 : return eErr;
2948 : }
2949 :
2950 : /************************************************************************/
2951 : /* OGR_F_SetFrom() */
2952 : /************************************************************************/
2953 :
2954 : /**
2955 : * \brief Set one feature from another.
2956 : *
2957 : * Overwrite the contents of this feature from the geometry and attributes
2958 : * of another. The hOtherFeature does not need to have the same
2959 : * OGRFeatureDefn. Field values are copied by corresponding field names.
2960 : * Field types do not have to exactly match. OGR_F_SetField*() function
2961 : * conversion rules will be applied as needed.
2962 : *
2963 : * This function is the same as the C++ method OGRFeature::SetFrom().
2964 : *
2965 : * @param hFeat handle to the feature to set to.
2966 : * @param hOtherFeat handle to the feature from which geometry,
2967 : * and field values will be copied.
2968 : *
2969 : * @param bForgiving TRUE if the operation should continue despite lacking
2970 : * output fields matching some of the source fields.
2971 : *
2972 : * @return OGRERR_NONE if the operation succeeds, even if some values are
2973 : * not transferred, otherwise an error code.
2974 : */
2975 :
2976 227 : OGRErr OGR_F_SetFrom( OGRFeatureH hFeat, OGRFeatureH hOtherFeat,
2977 : int bForgiving )
2978 :
2979 : {
2980 227 : VALIDATE_POINTER1( hFeat, "OGR_F_SetFrom", CE_Failure );
2981 227 : VALIDATE_POINTER1( hOtherFeat, "OGR_F_SetFrom", CE_Failure );
2982 :
2983 : return ((OGRFeature *) hFeat)->SetFrom( (OGRFeature *) hOtherFeat,
2984 227 : bForgiving );
2985 : }
2986 :
2987 : /************************************************************************/
2988 : /* SetFrom() */
2989 : /************************************************************************/
2990 :
2991 : /**
2992 : * \brief Set one feature from another.
2993 : *
2994 : * Overwrite the contents of this feature from the geometry and attributes
2995 : * of another. The poSrcFeature does not need to have the same
2996 : * OGRFeatureDefn. Field values are copied according to the provided indices
2997 : * map. Field types do not have to exactly match. SetField() method
2998 : * conversion rules will be applied as needed. This is more efficient than
2999 : * OGR_F_SetFrom() in that this doesn't lookup the fields by their names.
3000 : * Particularly useful when the field names don't match.
3001 : *
3002 : * This method is the same as the C function OGR_F_SetFromWithMap().
3003 : *
3004 : * @param poSrcFeature the feature from which geometry, and field values will
3005 : * be copied.
3006 : *
3007 : * @param panMap Array of the indices of the feature's fields
3008 : * stored at the corresponding index of the source feature's fields. A value of
3009 : * -1 should be used to ignore the source's field. The array should not be NULL
3010 : * and be as long as the number of fields in the source feature.
3011 : *
3012 : * @param bForgiving TRUE if the operation should continue despite lacking
3013 : * output fields matching some of the source fields.
3014 : *
3015 : * @return OGRERR_NONE if the operation succeeds, even if some values are
3016 : * not transferred, otherwise an error code.
3017 : */
3018 :
3019 126137 : OGRErr OGRFeature::SetFrom( OGRFeature * poSrcFeature, int *panMap ,
3020 : int bForgiving )
3021 :
3022 : {
3023 : OGRErr eErr;
3024 :
3025 126137 : SetFID( OGRNullFID );
3026 :
3027 : /* -------------------------------------------------------------------- */
3028 : /* Set the geometry. */
3029 : /* -------------------------------------------------------------------- */
3030 126137 : eErr = SetGeometry( poSrcFeature->GetGeometryRef() );
3031 126137 : if( eErr != OGRERR_NONE )
3032 0 : return eErr;
3033 :
3034 : /* -------------------------------------------------------------------- */
3035 : /* Copy feature style string. */
3036 : /* -------------------------------------------------------------------- */
3037 126137 : SetStyleString( poSrcFeature->GetStyleString() );
3038 :
3039 : /* -------------------------------------------------------------------- */
3040 : /* Set the fields by name. */
3041 : /* -------------------------------------------------------------------- */
3042 : int iField, iDstField;
3043 :
3044 2208128 : for( iField = 0; iField < poSrcFeature->GetFieldCount(); iField++ )
3045 : {
3046 2081991 : iDstField = panMap[iField];
3047 :
3048 2081991 : if( iDstField < 0 )
3049 156 : continue;
3050 :
3051 2081835 : if( GetFieldCount() <= iDstField )
3052 0 : return OGRERR_FAILURE;
3053 :
3054 2081835 : if( !poSrcFeature->IsFieldSet(iField) )
3055 : {
3056 933884 : UnsetField( iDstField );
3057 933884 : continue;
3058 : }
3059 :
3060 1147951 : switch( poSrcFeature->GetFieldDefnRef(iField)->GetType() )
3061 : {
3062 : case OFTInteger:
3063 727796 : SetField( iDstField, poSrcFeature->GetFieldAsInteger( iField ) );
3064 727796 : break;
3065 :
3066 : case OFTReal:
3067 4106 : SetField( iDstField, poSrcFeature->GetFieldAsDouble( iField ) );
3068 4106 : break;
3069 :
3070 : case OFTString:
3071 413128 : SetField( iDstField, poSrcFeature->GetFieldAsString( iField ) );
3072 413128 : break;
3073 :
3074 : case OFTDate:
3075 : case OFTDateTime:
3076 : case OFTTime:
3077 50 : if (GetFieldDefnRef(iDstField)->GetType() == OFTDate ||
3078 : GetFieldDefnRef(iDstField)->GetType() == OFTTime ||
3079 : GetFieldDefnRef(iDstField)->GetType() == OFTDateTime)
3080 : {
3081 29 : SetField( iDstField, poSrcFeature->GetRawFieldRef( iField ) );
3082 : }
3083 21 : else if (GetFieldDefnRef(iDstField)->GetType() == OFTString)
3084 : {
3085 3 : SetField( iDstField, poSrcFeature->GetFieldAsString( iField ) );
3086 : }
3087 18 : else if( !bForgiving )
3088 0 : return OGRERR_FAILURE;
3089 50 : break;
3090 :
3091 : default:
3092 2871 : if( poSrcFeature->GetFieldDefnRef(iField)->GetType()
3093 : == GetFieldDefnRef(iDstField)->GetType() )
3094 : {
3095 2844 : SetField( iDstField, poSrcFeature->GetRawFieldRef(iField) );
3096 : }
3097 27 : else if (GetFieldDefnRef(iDstField)->GetType() == OFTString)
3098 : {
3099 3 : SetField( iDstField, poSrcFeature->GetFieldAsString( iField ) );
3100 : }
3101 24 : else if( !bForgiving )
3102 0 : return OGRERR_FAILURE;
3103 : break;
3104 : }
3105 : }
3106 :
3107 126137 : return OGRERR_NONE;
3108 : }
3109 :
3110 : /************************************************************************/
3111 : /* OGR_F_SetFromWithMap() */
3112 : /************************************************************************/
3113 :
3114 : /**
3115 : * \brief Set one feature from another.
3116 : *
3117 : * Overwrite the contents of this feature from the geometry and attributes
3118 : * of another. The hOtherFeature does not need to have the same
3119 : * OGRFeatureDefn. Field values are copied according to the provided indices
3120 : * map. Field types do not have to exactly match. OGR_F_SetField*() function
3121 : * conversion rules will be applied as needed. This is more efficient than
3122 : * OGR_F_SetFrom() in that this doesn't lookup the fields by their names.
3123 : * Particularly useful when the field names don't match.
3124 : *
3125 : * This function is the same as the C++ method OGRFeature::SetFrom().
3126 : *
3127 : * @param hFeat handle to the feature to set to.
3128 : * @param hOtherFeat handle to the feature from which geometry,
3129 : * and field values will be copied.
3130 : *
3131 : * @param panMap Array of the indices of the destination feature's fields
3132 : * stored at the corresponding index of the source feature's fields. A value of
3133 : * -1 should be used to ignore the source's field. The array should not be NULL
3134 : * and be as long as the number of fields in the source feature.
3135 : *
3136 : * @param bForgiving TRUE if the operation should continue despite lacking
3137 : * output fields matching some of the source fields.
3138 : *
3139 : * @return OGRERR_NONE if the operation succeeds, even if some values are
3140 : * not transferred, otherwise an error code.
3141 : */
3142 :
3143 361 : OGRErr OGR_F_SetFromWithMap( OGRFeatureH hFeat, OGRFeatureH hOtherFeat,
3144 : int bForgiving, int *panMap )
3145 :
3146 : {
3147 361 : VALIDATE_POINTER1( hFeat, "OGR_F_SetFrom", CE_Failure );
3148 361 : VALIDATE_POINTER1( hOtherFeat, "OGR_F_SetFrom", CE_Failure );
3149 361 : VALIDATE_POINTER1( panMap, "OGR_F_SetFrom", CE_Failure);
3150 :
3151 : return ((OGRFeature *) hFeat)->SetFrom( (OGRFeature *) hOtherFeat,
3152 361 : panMap, bForgiving );
3153 : }
3154 :
3155 : /************************************************************************/
3156 : /* GetStyleString() */
3157 : /************************************************************************/
3158 :
3159 : /**
3160 : * \brief Fetch style string for this feature.
3161 : *
3162 : * Set the OGR Feature Style Specification for details on the format of
3163 : * this string, and ogr_featurestyle.h for services available to parse it.
3164 : *
3165 : * This method is the same as the C function OGR_F_GetStyleString().
3166 : *
3167 : * @return a reference to a representation in string format, or NULL if
3168 : * there isn't one.
3169 : */
3170 :
3171 194253 : const char *OGRFeature::GetStyleString()
3172 : {
3173 : int iStyleFieldIndex;
3174 :
3175 194253 : if (m_pszStyleString)
3176 900 : return m_pszStyleString;
3177 :
3178 193353 : iStyleFieldIndex = GetFieldIndex("OGR_STYLE");
3179 193353 : if (iStyleFieldIndex >= 0)
3180 0 : return GetFieldAsString(iStyleFieldIndex);
3181 :
3182 193353 : return NULL;
3183 : }
3184 :
3185 : /************************************************************************/
3186 : /* OGR_F_GetStyleString() */
3187 : /************************************************************************/
3188 :
3189 : /**
3190 : * \brief Fetch style string for this feature.
3191 : *
3192 : * Set the OGR Feature Style Specification for details on the format of
3193 : * this string, and ogr_featurestyle.h for services available to parse it.
3194 : *
3195 : * This function is the same as the C++ method OGRFeature::GetStyleString().
3196 : *
3197 : * @param hFeat handle to the feature to get the style from.
3198 : * @return a reference to a representation in string format, or NULL if
3199 : * there isn't one.
3200 : */
3201 :
3202 78 : const char *OGR_F_GetStyleString( OGRFeatureH hFeat )
3203 : {
3204 78 : VALIDATE_POINTER1( hFeat, "OGR_F_GetStyleString", NULL );
3205 :
3206 78 : return ((OGRFeature *)hFeat)->GetStyleString();
3207 : }
3208 :
3209 : /************************************************************************/
3210 : /* SetStyleString() */
3211 : /************************************************************************/
3212 :
3213 : /**
3214 : * \brief Set feature style string.
3215 : * This method operate exactly as
3216 : * OGRFeature::SetStyleStringDirectly() except that it does not assume
3217 : * ownership of the passed string, but instead makes a copy of it.
3218 : *
3219 : * This method is the same as the C function OGR_F_SetStyleString().
3220 : *
3221 : * @param pszString the style string to apply to this feature, cannot be NULL.
3222 : */
3223 :
3224 183899 : void OGRFeature::SetStyleString(const char *pszString)
3225 : {
3226 183899 : if (m_pszStyleString)
3227 : {
3228 16 : CPLFree(m_pszStyleString);
3229 16 : m_pszStyleString = NULL;
3230 : }
3231 :
3232 183899 : if( pszString )
3233 1055 : m_pszStyleString = CPLStrdup(pszString);
3234 183899 : }
3235 :
3236 : /************************************************************************/
3237 : /* OGR_F_SetStyleString() */
3238 : /************************************************************************/
3239 :
3240 : /**
3241 : * \brief Set feature style string.
3242 : * This method operate exactly as
3243 : * OGR_F_SetStyleStringDirectly() except that it does not assume ownership
3244 : * of the passed string, but instead makes a copy of it.
3245 : *
3246 : * This function is the same as the C++ method OGRFeature::SetStyleString().
3247 : *
3248 : * @param hFeat handle to the feature to set style to.
3249 : * @param pszStyle the style string to apply to this feature, cannot be NULL.
3250 : */
3251 :
3252 3 : void OGR_F_SetStyleString( OGRFeatureH hFeat, const char *pszStyle )
3253 :
3254 : {
3255 3 : VALIDATE_POINTER0( hFeat, "OGR_F_SetStyleString" );
3256 :
3257 3 : ((OGRFeature *)hFeat)->SetStyleString( pszStyle );
3258 : }
3259 :
3260 : /************************************************************************/
3261 : /* SetStyleStringDirectly() */
3262 : /************************************************************************/
3263 :
3264 : /**
3265 : * \brief Set feature style string.
3266 : * This method operate exactly as
3267 : * OGRFeature::SetStyleString() except that it assumes ownership of the passed
3268 : * string.
3269 : *
3270 : * This method is the same as the C function OGR_F_SetStyleStringDirectly().
3271 : *
3272 : * @param pszString the style string to apply to this feature, cannot be NULL.
3273 : */
3274 :
3275 0 : void OGRFeature::SetStyleStringDirectly(char *pszString)
3276 : {
3277 0 : if (m_pszStyleString)
3278 0 : CPLFree(m_pszStyleString);
3279 0 : m_pszStyleString = pszString;
3280 0 : }
3281 :
3282 : /************************************************************************/
3283 : /* OGR_F_SetStyleStringDirectly() */
3284 : /************************************************************************/
3285 :
3286 : /**
3287 : * \brief Set feature style string.
3288 : * This method operate exactly as
3289 : * OGR_F_SetStyleString() except that it assumes ownership of the passed
3290 : * string.
3291 : *
3292 : * This function is the same as the C++ method
3293 : * OGRFeature::SetStyleStringDirectly().
3294 : *
3295 : * @param hFeat handle to the feature to set style to.
3296 : * @param pszStyle the style string to apply to this feature, cannot be NULL.
3297 : */
3298 :
3299 0 : void OGR_F_SetStyleStringDirectly( OGRFeatureH hFeat, char *pszStyle )
3300 :
3301 : {
3302 0 : VALIDATE_POINTER0( hFeat, "OGR_F_SetStyleStringDirectly" );
3303 :
3304 0 : ((OGRFeature *)hFeat)->SetStyleStringDirectly( pszStyle );
3305 : }
3306 :
3307 : //************************************************************************/
3308 : /* SetStyleTable() */
3309 : /************************************************************************/
3310 0 : void OGRFeature::SetStyleTable(OGRStyleTable *poStyleTable)
3311 : {
3312 0 : if ( m_poStyleTable )
3313 0 : delete m_poStyleTable;
3314 0 : m_poStyleTable = ( poStyleTable ) ? poStyleTable->Clone() : NULL;
3315 0 : }
3316 :
3317 : /************************************************************************/
3318 : /* RemapFields() */
3319 : /* */
3320 : /* This is used to transform a feature "in place" from one */
3321 : /* feature defn to another with minimum work. */
3322 : /************************************************************************/
3323 :
3324 71 : OGRErr OGRFeature::RemapFields( OGRFeatureDefn *poNewDefn,
3325 : int *panRemapSource )
3326 :
3327 : {
3328 : int iDstField;
3329 : OGRField *pauNewFields;
3330 :
3331 71 : if( poNewDefn == NULL )
3332 71 : poNewDefn = poDefn;
3333 :
3334 : pauNewFields = (OGRField *) CPLCalloc( poNewDefn->GetFieldCount(),
3335 71 : sizeof(OGRField) );
3336 :
3337 384 : for( iDstField = 0; iDstField < poDefn->GetFieldCount(); iDstField++ )
3338 : {
3339 313 : if( panRemapSource[iDstField] == -1 )
3340 : {
3341 31 : pauNewFields[iDstField].Set.nMarker1 = OGRUnsetMarker;
3342 31 : pauNewFields[iDstField].Set.nMarker2 = OGRUnsetMarker;
3343 : }
3344 : else
3345 : {
3346 : memcpy( pauNewFields + iDstField,
3347 282 : pauFields + panRemapSource[iDstField],
3348 564 : sizeof(OGRField) );
3349 : }
3350 : }
3351 :
3352 : /*
3353 : ** We really should be freeing memory for old columns that
3354 : ** are no longer present. We don't for now because it is a bit messy
3355 : ** and would take too long to test.
3356 : */
3357 :
3358 : /* -------------------------------------------------------------------- */
3359 : /* Apply new definition and fields. */
3360 : /* -------------------------------------------------------------------- */
3361 71 : CPLFree( pauFields );
3362 71 : pauFields = pauNewFields;
3363 :
3364 71 : poDefn = poNewDefn;
3365 :
3366 71 : return OGRERR_NONE;
3367 : }
3368 :
3369 : /************************************************************************/
3370 : /* OGR_F_GetStyleTable() */
3371 : /************************************************************************/
3372 :
3373 0 : OGRStyleTableH OGR_F_GetStyleTable( OGRFeatureH hFeat )
3374 :
3375 : {
3376 0 : VALIDATE_POINTER1( hFeat, "OGR_F_GetStyleTable", NULL );
3377 :
3378 0 : return (OGRStyleTableH) ((OGRFeature *) hFeat)->GetStyleTable( );
3379 : }
3380 :
3381 : /************************************************************************/
3382 : /* OGR_F_SetStyleTableDirectly() */
3383 : /************************************************************************/
3384 :
3385 0 : void OGR_F_SetStyleTableDirectly( OGRFeatureH hFeat,
3386 : OGRStyleTableH hStyleTable )
3387 :
3388 : {
3389 0 : VALIDATE_POINTER0( hFeat, "OGR_F_SetStyleTableDirectly" );
3390 :
3391 0 : ((OGRFeature *) hFeat)->SetStyleTableDirectly( (OGRStyleTable *) hStyleTable);
3392 : }
3393 :
3394 : /************************************************************************/
3395 : /* OGR_F_SetStyleTable() */
3396 : /************************************************************************/
3397 :
3398 0 : void OGR_F_SetStyleTable( OGRFeatureH hFeat,
3399 : OGRStyleTableH hStyleTable )
3400 :
3401 : {
3402 0 : VALIDATE_POINTER0( hFeat, "OGR_F_SetStyleTable" );
3403 0 : VALIDATE_POINTER0( hStyleTable, "OGR_F_SetStyleTable" );
3404 :
3405 0 : ((OGRFeature *) hFeat)->SetStyleTable( (OGRStyleTable *) hStyleTable);
3406 : }
|