LCOV - code coverage report
Current view: directory - ogr - ogrfeature.cpp (source / functions) Found Hit Coverage
Test: gdal_filtered.info Lines: 851 718 84.4 %
Date: 2012-04-28 Functions: 83 73 88.0 %

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

Generated by: LCOV version 1.7