LCOV - code coverage report
Current view: directory - ogr - ogr_feature.h (source / functions) Found Hit Coverage
Test: gdal_filtered.info Lines: 35 28 80.0 %
Date: 2010-01-09 Functions: 26 22 84.6 %

       1                 : /******************************************************************************
       2                 :  * $Id: ogr_feature.h 18226 2009-12-09 09:30:48Z chaitanya $
       3                 :  *
       4                 :  * Project:  OpenGIS Simple Features Reference Implementation
       5                 :  * Purpose:  Class for representing a whole feature, and layer schemas.
       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                 : #ifndef _OGR_FEATURE_H_INCLUDED
      31                 : #define _OGR_FEATURE_H_INCLUDED
      32                 : 
      33                 : #include "ogr_geometry.h"
      34                 : #include "ogr_featurestyle.h"
      35                 : #include "cpl_atomic_ops.h"
      36                 : 
      37                 : /**
      38                 :  * \file ogr_feature.h
      39                 :  *
      40                 :  * Simple feature classes.
      41                 :  */
      42                 : 
      43                 : /************************************************************************/
      44                 : /*                             OGRFieldDefn                             */
      45                 : /************************************************************************/
      46                 : 
      47                 : /**
      48                 :  * Definition of an attribute of an OGRFeatureDefn.
      49                 :  */
      50                 : 
      51                 : class CPL_DLL OGRFieldDefn
      52                 : {
      53                 :   private:
      54                 :     char                *pszName;
      55                 :     OGRFieldType        eType;                  
      56                 :     OGRJustification    eJustify;               
      57                 :     int                 nWidth;                 /* zero is variable */
      58                 :     int                 nPrecision;
      59                 :     OGRField            uDefault;
      60                 : 
      61                 :     void                Initialize( const char *, OGRFieldType );
      62                 :     
      63                 :   public:
      64                 :                         OGRFieldDefn( const char *, OGRFieldType );
      65                 :                         OGRFieldDefn( OGRFieldDefn * );
      66                 :                         ~OGRFieldDefn();
      67                 : 
      68                 :     void                SetName( const char * );
      69          102262 :     const char         *GetNameRef() { return pszName; }
      70                 : 
      71          894018 :     OGRFieldType        GetType() { return eType; }
      72            5250 :     void                SetType( OGRFieldType eTypeIn ) { eType = eTypeIn;}
      73                 :     static const char  *GetFieldTypeName( OGRFieldType );
      74                 : 
      75            7910 :     OGRJustification    GetJustify() { return eJustify; }
      76            8213 :     void                SetJustify( OGRJustification eJustifyIn )
      77            8213 :                                                 { eJustify = eJustifyIn; }
      78                 : 
      79           12090 :     int                 GetWidth() { return nWidth; }
      80           11731 :     void                SetWidth( int nWidthIn ) { nWidth = MAX(0,nWidthIn); }
      81                 : 
      82            8453 :     int                 GetPrecision() { return nPrecision; }
      83           10405 :     void                SetPrecision( int nPrecisionIn )
      84           10405 :                                                 { nPrecision = nPrecisionIn; }
      85                 : 
      86                 :     void                Set( const char *, OGRFieldType, int = 0, int = 0,
      87                 :                              OGRJustification = OJUndefined );
      88                 : 
      89                 :     void                SetDefault( const OGRField * );
      90                 :     const OGRField     *GetDefaultRef() { return &uDefault; }
      91                 : };
      92                 : 
      93                 : /************************************************************************/
      94                 : /*                            OGRFeatureDefn                            */
      95                 : /************************************************************************/
      96                 : 
      97                 : /**
      98                 :  * Definition of a feature class or feature layer.
      99                 :  *
     100                 :  * This object contains schema information for a set of OGRFeatures.  In
     101                 :  * table based systems, an OGRFeatureDefn is essentially a layer.  In more
     102                 :  * object oriented approaches (such as SF CORBA) this can represent a class
     103                 :  * of features but doesn't necessarily relate to all of a layer, or just one
     104                 :  * layer.
     105                 :  *
     106                 :  * This object also can contain some other information such as a name, the
     107                 :  * base geometry type and potentially other metadata.
     108                 :  *
     109                 :  * It is reasonable for different translators to derive classes from
     110                 :  * OGRFeatureDefn with additional translator specific information. 
     111                 :  */
     112                 : 
     113                 : class CPL_DLL OGRFeatureDefn
     114                 : {
     115                 :   private:
     116                 :     volatile int nRefCount;
     117                 :     
     118                 :     int         nFieldCount;
     119                 :     OGRFieldDefn **papoFieldDefn;
     120                 : 
     121                 :     OGRwkbGeometryType eGeomType;
     122                 : 
     123                 :     char        *pszFeatureClassName;
     124                 :     
     125                 :   public:
     126                 :                 OGRFeatureDefn( const char * pszName = NULL );
     127                 :     virtual    ~OGRFeatureDefn();
     128                 : 
     129           16792 :     const char  *GetName() { return pszFeatureClassName; }
     130                 : 
     131         1435594 :     int         GetFieldCount() { return nFieldCount; }
     132                 :     OGRFieldDefn *GetFieldDefn( int i );
     133                 :     int         GetFieldIndex( const char * );
     134                 : 
     135                 :     void        AddFieldDefn( OGRFieldDefn * );
     136                 : 
     137             386 :     OGRwkbGeometryType GetGeomType() { return eGeomType; }
     138                 :     void        SetGeomType( OGRwkbGeometryType );
     139                 : 
     140                 :     OGRFeatureDefn *Clone();
     141                 : 
     142           71885 :     int         Reference() { return CPLAtomicInc(&nRefCount); }
     143           71885 :     int         Dereference() { return CPLAtomicDec(&nRefCount); }
     144               0 :     int         GetReferenceCount() { return nRefCount; }
     145                 :     void        Release();
     146                 : 
     147                 :     static OGRFeatureDefn  *CreateFeatureDefn( const char *pszName = NULL );
     148                 :     static void         DestroyFeatureDefn( OGRFeatureDefn * );
     149                 : };
     150                 : 
     151                 : /************************************************************************/
     152                 : /*                              OGRFeature                              */
     153                 : /************************************************************************/
     154                 : 
     155                 : /**
     156                 :  * A simple feature, including geometry and attributes.
     157                 :  */
     158                 : 
     159                 : class CPL_DLL OGRFeature
     160                 : {
     161                 :   private:
     162                 : 
     163                 :     long                nFID;
     164                 :     OGRFeatureDefn      *poDefn;
     165                 :     OGRGeometry         *poGeometry;
     166                 :     OGRField            *pauFields;
     167                 : 
     168                 :   protected: 
     169                 :     char *              m_pszStyleString;
     170                 :     OGRStyleTable       *m_poStyleTable;
     171                 :     char *              m_pszTmpFieldValue;
     172                 :     
     173                 :   public:
     174                 :                         OGRFeature( OGRFeatureDefn * );
     175                 :     virtual            ~OGRFeature();                        
     176                 : 
     177           13071 :     OGRFeatureDefn     *GetDefnRef() { return poDefn; }
     178                 :     
     179                 :     OGRErr              SetGeometryDirectly( OGRGeometry * );
     180                 :     OGRErr              SetGeometry( OGRGeometry * );
     181           69711 :     OGRGeometry        *GetGeometryRef() { return poGeometry; }
     182                 :     OGRGeometry        *StealGeometry();
     183                 : 
     184                 :     OGRFeature         *Clone();
     185                 :     virtual OGRBoolean  Equal( OGRFeature * poFeature );
     186                 : 
     187            6147 :     int                 GetFieldCount() { return poDefn->GetFieldCount(); }
     188            3669 :     OGRFieldDefn       *GetFieldDefnRef( int iField )
     189            3669 :                                       { return poDefn->GetFieldDefn(iField); }
     190            6499 :     int                 GetFieldIndex( const char * pszName)
     191            6499 :                                       { return poDefn->GetFieldIndex(pszName);}
     192                 : 
     193          685159 :     int                 IsFieldSet( int iField ) const
     194                 :                         { return
     195          685159 :                               pauFields[iField].Set.nMarker1 != OGRUnsetMarker
     196          685159 :                            || pauFields[iField].Set.nMarker2 != OGRUnsetMarker;
     197                 :                               }
     198                 :     
     199                 :     void                UnsetField( int iField );
     200                 :     
     201            1777 :     OGRField           *GetRawFieldRef( int i ) { return pauFields + i; }
     202                 : 
     203                 :     int                 GetFieldAsInteger( int i );
     204                 :     double              GetFieldAsDouble( int i );
     205                 :     const char         *GetFieldAsString( int i );
     206                 :     const int          *GetFieldAsIntegerList( int i, int *pnCount );
     207                 :     const double       *GetFieldAsDoubleList( int i, int *pnCount );
     208                 :     char              **GetFieldAsStringList( int i ) const;
     209                 :     GByte              *GetFieldAsBinary( int i, int *pnCount );
     210                 :     int                 GetFieldAsDateTime( int i, 
     211                 :                                      int *pnYear, int *pnMonth, int *pnDay,
     212                 :                                      int *pnHour, int *pnMinute, int *pnSecond, 
     213                 :                                      int *pnTZFlag );
     214                 : 
     215                 :     int                 GetFieldAsInteger( const char *pszFName )
     216                 :                       { return GetFieldAsInteger( GetFieldIndex(pszFName) ); }
     217                 :     double              GetFieldAsDouble( const char *pszFName )
     218                 :                       { return GetFieldAsDouble( GetFieldIndex(pszFName) ); }
     219                 :     const char         *GetFieldAsString( const char *pszFName )
     220                 :                       { return GetFieldAsString( GetFieldIndex(pszFName) ); }
     221                 :     const int          *GetFieldAsIntegerList( const char *pszFName,
     222                 :                                                int *pnCount )
     223                 :                       { return GetFieldAsIntegerList( GetFieldIndex(pszFName),
     224                 :                                                       pnCount ); }
     225                 :     const double       *GetFieldAsDoubleList( const char *pszFName,
     226                 :                                               int *pnCount )
     227                 :                       { return GetFieldAsDoubleList( GetFieldIndex(pszFName),
     228                 :                                                      pnCount ); }
     229                 :     char              **GetFieldAsStringList( const char *pszFName )
     230                 :                       { return GetFieldAsStringList(GetFieldIndex(pszFName)); }
     231                 : 
     232                 :     void                SetField( int i, int nValue );
     233                 :     void                SetField( int i, double dfValue );
     234                 :     void                SetField( int i, const char * pszValue );
     235                 :     void                SetField( int i, int nCount, int * panValues );
     236                 :     void                SetField( int i, int nCount, double * padfValues );
     237                 :     void                SetField( int i, char ** papszValues );
     238                 :     void                SetField( int i, OGRField * puValue );
     239                 :     void                SetField( int i, int nCount, GByte * pabyBinary );
     240                 :     void                SetField( int i, int nYear, int nMonth, int nDay,
     241                 :                                   int nHour=0, int nMinute=0, int nSecond=0, 
     242                 :                                   int nTZFlag = 0 );
     243                 : 
     244                 :     void                SetField( const char *pszFName, int nValue )
     245                 :                            { SetField( GetFieldIndex(pszFName), nValue ); }
     246                 :     void                SetField( const char *pszFName, double dfValue )
     247                 :                            { SetField( GetFieldIndex(pszFName), dfValue ); }
     248               0 :     void                SetField( const char *pszFName, const char * pszValue)
     249               0 :                            { SetField( GetFieldIndex(pszFName), pszValue ); }
     250                 :     void                SetField( const char *pszFName, int nCount,
     251                 :                                   int * panValues )
     252                 :                          { SetField(GetFieldIndex(pszFName),nCount,panValues);}
     253                 :     void                SetField( const char *pszFName, int nCount,
     254                 :                                   double * padfValues )
     255                 :                          {SetField(GetFieldIndex(pszFName),nCount,padfValues);}
     256                 :     void                SetField( const char *pszFName, char ** papszValues )
     257                 :                            { SetField( GetFieldIndex(pszFName), papszValues); }
     258                 :     void                SetField( const char *pszFName, OGRField * puValue )
     259                 :                            { SetField( GetFieldIndex(pszFName), puValue ); }
     260                 :     void                SetField( const char *pszFName, 
     261                 :                                   int nYear, int nMonth, int nDay,
     262                 :                                   int nHour=0, int nMinute=0, int nSecond=0, 
     263                 :                                   int nTZFlag = 0 )
     264                 :                            { SetField( GetFieldIndex(pszFName), 
     265                 :                                        nYear, nMonth, nDay, 
     266                 :                                        nHour, nMinute, nSecond, nTZFlag ); }
     267                 : 
     268           70875 :     long                GetFID() { return nFID; }
     269                 :     virtual OGRErr      SetFID( long nFID );
     270                 : 
     271                 :     void                DumpReadable( FILE *, char** papszOptions = NULL );
     272                 : 
     273                 :     OGRErr              SetFrom( OGRFeature *, int = TRUE);
     274                 :     OGRErr              SetFrom( OGRFeature *, int *, int = TRUE );
     275                 : 
     276                 :     OGRErr              RemapFields( OGRFeatureDefn *poNewDefn, 
     277                 :                                      int *panRemapSource );
     278                 : 
     279                 :     virtual const char *GetStyleString();
     280                 :     virtual void        SetStyleString( const char * );
     281                 :     virtual void        SetStyleStringDirectly( char * );
     282               0 :     virtual OGRStyleTable *GetStyleTable() { return m_poStyleTable; }
     283                 :     virtual void        SetStyleTable(OGRStyleTable *poStyleTable);
     284               0 :     virtual void        SetStyleTableDirectly(OGRStyleTable *poStyleTable)
     285               0 :                             { if ( m_poStyleTable ) delete m_poStyleTable;
     286               0 :                               m_poStyleTable = poStyleTable; }
     287                 : 
     288                 :     static OGRFeature  *CreateFeature( OGRFeatureDefn * );
     289                 :     static void         DestroyFeature( OGRFeature * );
     290                 : };
     291                 : 
     292                 : /************************************************************************/
     293                 : /*                           OGRFeatureQuery                            */
     294                 : /************************************************************************/
     295                 : 
     296                 : class OGRLayer;
     297                 : 
     298                 : class CPL_DLL OGRFeatureQuery
     299                 : {
     300                 :   private:
     301                 :     OGRFeatureDefn *poTargetDefn;
     302                 :     void           *pSWQExpr;
     303                 : 
     304                 :     char          **FieldCollector( void *, char ** );
     305                 :     
     306                 :   public:
     307                 :                 OGRFeatureQuery();
     308                 :                 ~OGRFeatureQuery();
     309                 : 
     310                 :     OGRErr      Compile( OGRFeatureDefn *, const char * );
     311                 :     int         Evaluate( OGRFeature * );
     312                 : 
     313                 :     long       *EvaluateAgainstIndices( OGRLayer *, OGRErr * );
     314                 : 
     315                 :     char      **GetUsedFields();
     316                 : 
     317                 :     void       *GetSWGExpr() { return pSWQExpr; }
     318                 : };
     319                 : 
     320                 : #endif /* ndef _OGR_FEATURE_H_INCLUDED */

Generated by: LCOV version 1.7