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