LCOV - code coverage report
Current view: directory - ogr/ogrsf_frmts/edigeo - ogredigeolayer.cpp (source / functions) Found Hit Coverage
Test: gdal_filtered.info Lines: 68 50 73.5 %
Date: 2012-04-28 Functions: 15 9 60.0 %

       1                 : /******************************************************************************
       2                 :  * $Id: ogredigeolayer.cpp 22195 2011-04-17 18:21:14Z rouault $
       3                 :  *
       4                 :  * Project:  EDIGEO Translator
       5                 :  * Purpose:  Implements OGREDIGEOLayer class.
       6                 :  * Author:   Even Rouault, <even dot rouault at mines dash paris dot org>
       7                 :  *
       8                 :  ******************************************************************************
       9                 :  * Copyright (c) 2011, Even Rouault <even dot rouault at mines dash paris dot org>
      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_edigeo.h"
      31                 : #include "cpl_conv.h"
      32                 : #include "cpl_string.h"
      33                 : #include "ogr_p.h"
      34                 : #include "ogr_srs_api.h"
      35                 : 
      36                 : CPL_CVSID("$Id: ogredigeolayer.cpp 22195 2011-04-17 18:21:14Z rouault $");
      37                 : 
      38                 : /************************************************************************/
      39                 : /*                          OGREDIGEOLayer()                            */
      40                 : /************************************************************************/
      41                 : 
      42              58 : OGREDIGEOLayer::OGREDIGEOLayer( OGREDIGEODataSource* poDS,
      43                 :                                 const char* pszName, OGRwkbGeometryType eType,
      44              58 :                                 OGRSpatialReference* poSRS )
      45                 : 
      46                 : {
      47              58 :     this->poDS = poDS;
      48              58 :     nNextFID = 0;
      49                 : 
      50              58 :     this->poSRS = poSRS;
      51              58 :     if (poSRS)
      52              58 :         poSRS->Reference();
      53                 : 
      54              58 :     poFeatureDefn = new OGRFeatureDefn( pszName );
      55              58 :     poFeatureDefn->Reference();
      56              58 :     poFeatureDefn->SetGeomType( eType );
      57              58 : }
      58                 : 
      59                 : /************************************************************************/
      60                 : /*                          ~OGREDIGEOLayer()                           */
      61                 : /************************************************************************/
      62                 : 
      63              58 : OGREDIGEOLayer::~OGREDIGEOLayer()
      64                 : 
      65                 : {
      66            2056 :     for(int i=0;i<(int)aosFeatures.size();i++)
      67            1998 :         delete aosFeatures[i];
      68                 : 
      69              58 :     poFeatureDefn->Release();
      70                 : 
      71              58 :     if (poSRS)
      72              58 :         poSRS->Release();
      73              58 : }
      74                 : 
      75                 : 
      76                 : /************************************************************************/
      77                 : /*                            ResetReading()                            */
      78                 : /************************************************************************/
      79                 : 
      80               2 : void OGREDIGEOLayer::ResetReading()
      81                 : 
      82                 : {
      83               2 :     nNextFID = 0;
      84               2 : }
      85                 : 
      86                 : 
      87                 : /************************************************************************/
      88                 : /*                           GetNextFeature()                           */
      89                 : /************************************************************************/
      90                 : 
      91             504 : OGRFeature *OGREDIGEOLayer::GetNextFeature()
      92                 : {
      93                 :     OGRFeature  *poFeature;
      94                 : 
      95               0 :     while(TRUE)
      96                 :     {
      97             504 :         poFeature = GetNextRawFeature();
      98             504 :         if (poFeature == NULL)
      99               2 :             return NULL;
     100                 : 
     101             502 :         if((m_poFilterGeom == NULL
     102                 :             || FilterGeometry( poFeature->GetGeometryRef() ) )
     103                 :         && (m_poAttrQuery == NULL
     104                 :             || m_poAttrQuery->Evaluate( poFeature )) )
     105                 :         {
     106             502 :             return poFeature;
     107                 :         }
     108                 :         else
     109               0 :             delete poFeature;
     110                 :     }
     111                 : }
     112                 : 
     113                 : /************************************************************************/
     114                 : /*                         GetNextRawFeature()                          */
     115                 : /************************************************************************/
     116                 : 
     117             504 : OGRFeature *OGREDIGEOLayer::GetNextRawFeature()
     118                 : {
     119             504 :     if (nNextFID < (int)aosFeatures.size())
     120                 :     {
     121             502 :         OGRFeature* poFeature = aosFeatures[nNextFID]->Clone();
     122             502 :         nNextFID++;
     123             502 :         return poFeature;
     124                 :     }
     125                 :     else
     126               2 :         return NULL;
     127                 : }
     128                 : 
     129                 : /************************************************************************/
     130                 : /*                            GetFeature()                              */
     131                 : /************************************************************************/
     132                 : 
     133               0 : OGRFeature * OGREDIGEOLayer::GetFeature(long nFID)
     134                 : {
     135               0 :     if (nFID >= 0 && nFID < (int)aosFeatures.size())
     136               0 :         return aosFeatures[nFID]->Clone();
     137                 :     else
     138               0 :         return NULL;
     139                 : }
     140                 : 
     141                 : /************************************************************************/
     142                 : /*                           TestCapability()                           */
     143                 : /************************************************************************/
     144                 : 
     145               0 : int OGREDIGEOLayer::TestCapability( const char * pszCap )
     146                 : 
     147                 : {
     148               0 :     if (EQUAL(pszCap, OLCFastFeatureCount))
     149               0 :         return m_poFilterGeom == NULL && m_poAttrQuery == NULL;
     150                 : 
     151               0 :     else if (EQUAL(pszCap, OLCRandomRead))
     152               0 :         return TRUE;
     153                 : 
     154               0 :     else if (EQUAL(pszCap, OLCStringsAsUTF8))
     155               0 :         return poDS->HasUTF8ContentOnly();
     156                 : 
     157               0 :     return FALSE;
     158                 : }
     159                 : 
     160                 : /************************************************************************/
     161                 : /*                              GetExtent()                             */
     162                 : /************************************************************************/
     163                 : 
     164               0 : OGRErr OGREDIGEOLayer::GetExtent(OGREnvelope *psExtent, int bForce)
     165                 : {
     166                 :     /*if (poDS->bExtentValid)
     167                 :     {
     168                 :         psExtent->MinX = poDS->dfMinX;
     169                 :         psExtent->MinY = poDS->dfMinY;
     170                 :         psExtent->MaxX = poDS->dfMaxX;
     171                 :         psExtent->MaxY = poDS->dfMaxY;
     172                 :         return OGRERR_NONE;
     173                 :     }*/
     174                 : 
     175               0 :     return OGRLayer::GetExtent(psExtent, bForce);
     176                 : }
     177                 : 
     178                 : /************************************************************************/
     179                 : /*                          GetFeatureCount()                           */
     180                 : /************************************************************************/
     181                 : 
     182              78 : int OGREDIGEOLayer::GetFeatureCount( int bForce )
     183                 : {
     184              78 :     if (m_poFilterGeom != NULL || m_poAttrQuery != NULL)
     185               0 :         return OGRLayer::GetFeatureCount(bForce);
     186                 : 
     187              78 :     return (int)aosFeatures.size();
     188                 : }
     189                 : 
     190                 : /************************************************************************/
     191                 : /*                             AddFeature()                             */
     192                 : /************************************************************************/
     193                 : 
     194            1998 : void OGREDIGEOLayer::AddFeature(OGRFeature* poFeature)
     195                 : {
     196            1998 :     poFeature->SetFID(aosFeatures.size());
     197            1998 :     aosFeatures.push_back(poFeature);
     198            1998 : }
     199                 : 
     200                 : /************************************************************************/
     201                 : /*                         GetAttributeIndex()                          */
     202                 : /************************************************************************/
     203                 : 
     204            8504 : int OGREDIGEOLayer::GetAttributeIndex(const CPLString& osRID)
     205                 : {
     206                 :     std::map<CPLString,int>::iterator itAttrIndex =
     207            8504 :                                             mapAttributeToIndex.find(osRID);
     208            8504 :     if (itAttrIndex != mapAttributeToIndex.end())
     209            8504 :         return itAttrIndex->second;
     210                 :     else
     211               0 :         return -1;
     212                 : }
     213                 : 
     214                 : /************************************************************************/
     215                 : /*                           AddFieldDefn()                             */
     216                 : /************************************************************************/
     217                 : 
     218             352 : void OGREDIGEOLayer::AddFieldDefn(const CPLString& osName,
     219                 :                                   OGRFieldType eType,
     220                 :                                   const CPLString& osRID)
     221                 : {
     222             352 :     if (osRID.size() != 0)
     223             214 :         mapAttributeToIndex[osRID] = poFeatureDefn->GetFieldCount();
     224                 : 
     225             352 :     OGRFieldDefn oFieldDefn(osName, eType);
     226             352 :     poFeatureDefn->AddFieldDefn(&oFieldDefn);
     227             352 : }

Generated by: LCOV version 1.7