ogr_feature.h

Go to the documentation of this file.
00001 /******************************************************************************
00002  * $Id: ogr_feature.h,v 1.36 2006/12/13 18:34:25 dron Exp $
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  * $Log: ogr_feature.h,v $
00031  * Revision 1.36  2006/12/13 18:34:25  dron
00032  * Added SetStyleStringDirectly(), GetStyleTable() and SetStyleTableDirectly()
00033  * methods.
00034  *
00035  * Revision 1.35  2006/11/28 00:00:35  tamas
00036  * RFC 6: Geometry and Feature Style as OGR Special Fields
00037  *
00038  * Revision 1.34  2006/09/20 13:01:51  osemykin
00039  * Make the functions GetFieldAsStringList(...) and IsFieldSet(...) const
00040  *
00041  * Revision 1.33  2006/04/02 18:25:59  fwarmerdam
00042  * added OFTDateTime, and OFTTime support
00043  *
00044  * Revision 1.32  2006/02/15 04:25:37  fwarmerdam
00045  * added date support
00046  *
00047  * Revision 1.31  2005/09/21 00:50:08  fwarmerdam
00048  * Added Release
00049  *
00050  * Revision 1.30  2005/08/30 23:52:35  fwarmerdam
00051  * implement preliminary OFTBinary support
00052  *
00053  * Revision 1.29  2004/02/23 21:47:23  warmerda
00054  * Added GetUsedFields() and GetSWGExpr() methods on OGRFeatureQuery class
00055  *
00056  * Revision 1.28  2003/05/28 19:16:42  warmerda
00057  * fixed up argument names and stuff for docs
00058  *
00059  * Revision 1.27  2003/04/08 20:57:28  warmerda
00060  * added RemapFields on OGRFeature
00061  *
00062  * Revision 1.26  2003/03/04 05:46:31  warmerda
00063  * added EvaluateAgainstIndices for OGRFeatureQuery
00064  *
00065  * Revision 1.25  2003/01/08 22:03:44  warmerda
00066  * added StealGeometry() method on OGRFeature
00067  *
00068  * Revision 1.24  2002/10/09 14:31:06  warmerda
00069  * dont permit negative widths to be assigned to field definition
00070  *
00071  * Revision 1.23  2002/09/26 18:13:17  warmerda
00072  * moved some defs to ogr_core.h for sharing with ogr_api.h
00073  *
00074  * Revision 1.22  2002/08/07 21:37:47  warmerda
00075  * added indirect OGRFeaturedefn constructor/destructor
00076  *
00077  * Revision 1.21  2001/11/01 16:54:16  warmerda
00078  * added DestroyFeature
00079  *
00080  * Revision 1.20  2001/07/19 18:25:07  warmerda
00081  * expanded tabs
00082  *
00083  * Revision 1.19  2001/06/19 15:48:36  warmerda
00084  * added feature attribute query support
00085  *
00086  * Revision 1.18  2001/06/01 14:33:00  warmerda
00087  * added CreateFeature factory method
00088  *
00089  * Revision 1.17  2001/02/06 17:10:28  warmerda
00090  * export entry points from DLL
00091  *
00092  * Revision 1.16  2001/01/19 21:10:47  warmerda
00093  * replaced tabs
00094  *
00095  * Revision 1.15  2000/12/07 03:40:13  danmo
00096  * Removed stray comma in OGRFieldType enum defn
00097  *
00098  * Revision 1.14  2000/10/03 19:19:56  danmo
00099  * Made m_pszStyleString protected (was private)
00100  *
00101  * Revision 1.13  2000/10/03 18:14:29  danmo
00102  * Made OGRFeature::Get/SetStyleString() virtual
00103  *
00104  * Revision 1.12  2000/08/18 21:26:53  svillene
00105  * Add representation
00106  *
00107  * Revision 1.11  1999/11/26 03:05:38  warmerda
00108  * added unset field support
00109  *
00110  * Revision 1.10  1999/11/18 19:02:20  warmerda
00111  * expanded tabs
00112  *
00113  * Revision 1.9  1999/11/04 21:05:49  warmerda
00114  * Added the Set() method on OGRFieldDefn to set all info in one call,
00115  * and the SetFrom() method on OGRFeature to copy the contents of one
00116  * feature to another, even if of a different OGRFeatureDefn.
00117  *
00118  * Revision 1.8  1999/10/01 14:47:05  warmerda
00119  * added full family of get/set field methods with field names
00120  *
00121  * Revision 1.7  1999/08/30 14:52:33  warmerda
00122  * added support for StringList fields
00123  *
00124  * Revision 1.6  1999/08/26 17:38:00  warmerda
00125  * added support for real and integer lists
00126  *
00127  * Revision 1.5  1999/07/27 00:47:37  warmerda
00128  * Added FID to OGRFeature class
00129  *
00130  * Revision 1.4  1999/07/07 04:23:07  danmo
00131  * Fixed typo in  #define _OGR_..._H_INCLUDED  line
00132  *
00133  * Revision 1.3  1999/07/05 17:18:39  warmerda
00134  * added docs
00135  *
00136  * Revision 1.2  1999/06/11 19:21:27  warmerda
00137  * Fleshed out operational definitions
00138  *
00139  * Revision 1.1  1999/05/31 17:14:53  warmerda
00140  * New
00141  *
00142  */
00143 
00144 #ifndef _OGR_FEATURE_H_INCLUDED
00145 #define _OGR_FEATURE_H_INCLUDED
00146 
00147 #include "ogr_geometry.h"
00148 #include "ogr_featurestyle.h"
00149 
00156 /************************************************************************/
00157 /*                             OGRFieldDefn                             */
00158 /************************************************************************/
00159 
00164 class CPL_DLL OGRFieldDefn
00165 {
00166   private:
00167     char                *pszName;
00168     OGRFieldType        eType;                  
00169     OGRJustification    eJustify;               
00170     int                 nWidth;                 /* zero is variable */
00171     int                 nPrecision;
00172     OGRField            uDefault;
00173 
00174     void                Initialize( const char *, OGRFieldType );
00175     
00176   public:
00177                         OGRFieldDefn( const char *, OGRFieldType );
00178                         OGRFieldDefn( OGRFieldDefn * );
00179                         ~OGRFieldDefn();
00180 
00181     void                SetName( const char * );
00182     const char         *GetNameRef() { return pszName; }
00183 
00184     OGRFieldType        GetType() { return eType; }
00185     void                SetType( OGRFieldType eTypeIn ) { eType = eTypeIn;}
00186     static const char  *GetFieldTypeName( OGRFieldType );
00187 
00188     OGRJustification    GetJustify() { return eJustify; }
00189     void                SetJustify( OGRJustification eJustifyIn )
00190                                                 { eJustify = eJustifyIn; }
00191 
00192     int                 GetWidth() { return nWidth; }
00193     void                SetWidth( int nWidthIn ) { nWidth = MAX(0,nWidthIn); }
00194 
00195     int                 GetPrecision() { return nPrecision; }
00196     void                SetPrecision( int nPrecisionIn )
00197                                                 { nPrecision = nPrecisionIn; }
00198 
00199     void                Set( const char *, OGRFieldType, int = 0, int = 0,
00200                              OGRJustification = OJUndefined );
00201 
00202     void                SetDefault( const OGRField * );
00203     const OGRField     *GetDefaultRef() { return &uDefault; }
00204 };
00205 
00206 /************************************************************************/
00207 /*                            OGRFeatureDefn                            */
00208 /************************************************************************/
00209 
00226 class CPL_DLL OGRFeatureDefn
00227 {
00228   private:
00229     int         nRefCount;
00230     
00231     int         nFieldCount;
00232     OGRFieldDefn **papoFieldDefn;
00233 
00234     OGRwkbGeometryType eGeomType;
00235 
00236     char        *pszFeatureClassName;
00237     
00238   public:
00239                 OGRFeatureDefn( const char * pszName = NULL );
00240     virtual    ~OGRFeatureDefn();
00241 
00242     const char  *GetName() { return pszFeatureClassName; }
00243 
00244     int         GetFieldCount() { return nFieldCount; }
00245     OGRFieldDefn *GetFieldDefn( int i );
00246     int         GetFieldIndex( const char * );
00247 
00248     void        AddFieldDefn( OGRFieldDefn * );
00249 
00250     OGRwkbGeometryType GetGeomType() { return eGeomType; }
00251     void        SetGeomType( OGRwkbGeometryType );
00252 
00253     OGRFeatureDefn *Clone();
00254 
00255     int         Reference() { return ++nRefCount; }
00256     int         Dereference() { return --nRefCount; }
00257     int         GetReferenceCount() { return nRefCount; }
00258     void        Release();
00259 
00260     static OGRFeatureDefn  *CreateFeatureDefn( const char *pszName = NULL );
00261     static void         DestroyFeatureDefn( OGRFeatureDefn * );
00262 };
00263 
00264 /************************************************************************/
00265 /*                              OGRFeature                              */
00266 /************************************************************************/
00267 
00272 class CPL_DLL OGRFeature
00273 {
00274   private:
00275 
00276     long                nFID;
00277     OGRFeatureDefn      *poDefn;
00278     OGRGeometry         *poGeometry;
00279     OGRField            *pauFields;
00280 
00281   protected: 
00282     char *              m_pszStyleString;
00283     OGRStyleTable       *m_poStyleTable;
00284     char *              m_pszTmpFieldValue;
00285     
00286   public:
00287                         OGRFeature( OGRFeatureDefn * );
00288     virtual            ~OGRFeature();                        
00289 
00290     OGRFeatureDefn     *GetDefnRef() { return poDefn; }
00291     
00292     OGRErr              SetGeometryDirectly( OGRGeometry * );
00293     OGRErr              SetGeometry( OGRGeometry * );
00294     OGRGeometry        *GetGeometryRef() { return poGeometry; }
00295     OGRGeometry        *StealGeometry();
00296 
00297     OGRFeature         *Clone();
00298     virtual OGRBoolean  Equal( OGRFeature * poFeature );
00299 
00300     int                 GetFieldCount() { return poDefn->GetFieldCount(); }
00301     OGRFieldDefn       *GetFieldDefnRef( int iField )
00302                                       { return poDefn->GetFieldDefn(iField); }
00303     int                 GetFieldIndex( const char * pszName)
00304                                       { return poDefn->GetFieldIndex(pszName);}
00305 
00306     int                 IsFieldSet( int iField ) const
00307                         { return
00308                               pauFields[iField].Set.nMarker1 != OGRUnsetMarker
00309                            || pauFields[iField].Set.nMarker2 != OGRUnsetMarker;
00310                               }
00311     
00312     void                UnsetField( int iField );
00313     
00314     OGRField           *GetRawFieldRef( int i ) { return pauFields + i; }
00315 
00316     int                 GetFieldAsInteger( int i );
00317     double              GetFieldAsDouble( int i );
00318     const char         *GetFieldAsString( int i );
00319     const int          *GetFieldAsIntegerList( int i, int *pnCount );
00320     const double       *GetFieldAsDoubleList( int i, int *pnCount );
00321     char              **GetFieldAsStringList( int i ) const;
00322     GByte              *GetFieldAsBinary( int i, int *pnCount );
00323     int                 GetFieldAsDateTime( int i, 
00324                                      int *pnYear, int *pnMonth, int *pnDay,
00325                                      int *pnHour, int *pnMinute, int *pnSecond, 
00326                                      int *pnTZFlag );
00327 
00328     int                 GetFieldAsInteger( const char *pszFName )
00329                       { return GetFieldAsInteger( GetFieldIndex(pszFName) ); }
00330     double              GetFieldAsDouble( const char *pszFName )
00331                       { return GetFieldAsDouble( GetFieldIndex(pszFName) ); }
00332     const char         *GetFieldAsString( const char *pszFName )
00333                       { return GetFieldAsString( GetFieldIndex(pszFName) ); }
00334     const int          *GetFieldAsIntegerList( const char *pszFName,
00335                                                int *pnCount )
00336                       { return GetFieldAsIntegerList( GetFieldIndex(pszFName),
00337                                                       pnCount ); }
00338     const double       *GetFieldAsDoubleList( const char *pszFName,
00339                                               int *pnCount )
00340                       { return GetFieldAsDoubleList( GetFieldIndex(pszFName),
00341                                                      pnCount ); }
00342     char              **GetFieldAsStringList( const char *pszFName )
00343                       { return GetFieldAsStringList(GetFieldIndex(pszFName)); }
00344 
00345     void                SetField( int i, int nValue );
00346     void                SetField( int i, double dfValue );
00347     void                SetField( int i, const char * pszValue );
00348     void                SetField( int i, int nCount, int * panValues );
00349     void                SetField( int i, int nCount, double * padfValues );
00350     void                SetField( int i, char ** papszValues );
00351     void                SetField( int i, OGRField * puValue );
00352     void                SetField( int i, int nCount, GByte * pabyBinary );
00353     void                SetField( int i, int nYear, int nMonth, int nDay,
00354                                   int nHour=0, int nMinute=0, int nSecond=0, 
00355                                   int nTZFlag = 0 );
00356 
00357     void                SetField( const char *pszFName, int nValue )
00358                            { SetField( GetFieldIndex(pszFName), nValue ); }
00359     void                SetField( const char *pszFName, double dfValue )
00360                            { SetField( GetFieldIndex(pszFName), dfValue ); }
00361     void                SetField( const char *pszFName, const char * pszValue)
00362                            { SetField( GetFieldIndex(pszFName), pszValue ); }
00363     void                SetField( const char *pszFName, int nCount,
00364                                   int * panValues )
00365                          { SetField(GetFieldIndex(pszFName),nCount,panValues);}
00366     void                SetField( const char *pszFName, int nCount,
00367                                   double * padfValues )
00368                          {SetField(GetFieldIndex(pszFName),nCount,padfValues);}
00369     void                SetField( const char *pszFName, char ** papszValues )
00370                            { SetField( GetFieldIndex(pszFName), papszValues); }
00371     void                SetField( const char *pszFName, OGRField * puValue )
00372                            { SetField( GetFieldIndex(pszFName), puValue ); }
00373     void                SetField( const char *pszFName, 
00374                                   int nYear, int nMonth, int nDay,
00375                                   int nHour=0, int nMinute=0, int nSecond=0, 
00376                                   int nTZFlag = 0 )
00377                            { SetField( GetFieldIndex(pszFName), 
00378                                        nYear, nMonth, nDay, 
00379                                        nHour, nMinute, nSecond, nTZFlag ); }
00380 
00381     long                GetFID() { return nFID; }
00382     virtual OGRErr      SetFID( long nFID );
00383 
00384     void                DumpReadable( FILE * );
00385 
00386     OGRErr              SetFrom( OGRFeature *, int = TRUE);
00387 
00388     OGRErr              RemapFields( OGRFeatureDefn *poNewDefn, 
00389                                      int *panRemapSource );
00390 
00391     virtual const char *GetStyleString();
00392     virtual void        SetStyleString( const char * );
00393     virtual void        SetStyleStringDirectly( char * );
00394     virtual OGRStyleTable *GetStyleTable() { return m_poStyleTable; }
00395     virtual void        SetStyleTable(OGRStyleTable *poStyleTable);
00396     virtual void        SetStyleTableDirectly(OGRStyleTable *poStyleTable)
00397                             { if ( m_poStyleTable ) delete m_poStyleTable;
00398                               m_poStyleTable = poStyleTable; }
00399 
00400     static OGRFeature  *CreateFeature( OGRFeatureDefn * );
00401     static void         DestroyFeature( OGRFeature * );
00402 };
00403 
00404 /************************************************************************/
00405 /*                           OGRFeatureQuery                            */
00406 /************************************************************************/
00407 
00408 class OGRLayer;
00409 
00410 class CPL_DLL OGRFeatureQuery
00411 {
00412   private:
00413     OGRFeatureDefn *poTargetDefn;
00414     void           *pSWQExpr;
00415 
00416     char          **FieldCollector( void *, char ** );
00417     
00418   public:
00419                 OGRFeatureQuery();
00420                 ~OGRFeatureQuery();
00421 
00422     OGRErr      Compile( OGRFeatureDefn *, const char * );
00423     int         Evaluate( OGRFeature * );
00424 
00425     long       *EvaluateAgainstIndices( OGRLayer *, OGRErr * );
00426 
00427     char      **GetUsedFields();
00428 
00429     void       *GetSWGExpr() { return pSWQExpr; }
00430 };
00431 
00432 #endif /* ndef _OGR_FEATURE_H_INCLUDED */

Generated for GDAL by doxygen 1.5.1.