LCOV - code coverage report
Current view: directory - ogr/ogrsf_frmts/shape - ogrshape.h (source / functions) Found Hit Coverage
Test: gdal_filtered.info Lines: 5 5 100.0 %
Date: 2011-12-18 Functions: 5 5 100.0 %

       1                 : /******************************************************************************
       2                 :  * $Id: ogrshape.h 23534 2011-12-11 22:35:51Z warmerdam $
       3                 :  *
       4                 :  * Project:  OpenGIS Simple Features Reference Implementation
       5                 :  * Purpose:  Private definitions within the Shapefile driver to implement
       6                 :  *           integration with OGR.
       7                 :  * Author:   Frank Warmerdam, warmerdam@pobox.com
       8                 :  *
       9                 :  ******************************************************************************
      10                 :  * Copyright (c) 1999,  Les Technologies SoftMap Inc.
      11                 :  *
      12                 :  * Permission is hereby granted, free of charge, to any person obtaining a
      13                 :  * copy of this software and associated documentation files (the "Software"),
      14                 :  * to deal in the Software without restriction, including without limitation
      15                 :  * the rights to use, copy, modify, merge, publish, distribute, sublicense,
      16                 :  * and/or sell copies of the Software, and to permit persons to whom the
      17                 :  * Software is furnished to do so, subject to the following conditions:
      18                 :  *
      19                 :  * The above copyright notice and this permission notice shall be included
      20                 :  * in all copies or substantial portions of the Software.
      21                 :  *
      22                 :  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
      23                 :  * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
      24                 :  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
      25                 :  * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
      26                 :  * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
      27                 :  * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
      28                 :  * DEALINGS IN THE SOFTWARE.
      29                 :  ****************************************************************************/
      30                 : 
      31                 : #ifndef _OGRSHAPE_H_INCLUDED
      32                 : #define _OGRSHAPE_H_INCLUDED
      33                 : 
      34                 : #include "ogrsf_frmts.h"
      35                 : #include "shapefil.h"
      36                 : 
      37                 : /* ==================================================================== */
      38                 : /*      Functions from Shape2ogr.cpp.                                   */
      39                 : /* ==================================================================== */
      40                 : OGRFeature *SHPReadOGRFeature( SHPHandle hSHP, DBFHandle hDBF,
      41                 :                                OGRFeatureDefn * poDefn, int iShape, 
      42                 :                                SHPObject *psShape, const char *pszSHPEncoding );
      43                 : OGRGeometry *SHPReadOGRObject( SHPHandle hSHP, int iShape, SHPObject *psShape );
      44                 : OGRFeatureDefn *SHPReadOGRFeatureDefn( const char * pszName,
      45                 :                                        SHPHandle hSHP, DBFHandle hDBF,
      46                 :                                        const char *pszSHPEncoding );
      47                 : OGRErr SHPWriteOGRFeature( SHPHandle hSHP, DBFHandle hDBF,
      48                 :                            OGRFeatureDefn *poFeatureDefn,
      49                 :                            OGRFeature *poFeature, const char *pszSHPEncoding,
      50                 :                            int* pbTruncationWarningEmitted );
      51                 : 
      52                 : /************************************************************************/
      53                 : /*                            OGRShapeLayer                             */
      54                 : /************************************************************************/
      55                 : 
      56                 : class OGRShapeDataSource;
      57                 : 
      58                 : class OGRShapeLayer : public OGRLayer
      59                 : {
      60                 :     OGRShapeDataSource  *poDS;
      61                 :     OGRSpatialReference *poSRS; /* lazy loaded --> use GetSpatialRef() */
      62                 :     int                 bSRSSet;
      63                 :     OGRFeatureDefn     *poFeatureDefn;
      64                 :     int                 iNextShapeId;
      65                 :     int                 nTotalShapeCount;
      66                 : 
      67                 :     char                *pszFullName;
      68                 : 
      69                 :     SHPHandle           hSHP;
      70                 :     DBFHandle           hDBF;
      71                 : 
      72                 :     int                 bUpdateAccess;
      73                 : 
      74                 :     OGRwkbGeometryType  eRequestedGeomType;
      75                 :     int                 ResetGeomType( int nNewType );
      76                 : 
      77                 :     int                 ScanIndices();
      78                 : 
      79                 :     long               *panMatchingFIDs;
      80                 :     int                 iMatchingFID;
      81                 : 
      82                 :     int                 bHeaderDirty;
      83                 : 
      84                 :     int                 bCheckedForQIX;
      85                 :     SHPTreeDiskHandle   hQIX;
      86                 : 
      87                 :     int                 CheckForQIX();
      88                 : 
      89                 :     int                 bSbnSbxDeleted;
      90                 : 
      91                 :     CPLString           ConvertCodePage( const char * );
      92                 :     CPLString           osEncoding;
      93                 : 
      94                 :     int                 bTruncationWarningEmitted;
      95                 : 
      96                 :     int                 bHSHPWasNonNULL; /* to know if we must try to reopen a .shp */
      97                 :     int                 bHDBFWasNonNULL; /* to know if we must try to reopen a .dbf */
      98                 :     int                 eFileDescriptorsState; /* current state of opening of file descriptor to .shp and .dbf */
      99                 :     int                 TouchLayer();
     100                 :     int                 ReopenFileDescriptors();
     101                 : 
     102                 : /* WARNING: each of the below public methods should start with a call to */
     103                 : /* TouchLayer() and test its return value, so as to make sure that */
     104                 : /* the layer is properly re-opened if necessary */
     105                 : 
     106                 :   public:
     107                 :     OGRErr              CreateSpatialIndex( int nMaxDepth );
     108                 :     OGRErr              DropSpatialIndex();
     109                 :     OGRErr              Repack();
     110                 :     OGRErr              RecomputeExtent();
     111                 : 
     112             516 :     const char         *GetFullName() { return pszFullName; }
     113                 : 
     114                 :     void                CloseFileDescriptors();
     115                 : 
     116                 :     /* The 2 following members should not be used by OGRShapeLayer, except */
     117                 :     /* in its constructor */
     118                 :     OGRShapeLayer      *poPrevLayer; /* Chain to a layer that was used more recently */
     119                 :     OGRShapeLayer      *poNextLayer; /* Chain to a layer that was used less recently */
     120                 : 
     121                 :     OGRFeature *        FetchShape(int iShapeId);
     122                 :     int                 GetFeatureCountWithSpatialFilterOnly();
     123                 : 
     124                 :   public:
     125                 :                         OGRShapeLayer( OGRShapeDataSource* poDSIn,
     126                 :                                        const char * pszName,
     127                 :                                        SHPHandle hSHP, DBFHandle hDBF,
     128                 :                                        OGRSpatialReference *poSRS, int bSRSSet,
     129                 :                                        int bUpdate, 
     130                 :                                        OGRwkbGeometryType eReqType );
     131                 :                         ~OGRShapeLayer();
     132                 : 
     133                 :     void                ResetReading();
     134                 :     OGRFeature *        GetNextFeature();
     135                 :     virtual OGRErr      SetNextByIndex( long nIndex );
     136                 : 
     137                 :     OGRFeature         *GetFeature( long nFeatureId );
     138                 :     OGRErr              SetFeature( OGRFeature *poFeature );
     139                 :     OGRErr              DeleteFeature( long nFID );
     140                 :     OGRErr              CreateFeature( OGRFeature *poFeature );
     141                 :     OGRErr              SyncToDisk();
     142                 :     
     143         1835047 :     OGRFeatureDefn *    GetLayerDefn() { return poFeatureDefn; }
     144                 : 
     145                 :     int                 GetFeatureCount( int );
     146                 :     OGRErr              GetExtent(OGREnvelope *psExtent, int bForce);
     147                 : 
     148                 :     virtual OGRErr      CreateField( OGRFieldDefn *poField,
     149                 :                                      int bApproxOK = TRUE );
     150                 :     virtual OGRErr      DeleteField( int iField );
     151                 :     virtual OGRErr      ReorderFields( int* panMap );
     152                 :     virtual OGRErr      AlterFieldDefn( int iField, OGRFieldDefn* poNewFieldDefn, int nFlags );
     153                 : 
     154                 :     virtual OGRSpatialReference *GetSpatialRef();
     155                 :     
     156                 :     int                 TestCapability( const char * );
     157                 : 
     158                 : };
     159                 : 
     160                 : /************************************************************************/
     161                 : /*                          OGRShapeDataSource                          */
     162                 : /************************************************************************/
     163                 : 
     164                 : class OGRShapeDataSource : public OGRDataSource
     165                 : {
     166                 :     OGRShapeLayer     **papoLayers;
     167                 :     int                 nLayers;
     168                 :     
     169                 :     char                *pszName;
     170                 : 
     171                 :     int                 bDSUpdate;
     172                 : 
     173                 :     int                 bSingleFileDataSource;
     174                 : 
     175                 :     OGRShapeLayer      *poMRULayer; /* the most recently used layer */
     176                 :     OGRShapeLayer      *poLRULayer; /* the least recently used layer (still opened) */
     177                 :     int                 nMRUListSize; /* the size of the list */
     178                 : 
     179                 :     void                AddLayer(OGRShapeLayer* poLayer);
     180                 : 
     181                 :   public:
     182                 :                         OGRShapeDataSource();
     183                 :                         ~OGRShapeDataSource();
     184                 : 
     185                 :     int                 Open( const char *, int bUpdate, int bTestOpen,
     186                 :                               int bForceSingleFileDataSource = FALSE );
     187                 :     int                 OpenFile( const char *, int bUpdate, int bTestOpen );
     188                 : 
     189             427 :     const char          *GetName() { return pszName; }
     190          297162 :     int                 GetLayerCount() { return nLayers; }
     191                 :     OGRLayer            *GetLayer( int );
     192                 : 
     193                 :     virtual OGRLayer    *CreateLayer( const char *, 
     194                 :                                       OGRSpatialReference * = NULL,
     195                 :                                       OGRwkbGeometryType = wkbUnknown,
     196                 :                                       char ** = NULL );
     197                 : 
     198                 :     virtual OGRLayer    *ExecuteSQL( const char *pszStatement,
     199                 :                                      OGRGeometry *poSpatialFilter,
     200                 :                                      const char *pszDialect );
     201                 : 
     202                 :     virtual int          TestCapability( const char * );
     203                 :     virtual OGRErr       DeleteLayer( int iLayer );
     204                 : 
     205                 :     void                 SetLastUsedLayer( OGRShapeLayer* poLayer );
     206                 :     void                 UnchainLayer( OGRShapeLayer* poLayer );
     207                 : };
     208                 : 
     209                 : /************************************************************************/
     210                 : /*                            OGRShapeDriver                            */
     211                 : /************************************************************************/
     212                 : 
     213                 : class OGRShapeDriver : public OGRSFDriver
     214             178 : {
     215                 :   public:
     216                 :                 ~OGRShapeDriver();
     217                 :                 
     218                 :     const char *GetName();
     219                 :     OGRDataSource *Open( const char *, int );
     220                 : 
     221                 :     virtual OGRDataSource *CreateDataSource( const char *pszName,
     222                 :                                              char ** = NULL );
     223                 :     OGRErr              DeleteDataSource( const char *pszDataSource );
     224                 :     
     225                 :     int                 TestCapability( const char * );
     226                 : };
     227                 : 
     228                 : 
     229                 : #endif /* ndef _OGRSHAPE_H_INCLUDED */

Generated by: LCOV version 1.7