OGR
ogr_feature.h
Go to the documentation of this file.
00001 /******************************************************************************
00002  * $Id: ogr_feature.h 18226 2009-12-09 09:30:48Z chaitanya $
00003  *
00004  * Project:  OpenGIS Simple Features Reference Implementation
00005  * Purpose:  Class for representing a whole feature, and layer schemas.
00006  * Author:   Frank Warmerdam, warmerdam@pobox.com
00007  *
00008  ******************************************************************************
00009  * Copyright (c) 1999,  Les Technologies SoftMap Inc.
00010  *
00011  * Permission is hereby granted, free of charge, to any person obtaining a
00012  * copy of this software and associated documentation files (the "Software"),
00013  * to deal in the Software without restriction, including without limitation
00014  * the rights to use, copy, modify, merge, publish, distribute, sublicense,
00015  * and/or sell copies of the Software, and to permit persons to whom the
00016  * Software is furnished to do so, subject to the following conditions:
00017  *
00018  * The above copyright notice and this permission notice shall be included
00019  * in all copies or substantial portions of the Software.
00020  *
00021  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
00022  * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
00023  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
00024  * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
00025  * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
00026  * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
00027  * DEALINGS IN THE SOFTWARE.
00028  ****************************************************************************/
00029 
00030 #ifndef _OGR_FEATURE_H_INCLUDED
00031 #define _OGR_FEATURE_H_INCLUDED
00032 
00033 #include "ogr_geometry.h"
00034 #include "ogr_featurestyle.h"
00035 #include "cpl_atomic_ops.h"
00036 
00043 /************************************************************************/
00044 /*                             OGRFieldDefn                             */
00045 /************************************************************************/
00046 
00051 class CPL_DLL OGRFieldDefn
00052 {
00053   private:
00054     char                *pszName;
00055     OGRFieldType        eType;                  
00056     OGRJustification    eJustify;               
00057     int                 nWidth;                 /* zero is variable */
00058     int                 nPrecision;
00059     OGRField            uDefault;
00060 
00061     void                Initialize( const char *, OGRFieldType );
00062     
00063   public:
00064                         OGRFieldDefn( const char *, OGRFieldType );
00065                         OGRFieldDefn( OGRFieldDefn * );
00066                         ~OGRFieldDefn();
00067 
00068     void                SetName( const char * );
00069     const char         *GetNameRef() { return pszName; }
00070 
00071     OGRFieldType        GetType() { return eType; }
00072     void                SetType( OGRFieldType eTypeIn ) { eType = eTypeIn;}
00073     static const char  *GetFieldTypeName( OGRFieldType );
00074 
00075     OGRJustification    GetJustify() { return eJustify; }
00076     void                SetJustify( OGRJustification eJustifyIn )
00077                                                 { eJustify = eJustifyIn; }
00078 
00079     int                 GetWidth() { return nWidth; }
00080     void                SetWidth( int nWidthIn ) { nWidth = MAX(0,nWidthIn); }
00081 
00082     int                 GetPrecision() { return nPrecision; }
00083     void                SetPrecision( int nPrecisionIn )
00084                                                 { nPrecision = nPrecisionIn; }
00085 
00086     void                Set( const char *, OGRFieldType, int = 0, int = 0,
00087                              OGRJustification = OJUndefined );
00088 
00089     void                SetDefault( const OGRField * );
00090     const OGRField     *GetDefaultRef() { return &uDefault; }
00091 };
00092 
00093 /************************************************************************/
00094 /*                            OGRFeatureDefn                            */
00095 /************************************************************************/
00096 
00113 class CPL_DLL OGRFeatureDefn
00114 {
00115   private:
00116     volatile int nRefCount;
00117     
00118     int         nFieldCount;
00119     OGRFieldDefn **papoFieldDefn;
00120 
00121     OGRwkbGeometryType eGeomType;
00122 
00123     char        *pszFeatureClassName;
00124     
00125   public:
00126                 OGRFeatureDefn( const char * pszName = NULL );
00127     virtual    ~OGRFeatureDefn();
00128 
00129     const char  *GetName() { return pszFeatureClassName; }
00130 
00131     int         GetFieldCount() { return nFieldCount; }
00132     OGRFieldDefn *GetFieldDefn( int i );
00133     int         GetFieldIndex( const char * );
00134 
00135     void        AddFieldDefn( OGRFieldDefn * );
00136 
00137     OGRwkbGeometryType GetGeomType() { return eGeomType; }
00138     void        SetGeomType( OGRwkbGeometryType );
00139 
00140     OGRFeatureDefn *Clone();
00141 
00142     int         Reference() { return CPLAtomicInc(&nRefCount); }
00143     int         Dereference() { return CPLAtomicDec(&nRefCount); }
00144     int         GetReferenceCount() { return nRefCount; }
00145     void        Release();
00146 
00147     static OGRFeatureDefn  *CreateFeatureDefn( const char *pszName = NULL );
00148     static void         DestroyFeatureDefn( OGRFeatureDefn * );
00149 };
00150 
00151 /************************************************************************/
00152 /*                              OGRFeature                              */
00153 /************************************************************************/
00154 
00159 class CPL_DLL OGRFeature
00160 {
00161   private:
00162 
00163     long                nFID;
00164     OGRFeatureDefn      *poDefn;
00165     OGRGeometry         *poGeometry;
00166     OGRField            *pauFields;
00167 
00168   protected: 
00169     char *              m_pszStyleString;
00170     OGRStyleTable       *m_poStyleTable;
00171     char *              m_pszTmpFieldValue;
00172     
00173   public:
00174                         OGRFeature( OGRFeatureDefn * );
00175     virtual            ~OGRFeature();                        
00176 
00177     OGRFeatureDefn     *GetDefnRef() { return poDefn; }
00178     
00179     OGRErr              SetGeometryDirectly( OGRGeometry * );
00180     OGRErr              SetGeometry( OGRGeometry * );
00181     OGRGeometry        *GetGeometryRef() { return poGeometry; }
00182     OGRGeometry        *StealGeometry();
00183 
00184     OGRFeature         *Clone();
00185     virtual OGRBoolean  Equal( OGRFeature * poFeature );
00186 
00187     int                 GetFieldCount() { return poDefn->GetFieldCount(); }
00188     OGRFieldDefn       *GetFieldDefnRef( int iField )
00189                                       { return poDefn->GetFieldDefn(iField); }
00190     int                 GetFieldIndex( const char * pszName)
00191                                       { return poDefn->GetFieldIndex(pszName);}
00192 
00193     int                 IsFieldSet( int iField ) const
00194                         { return
00195                               pauFields[iField].Set.nMarker1 != OGRUnsetMarker
00196                            || pauFields[iField].Set.nMarker2 != OGRUnsetMarker;
00197                               }
00198     
00199     void                UnsetField( int iField );
00200     
00201     OGRField           *GetRawFieldRef( int i ) { return pauFields + i; }
00202 
00203     int                 GetFieldAsInteger( int i );
00204     double              GetFieldAsDouble( int i );
00205     const char         *GetFieldAsString( int i );
00206     const int          *GetFieldAsIntegerList( int i, int *pnCount );
00207     const double       *GetFieldAsDoubleList( int i, int *pnCount );
00208     char              **GetFieldAsStringList( int i ) const;
00209     GByte              *GetFieldAsBinary( int i, int *pnCount );
00210     int                 GetFieldAsDateTime( int i, 
00211                                      int *pnYear, int *pnMonth, int *pnDay,
00212                                      int *pnHour, int *pnMinute, int *pnSecond, 
00213                                      int *pnTZFlag );
00214 
00215     int                 GetFieldAsInteger( const char *pszFName )
00216                       { return GetFieldAsInteger( GetFieldIndex(pszFName) ); }
00217     double              GetFieldAsDouble( const char *pszFName )
00218                       { return GetFieldAsDouble( GetFieldIndex(pszFName) ); }
00219     const char         *GetFieldAsString( const char *pszFName )
00220                       { return GetFieldAsString( GetFieldIndex(pszFName) ); }
00221     const int          *GetFieldAsIntegerList( const char *pszFName,
00222                                                int *pnCount )
00223                       { return GetFieldAsIntegerList( GetFieldIndex(pszFName),
00224                                                       pnCount ); }
00225     const double       *GetFieldAsDoubleList( const char *pszFName,
00226                                               int *pnCount )
00227                       { return GetFieldAsDoubleList( GetFieldIndex(pszFName),
00228                                                      pnCount ); }
00229     char              **GetFieldAsStringList( const char *pszFName )
00230                       { return GetFieldAsStringList(GetFieldIndex(pszFName)); }
00231 
00232     void                SetField( int i, int nValue );
00233     void                SetField( int i, double dfValue );
00234     void                SetField( int i, const char * pszValue );
00235     void                SetField( int i, int nCount, int * panValues );
00236     void                SetField( int i, int nCount, double * padfValues );
00237     void                SetField( int i, char ** papszValues );
00238     void                SetField( int i, OGRField * puValue );
00239     void                SetField( int i, int nCount, GByte * pabyBinary );
00240     void                SetField( int i, int nYear, int nMonth, int nDay,
00241                                   int nHour=0, int nMinute=0, int nSecond=0, 
00242                                   int nTZFlag = 0 );
00243 
00244     void                SetField( const char *pszFName, int nValue )
00245                            { SetField( GetFieldIndex(pszFName), nValue ); }
00246     void                SetField( const char *pszFName, double dfValue )
00247                            { SetField( GetFieldIndex(pszFName), dfValue ); }
00248     void                SetField( const char *pszFName, const char * pszValue)
00249                            { SetField( GetFieldIndex(pszFName), pszValue ); }
00250     void                SetField( const char *pszFName, int nCount,
00251                                   int * panValues )
00252                          { SetField(GetFieldIndex(pszFName),nCount,panValues);}
00253     void                SetField( const char *pszFName, int nCount,
00254                                   double * padfValues )
00255                          {SetField(GetFieldIndex(pszFName),nCount,padfValues);}
00256     void                SetField( const char *pszFName, char ** papszValues )
00257                            { SetField( GetFieldIndex(pszFName), papszValues); }
00258     void                SetField( const char *pszFName, OGRField * puValue )
00259                            { SetField( GetFieldIndex(pszFName), puValue ); }
00260     void                SetField( const char *pszFName, 
00261                                   int nYear, int nMonth, int nDay,
00262                                   int nHour=0, int nMinute=0, int nSecond=0, 
00263                                   int nTZFlag = 0 )
00264                            { SetField( GetFieldIndex(pszFName), 
00265                                        nYear, nMonth, nDay, 
00266                                        nHour, nMinute, nSecond, nTZFlag ); }
00267 
00268     long                GetFID() { return nFID; }
00269     virtual OGRErr      SetFID( long nFID );
00270 
00271     void                DumpReadable( FILE *, char** papszOptions = NULL );
00272 
00273     OGRErr              SetFrom( OGRFeature *, int = TRUE);
00274     OGRErr              SetFrom( OGRFeature *, int *, int = TRUE );
00275 
00276     OGRErr              RemapFields( OGRFeatureDefn *poNewDefn, 
00277                                      int *panRemapSource );
00278 
00279     virtual const char *GetStyleString();
00280     virtual void        SetStyleString( const char * );
00281     virtual void        SetStyleStringDirectly( char * );
00282     virtual OGRStyleTable *GetStyleTable() { return m_poStyleTable; }
00283     virtual void        SetStyleTable(OGRStyleTable *poStyleTable);
00284     virtual void        SetStyleTableDirectly(OGRStyleTable *poStyleTable)
00285                             { if ( m_poStyleTable ) delete m_poStyleTable;
00286                               m_poStyleTable = poStyleTable; }
00287 
00288     static OGRFeature  *CreateFeature( OGRFeatureDefn * );
00289     static void         DestroyFeature( OGRFeature * );
00290 };
00291 
00292 /************************************************************************/
00293 /*                           OGRFeatureQuery                            */
00294 /************************************************************************/
00295 
00296 class OGRLayer;
00297 
00298 class CPL_DLL OGRFeatureQuery
00299 {
00300   private:
00301     OGRFeatureDefn *poTargetDefn;
00302     void           *pSWQExpr;
00303 
00304     char          **FieldCollector( void *, char ** );
00305     
00306   public:
00307                 OGRFeatureQuery();
00308                 ~OGRFeatureQuery();
00309 
00310     OGRErr      Compile( OGRFeatureDefn *, const char * );
00311     int         Evaluate( OGRFeature * );
00312 
00313     long       *EvaluateAgainstIndices( OGRLayer *, OGRErr * );
00314 
00315     char      **GetUsedFields();
00316 
00317     void       *GetSWGExpr() { return pSWQExpr; }
00318 };
00319 
00320 #endif /* ndef _OGR_FEATURE_H_INCLUDED */

Generated for GDAL by doxygen 1.7.4.