LCOV - code coverage report
Current view: directory - ogr/ogrsf_frmts/generic - ogrlayer.cpp (source / functions) Found Hit Coverage
Test: gdal_filtered.info Lines: 420 339 80.7 %
Date: 2012-04-28 Functions: 80 56 70.0 %

       1                 : /******************************************************************************
       2                 :  * $Id: ogrlayer.cpp 24238 2012-04-14 15:39:55Z rouault $
       3                 :  *
       4                 :  * Project:  OpenGIS Simple Features Reference Implementation
       5                 :  * Purpose:  The generic portions of the OGRSFLayer class.
       6                 :  * Author:   Frank Warmerdam, warmerdam@pobox.com
       7                 :  *
       8                 :  ******************************************************************************
       9                 :  * Copyright (c) 1999,  Les Technologies SoftMap Inc.
      10                 :  *
      11                 :  * Permission is hereby granted, free of charge, to any person obtaining a
      12                 :  * copy of this software and associated documentation files (the "Software"),
      13                 :  * to deal in the Software without restriction, including without limitation
      14                 :  * the rights to use, copy, modify, merge, publish, distribute, sublicense,
      15                 :  * and/or sell copies of the Software, and to permit persons to whom the
      16                 :  * Software is furnished to do so, subject to the following conditions:
      17                 :  *
      18                 :  * The above copyright notice and this permission notice shall be included
      19                 :  * in all copies or substantial portions of the Software.
      20                 :  *
      21                 :  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
      22                 :  * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
      23                 :  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
      24                 :  * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
      25                 :  * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
      26                 :  * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
      27                 :  * DEALINGS IN THE SOFTWARE.
      28                 :  ****************************************************************************/
      29                 : 
      30                 : #include "ogrsf_frmts.h"
      31                 : #include "ogr_api.h"
      32                 : #include "ogr_p.h"
      33                 : #include "ogr_attrind.h"
      34                 : #include "swq.h"
      35                 : 
      36                 : CPL_CVSID("$Id: ogrlayer.cpp 24238 2012-04-14 15:39:55Z rouault $");
      37                 : 
      38                 : /************************************************************************/
      39                 : /*                              OGRLayer()                              */
      40                 : /************************************************************************/
      41                 : 
      42           32278 : OGRLayer::OGRLayer()
      43                 : 
      44                 : {
      45           32278 :     m_poStyleTable = NULL;
      46           32278 :     m_poAttrQuery = NULL;
      47           32278 :     m_poAttrIndex = NULL;
      48           32278 :     m_nRefCount = 0;
      49                 : 
      50           32278 :     m_nFeaturesRead = 0;
      51                 : 
      52           32278 :     m_poFilterGeom = NULL;
      53           32278 :     m_bFilterIsEnvelope = FALSE;
      54           32278 : }
      55                 : 
      56                 : /************************************************************************/
      57                 : /*                             ~OGRLayer()                              */
      58                 : /************************************************************************/
      59                 : 
      60           32278 : OGRLayer::~OGRLayer()
      61                 : 
      62                 : {
      63           32278 :     if ( m_poStyleTable )
      64                 :     {
      65               6 :         delete m_poStyleTable;
      66               6 :         m_poStyleTable = NULL;
      67                 :     }
      68                 : 
      69           32278 :     if( m_poAttrIndex != NULL )
      70                 :     {
      71              58 :         delete m_poAttrIndex;
      72              58 :         m_poAttrIndex = NULL;
      73                 :     }
      74                 : 
      75           32278 :     if( m_poAttrQuery != NULL )
      76                 :     {
      77              58 :         delete m_poAttrQuery;
      78              58 :         m_poAttrQuery = NULL;
      79                 :     }
      80                 : 
      81           32278 :     if( m_poFilterGeom )
      82                 :     {
      83              80 :         delete m_poFilterGeom;
      84              80 :         m_poFilterGeom = NULL;
      85                 :     }
      86           32278 : }
      87                 : 
      88                 : /************************************************************************/
      89                 : /*                             Reference()                              */
      90                 : /************************************************************************/
      91                 : 
      92               0 : int OGRLayer::Reference()
      93                 : 
      94                 : {
      95               0 :     return ++m_nRefCount;
      96                 : }
      97                 : 
      98                 : /************************************************************************/
      99                 : /*                          OGR_L_Reference()                           */
     100                 : /************************************************************************/
     101                 : 
     102               0 : int OGR_L_Reference( OGRLayerH hLayer )
     103                 : 
     104                 : {
     105               0 :     VALIDATE_POINTER1( hLayer, "OGR_L_Reference", 0 );
     106                 : 
     107               0 :     return ((OGRLayer *) hLayer)->Reference();
     108                 : }
     109                 : 
     110                 : /************************************************************************/
     111                 : /*                            Dereference()                             */
     112                 : /************************************************************************/
     113                 : 
     114               0 : int OGRLayer::Dereference()
     115                 : 
     116                 : {
     117               0 :     return --m_nRefCount;
     118                 : }
     119                 : 
     120                 : /************************************************************************/
     121                 : /*                         OGR_L_Dereference()                          */
     122                 : /************************************************************************/
     123                 : 
     124               0 : int OGR_L_Dereference( OGRLayerH hLayer )
     125                 : 
     126                 : {
     127               0 :     VALIDATE_POINTER1( hLayer, "OGR_L_Dereference", 0 );
     128                 : 
     129               0 :     return ((OGRLayer *) hLayer)->Dereference();
     130                 : }
     131                 : 
     132                 : /************************************************************************/
     133                 : /*                            GetRefCount()                             */
     134                 : /************************************************************************/
     135                 : 
     136              32 : int OGRLayer::GetRefCount() const
     137                 : 
     138                 : {
     139              32 :     return m_nRefCount;
     140                 : }
     141                 : 
     142                 : /************************************************************************/
     143                 : /*                         OGR_L_GetRefCount()                          */
     144                 : /************************************************************************/
     145                 : 
     146               0 : int OGR_L_GetRefCount( OGRLayerH hLayer )
     147                 : 
     148                 : {
     149               0 :     VALIDATE_POINTER1( hLayer, "OGR_L_GetRefCount", 0 );
     150                 : 
     151               0 :     return ((OGRLayer *) hLayer)->GetRefCount();
     152                 : }
     153                 : 
     154                 : /************************************************************************/
     155                 : /*                          GetFeatureCount()                           */
     156                 : /************************************************************************/
     157                 : 
     158            1052 : int OGRLayer::GetFeatureCount( int bForce )
     159                 : 
     160                 : {
     161                 :     OGRFeature     *poFeature;
     162            1052 :     int            nFeatureCount = 0;
     163                 : 
     164            1052 :     if( !bForce )
     165               0 :         return -1;
     166                 : 
     167            1052 :     ResetReading();
     168          427988 :     while( (poFeature = GetNextFeature()) != NULL )
     169                 :     {
     170          425884 :         nFeatureCount++;
     171          425884 :         delete poFeature;
     172                 :     }
     173            1052 :     ResetReading();
     174                 : 
     175            1052 :     return nFeatureCount;
     176                 : }
     177                 : 
     178                 : /************************************************************************/
     179                 : /*                       OGR_L_GetFeatureCount()                        */
     180                 : /************************************************************************/
     181                 : 
     182            1240 : int OGR_L_GetFeatureCount( OGRLayerH hLayer, int bForce )
     183                 : 
     184                 : {
     185            1240 :     VALIDATE_POINTER1( hLayer, "OGR_L_GetFeature", 0 );
     186                 : 
     187            1240 :     return ((OGRLayer *) hLayer)->GetFeatureCount(bForce);
     188                 : }
     189                 : 
     190                 : /************************************************************************/
     191                 : /*                             GetExtent()                              */
     192                 : /************************************************************************/
     193                 : 
     194             416 : OGRErr OGRLayer::GetExtent(OGREnvelope *psExtent, int bForce )
     195                 : 
     196                 : {
     197                 :     OGRFeature  *poFeature;
     198             416 :     OGREnvelope oEnv;
     199             416 :     GBool       bExtentSet = FALSE;
     200                 : 
     201             416 :     psExtent->MinX = 0.0;
     202             416 :     psExtent->MaxX = 0.0;
     203             416 :     psExtent->MinY = 0.0;
     204             416 :     psExtent->MaxY = 0.0;
     205                 : 
     206                 : /* -------------------------------------------------------------------- */
     207                 : /*      If this layer has a none geometry type, then we can             */
     208                 : /*      reasonably assume there are not extents available.              */
     209                 : /* -------------------------------------------------------------------- */
     210             416 :     if( GetLayerDefn()->GetGeomType() == wkbNone )
     211             136 :         return OGRERR_FAILURE;
     212                 : 
     213                 : /* -------------------------------------------------------------------- */
     214                 : /*      If not forced, we should avoid having to scan all the           */
     215                 : /*      features and just return a failure.                             */
     216                 : /* -------------------------------------------------------------------- */
     217             280 :     if( !bForce )
     218               0 :         return OGRERR_FAILURE;
     219                 : 
     220                 : /* -------------------------------------------------------------------- */
     221                 : /*      OK, we hate to do this, but go ahead and read through all       */
     222                 : /*      the features to collect geometries and build extents.           */
     223                 : /* -------------------------------------------------------------------- */
     224             280 :     ResetReading();
     225          140928 :     while( (poFeature = GetNextFeature()) != NULL )
     226                 :     {
     227          140368 :         OGRGeometry *poGeom = poFeature->GetGeometryRef();
     228          140368 :         if (poGeom == NULL || poGeom->IsEmpty())
     229                 :         {
     230                 :             /* Do nothing */
     231                 :         }
     232          139552 :         else if (!bExtentSet)
     233                 :         {
     234             264 :             poGeom->getEnvelope(psExtent);
     235             264 :             bExtentSet = TRUE;
     236                 :         }
     237                 :         else
     238                 :         {
     239          139288 :             poGeom->getEnvelope(&oEnv);
     240          139288 :             if (oEnv.MinX < psExtent->MinX) 
     241             358 :                 psExtent->MinX = oEnv.MinX;
     242          139288 :             if (oEnv.MinY < psExtent->MinY) 
     243            4050 :                 psExtent->MinY = oEnv.MinY;
     244          139288 :             if (oEnv.MaxX > psExtent->MaxX) 
     245             526 :                 psExtent->MaxX = oEnv.MaxX;
     246          139288 :             if (oEnv.MaxY > psExtent->MaxY) 
     247             332 :                 psExtent->MaxY = oEnv.MaxY;
     248                 :         }
     249          140368 :         delete poFeature;
     250                 :     }
     251             280 :     ResetReading();
     252                 : 
     253             280 :     return (bExtentSet ? OGRERR_NONE : OGRERR_FAILURE);
     254                 : }
     255                 : 
     256                 : /************************************************************************/
     257                 : /*                          OGR_L_GetExtent()                           */
     258                 : /************************************************************************/
     259                 : 
     260             204 : OGRErr OGR_L_GetExtent( OGRLayerH hLayer, OGREnvelope *psExtent, int bForce )
     261                 : 
     262                 : {
     263             204 :     VALIDATE_POINTER1( hLayer, "OGR_L_GetExtent", OGRERR_INVALID_HANDLE );
     264                 : 
     265             204 :     return ((OGRLayer *) hLayer)->GetExtent( psExtent, bForce );
     266                 : }
     267                 : 
     268                 : /************************************************************************/
     269                 : /*                         SetAttributeFilter()                         */
     270                 : /************************************************************************/
     271                 : 
     272            2776 : OGRErr OGRLayer::SetAttributeFilter( const char *pszQuery )
     273                 : 
     274                 : {
     275                 : /* -------------------------------------------------------------------- */
     276                 : /*      Are we just clearing any existing query?                        */
     277                 : /* -------------------------------------------------------------------- */
     278            2776 :     if( pszQuery == NULL || strlen(pszQuery) == 0 )
     279                 :     {
     280            1798 :         if( m_poAttrQuery )
     281                 :         {
     282             546 :             delete m_poAttrQuery;
     283             546 :             m_poAttrQuery = NULL;
     284             546 :             ResetReading();
     285                 :         }
     286            1798 :         return OGRERR_NONE;
     287                 :     }
     288                 : 
     289                 : /* -------------------------------------------------------------------- */
     290                 : /*      Or are we installing a new query?                               */
     291                 : /* -------------------------------------------------------------------- */
     292                 :     OGRErr      eErr;
     293                 : 
     294             978 :     if( !m_poAttrQuery )
     295             604 :         m_poAttrQuery = new OGRFeatureQuery();
     296                 : 
     297             978 :     eErr = m_poAttrQuery->Compile( GetLayerDefn(), pszQuery );
     298             978 :     if( eErr != OGRERR_NONE )
     299                 :     {
     300               0 :         delete m_poAttrQuery;
     301               0 :         m_poAttrQuery = NULL;
     302                 :     }
     303                 : 
     304             978 :     ResetReading();
     305                 : 
     306             978 :     return eErr;
     307                 : }
     308                 : 
     309                 : /************************************************************************/
     310                 : /*                        ContainGeomSpecialField()                     */
     311                 : /************************************************************************/
     312                 : 
     313            1672 : static int ContainGeomSpecialField(swq_expr_node* expr,
     314                 :                                    int nLayerFieldCount)
     315                 : {
     316            1672 :     if (expr->eNodeType == SNT_COLUMN)
     317                 :     {
     318             260 :         if( expr->table_index == 0 && expr->field_index != -1 )
     319                 :         {
     320                 :             int nSpecialFieldIdx = expr->field_index -
     321             260 :                                     nLayerFieldCount;
     322                 :             return nSpecialFieldIdx == SPF_OGR_GEOMETRY ||
     323                 :                    nSpecialFieldIdx == SPF_OGR_GEOM_WKT ||
     324             260 :                    nSpecialFieldIdx == SPF_OGR_GEOM_AREA;
     325                 :         }
     326                 :     }
     327            1412 :     else if (expr->eNodeType == SNT_OPERATION)
     328                 :     {
     329            2098 :         for( int i = 0; i < expr->nSubExprCount; i++ )
     330                 :         {
     331            1412 :             if (ContainGeomSpecialField(expr->papoSubExpr[i],
     332                 :                                         nLayerFieldCount))
     333               0 :                 return TRUE;
     334                 :         }
     335                 :     }
     336            1412 :     return FALSE;
     337                 : }
     338                 : 
     339                 : /************************************************************************/
     340                 : /*                AttributeFilterEvaluationNeedsGeometry()              */
     341                 : /************************************************************************/
     342                 : 
     343             260 : int OGRLayer::AttributeFilterEvaluationNeedsGeometry()
     344                 : {
     345             260 :     if( !m_poAttrQuery )
     346               0 :         return FALSE;
     347                 : 
     348             260 :     swq_expr_node* expr = (swq_expr_node *) m_poAttrQuery->GetSWGExpr();
     349             260 :     int nLayerFieldCount = GetLayerDefn()->GetFieldCount();
     350                 : 
     351             260 :     return ContainGeomSpecialField(expr, nLayerFieldCount);
     352                 : }
     353                 : 
     354                 : /************************************************************************/
     355                 : /*                      OGR_L_SetAttributeFilter()                      */
     356                 : /************************************************************************/
     357                 : 
     358             412 : OGRErr OGR_L_SetAttributeFilter( OGRLayerH hLayer, const char *pszQuery )
     359                 : 
     360                 : {
     361             412 :     VALIDATE_POINTER1( hLayer, "OGR_L_SetAttributeFilter", OGRERR_INVALID_HANDLE );
     362                 : 
     363             412 :     return ((OGRLayer *) hLayer)->SetAttributeFilter( pszQuery );
     364                 : }
     365                 : 
     366                 : /************************************************************************/
     367                 : /*                             GetFeature()                             */
     368                 : /************************************************************************/
     369                 : 
     370              26 : OGRFeature *OGRLayer::GetFeature( long nFID )
     371                 : 
     372                 : {
     373                 :     OGRFeature *poFeature;
     374                 : 
     375              26 :     ResetReading();
     376           18946 :     while( (poFeature = GetNextFeature()) != NULL )
     377                 :     {
     378           18912 :         if( poFeature->GetFID() == nFID )
     379              18 :             return poFeature;
     380                 :         else
     381           18894 :             delete poFeature;
     382                 :     }
     383                 :     
     384               8 :     return NULL;
     385                 : }
     386                 : 
     387                 : /************************************************************************/
     388                 : /*                          OGR_L_GetFeature()                          */
     389                 : /************************************************************************/
     390                 : 
     391             178 : OGRFeatureH OGR_L_GetFeature( OGRLayerH hLayer, long nFeatureId )
     392                 : 
     393                 : {
     394             178 :     VALIDATE_POINTER1( hLayer, "OGR_L_GetFeature", NULL );
     395                 : 
     396             178 :     return (OGRFeatureH) ((OGRLayer *)hLayer)->GetFeature( nFeatureId );
     397                 : }
     398                 : 
     399                 : /************************************************************************/
     400                 : /*                           SetNextByIndex()                           */
     401                 : /************************************************************************/
     402                 : 
     403              56 : OGRErr OGRLayer::SetNextByIndex( long nIndex )
     404                 : 
     405                 : {
     406                 :     OGRFeature *poFeature;
     407                 : 
     408              56 :     if( nIndex < 0 )
     409               6 :         return OGRERR_FAILURE;
     410                 : 
     411              50 :     ResetReading();
     412             296 :     while( nIndex-- > 0 )
     413                 :     {
     414             202 :         poFeature = GetNextFeature();
     415             202 :         if( poFeature == NULL )
     416               6 :             return OGRERR_FAILURE;
     417                 : 
     418             196 :         delete poFeature;
     419                 :     }
     420                 : 
     421              44 :     return OGRERR_NONE;
     422                 : }
     423                 : 
     424                 : /************************************************************************/
     425                 : /*                        OGR_L_SetNextByIndex()                        */
     426                 : /************************************************************************/
     427                 : 
     428              20 : OGRErr OGR_L_SetNextByIndex( OGRLayerH hLayer, long nIndex )
     429                 : 
     430                 : {
     431              20 :     VALIDATE_POINTER1( hLayer, "OGR_L_SetNextByIndex", OGRERR_INVALID_HANDLE );
     432                 : 
     433              20 :     return ((OGRLayer *)hLayer)->SetNextByIndex( nIndex );
     434                 : }
     435                 : 
     436                 : /************************************************************************/
     437                 : /*                        OGR_L_GetNextFeature()                        */
     438                 : /************************************************************************/
     439                 : 
     440          116830 : OGRFeatureH OGR_L_GetNextFeature( OGRLayerH hLayer )
     441                 : 
     442                 : {
     443          116830 :     VALIDATE_POINTER1( hLayer, "OGR_L_GetNextFeature", NULL );
     444                 : 
     445          116830 :     return (OGRFeatureH) ((OGRLayer *)hLayer)->GetNextFeature();
     446                 : }
     447                 : 
     448                 : /************************************************************************/
     449                 : /*                             SetFeature()                             */
     450                 : /************************************************************************/
     451                 : 
     452               0 : OGRErr OGRLayer::SetFeature( OGRFeature * )
     453                 : 
     454                 : {
     455               0 :     return OGRERR_UNSUPPORTED_OPERATION;
     456                 : }
     457                 : 
     458                 : /************************************************************************/
     459                 : /*                          OGR_L_SetFeature()                          */
     460                 : /************************************************************************/
     461                 : 
     462            4088 : OGRErr OGR_L_SetFeature( OGRLayerH hLayer, OGRFeatureH hFeat )
     463                 : 
     464                 : {
     465            4088 :     VALIDATE_POINTER1( hLayer, "OGR_L_SetFeature", OGRERR_INVALID_HANDLE );
     466            4088 :     VALIDATE_POINTER1( hFeat, "OGR_L_SetFeature", OGRERR_INVALID_HANDLE );
     467                 : 
     468            4088 :     return ((OGRLayer *)hLayer)->SetFeature( (OGRFeature *) hFeat );
     469                 : }
     470                 : 
     471                 : /************************************************************************/
     472                 : /*                           CreateFeature()                            */
     473                 : /************************************************************************/
     474                 : 
     475               0 : OGRErr OGRLayer::CreateFeature( OGRFeature * )
     476                 : 
     477                 : {
     478               0 :     return OGRERR_UNSUPPORTED_OPERATION;
     479                 : }
     480                 : 
     481                 : /************************************************************************/
     482                 : /*                        OGR_L_CreateFeature()                         */
     483                 : /************************************************************************/
     484                 : 
     485           67418 : OGRErr OGR_L_CreateFeature( OGRLayerH hLayer, OGRFeatureH hFeat )
     486                 : 
     487                 : {
     488           67418 :     VALIDATE_POINTER1( hLayer, "OGR_L_CreateFeature", OGRERR_INVALID_HANDLE );
     489           67418 :     VALIDATE_POINTER1( hFeat, "OGR_L_CreateFeature", OGRERR_INVALID_HANDLE );
     490                 : 
     491           67418 :     return ((OGRLayer *) hLayer)->CreateFeature( (OGRFeature *) hFeat );
     492                 : }
     493                 : 
     494                 : /************************************************************************/
     495                 : /*                              GetInfo()                               */
     496                 : /************************************************************************/
     497                 : 
     498               0 : const char *OGRLayer::GetInfo( const char * pszTag )
     499                 : 
     500                 : {
     501                 :     (void) pszTag;
     502               0 :     return NULL;
     503                 : }
     504                 : 
     505                 : /************************************************************************/
     506                 : /*                            CreateField()                             */
     507                 : /************************************************************************/
     508                 : 
     509               0 : OGRErr OGRLayer::CreateField( OGRFieldDefn * poField, int bApproxOK )
     510                 : 
     511                 : {
     512                 :     (void) poField;
     513                 :     (void) bApproxOK;
     514                 : 
     515                 :     CPLError( CE_Failure, CPLE_NotSupported,
     516               0 :               "CreateField() not supported by this layer.\n" );
     517                 :               
     518               0 :     return OGRERR_UNSUPPORTED_OPERATION;
     519                 : }
     520                 : 
     521                 : /************************************************************************/
     522                 : /*                         OGR_L_CreateField()                          */
     523                 : /************************************************************************/
     524                 : 
     525            9082 : OGRErr OGR_L_CreateField( OGRLayerH hLayer, OGRFieldDefnH hField, 
     526                 :                           int bApproxOK )
     527                 : 
     528                 : {
     529            9082 :     VALIDATE_POINTER1( hLayer, "OGR_L_CreateField", OGRERR_INVALID_HANDLE );
     530            9082 :     VALIDATE_POINTER1( hField, "OGR_L_CreateField", OGRERR_INVALID_HANDLE );
     531                 : 
     532                 :     return ((OGRLayer *) hLayer)->CreateField( (OGRFieldDefn *) hField, 
     533            9082 :                                                bApproxOK );
     534                 : }
     535                 : 
     536                 : /************************************************************************/
     537                 : /*                            DeleteField()                             */
     538                 : /************************************************************************/
     539                 : 
     540               0 : OGRErr OGRLayer::DeleteField( int iField )
     541                 : 
     542                 : {
     543                 :     (void) iField;
     544                 : 
     545                 :     CPLError( CE_Failure, CPLE_NotSupported,
     546               0 :               "DeleteField() not supported by this layer.\n" );
     547                 : 
     548               0 :     return OGRERR_UNSUPPORTED_OPERATION;
     549                 : }
     550                 : 
     551                 : /************************************************************************/
     552                 : /*                         OGR_L_DeleteField()                          */
     553                 : /************************************************************************/
     554                 : 
     555              58 : OGRErr OGR_L_DeleteField( OGRLayerH hLayer, int iField )
     556                 : 
     557                 : {
     558              58 :     VALIDATE_POINTER1( hLayer, "OGR_L_DeleteField", OGRERR_INVALID_HANDLE );
     559                 : 
     560              58 :     return ((OGRLayer *) hLayer)->DeleteField( iField );
     561                 : }
     562                 : 
     563                 : /************************************************************************/
     564                 : /*                           ReorderFields()                            */
     565                 : /************************************************************************/
     566                 : 
     567               0 : OGRErr OGRLayer::ReorderFields( int* panMap )
     568                 : 
     569                 : {
     570                 :     (void) panMap;
     571                 : 
     572                 :     CPLError( CE_Failure, CPLE_NotSupported,
     573               0 :               "ReorderFields() not supported by this layer.\n" );
     574                 : 
     575               0 :     return OGRERR_UNSUPPORTED_OPERATION;
     576                 : }
     577                 : 
     578                 : /************************************************************************/
     579                 : /*                       OGR_L_ReorderFields()                          */
     580                 : /************************************************************************/
     581                 : 
     582              30 : OGRErr OGR_L_ReorderFields( OGRLayerH hLayer, int* panMap )
     583                 : 
     584                 : {
     585              30 :     VALIDATE_POINTER1( hLayer, "OGR_L_ReorderFields", OGRERR_INVALID_HANDLE );
     586                 : 
     587              30 :     return ((OGRLayer *) hLayer)->ReorderFields( panMap );
     588                 : }
     589                 : 
     590                 : /************************************************************************/
     591                 : /*                            ReorderField()                            */
     592                 : /************************************************************************/
     593                 : 
     594              48 : OGRErr OGRLayer::ReorderField( int iOldFieldPos, int iNewFieldPos )
     595                 : 
     596                 : {
     597                 :     OGRErr eErr;
     598                 : 
     599              48 :     int nFieldCount = GetLayerDefn()->GetFieldCount();
     600                 : 
     601              48 :     if (iOldFieldPos < 0 || iOldFieldPos >= nFieldCount)
     602                 :     {
     603                 :         CPLError( CE_Failure, CPLE_NotSupported,
     604               0 :                   "Invalid field index");
     605               0 :         return OGRERR_FAILURE;
     606                 :     }
     607              48 :     if (iNewFieldPos < 0 || iNewFieldPos >= nFieldCount)
     608                 :     {
     609                 :         CPLError( CE_Failure, CPLE_NotSupported,
     610               0 :                   "Invalid field index");
     611               0 :         return OGRERR_FAILURE;
     612                 :     }
     613              48 :     if (iNewFieldPos == iOldFieldPos)
     614               0 :         return OGRERR_NONE;
     615                 : 
     616              48 :     int* panMap = (int*) CPLMalloc(sizeof(int) * nFieldCount);
     617                 :     int i;
     618              48 :     if (iOldFieldPos < iNewFieldPos)
     619                 :     {
     620                 :         /* "0","1","2","3","4" (1,3) -> "0","2","3","1","4" */
     621              24 :         for(i=0;i<iOldFieldPos;i++)
     622               6 :             panMap[i] = i;
     623              48 :         for(;i<iNewFieldPos;i++)
     624              30 :             panMap[i] = i + 1;
     625              18 :         panMap[iNewFieldPos] = iOldFieldPos;
     626              36 :         for(i=iNewFieldPos+1;i<nFieldCount;i++)
     627              18 :             panMap[i] = i;
     628                 :     }
     629                 :     else
     630                 :     {
     631                 :         /* "0","1","2","3","4" (3,1) -> "0","3","1","2","4" */
     632              36 :         for(i=0;i<iNewFieldPos;i++)
     633               6 :             panMap[i] = i;
     634              30 :         panMap[iNewFieldPos] = iOldFieldPos;
     635             108 :         for(i=iNewFieldPos+1;i<=iOldFieldPos;i++)
     636              78 :             panMap[i] = i - 1;
     637              48 :         for(;i<nFieldCount;i++)
     638              18 :             panMap[i] = i;
     639                 :     }
     640                 : 
     641              48 :     eErr = ReorderFields(panMap);
     642                 : 
     643              48 :     CPLFree(panMap);
     644                 : 
     645              48 :     return eErr;
     646                 : }
     647                 : 
     648                 : /************************************************************************/
     649                 : /*                        OGR_L_ReorderField()                          */
     650                 : /************************************************************************/
     651                 : 
     652              48 : OGRErr OGR_L_ReorderField( OGRLayerH hLayer, int iOldFieldPos, int iNewFieldPos )
     653                 : 
     654                 : {
     655              48 :     VALIDATE_POINTER1( hLayer, "OGR_L_ReorderField", OGRERR_INVALID_HANDLE );
     656                 : 
     657              48 :     return ((OGRLayer *) hLayer)->ReorderField( iOldFieldPos, iNewFieldPos );
     658                 : }
     659                 : 
     660                 : /************************************************************************/
     661                 : /*                           AlterFieldDefn()                           */
     662                 : /************************************************************************/
     663                 : 
     664               0 : OGRErr OGRLayer::AlterFieldDefn( int iField, OGRFieldDefn* poNewFieldDefn,
     665                 :                                  int nFlags )
     666                 : 
     667                 : {
     668                 :     (void) iField;
     669                 :     (void) poNewFieldDefn;
     670                 :     (void) nFlags;
     671                 : 
     672                 :     CPLError( CE_Failure, CPLE_NotSupported,
     673               0 :               "AlterFieldDefn() not supported by this layer.\n" );
     674                 : 
     675               0 :     return OGRERR_UNSUPPORTED_OPERATION;
     676                 : }
     677                 : 
     678                 : /************************************************************************/
     679                 : /*                        OGR_L_AlterFieldDefn()                        */
     680                 : /************************************************************************/
     681                 : 
     682              64 : OGRErr OGR_L_AlterFieldDefn( OGRLayerH hLayer, int iField, OGRFieldDefnH hNewFieldDefn,
     683                 :                              int nFlags )
     684                 : 
     685                 : {
     686              64 :     VALIDATE_POINTER1( hLayer, "OGR_L_AlterFieldDefn", OGRERR_INVALID_HANDLE );
     687              64 :     VALIDATE_POINTER1( hNewFieldDefn, "OGR_L_AlterFieldDefn", OGRERR_INVALID_HANDLE );
     688                 : 
     689              64 :     return ((OGRLayer *) hLayer)->AlterFieldDefn( iField, (OGRFieldDefn*) hNewFieldDefn, nFlags );
     690                 : }
     691                 : 
     692                 : /************************************************************************/
     693                 : /*                          StartTransaction()                          */
     694                 : /************************************************************************/
     695                 : 
     696            1536 : OGRErr OGRLayer::StartTransaction()
     697                 : 
     698                 : {
     699            1536 :     return OGRERR_NONE;
     700                 : }
     701                 : 
     702                 : /************************************************************************/
     703                 : /*                       OGR_L_StartTransaction()                       */
     704                 : /************************************************************************/
     705                 : 
     706             128 : OGRErr OGR_L_StartTransaction( OGRLayerH hLayer )
     707                 : 
     708                 : {
     709             128 :     VALIDATE_POINTER1( hLayer, "OGR_L_StartTransaction", OGRERR_INVALID_HANDLE );
     710                 : 
     711             128 :     return ((OGRLayer *)hLayer)->StartTransaction();
     712                 : }
     713                 : 
     714                 : /************************************************************************/
     715                 : /*                         CommitTransaction()                          */
     716                 : /************************************************************************/
     717                 : 
     718            1494 : OGRErr OGRLayer::CommitTransaction()
     719                 : 
     720                 : {
     721            1494 :     return OGRERR_NONE;
     722                 : }
     723                 : 
     724                 : /************************************************************************/
     725                 : /*                       OGR_L_CommitTransaction()                      */
     726                 : /************************************************************************/
     727                 : 
     728             124 : OGRErr OGR_L_CommitTransaction( OGRLayerH hLayer )
     729                 : 
     730                 : {
     731             124 :     VALIDATE_POINTER1( hLayer, "OGR_L_CommitTransaction", OGRERR_INVALID_HANDLE );
     732                 : 
     733             124 :     return ((OGRLayer *)hLayer)->CommitTransaction();
     734                 : }
     735                 : 
     736                 : /************************************************************************/
     737                 : /*                        RollbackTransaction()                         */
     738                 : /************************************************************************/
     739                 : 
     740              42 : OGRErr OGRLayer::RollbackTransaction()
     741                 : 
     742                 : {
     743              42 :     return OGRERR_UNSUPPORTED_OPERATION;
     744                 : }
     745                 : 
     746                 : /************************************************************************/
     747                 : /*                     OGR_L_RollbackTransaction()                      */
     748                 : /************************************************************************/
     749                 : 
     750               6 : OGRErr OGR_L_RollbackTransaction( OGRLayerH hLayer )
     751                 : 
     752                 : {
     753               6 :     VALIDATE_POINTER1( hLayer, "OGR_L_RollbackTransaction", OGRERR_INVALID_HANDLE );
     754                 : 
     755               6 :     return ((OGRLayer *)hLayer)->RollbackTransaction();
     756                 : }
     757                 : 
     758                 : /************************************************************************/
     759                 : /*                         OGR_L_GetLayerDefn()                         */
     760                 : /************************************************************************/
     761                 : 
     762           65830 : OGRFeatureDefnH OGR_L_GetLayerDefn( OGRLayerH hLayer )
     763                 : 
     764                 : {
     765           65830 :     VALIDATE_POINTER1( hLayer, "OGR_L_GetLayerDefn", NULL );
     766                 : 
     767           65830 :     return (OGRFeatureDefnH) ((OGRLayer *)hLayer)->GetLayerDefn();
     768                 : }
     769                 : 
     770                 : /************************************************************************/
     771                 : /*                        OGR_L_GetSpatialRef()                         */
     772                 : /************************************************************************/
     773                 : 
     774             484 : OGRSpatialReferenceH OGR_L_GetSpatialRef( OGRLayerH hLayer )
     775                 : 
     776                 : {
     777             484 :     VALIDATE_POINTER1( hLayer, "OGR_L_GetSpatialRef", NULL );
     778                 : 
     779             484 :     return (OGRSpatialReferenceH) ((OGRLayer *) hLayer)->GetSpatialRef();
     780                 : }
     781                 : 
     782                 : /************************************************************************/
     783                 : /*                        OGR_L_TestCapability()                        */
     784                 : /************************************************************************/
     785                 : 
     786             214 : int OGR_L_TestCapability( OGRLayerH hLayer, const char *pszCap )
     787                 : 
     788                 : {
     789             214 :     VALIDATE_POINTER1( hLayer, "OGR_L_TestCapability", 0 );
     790             214 :     VALIDATE_POINTER1( pszCap, "OGR_L_TestCapability", 0 );
     791                 : 
     792             214 :     return ((OGRLayer *) hLayer)->TestCapability( pszCap );
     793                 : }
     794                 : 
     795                 : /************************************************************************/
     796                 : /*                          GetSpatialFilter()                          */
     797                 : /************************************************************************/
     798                 : 
     799             190 : OGRGeometry *OGRLayer::GetSpatialFilter()
     800                 : 
     801                 : {
     802             190 :     return m_poFilterGeom;
     803                 : }
     804                 : 
     805                 : /************************************************************************/
     806                 : /*                       OGR_L_GetSpatialFilter()                       */
     807                 : /************************************************************************/
     808                 : 
     809               0 : OGRGeometryH OGR_L_GetSpatialFilter( OGRLayerH hLayer )
     810                 : 
     811                 : {
     812               0 :     VALIDATE_POINTER1( hLayer, "OGR_L_GetSpatialFilter", NULL );
     813                 : 
     814               0 :     return (OGRGeometryH) ((OGRLayer *) hLayer)->GetSpatialFilter();
     815                 : }
     816                 : 
     817                 : /************************************************************************/
     818                 : /*                          SetSpatialFilter()                          */
     819                 : /************************************************************************/
     820                 : 
     821           27072 : void OGRLayer::SetSpatialFilter( OGRGeometry * poGeomIn )
     822                 : 
     823                 : {
     824           27072 :     if( InstallFilter( poGeomIn ) )
     825           24974 :         ResetReading();
     826           27072 : }
     827                 : 
     828                 : /************************************************************************/
     829                 : /*                       OGR_L_SetSpatialFilter()                       */
     830                 : /************************************************************************/
     831                 : 
     832             110 : void OGR_L_SetSpatialFilter( OGRLayerH hLayer, OGRGeometryH hGeom )
     833                 : 
     834                 : {
     835             110 :     VALIDATE_POINTER0( hLayer, "OGR_L_SetSpatialFilter" );
     836                 : 
     837             110 :     ((OGRLayer *) hLayer)->SetSpatialFilter( (OGRGeometry *) hGeom );
     838                 : }
     839                 : 
     840                 : /************************************************************************/
     841                 : /*                        SetSpatialFilterRect()                        */
     842                 : /************************************************************************/
     843                 : 
     844           24686 : void OGRLayer::SetSpatialFilterRect( double dfMinX, double dfMinY, 
     845                 :                                      double dfMaxX, double dfMaxY )
     846                 : 
     847                 : {
     848           24686 :     OGRLinearRing  oRing;
     849           24686 :     OGRPolygon oPoly;
     850                 : 
     851           24686 :     oRing.addPoint( dfMinX, dfMinY );
     852           24686 :     oRing.addPoint( dfMinX, dfMaxY );
     853           24686 :     oRing.addPoint( dfMaxX, dfMaxY );
     854           24686 :     oRing.addPoint( dfMaxX, dfMinY );
     855           24686 :     oRing.addPoint( dfMinX, dfMinY );
     856                 : 
     857           24686 :     oPoly.addRing( &oRing );
     858                 : 
     859           24686 :     SetSpatialFilter( &oPoly );
     860           24686 : }
     861                 : 
     862                 : /************************************************************************/
     863                 : /*                     OGR_L_SetSpatialFilterRect()                     */
     864                 : /************************************************************************/
     865                 : 
     866           24686 : void OGR_L_SetSpatialFilterRect( OGRLayerH hLayer, 
     867                 :                                  double dfMinX, double dfMinY, 
     868                 :                                  double dfMaxX, double dfMaxY )
     869                 : 
     870                 : {
     871           24686 :     VALIDATE_POINTER0( hLayer, "OGR_L_SetSpatialFilterRect" );
     872                 : 
     873                 :     ((OGRLayer *) hLayer)->SetSpatialFilterRect( dfMinX, dfMinY, 
     874           24686 :                                                  dfMaxX, dfMaxY );
     875                 : }
     876                 : 
     877                 : /************************************************************************/
     878                 : /*                           InstallFilter()                            */
     879                 : /*                                                                      */
     880                 : /*      This method is only intended to be used from within             */
     881                 : /*      drivers, normally from the SetSpatialFilter() method.           */
     882                 : /*      It installs a filter, and also tests it to see if it is         */
     883                 : /*      rectangular.  If so, it this is kept track of alongside the     */
     884                 : /*      filter geometry itself so we can do cheaper comparisons in      */
     885                 : /*      the FilterGeometry() call.                                      */
     886                 : /*                                                                      */
     887                 : /*      Returns TRUE if the newly installed filter differs in some      */
     888                 : /*      way from the current one.                                       */
     889                 : /************************************************************************/
     890                 : 
     891           27322 : int OGRLayer::InstallFilter( OGRGeometry * poFilter )
     892                 : 
     893                 : {
     894           27322 :     if( m_poFilterGeom == NULL && poFilter == NULL )
     895            2226 :         return FALSE;
     896                 : 
     897                 : /* -------------------------------------------------------------------- */
     898                 : /*      Replace the existing filter.                                    */
     899                 : /* -------------------------------------------------------------------- */
     900           25096 :     if( m_poFilterGeom != NULL )
     901                 :     {
     902           24872 :         delete m_poFilterGeom;
     903           24872 :         m_poFilterGeom = NULL;
     904                 :     }
     905                 : 
     906           25096 :     if( poFilter != NULL )
     907           24952 :         m_poFilterGeom = poFilter->clone();
     908                 : 
     909           25096 :     m_bFilterIsEnvelope = FALSE;
     910                 : 
     911           25096 :     if( m_poFilterGeom == NULL )
     912             144 :         return TRUE;
     913                 : 
     914           24952 :     if( m_poFilterGeom != NULL )
     915           24952 :         m_poFilterGeom->getEnvelope( &m_sFilterEnvelope );
     916                 : 
     917                 : /* -------------------------------------------------------------------- */
     918                 : /*      Now try to determine if the filter is really a rectangle.       */
     919                 : /* -------------------------------------------------------------------- */
     920           24952 :     if( wkbFlatten(m_poFilterGeom->getGeometryType()) != wkbPolygon )
     921              22 :         return TRUE;
     922                 : 
     923           24930 :     OGRPolygon *poPoly = (OGRPolygon *) m_poFilterGeom;
     924                 : 
     925           24930 :     if( poPoly->getNumInteriorRings() != 0 )
     926               0 :         return TRUE;
     927                 : 
     928           24930 :     OGRLinearRing *poRing = poPoly->getExteriorRing();
     929           24930 :     if (poRing == NULL)
     930               0 :         return TRUE;
     931                 : 
     932           24930 :     if( poRing->getNumPoints() > 5 || poRing->getNumPoints() < 4 )
     933               0 :         return TRUE;
     934                 : 
     935                 :     // If the ring has 5 points, the last should be the first. 
     936           24930 :     if( poRing->getNumPoints() == 5 
     937                 :         && ( poRing->getX(0) != poRing->getX(4)
     938                 :              || poRing->getY(0) != poRing->getY(4) ) )
     939               0 :         return TRUE;
     940                 : 
     941                 :     // Polygon with first segment in "y" direction. 
     942           24930 :     if( poRing->getX(0) == poRing->getX(1)
     943                 :         && poRing->getY(1) == poRing->getY(2)
     944                 :         && poRing->getX(2) == poRing->getX(3)
     945                 :         && poRing->getY(3) == poRing->getY(0) )
     946           24830 :         m_bFilterIsEnvelope = TRUE;
     947                 : 
     948                 :     // Polygon with first segment in "x" direction. 
     949           24930 :     if( poRing->getY(0) == poRing->getY(1)
     950                 :         && poRing->getX(1) == poRing->getX(2)
     951                 :         && poRing->getY(2) == poRing->getY(3)
     952                 :         && poRing->getX(3) == poRing->getX(0) )
     953             100 :         m_bFilterIsEnvelope = TRUE;
     954                 : 
     955           24930 :     return TRUE;
     956                 : }
     957                 : 
     958                 : /************************************************************************/
     959                 : /*                           FilterGeometry()                           */
     960                 : /*                                                                      */
     961                 : /*      Compare the passed in geometry to the currently installed       */
     962                 : /*      filter.  Optimize for case where filter is just an              */
     963                 : /*      envelope.                                                       */
     964                 : /************************************************************************/
     965                 : 
     966          310644 : int OGRLayer::FilterGeometry( OGRGeometry *poGeometry )
     967                 : 
     968                 : {
     969                 : /* -------------------------------------------------------------------- */
     970                 : /*      In trivial cases of new filter or target geometry, we accept    */
     971                 : /*      an intersection.  No geometry is taken to mean "the whole       */
     972                 : /*      world".                                                         */
     973                 : /* -------------------------------------------------------------------- */
     974          310644 :     if( m_poFilterGeom == NULL )
     975              56 :         return TRUE;
     976                 : 
     977          310588 :     if( poGeometry == NULL )
     978             854 :         return TRUE;
     979                 : 
     980                 : /* -------------------------------------------------------------------- */
     981                 : /*      Compute the target geometry envelope, and if there is no        */
     982                 : /*      intersection between the envelopes we are sure not to have      */
     983                 : /*      any intersection.                                               */
     984                 : /* -------------------------------------------------------------------- */
     985          309734 :     OGREnvelope sGeomEnv;
     986                 : 
     987          309734 :     poGeometry->getEnvelope( &sGeomEnv );
     988                 : 
     989          309734 :     if( sGeomEnv.MaxX < m_sFilterEnvelope.MinX
     990                 :         || sGeomEnv.MaxY < m_sFilterEnvelope.MinY
     991                 :         || m_sFilterEnvelope.MaxX < sGeomEnv.MinX
     992                 :         || m_sFilterEnvelope.MaxY < sGeomEnv.MinY )
     993          217090 :         return FALSE;
     994                 : 
     995                 : 
     996                 : /* -------------------------------------------------------------------- */
     997                 : /*      If the filter geometry is its own envelope and if the           */
     998                 : /*      envelope of the geometry is inside the filter geometry,         */
     999                 : /*      the geometry itself is inside the filter geometry               */
    1000                 : /* -------------------------------------------------------------------- */
    1001           92644 :     if( m_bFilterIsEnvelope &&
    1002                 :         sGeomEnv.MinX >= m_sFilterEnvelope.MinX &&
    1003                 :         sGeomEnv.MinY >= m_sFilterEnvelope.MinY &&
    1004                 :         sGeomEnv.MaxX <= m_sFilterEnvelope.MaxX &&
    1005                 :         sGeomEnv.MaxY <= m_sFilterEnvelope.MaxY)
    1006                 :     {
    1007           89047 :         return TRUE;
    1008                 :     }
    1009                 :     else
    1010                 :     {
    1011                 : /* -------------------------------------------------------------------- */
    1012                 : /*      If the filter geometry is its own envelope and if the           */
    1013                 : /*      the geometry (line, or polygon without hole) h has at least one */
    1014                 : /*      point inside the filter geometry, the geometry itself is inside */
    1015                 : /*      the filter geometry.                                            */
    1016                 : /* -------------------------------------------------------------------- */
    1017            3597 :         if( m_bFilterIsEnvelope )
    1018                 :         {
    1019            3575 :             OGRLineString* poLS = NULL;
    1020                 : 
    1021            3575 :             switch( wkbFlatten(poGeometry->getGeometryType()) )
    1022                 :             {
    1023                 :                 case wkbPolygon:
    1024                 :                 {
    1025            3529 :                     OGRPolygon* poPoly = (OGRPolygon* )poGeometry;
    1026            3529 :                     OGRLinearRing* poRing = poPoly->getExteriorRing();
    1027            3529 :                     if (poRing != NULL && poPoly->getNumInteriorRings() == 0)
    1028                 :                     {
    1029            3523 :                         poLS = poRing;
    1030                 :                     }
    1031            3529 :                     break;
    1032                 :                 }
    1033                 : 
    1034                 :                 case wkbLineString:
    1035              44 :                     poLS = (OGRLineString* )poGeometry;
    1036                 :                     break;
    1037                 : 
    1038                 :                 default:
    1039                 :                     break;
    1040                 :             }
    1041                 : 
    1042            3575 :             if( poLS != NULL )
    1043                 :             {
    1044            3567 :                 int nNumPoints = poLS->getNumPoints();
    1045           15166 :                 for(int i = 0; i < nNumPoints; i++)
    1046                 :                 {
    1047           14445 :                     double x = poLS->getX(i);
    1048           14445 :                     double y = poLS->getY(i);
    1049           14445 :                     if (x >= m_sFilterEnvelope.MinX &&
    1050                 :                         y >= m_sFilterEnvelope.MinY &&
    1051                 :                         x <= m_sFilterEnvelope.MaxX &&
    1052                 :                         y <= m_sFilterEnvelope.MaxY)
    1053                 :                     {
    1054            2846 :                         return TRUE;
    1055                 :                     }
    1056                 :                 }
    1057                 :             }
    1058                 :         }
    1059                 : 
    1060                 : /* -------------------------------------------------------------------- */
    1061                 : /*      Fallback to full intersect test (using GEOS) if we still        */
    1062                 : /*      don't know for sure.                                            */
    1063                 : /* -------------------------------------------------------------------- */
    1064             751 :         if( OGRGeometryFactory::haveGEOS() )
    1065                 :         {
    1066                 :             //CPLDebug("OGRLayer", "GEOS intersection");
    1067             751 :             return m_poFilterGeom->Intersects( poGeometry );
    1068                 :         }
    1069                 :         else
    1070               0 :             return TRUE;
    1071                 :     }
    1072                 : }
    1073                 : 
    1074                 : /************************************************************************/
    1075                 : /*                         OGR_L_ResetReading()                         */
    1076                 : /************************************************************************/
    1077                 : 
    1078           27542 : void OGR_L_ResetReading( OGRLayerH hLayer )
    1079                 : 
    1080                 : {
    1081           27542 :     VALIDATE_POINTER0( hLayer, "OGR_L_ResetReading" );
    1082                 : 
    1083           27542 :     ((OGRLayer *) hLayer)->ResetReading();
    1084                 : }
    1085                 : 
    1086                 : /************************************************************************/
    1087                 : /*                       InitializeIndexSupport()                       */
    1088                 : /*                                                                      */
    1089                 : /*      This is only intended to be called by driver layer              */
    1090                 : /*      implementations but we don't make it protected so that the      */
    1091                 : /*      datasources can do it too if that is more appropriate.          */
    1092                 : /************************************************************************/
    1093                 : 
    1094             650 : OGRErr OGRLayer::InitializeIndexSupport( const char *pszFilename )
    1095                 : 
    1096                 : {
    1097                 :     OGRErr eErr;
    1098                 : 
    1099             650 :     if (m_poAttrIndex != NULL)
    1100             592 :         return OGRERR_NONE;
    1101                 : 
    1102              58 :     m_poAttrIndex = OGRCreateDefaultLayerIndex();
    1103                 : 
    1104              58 :     eErr = m_poAttrIndex->Initialize( pszFilename, this );
    1105              58 :     if( eErr != OGRERR_NONE )
    1106                 :     {
    1107               0 :         delete m_poAttrIndex;
    1108               0 :         m_poAttrIndex = NULL;
    1109                 :     }
    1110                 : 
    1111              58 :     return eErr;
    1112                 : }
    1113                 : 
    1114                 : /************************************************************************/
    1115                 : /*                             SyncToDisk()                             */
    1116                 : /************************************************************************/
    1117                 : 
    1118               0 : OGRErr OGRLayer::SyncToDisk()
    1119                 : 
    1120                 : {
    1121               0 :     return OGRERR_NONE;
    1122                 : }
    1123                 : 
    1124                 : /************************************************************************/
    1125                 : /*                          OGR_L_SyncToDisk()                          */
    1126                 : /************************************************************************/
    1127                 : 
    1128               4 : OGRErr OGR_L_SyncToDisk( OGRLayerH hDS )
    1129                 : 
    1130                 : {
    1131               4 :     VALIDATE_POINTER1( hDS, "OGR_L_SyncToDisk", OGRERR_INVALID_HANDLE );
    1132                 : 
    1133               4 :     return ((OGRLayer *) hDS)->SyncToDisk();
    1134                 : }
    1135                 : 
    1136                 : /************************************************************************/
    1137                 : /*                           DeleteFeature()                            */
    1138                 : /************************************************************************/
    1139                 : 
    1140               0 : OGRErr OGRLayer::DeleteFeature( long nFID )
    1141                 : 
    1142                 : {
    1143               0 :     return OGRERR_UNSUPPORTED_OPERATION;
    1144                 : }
    1145                 : 
    1146                 : /************************************************************************/
    1147                 : /*                        OGR_L_DeleteFeature()                         */
    1148                 : /************************************************************************/
    1149                 : 
    1150              38 : OGRErr OGR_L_DeleteFeature( OGRLayerH hDS, long nFID )
    1151                 : 
    1152                 : {
    1153              38 :     VALIDATE_POINTER1( hDS, "OGR_L_DeleteFeature", OGRERR_INVALID_HANDLE );
    1154                 : 
    1155              38 :     return ((OGRLayer *) hDS)->DeleteFeature( nFID );
    1156                 : }
    1157                 : 
    1158                 : /************************************************************************/
    1159                 : /*                          GetFeaturesRead()                           */
    1160                 : /************************************************************************/
    1161                 : 
    1162               0 : GIntBig OGRLayer::GetFeaturesRead()
    1163                 : 
    1164                 : {
    1165               0 :     return m_nFeaturesRead;
    1166                 : }
    1167                 : 
    1168                 : /************************************************************************/
    1169                 : /*                       OGR_L_GetFeaturesRead()                        */
    1170                 : /************************************************************************/
    1171                 : 
    1172               0 : GIntBig OGR_L_GetFeaturesRead( OGRLayerH hLayer )
    1173                 : 
    1174                 : {
    1175               0 :     VALIDATE_POINTER1( hLayer, "OGR_L_GetFeaturesRead", 0 );
    1176                 : 
    1177               0 :     return ((OGRLayer *) hLayer)->GetFeaturesRead();
    1178                 : }
    1179                 : 
    1180                 : /************************************************************************/
    1181                 : /*                             GetFIDColumn                             */
    1182                 : /************************************************************************/
    1183                 : 
    1184              38 : const char *OGRLayer::GetFIDColumn()
    1185                 : 
    1186                 : {
    1187              38 :     return "";
    1188                 : }
    1189                 : 
    1190                 : /************************************************************************/
    1191                 : /*                         OGR_L_GetFIDColumn()                         */
    1192                 : /************************************************************************/
    1193                 : 
    1194              40 : const char *OGR_L_GetFIDColumn( OGRLayerH hLayer )
    1195                 : 
    1196                 : {
    1197              40 :     VALIDATE_POINTER1( hLayer, "OGR_L_GetFIDColumn", NULL );
    1198                 : 
    1199              40 :     return ((OGRLayer *) hLayer)->GetFIDColumn();
    1200                 : }
    1201                 : 
    1202                 : /************************************************************************/
    1203                 : /*                         GetGeometryColumn()                          */
    1204                 : /************************************************************************/
    1205                 : 
    1206              38 : const char *OGRLayer::GetGeometryColumn()
    1207                 : 
    1208                 : {
    1209              38 :     return "";
    1210                 : }
    1211                 : 
    1212                 : /************************************************************************/
    1213                 : /*                      OGR_L_GetGeometryColumn()                       */
    1214                 : /************************************************************************/
    1215                 : 
    1216              40 : const char *OGR_L_GetGeometryColumn( OGRLayerH hLayer )
    1217                 : 
    1218                 : {
    1219              40 :     VALIDATE_POINTER1( hLayer, "OGR_L_GetGeometryColumn", NULL );
    1220                 : 
    1221              40 :     return ((OGRLayer *) hLayer)->GetGeometryColumn();
    1222                 : }
    1223                 : 
    1224                 : /************************************************************************/
    1225                 : /*                            GetStyleTable()                           */
    1226                 : /************************************************************************/
    1227                 : 
    1228             206 : OGRStyleTable *OGRLayer::GetStyleTable()
    1229                 : {
    1230             206 :     return m_poStyleTable;
    1231                 : }
    1232                 : 
    1233                 : /************************************************************************/
    1234                 : /*                         SetStyleTableDirectly()                      */
    1235                 : /************************************************************************/
    1236                 : 
    1237               0 : void OGRLayer::SetStyleTableDirectly( OGRStyleTable *poStyleTable )
    1238                 : {
    1239               0 :     if ( m_poStyleTable )
    1240               0 :         delete m_poStyleTable;
    1241               0 :     m_poStyleTable = poStyleTable;
    1242               0 : }
    1243                 : 
    1244                 : /************************************************************************/
    1245                 : /*                            SetStyleTable()                           */
    1246                 : /************************************************************************/
    1247                 : 
    1248             206 : void OGRLayer::SetStyleTable(OGRStyleTable *poStyleTable)
    1249                 : {
    1250             206 :     if ( m_poStyleTable )
    1251               0 :         delete m_poStyleTable;
    1252             206 :     if ( poStyleTable )
    1253               0 :         m_poStyleTable = poStyleTable->Clone();
    1254             206 : }
    1255                 : 
    1256                 : /************************************************************************/
    1257                 : /*                         OGR_L_GetStyleTable()                        */
    1258                 : /************************************************************************/
    1259                 : 
    1260               0 : OGRStyleTableH OGR_L_GetStyleTable( OGRLayerH hLayer )
    1261                 : 
    1262                 : {
    1263               0 :     VALIDATE_POINTER1( hLayer, "OGR_L_GetStyleTable", NULL );
    1264                 :     
    1265               0 :     return (OGRStyleTableH) ((OGRLayer *) hLayer)->GetStyleTable( );
    1266                 : }
    1267                 : 
    1268                 : /************************************************************************/
    1269                 : /*                         OGR_L_SetStyleTableDirectly()                */
    1270                 : /************************************************************************/
    1271                 : 
    1272               0 : void OGR_L_SetStyleTableDirectly( OGRLayerH hLayer,
    1273                 :                                   OGRStyleTableH hStyleTable )
    1274                 : 
    1275                 : {
    1276               0 :     VALIDATE_POINTER0( hLayer, "OGR_L_SetStyleTableDirectly" );
    1277                 :     
    1278               0 :     ((OGRLayer *) hLayer)->SetStyleTableDirectly( (OGRStyleTable *) hStyleTable);
    1279                 : }
    1280                 : 
    1281                 : /************************************************************************/
    1282                 : /*                         OGR_L_SetStyleTable()                        */
    1283                 : /************************************************************************/
    1284                 : 
    1285               0 : void OGR_L_SetStyleTable( OGRLayerH hLayer,
    1286                 :                           OGRStyleTableH hStyleTable )
    1287                 : 
    1288                 : {
    1289               0 :     VALIDATE_POINTER0( hLayer, "OGR_L_SetStyleTable" );
    1290               0 :     VALIDATE_POINTER0( hStyleTable, "OGR_L_SetStyleTable" );
    1291                 :     
    1292               0 :     ((OGRLayer *) hLayer)->SetStyleTable( (OGRStyleTable *) hStyleTable);
    1293                 : }
    1294                 : 
    1295                 : /************************************************************************/
    1296                 : /*                               GetName()                              */
    1297                 : /************************************************************************/
    1298                 : 
    1299         2110784 : const char *OGRLayer::GetName()
    1300                 : 
    1301                 : {
    1302         2110784 :     return GetLayerDefn()->GetName();
    1303                 : }
    1304                 : 
    1305                 : /************************************************************************/
    1306                 : /*                           OGR_L_GetName()                            */
    1307                 : /************************************************************************/
    1308                 : 
    1309            4483 : const char* OGR_L_GetName( OGRLayerH hLayer )
    1310                 : 
    1311                 : {
    1312            4483 :     VALIDATE_POINTER1( hLayer, "OGR_L_GetName", "" );
    1313                 : 
    1314            4483 :     return ((OGRLayer *) hLayer)->GetName();
    1315                 : }
    1316                 : 
    1317                 : /************************************************************************/
    1318                 : /*                            GetGeomType()                             */
    1319                 : /************************************************************************/
    1320                 : 
    1321             936 : OGRwkbGeometryType OGRLayer::GetGeomType()
    1322                 : {
    1323             936 :     return GetLayerDefn()->GetGeomType();
    1324                 : }
    1325                 : /************************************************************************/
    1326                 : /*                         OGR_L_GetGeomType()                          */
    1327                 : /************************************************************************/
    1328                 : 
    1329             144 : OGRwkbGeometryType OGR_L_GetGeomType( OGRLayerH hLayer )
    1330                 : 
    1331                 : {
    1332             144 :     VALIDATE_POINTER1( hLayer, "OGR_L_GetGeomType", wkbUnknown );
    1333                 : 
    1334             144 :     return ((OGRLayer *) hLayer)->GetGeomType();
    1335                 : }
    1336                 : 
    1337                 : /************************************************************************/
    1338                 : /*                          SetIgnoredFields()                          */
    1339                 : /************************************************************************/
    1340                 : 
    1341            1442 : OGRErr OGRLayer::SetIgnoredFields( const char **papszFields )
    1342                 : {
    1343            1442 :     OGRFeatureDefn *poDefn = GetLayerDefn();
    1344                 : 
    1345                 :     // first set everything as *not* ignored
    1346            7484 :     for( int iField = 0; iField < poDefn->GetFieldCount(); iField++ )
    1347                 :     {
    1348            6042 :         poDefn->GetFieldDefn(iField)->SetIgnored( FALSE );
    1349                 :     }
    1350            1442 :     poDefn->SetGeometryIgnored( FALSE );
    1351            1442 :     poDefn->SetStyleIgnored( FALSE );
    1352                 :     
    1353            1442 :     if ( papszFields == NULL )
    1354            1112 :         return OGRERR_NONE;
    1355                 : 
    1356                 :     // ignore some fields
    1357            2382 :     while ( *papszFields )
    1358                 :     {
    1359            1722 :         const char* pszFieldName = *papszFields;
    1360                 :         // check special fields
    1361            1722 :         if ( EQUAL(pszFieldName, "OGR_GEOMETRY") )
    1362               0 :             poDefn->SetGeometryIgnored( TRUE );
    1363            1722 :         else if ( EQUAL(pszFieldName, "OGR_STYLE") )
    1364               0 :             poDefn->SetStyleIgnored( TRUE );
    1365                 :         else
    1366                 :         {
    1367                 :             // check ordinary fields
    1368            1722 :             int iField = poDefn->GetFieldIndex(pszFieldName);
    1369            1722 :             if ( iField == -1 )
    1370               0 :                 return OGRERR_FAILURE;
    1371                 :             else
    1372            1722 :                 poDefn->GetFieldDefn(iField)->SetIgnored( TRUE );
    1373                 :         }
    1374            1722 :         papszFields++;
    1375                 :     }
    1376                 : 
    1377             330 :     return OGRERR_NONE;
    1378                 : }
    1379                 : 
    1380                 : /************************************************************************/
    1381                 : /*                       OGR_L_SetIgnoredFields()                       */
    1382                 : /************************************************************************/
    1383                 : 
    1384               6 : OGRErr OGR_L_SetIgnoredFields( OGRLayerH hLayer, const char **papszFields )
    1385                 : 
    1386                 : {
    1387               6 :     VALIDATE_POINTER1( hLayer, "OGR_L_SetIgnoredFields", OGRERR_INVALID_HANDLE );
    1388                 : 
    1389               6 :     return ((OGRLayer *) hLayer)->SetIgnoredFields( papszFields );
    1390                 : }

Generated by: LCOV version 1.7