- Main Page
- Related Pages
- Classes
- Files
- Directories

- File List
- File Members

# ogr_feature.h

Go to the documentation of this file.

    00001 /******************************************************************************
    00002  * $Id: ogr_feature.h 27110 2014-03-28 21:29:20Z 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  * Copyright (c) 2008-2013, Even Rouault <even dot rouault at mines-paris dot org>
    00011  *
    00012  * Permission is hereby granted, free of charge, to any person obtaining a
    00013  * copy of this software and associated documentation files (the "Software"),
    00014  * to deal in the Software without restriction, including without limitation
    00015  * the rights to use, copy, modify, merge, publish, distribute, sublicense,
    00016  * and/or sell copies of the Software, and to permit persons to whom the
    00017  * Software is furnished to do so, subject to the following conditions:
    00018  *
    00019  * The above copyright notice and this permission notice shall be included
    00020  * in all copies or substantial portions of the Software.
    00021  *
    00022  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
    00023  * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
    00024  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
    00025  * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
    00026  * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
    00027  * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
    00028  * DEALINGS IN THE SOFTWARE.
    00029  ****************************************************************************/
    00030
    00031 #ifndef _OGR_FEATURE_H_INCLUDED
    00032 #define _OGR_FEATURE_H_INCLUDED
    00033
    00034 #include "ogr_geometry.h"
    00035 #include "ogr_featurestyle.h"
    00036 #include "cpl_atomic_ops.h"
    00037
    00044 /************************************************************************/
    00045 /*                             OGRFieldDefn                             */
    00046 /************************************************************************/
    00047
    00052 class CPL_DLL OGRFieldDefn
    00053 {
    00054   private:
    00055     char                *pszName;
    00056     OGRFieldType        eType;
    00057     OGRJustification    eJustify;
    00058     int                 nWidth;                 /* zero is variable */
    00059     int                 nPrecision;
    00060     OGRField            uDefault;
    00061
    00062     int                 bIgnore;
    00063
    00064     void                Initialize( const char *, OGRFieldType );
    00065
    00066   public:
    00067                         OGRFieldDefn( const char *, OGRFieldType );
    00068                         OGRFieldDefn( OGRFieldDefn * );
    00069                         ~OGRFieldDefn();
    00070
    00071     void                SetName( const char * );
    00072     const char         *GetNameRef() { return pszName; }
    00073
    00074     OGRFieldType        GetType() { return eType; }
    00075     void                SetType( OGRFieldType eTypeIn ) { eType = eTypeIn;}
    00076     static const char  *GetFieldTypeName( OGRFieldType );
    00077
    00078     OGRJustification    GetJustify() { return eJustify; }
    00079     void                SetJustify( OGRJustification eJustifyIn )
    00080                                                 { eJustify = eJustifyIn; }
    00081
    00082     int                 GetWidth() { return nWidth; }
    00083     void                SetWidth( int nWidthIn ) { nWidth = MAX(0,nWidthIn); }
    00084
    00085     int                 GetPrecision() { return nPrecision; }
    00086     void                SetPrecision( int nPrecisionIn )
    00087                                                 { nPrecision = nPrecisionIn; }
    00088
    00089     void                Set( const char *, OGRFieldType, int = 0, int = 0,
    00090                              OGRJustification = OJUndefined );
    00091
    00092     void                SetDefault( const OGRField * );
    00093     const OGRField     *GetDefaultRef() { return &uDefault; }
    00094
    00095     int                 IsIgnored() { return bIgnore; }
    00096     void                SetIgnored( int bIgnore ) { this->bIgnore = bIgnore; }
    00097
    00098     int                 IsSame( const OGRFieldDefn * ) const;
    00099 };
    00100
    00101 /************************************************************************/
    00102 /*                          OGRGeomFieldDefn                            */
    00103 /************************************************************************/
    00104
    00112 class CPL_DLL OGRGeomFieldDefn
    00113 {
    00114 protected:
    00115         char                *pszName;
    00116         OGRwkbGeometryType   eGeomType; /* all values possible except wkbNone */
    00117         OGRSpatialReference* poSRS;
    00118
    00119         int                 bIgnore;
    00120
    00121         void                Initialize( const char *, OGRwkbGeometryType );
    00122
    00123 public:
    00124                             OGRGeomFieldDefn(const char *pszNameIn,
    00125                                              OGRwkbGeometryType eGeomTypeIn);
    00126                             OGRGeomFieldDefn( OGRGeomFieldDefn * );
    00127         virtual            ~OGRGeomFieldDefn();
    00128
    00129         void                SetName( const char * );
    00130         const char         *GetNameRef() { return pszName; }
    00131
    00132         OGRwkbGeometryType  GetType() { return eGeomType; }
    00133         void                SetType( OGRwkbGeometryType eTypeIn );
    00134
    00135         virtual OGRSpatialReference* GetSpatialRef();
    00136         void                 SetSpatialRef(OGRSpatialReference* poSRS);
    00137
    00138         int                 IsIgnored() { return bIgnore; }
    00139         void                SetIgnored( int bIgnore ) { this->bIgnore = bIgnore; }
    00140
    00141         int                 IsSame( OGRGeomFieldDefn * );
    00142 };
    00143
    00144 /************************************************************************/
    00145 /*                            OGRFeatureDefn                            */
    00146 /************************************************************************/
    00147
    00167 class CPL_DLL OGRFeatureDefn
    00168 {
    00169   protected:
    00170     volatile int nRefCount;
    00171
    00172     int         nFieldCount;
    00173     OGRFieldDefn **papoFieldDefn;
    00174
    00175     int                nGeomFieldCount;
    00176     OGRGeomFieldDefn **papoGeomFieldDefn;
    00177
    00178     char        *pszFeatureClassName;
    00179
    00180     int         bIgnoreStyle;
    00181
    00182   public:
    00183                 OGRFeatureDefn( const char * pszName = NULL );
    00184     virtual    ~OGRFeatureDefn();
    00185
    00186     virtual const char  *GetName();
    00187
    00188     virtual int         GetFieldCount();
    00189     virtual OGRFieldDefn *GetFieldDefn( int i );
    00190     virtual int         GetFieldIndex( const char * );
    00191
    00192     virtual void        AddFieldDefn( OGRFieldDefn * );
    00193     virtual OGRErr      DeleteFieldDefn( int iField );
    00194     virtual OGRErr      ReorderFieldDefns( int* panMap );
    00195
    00196     virtual int         GetGeomFieldCount();
    00197     virtual OGRGeomFieldDefn *GetGeomFieldDefn( int i );
    00198     virtual int         GetGeomFieldIndex( const char * );
    00199
    00200     virtual void        AddGeomFieldDefn( OGRGeomFieldDefn *, int bCopy = TRUE );
    00201     virtual OGRErr      DeleteGeomFieldDefn( int iGeomField );
    00202
    00203     virtual OGRwkbGeometryType GetGeomType();
    00204     virtual void        SetGeomType( OGRwkbGeometryType );
    00205
    00206     virtual OGRFeatureDefn *Clone();
    00207
    00208     int         Reference() { return CPLAtomicInc(&nRefCount); }
    00209     int         Dereference() { return CPLAtomicDec(&nRefCount); }
    00210     int         GetReferenceCount() { return nRefCount; }
    00211     void        Release();
    00212
    00213     virtual int         IsGeometryIgnored();
    00214     virtual void        SetGeometryIgnored( int bIgnore );
    00215     virtual int        IsStyleIgnored() { return bIgnoreStyle; }
    00216     virtual void        SetStyleIgnored( int bIgnore ) { bIgnoreStyle = bIgnore; }
    00217
    00218     virtual int         IsSame( OGRFeatureDefn * poOtherFeatureDefn );
    00219
    00220     static OGRFeatureDefn  *CreateFeatureDefn( const char *pszName = NULL );
    00221     static void         DestroyFeatureDefn( OGRFeatureDefn * );
    00222 };
    00223
    00224 /************************************************************************/
    00225 /*                              OGRFeature                              */
    00226 /************************************************************************/
    00227
    00232 class CPL_DLL OGRFeature
    00233 {
    00234   private:
    00235
    00236     long                nFID;
    00237     OGRFeatureDefn      *poDefn;
    00238     OGRGeometry        **papoGeometries;
    00239     OGRField            *pauFields;
    00240
    00241   protected:
    00242     char *              m_pszStyleString;
    00243     OGRStyleTable       *m_poStyleTable;
    00244     char *              m_pszTmpFieldValue;
    00245
    00246   public:
    00247                         OGRFeature( OGRFeatureDefn * );
    00248     virtual            ~OGRFeature();
    00249
    00250     OGRFeatureDefn     *GetDefnRef() { return poDefn; }
    00251
    00252     OGRErr              SetGeometryDirectly( OGRGeometry * );
    00253     OGRErr              SetGeometry( OGRGeometry * );
    00254     OGRGeometry        *GetGeometryRef();
    00255     OGRGeometry        *StealGeometry();
    00256
    00257     int                 GetGeomFieldCount()
    00258                                 { return poDefn->GetGeomFieldCount(); }
    00259     OGRGeomFieldDefn   *GetGeomFieldDefnRef( int iField )
    00260                                 { return poDefn->GetGeomFieldDefn(iField); }
    00261     int                 GetGeomFieldIndex( const char * pszName)
    00262                                 { return poDefn->GetGeomFieldIndex(pszName); }
    00263
    00264     OGRGeometry*        GetGeomFieldRef(int iField);
    00265     OGRGeometry*        StealGeometry(int iField);
    00266     OGRGeometry*        GetGeomFieldRef(const char* pszFName);
    00267     OGRErr              SetGeomFieldDirectly( int iField, OGRGeometry * );
    00268     OGRErr              SetGeomField( int iField, OGRGeometry * );
    00269
    00270     OGRFeature         *Clone();
    00271     virtual OGRBoolean  Equal( OGRFeature * poFeature );
    00272
    00273     int                 GetFieldCount() { return poDefn->GetFieldCount(); }
    00274     OGRFieldDefn       *GetFieldDefnRef( int iField )
    00275                                       { return poDefn->GetFieldDefn(iField); }
    00276     int                 GetFieldIndex( const char * pszName)
    00277                                       { return poDefn->GetFieldIndex(pszName);}
    00278
    00279     int                 IsFieldSet( int iField );
    00280
    00281     void                UnsetField( int iField );
    00282
    00283     OGRField           *GetRawFieldRef( int i ) { return pauFields + i; }
    00284
    00285     int                 GetFieldAsInteger( int i );
    00286     double              GetFieldAsDouble( int i );
    00287     const char         *GetFieldAsString( int i );
    00288     const int          *GetFieldAsIntegerList( int i, int *pnCount );
    00289     const double       *GetFieldAsDoubleList( int i, int *pnCount );
    00290     char              **GetFieldAsStringList( int i );
    00291     GByte              *GetFieldAsBinary( int i, int *pnCount );
    00292     int                 GetFieldAsDateTime( int i,
    00293                                      int *pnYear, int *pnMonth, int *pnDay,
    00294                                      int *pnHour, int *pnMinute, int *pnSecond,
    00295                                      int *pnTZFlag );
    00296
    00297     int                 GetFieldAsInteger( const char *pszFName )
    00298                       { return GetFieldAsInteger( GetFieldIndex(pszFName) ); }
    00299     double              GetFieldAsDouble( const char *pszFName )
    00300                       { return GetFieldAsDouble( GetFieldIndex(pszFName) ); }
    00301     const char         *GetFieldAsString( const char *pszFName )
    00302                       { return GetFieldAsString( GetFieldIndex(pszFName) ); }
    00303     const int          *GetFieldAsIntegerList( const char *pszFName,
    00304                                                int *pnCount )
    00305                       { return GetFieldAsIntegerList( GetFieldIndex(pszFName),
    00306                                                       pnCount ); }
    00307     const double       *GetFieldAsDoubleList( const char *pszFName,
    00308                                               int *pnCount )
    00309                       { return GetFieldAsDoubleList( GetFieldIndex(pszFName),
    00310                                                      pnCount ); }
    00311     char              **GetFieldAsStringList( const char *pszFName )
    00312                       { return GetFieldAsStringList(GetFieldIndex(pszFName)); }
    00313
    00314     void                SetField( int i, int nValue );
    00315     void                SetField( int i, double dfValue );
    00316     void                SetField( int i, const char * pszValue );
    00317     void                SetField( int i, int nCount, int * panValues );
    00318     void                SetField( int i, int nCount, double * padfValues );
    00319     void                SetField( int i, char ** papszValues );
    00320     void                SetField( int i, OGRField * puValue );
    00321     void                SetField( int i, int nCount, GByte * pabyBinary );
    00322     void                SetField( int i, int nYear, int nMonth, int nDay,
    00323                                   int nHour=0, int nMinute=0, int nSecond=0,
    00324                                   int nTZFlag = 0 );
    00325
    00326     void                SetField( const char *pszFName, int nValue )
    00327                            { SetField( GetFieldIndex(pszFName), nValue ); }
    00328     void                SetField( const char *pszFName, double dfValue )
    00329                            { SetField( GetFieldIndex(pszFName), dfValue ); }
    00330     void                SetField( const char *pszFName, const char * pszValue)
    00331                            { SetField( GetFieldIndex(pszFName), pszValue ); }
    00332     void                SetField( const char *pszFName, int nCount,
    00333                                   int * panValues )
    00334                          { SetField(GetFieldIndex(pszFName),nCount,panValues);}
    00335     void                SetField( const char *pszFName, int nCount,
    00336                                   double * padfValues )
    00337                          {SetField(GetFieldIndex(pszFName),nCount,padfValues);}
    00338     void                SetField( const char *pszFName, char ** papszValues )
    00339                            { SetField( GetFieldIndex(pszFName), papszValues); }
    00340     void                SetField( const char *pszFName, OGRField * puValue )
    00341                            { SetField( GetFieldIndex(pszFName), puValue ); }
    00342     void                SetField( const char *pszFName,
    00343                                   int nYear, int nMonth, int nDay,
    00344                                   int nHour=0, int nMinute=0, int nSecond=0,
    00345                                   int nTZFlag = 0 )
    00346                            { SetField( GetFieldIndex(pszFName),
    00347                                        nYear, nMonth, nDay,
    00348                                        nHour, nMinute, nSecond, nTZFlag ); }
    00349
    00350     long                GetFID() { return nFID; }
    00351     virtual OGRErr      SetFID( long nFID );
    00352
    00353     void                DumpReadable( FILE *, char** papszOptions = NULL );
    00354
    00355     OGRErr              SetFrom( OGRFeature *, int = TRUE);
    00356     OGRErr              SetFrom( OGRFeature *, int *, int = TRUE );
    00357     OGRErr              SetFieldsFrom( OGRFeature *, int *, int = TRUE );
    00358
    00359     OGRErr              RemapFields( OGRFeatureDefn *poNewDefn,
    00360                                      int *panRemapSource );
    00361     OGRErr              RemapGeomFields( OGRFeatureDefn *poNewDefn,
    00362                                      int *panRemapSource );
    00363
    00364     virtual const char *GetStyleString();
    00365     virtual void        SetStyleString( const char * );
    00366     virtual void        SetStyleStringDirectly( char * );
    00367     virtual OGRStyleTable *GetStyleTable() { return m_poStyleTable; }
    00368     virtual void        SetStyleTable(OGRStyleTable *poStyleTable);
    00369     virtual void        SetStyleTableDirectly(OGRStyleTable *poStyleTable)
    00370                             { if ( m_poStyleTable ) delete m_poStyleTable;
    00371                               m_poStyleTable = poStyleTable; }
    00372
    00373     static OGRFeature  *CreateFeature( OGRFeatureDefn * );
    00374     static void         DestroyFeature( OGRFeature * );
    00375 };
    00376
    00377 /************************************************************************/
    00378 /*                           OGRFeatureQuery                            */
    00379 /************************************************************************/
    00380
    00381 class OGRLayer;
    00382 class swq_expr_node;
    00383
    00384 class CPL_DLL OGRFeatureQuery
    00385 {
    00386   private:
    00387     OGRFeatureDefn *poTargetDefn;
    00388     void           *pSWQExpr;
    00389
    00390     char          **FieldCollector( void *, char ** );
    00391
    00392     long       *EvaluateAgainstIndices( swq_expr_node*, OGRLayer *, int& nFIDCount);
    00393
    00394     int         CanUseIndex( swq_expr_node*, OGRLayer * );
    00395
    00396   public:
    00397                 OGRFeatureQuery();
    00398                 ~OGRFeatureQuery();
    00399
    00400     OGRErr      Compile( OGRFeatureDefn *, const char * );
    00401     int         Evaluate( OGRFeature * );
    00402
    00403     long       *EvaluateAgainstIndices( OGRLayer *, OGRErr * );
    00404
    00405     int         CanUseIndex( OGRLayer * );
    00406
    00407     char      **GetUsedFields();
    00408
    00409     void       *GetSWGExpr() { return pSWQExpr; }
    00410 };
    00411
    00412 #endif /* ndef _OGR_FEATURE_H_INCLUDED */

Generated for GDAL by 1.7.1.