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: 2011-12-18 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              29 : OGREDIGEOLayer::OGREDIGEOLayer( OGREDIGEODataSource* poDS,
      43                 :                                 const char* pszName, OGRwkbGeometryType eType,
      44              29 :                                 OGRSpatialReference* poSRS )
      45                 : 
      46                 : {
      47              29 :     this->poDS = poDS;
      48              29 :     nNextFID = 0;
      49                 : 
      50              29 :     this->poSRS = poSRS;
      51              29 :     if (poSRS)
      52              29 :         poSRS->Reference();
      53                 : 
      54              29 :     poFeatureDefn = new OGRFeatureDefn( pszName );
      55              29 :     poFeatureDefn->Reference();
      56              29 :     poFeatureDefn->SetGeomType( eType );
      57              29 : }
      58                 : 
      59                 : /************************************************************************/
      60                 : /*                          ~OGREDIGEOLayer()                           */
      61                 : /************************************************************************/
      62                 : 
      63              29 : OGREDIGEOLayer::~OGREDIGEOLayer()
      64                 : 
      65                 : {
      66            1028 :     for(int i=0;i<(int)aosFeatures.size();i++)
      67             999 :         delete aosFeatures[i];
      68                 : 
      69              29 :     poFeatureDefn->Release();
      70                 : 
      71              29 :     if (poSRS)
      72              29 :         poSRS->Release();
      73              29 : }
      74                 : 
      75                 : 
      76                 : /************************************************************************/
      77                 : /*                            ResetReading()                            */
      78                 : /************************************************************************/
      79                 : 
      80               1 : void OGREDIGEOLayer::ResetReading()
      81                 : 
      82                 : {
      83               1 :     nNextFID = 0;
      84               1 : }
      85                 : 
      86                 : 
      87                 : /************************************************************************/
      88                 : /*                           GetNextFeature()                           */
      89                 : /************************************************************************/
      90                 : 
      91             252 : OGRFeature *OGREDIGEOLayer::GetNextFeature()
      92                 : {
      93                 :     OGRFeature  *poFeature;
      94                 : 
      95               0 :     while(TRUE)
      96                 :     {
      97             252 :         poFeature = GetNextRawFeature();
      98             252 :         if (poFeature == NULL)
      99               1 :             return NULL;
     100                 : 
     101             251 :         if((m_poFilterGeom == NULL
     102                 :             || FilterGeometry( poFeature->GetGeometryRef() ) )
     103                 :         && (m_poAttrQuery == NULL
     104                 :             || m_poAttrQuery->Evaluate( poFeature )) )
     105                 :         {
     106             251 :             return poFeature;
     107                 :         }
     108                 :         else
     109               0 :             delete poFeature;
     110                 :     }
     111                 : }
     112                 : 
     113                 : /************************************************************************/
     114                 : /*                         GetNextRawFeature()                          */
     115                 : /************************************************************************/
     116                 : 
     117             252 : OGRFeature *OGREDIGEOLayer::GetNextRawFeature()
     118                 : {
     119             252 :     if (nNextFID < (int)aosFeatures.size())
     120                 :     {
     121             251 :         OGRFeature* poFeature = aosFeatures[nNextFID]->Clone();
     122             251 :         nNextFID++;
     123             251 :         return poFeature;
     124                 :     }
     125                 :     else
     126               1 :         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              39 : int OGREDIGEOLayer::GetFeatureCount( int bForce )
     183                 : {
     184              39 :     if (m_poFilterGeom != NULL || m_poAttrQuery != NULL)
     185               0 :         return OGRLayer::GetFeatureCount(bForce);
     186                 : 
     187              39 :     return (int)aosFeatures.size();
     188                 : }
     189                 : 
     190                 : /************************************************************************/
     191                 : /*                             AddFeature()                             */
     192                 : /************************************************************************/
     193                 : 
     194             999 : void OGREDIGEOLayer::AddFeature(OGRFeature* poFeature)
     195                 : {
     196             999 :     poFeature->SetFID(aosFeatures.size());
     197             999 :     aosFeatures.push_back(poFeature);
     198             999 : }
     199                 : 
     200                 : /************************************************************************/
     201                 : /*                         GetAttributeIndex()                          */
     202                 : /************************************************************************/
     203                 : 
     204            4252 : int OGREDIGEOLayer::GetAttributeIndex(const CPLString& osRID)
     205                 : {
     206                 :     std::map<CPLString,int>::iterator itAttrIndex =
     207            4252 :                                             mapAttributeToIndex.find(osRID);
     208            4252 :     if (itAttrIndex != mapAttributeToIndex.end())
     209            4252 :         return itAttrIndex->second;
     210                 :     else
     211               0 :         return -1;
     212                 : }
     213                 : 
     214                 : /************************************************************************/
     215                 : /*                           AddFieldDefn()                             */
     216                 : /************************************************************************/
     217                 : 
     218             176 : void OGREDIGEOLayer::AddFieldDefn(const CPLString& osName,
     219                 :                                   OGRFieldType eType,
     220                 :                                   const CPLString& osRID)
     221                 : {
     222             176 :     if (osRID.size() != 0)
     223             107 :         mapAttributeToIndex[osRID] = poFeatureDefn->GetFieldCount();
     224                 : 
     225             176 :     OGRFieldDefn oFieldDefn(osName, eType);
     226             176 :     poFeatureDefn->AddFieldDefn(&oFieldDefn);
     227             176 : }

Generated by: LCOV version 1.7