OGR
ogr_feature.h
Go to the documentation of this file.
00001 /******************************************************************************
00002  * $Id: ogr_feature.h 22368 2011-05-13 17:59:41Z rouault $
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     int                 bIgnore;
00062 
00063     void                Initialize( const char *, OGRFieldType );
00064     
00065   public:
00066                         OGRFieldDefn( const char *, OGRFieldType );
00067                         OGRFieldDefn( OGRFieldDefn * );
00068                         ~OGRFieldDefn();
00069 
00070     void                SetName( const char * );
00071     const char         *GetNameRef() { return pszName; }
00072 
00073     OGRFieldType        GetType() { return eType; }
00074     void                SetType( OGRFieldType eTypeIn ) { eType = eTypeIn;}
00075     static const char  *GetFieldTypeName( OGRFieldType );
00076 
00077     OGRJustification    GetJustify() { return eJustify; }
00078     void                SetJustify( OGRJustification eJustifyIn )
00079                                                 { eJustify = eJustifyIn; }
00080 
00081     int                 GetWidth() { return nWidth; }
00082     void                SetWidth( int nWidthIn ) { nWidth = MAX(0,nWidthIn); }
00083 
00084     int                 GetPrecision() { return nPrecision; }
00085     void                SetPrecision( int nPrecisionIn )
00086                                                 { nPrecision = nPrecisionIn; }
00087 
00088     void                Set( const char *, OGRFieldType, int = 0, int = 0,
00089                              OGRJustification = OJUndefined );
00090 
00091     void                SetDefault( const OGRField * );
00092     const OGRField     *GetDefaultRef() { return &uDefault; }
00093     
00094     int                 IsIgnored() { return bIgnore; }
00095     void                SetIgnored( int bIgnore ) { this->bIgnore = bIgnore; }
00096 };
00097 
00098 /************************************************************************/
00099 /*                            OGRFeatureDefn                            */
00100 /************************************************************************/
00101 
00118 class CPL_DLL OGRFeatureDefn
00119 {
00120   private:
00121     volatile int nRefCount;
00122     
00123     int         nFieldCount;
00124     OGRFieldDefn **papoFieldDefn;
00125 
00126     OGRwkbGeometryType eGeomType;
00127 
00128     char        *pszFeatureClassName;
00129     
00130     int         bIgnoreGeometry;
00131     int         bIgnoreStyle;
00132     
00133   public:
00134                 OGRFeatureDefn( const char * pszName = NULL );
00135     virtual    ~OGRFeatureDefn();
00136 
00137     const char  *GetName() { return pszFeatureClassName; }
00138 
00139     int         GetFieldCount() { return nFieldCount; }
00140     OGRFieldDefn *GetFieldDefn( int i );
00141     int         GetFieldIndex( const char * );
00142 
00143     void        AddFieldDefn( OGRFieldDefn * );
00144     OGRErr      DeleteFieldDefn( int iField );
00145     OGRErr      ReorderFieldDefns( int* panMap );
00146 
00147     OGRwkbGeometryType GetGeomType() { return eGeomType; }
00148     void        SetGeomType( OGRwkbGeometryType );
00149 
00150     OGRFeatureDefn *Clone();
00151 
00152     int         Reference() { return CPLAtomicInc(&nRefCount); }
00153     int         Dereference() { return CPLAtomicDec(&nRefCount); }
00154     int         GetReferenceCount() { return nRefCount; }
00155     void        Release();
00156 
00157     int         IsGeometryIgnored() { return bIgnoreGeometry; }
00158     void        SetGeometryIgnored( int bIgnore ) { bIgnoreGeometry = bIgnore; }
00159     int        IsStyleIgnored() { return bIgnoreStyle; }
00160     void        SetStyleIgnored( int bIgnore ) { bIgnoreStyle = bIgnore; }
00161 
00162     static OGRFeatureDefn  *CreateFeatureDefn( const char *pszName = NULL );
00163     static void         DestroyFeatureDefn( OGRFeatureDefn * );
00164 };
00165 
00166 /************************************************************************/
00167 /*                              OGRFeature                              */
00168 /************************************************************************/
00169 
00174 class CPL_DLL OGRFeature
00175 {
00176   private:
00177 
00178     long                nFID;
00179     OGRFeatureDefn      *poDefn;
00180     OGRGeometry         *poGeometry;
00181     OGRField            *pauFields;
00182 
00183   protected: 
00184     char *              m_pszStyleString;
00185     OGRStyleTable       *m_poStyleTable;
00186     char *              m_pszTmpFieldValue;
00187     
00188   public:
00189                         OGRFeature( OGRFeatureDefn * );
00190     virtual            ~OGRFeature();                        
00191 
00192     OGRFeatureDefn     *GetDefnRef() { return poDefn; }
00193     
00194     OGRErr              SetGeometryDirectly( OGRGeometry * );
00195     OGRErr              SetGeometry( OGRGeometry * );
00196     OGRGeometry        *GetGeometryRef() { return poGeometry; }
00197     OGRGeometry        *StealGeometry();
00198 
00199     OGRFeature         *Clone();
00200     virtual OGRBoolean  Equal( OGRFeature * poFeature );
00201 
00202     int                 GetFieldCount() { return poDefn->GetFieldCount(); }
00203     OGRFieldDefn       *GetFieldDefnRef( int iField )
00204                                       { return poDefn->GetFieldDefn(iField); }
00205     int                 GetFieldIndex( const char * pszName)
00206                                       { return poDefn->GetFieldIndex(pszName);}
00207 
00208     int                 IsFieldSet( int iField ) const;
00209     
00210     void                UnsetField( int iField );
00211     
00212     OGRField           *GetRawFieldRef( int i ) { return pauFields + i; }
00213 
00214     int                 GetFieldAsInteger( int i );
00215     double              GetFieldAsDouble( int i );
00216     const char         *GetFieldAsString( int i );
00217     const int          *GetFieldAsIntegerList( int i, int *pnCount );
00218     const double       *GetFieldAsDoubleList( int i, int *pnCount );
00219     char              **GetFieldAsStringList( int i ) const;
00220     GByte              *GetFieldAsBinary( int i, int *pnCount );
00221     int                 GetFieldAsDateTime( int i, 
00222                                      int *pnYear, int *pnMonth, int *pnDay,
00223                                      int *pnHour, int *pnMinute, int *pnSecond, 
00224                                      int *pnTZFlag );
00225 
00226     int                 GetFieldAsInteger( const char *pszFName )
00227                       { return GetFieldAsInteger( GetFieldIndex(pszFName) ); }
00228     double              GetFieldAsDouble( const char *pszFName )
00229                       { return GetFieldAsDouble( GetFieldIndex(pszFName) ); }
00230     const char         *GetFieldAsString( const char *pszFName )
00231                       { return GetFieldAsString( GetFieldIndex(pszFName) ); }
00232     const int          *GetFieldAsIntegerList( const char *pszFName,
00233                                                int *pnCount )
00234                       { return GetFieldAsIntegerList( GetFieldIndex(pszFName),
00235                                                       pnCount ); }
00236     const double       *GetFieldAsDoubleList( const char *pszFName,
00237                                               int *pnCount )
00238                       { return GetFieldAsDoubleList( GetFieldIndex(pszFName),
00239                                                      pnCount ); }
00240     char              **GetFieldAsStringList( const char *pszFName )
00241                       { return GetFieldAsStringList(GetFieldIndex(pszFName)); }
00242 
00243     void                SetField( int i, int nValue );
00244     void                SetField( int i, double dfValue );
00245     void                SetField( int i, const char * pszValue );
00246     void                SetField( int i, int nCount, int * panValues );
00247     void                SetField( int i, int nCount, double * padfValues );
00248     void                SetField( int i, char ** papszValues );
00249     void                SetField( int i, OGRField * puValue );
00250     void                SetField( int i, int nCount, GByte * pabyBinary );
00251     void                SetField( int i, int nYear, int nMonth, int nDay,
00252                                   int nHour=0, int nMinute=0, int nSecond=0, 
00253                                   int nTZFlag = 0 );
00254 
00255     void                SetField( const char *pszFName, int nValue )
00256                            { SetField( GetFieldIndex(pszFName), nValue ); }
00257     void                SetField( const char *pszFName, double dfValue )
00258                            { SetField( GetFieldIndex(pszFName), dfValue ); }
00259     void                SetField( const char *pszFName, const char * pszValue)
00260                            { SetField( GetFieldIndex(pszFName), pszValue ); }
00261     void                SetField( const char *pszFName, int nCount,
00262                                   int * panValues )
00263                          { SetField(GetFieldIndex(pszFName),nCount,panValues);}
00264     void                SetField( const char *pszFName, int nCount,
00265                                   double * padfValues )
00266                          {SetField(GetFieldIndex(pszFName),nCount,padfValues);}
00267     void                SetField( const char *pszFName, char ** papszValues )
00268                            { SetField( GetFieldIndex(pszFName), papszValues); }
00269     void                SetField( const char *pszFName, OGRField * puValue )
00270                            { SetField( GetFieldIndex(pszFName), puValue ); }
00271     void                SetField( const char *pszFName, 
00272                                   int nYear, int nMonth, int nDay,
00273                                   int nHour=0, int nMinute=0, int nSecond=0, 
00274                                   int nTZFlag = 0 )
00275                            { SetField( GetFieldIndex(pszFName), 
00276                                        nYear, nMonth, nDay, 
00277                                        nHour, nMinute, nSecond, nTZFlag ); }
00278 
00279     long                GetFID() { return nFID; }
00280     virtual OGRErr      SetFID( long nFID );
00281 
00282     void                DumpReadable( FILE *, char** papszOptions = NULL );
00283 
00284     OGRErr              SetFrom( OGRFeature *, int = TRUE);
00285     OGRErr              SetFrom( OGRFeature *, int *, int = TRUE );
00286 
00287     OGRErr              RemapFields( OGRFeatureDefn *poNewDefn, 
00288                                      int *panRemapSource );
00289 
00290     virtual const char *GetStyleString();
00291     virtual void        SetStyleString( const char * );
00292     virtual void        SetStyleStringDirectly( char * );
00293     virtual OGRStyleTable *GetStyleTable() { return m_poStyleTable; }
00294     virtual void        SetStyleTable(OGRStyleTable *poStyleTable);
00295     virtual void        SetStyleTableDirectly(OGRStyleTable *poStyleTable)
00296                             { if ( m_poStyleTable ) delete m_poStyleTable;
00297                               m_poStyleTable = poStyleTable; }
00298 
00299     static OGRFeature  *CreateFeature( OGRFeatureDefn * );
00300     static void         DestroyFeature( OGRFeature * );
00301 };
00302 
00303 /************************************************************************/
00304 /*                           OGRFeatureQuery                            */
00305 /************************************************************************/
00306 
00307 class OGRLayer;
00308 
00309 class CPL_DLL OGRFeatureQuery
00310 {
00311   private:
00312     OGRFeatureDefn *poTargetDefn;
00313     void           *pSWQExpr;
00314 
00315     char          **FieldCollector( void *, char ** );
00316     
00317   public:
00318                 OGRFeatureQuery();
00319                 ~OGRFeatureQuery();
00320 
00321     OGRErr      Compile( OGRFeatureDefn *, const char * );
00322     int         Evaluate( OGRFeature * );
00323 
00324     long       *EvaluateAgainstIndices( OGRLayer *, OGRErr * );
00325 
00326     char      **GetUsedFields();
00327 
00328     void       *GetSWGExpr() { return pSWQExpr; }
00329 };
00330 
00331 #endif /* ndef _OGR_FEATURE_H_INCLUDED */

Generated for GDAL by doxygen 1.7.6.1.