GDAL
ogr_feature.h
Go to the documentation of this file.
00001 /******************************************************************************
00002  * $Id: ogr_feature.h 37371 2017-02-13 11:41:59Z 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 "cpl_atomic_ops.h"
00035 #include "ogr_featurestyle.h"
00036 #include "ogr_geometry.h"
00037 
00044 /************************************************************************/
00045 /*                             OGRFieldDefn                             */
00046 /************************************************************************/
00047 
00062 class CPL_DLL OGRFieldDefn
00063 {
00064   private:
00065     char                *pszName;
00066     OGRFieldType        eType;
00067     OGRJustification    eJustify;
00068     int                 nWidth;  // Zero is variable.
00069     int                 nPrecision;
00070     char                *pszDefault;
00071 
00072     int                 bIgnore;
00073     OGRFieldSubType     eSubType;
00074 
00075     int                 bNullable;
00076 
00077   public:
00078                         OGRFieldDefn( const char *, OGRFieldType );
00079                explicit OGRFieldDefn( OGRFieldDefn * );
00080                         ~OGRFieldDefn();
00081 
00082     void                SetName( const char * );
00083     const char         *GetNameRef() { return pszName; }
00084 
00085     OGRFieldType        GetType() const { return eType; }
00086     void                SetType( OGRFieldType eTypeIn );
00087     static const char  *GetFieldTypeName( OGRFieldType );
00088 
00089     OGRFieldSubType     GetSubType() const { return eSubType; }
00090     void                SetSubType( OGRFieldSubType eSubTypeIn );
00091     static const char  *GetFieldSubTypeName( OGRFieldSubType );
00092 
00093     OGRJustification    GetJustify() const { return eJustify; }
00094     void                SetJustify( OGRJustification eJustifyIn )
00095                                                 { eJustify = eJustifyIn; }
00096 
00097     int                 GetWidth() const { return nWidth; }
00098     void                SetWidth( int nWidthIn ) { nWidth = MAX(0,nWidthIn); }
00099 
00100     int                 GetPrecision() const { return nPrecision; }
00101     void                SetPrecision( int nPrecisionIn )
00102                                                 { nPrecision = nPrecisionIn; }
00103 
00104     void                Set( const char *, OGRFieldType, int = 0, int = 0,
00105                              OGRJustification = OJUndefined );
00106 
00107     void                SetDefault( const char* );
00108     const char         *GetDefault() const;
00109     int                 IsDefaultDriverSpecific() const;
00110 
00111     int                 IsIgnored() const { return bIgnore; }
00112     void                SetIgnored( int bIgnoreIn ) { bIgnore = bIgnoreIn; }
00113 
00114     int                 IsNullable() const { return bNullable; }
00115     void                SetNullable( int bNullableIn ) { bNullable = bNullableIn; }
00116 
00117     int                 IsSame( const OGRFieldDefn * ) const;
00118 
00119   private:
00120     CPL_DISALLOW_COPY_ASSIGN(OGRFieldDefn)
00121 };
00122 
00123 /************************************************************************/
00124 /*                          OGRGeomFieldDefn                            */
00125 /************************************************************************/
00126 
00141 class CPL_DLL OGRGeomFieldDefn
00142 {
00143 protected:
00145         char                *pszName;
00146         OGRwkbGeometryType   eGeomType; /* all values possible except wkbNone */
00147         OGRSpatialReference* poSRS;
00148 
00149         int                 bIgnore;
00150         int                 bNullable;
00151 
00152         void                Initialize( const char *, OGRwkbGeometryType );
00154 
00155 public:
00156                             OGRGeomFieldDefn( const char *pszNameIn,
00157                                               OGRwkbGeometryType eGeomTypeIn );
00158                   explicit OGRGeomFieldDefn( OGRGeomFieldDefn * );
00159         virtual            ~OGRGeomFieldDefn();
00160 
00161         void                SetName( const char * );
00162         const char         *GetNameRef() { return pszName; }
00163 
00164         OGRwkbGeometryType  GetType() const { return eGeomType; }
00165         void                SetType( OGRwkbGeometryType eTypeIn );
00166 
00167         virtual OGRSpatialReference* GetSpatialRef();
00168         void                 SetSpatialRef( OGRSpatialReference* poSRSIn );
00169 
00170         int                 IsIgnored() const { return bIgnore; }
00171         void                SetIgnored( int bIgnoreIn ) { bIgnore = bIgnoreIn; }
00172 
00173         int                 IsNullable() const { return bNullable; }
00174         void                SetNullable( int bNullableIn )
00175             { bNullable = bNullableIn; }
00176 
00177         int                 IsSame( OGRGeomFieldDefn * );
00178 
00179   private:
00180     CPL_DISALLOW_COPY_ASSIGN(OGRGeomFieldDefn)
00181 };
00182 
00183 /************************************************************************/
00184 /*                            OGRFeatureDefn                            */
00185 /************************************************************************/
00186 
00207 class CPL_DLL OGRFeatureDefn
00208 {
00209   protected:
00211     volatile int nRefCount;
00212 
00213     int         nFieldCount;
00214     OGRFieldDefn **papoFieldDefn;
00215 
00216     int                nGeomFieldCount;
00217     OGRGeomFieldDefn **papoGeomFieldDefn;
00218 
00219     char        *pszFeatureClassName;
00220 
00221     int         bIgnoreStyle;
00223 
00224   public:
00225        explicit OGRFeatureDefn( const char * pszName = NULL );
00226     virtual    ~OGRFeatureDefn();
00227 
00228     virtual const char  *GetName();
00229 
00230     virtual int         GetFieldCount();
00231     virtual OGRFieldDefn *GetFieldDefn( int i );
00232     virtual int         GetFieldIndex( const char * );
00233 
00234     virtual void        AddFieldDefn( OGRFieldDefn * );
00235     virtual OGRErr      DeleteFieldDefn( int iField );
00236     virtual OGRErr      ReorderFieldDefns( int* panMap );
00237 
00238     virtual int         GetGeomFieldCount();
00239     virtual OGRGeomFieldDefn *GetGeomFieldDefn( int i );
00240     virtual int         GetGeomFieldIndex( const char * );
00241 
00242     virtual void        AddGeomFieldDefn( OGRGeomFieldDefn *,
00243                                           int bCopy = TRUE );
00244     virtual OGRErr      DeleteGeomFieldDefn( int iGeomField );
00245 
00246     virtual OGRwkbGeometryType GetGeomType();
00247     virtual void        SetGeomType( OGRwkbGeometryType );
00248 
00249     virtual OGRFeatureDefn *Clone();
00250 
00251     int         Reference() { return CPLAtomicInc(&nRefCount); }
00252     int         Dereference() { return CPLAtomicDec(&nRefCount); }
00253     int         GetReferenceCount() { return nRefCount; }
00254     void        Release();
00255 
00256     virtual int         IsGeometryIgnored();
00257     virtual void        SetGeometryIgnored( int bIgnore );
00258     virtual int         IsStyleIgnored() const { return bIgnoreStyle; }
00259     virtual void        SetStyleIgnored( int bIgnore )
00260         { bIgnoreStyle = bIgnore; }
00261 
00262     virtual int         IsSame( OGRFeatureDefn * poOtherFeatureDefn );
00263 
00264     static OGRFeatureDefn  *CreateFeatureDefn( const char *pszName = NULL );
00265     static void         DestroyFeatureDefn( OGRFeatureDefn * );
00266 
00267   private:
00268     CPL_DISALLOW_COPY_ASSIGN(OGRFeatureDefn)
00269 };
00270 
00271 /************************************************************************/
00272 /*                              OGRFeature                              */
00273 /************************************************************************/
00274 
00279 class CPL_DLL OGRFeature
00280 {
00281   private:
00282 
00283     GIntBig              nFID;
00284     OGRFeatureDefn      *poDefn;
00285     OGRGeometry        **papoGeometries;
00286     OGRField            *pauFields;
00287     char                *m_pszNativeData;
00288     char                *m_pszNativeMediaType;
00289 
00290     bool                SetFieldInternal( int i, OGRField * puValue );
00291 
00292   protected:
00294     char                *m_pszStyleString;
00295     OGRStyleTable       *m_poStyleTable;
00296     char                *m_pszTmpFieldValue;
00298 
00299   public:
00300     explicit            OGRFeature( OGRFeatureDefn * );
00301     virtual            ~OGRFeature();
00302 
00303     OGRFeatureDefn     *GetDefnRef() { return poDefn; }
00304 
00305     OGRErr              SetGeometryDirectly( OGRGeometry * );
00306     OGRErr              SetGeometry( const OGRGeometry * );
00307     OGRGeometry        *GetGeometryRef();
00308     OGRGeometry        *StealGeometry() CPL_WARN_UNUSED_RESULT;
00309 
00310     int                 GetGeomFieldCount() const
00311                                 { return poDefn->GetGeomFieldCount(); }
00312     OGRGeomFieldDefn   *GetGeomFieldDefnRef( int iField )
00313                                 { return poDefn->GetGeomFieldDefn(iField); }
00314     int                 GetGeomFieldIndex( const char * pszName )
00315                                 { return poDefn->GetGeomFieldIndex(pszName); }
00316 
00317     OGRGeometry*        GetGeomFieldRef( int iField );
00318     OGRGeometry*        StealGeometry( int iField );
00319     OGRGeometry*        GetGeomFieldRef( const char* pszFName );
00320     OGRErr              SetGeomFieldDirectly( int iField, OGRGeometry * );
00321     OGRErr              SetGeomField( int iField, const OGRGeometry * );
00322 
00323     OGRFeature         *Clone() CPL_WARN_UNUSED_RESULT;
00324     virtual OGRBoolean  Equal( OGRFeature * poFeature );
00325 
00326     int                 GetFieldCount() const
00327         { return poDefn->GetFieldCount(); }
00328     OGRFieldDefn       *GetFieldDefnRef( int iField ) const
00329                                       { return poDefn->GetFieldDefn(iField); }
00330     int                 GetFieldIndex( const char * pszName )
00331                                       { return poDefn->GetFieldIndex(pszName); }
00332 
00333     int                 IsFieldSet( int iField );
00334 
00335     void                UnsetField( int iField );
00336 
00337     bool                IsFieldNull( int iField );
00338 
00339     void                SetFieldNull( int iField );
00340 
00341     bool                IsFieldSetAndNotNull( int iField );
00342 
00343     OGRField           *GetRawFieldRef( int i ) { return pauFields + i; }
00344 
00345     int                 GetFieldAsInteger( int i );
00346     GIntBig             GetFieldAsInteger64( int i );
00347     double              GetFieldAsDouble( int i );
00348     const char         *GetFieldAsString( int i );
00349     const int          *GetFieldAsIntegerList( int i, int *pnCount );
00350     const GIntBig      *GetFieldAsInteger64List( int i, int *pnCount );
00351     const double       *GetFieldAsDoubleList( int i, int *pnCount );
00352     char              **GetFieldAsStringList( int i );
00353     GByte              *GetFieldAsBinary( int i, int *pnCount );
00354     int                 GetFieldAsDateTime( int i,
00355                                             int *pnYear, int *pnMonth,
00356                                             int *pnDay,
00357                                             int *pnHour, int *pnMinute,
00358                                             int *pnSecond,
00359                                             int *pnTZFlag );
00360     int                 GetFieldAsDateTime( int i,
00361                                             int *pnYear, int *pnMonth,
00362                                             int *pnDay,
00363                                             int *pnHour, int *pnMinute,
00364                                             float *pfSecond,
00365                                             int *pnTZFlag );
00366     char               *GetFieldAsSerializedJSon( int i );
00367 
00368     int                 GetFieldAsInteger( const char *pszFName )
00369                       { return GetFieldAsInteger( GetFieldIndex(pszFName) ); }
00370     GIntBig             GetFieldAsInteger64( const char *pszFName )
00371                       { return GetFieldAsInteger64( GetFieldIndex(pszFName) ); }
00372     double              GetFieldAsDouble( const char *pszFName )
00373                       { return GetFieldAsDouble( GetFieldIndex(pszFName) ); }
00374     const char         *GetFieldAsString( const char *pszFName )
00375                       { return GetFieldAsString( GetFieldIndex(pszFName) ); }
00376     const int          *GetFieldAsIntegerList( const char *pszFName,
00377                                                int *pnCount )
00378                       { return GetFieldAsIntegerList( GetFieldIndex(pszFName),
00379                                                       pnCount ); }
00380     const GIntBig      *GetFieldAsInteger64List( const char *pszFName,
00381                                                int *pnCount )
00382                       { return GetFieldAsInteger64List( GetFieldIndex(pszFName),
00383                                                       pnCount ); }
00384     const double       *GetFieldAsDoubleList( const char *pszFName,
00385                                               int *pnCount )
00386                       { return GetFieldAsDoubleList( GetFieldIndex(pszFName),
00387                                                      pnCount ); }
00388     char              **GetFieldAsStringList( const char *pszFName )
00389                       { return GetFieldAsStringList(GetFieldIndex(pszFName)); }
00390 
00391     void                SetField( int i, int nValue );
00392     void                SetField( int i, GIntBig nValue );
00393     void                SetField( int i, double dfValue );
00394     void                SetField( int i, const char * pszValue );
00395     void                SetField( int i, int nCount, int * panValues );
00396     void                SetField( int i, int nCount,
00397                                   const GIntBig * panValues );
00398     void                SetField( int i, int nCount, double * padfValues );
00399     void                SetField( int i, char ** papszValues );
00400     void                SetField( int i, OGRField * puValue );
00401     void                SetField( int i, int nCount, GByte * pabyBinary );
00402     void                SetField( int i, int nYear, int nMonth, int nDay,
00403                                   int nHour=0, int nMinute=0, float fSecond=0.f,
00404                                   int nTZFlag = 0 );
00405 
00406     void                SetField( const char *pszFName, int nValue )
00407                            { SetField( GetFieldIndex(pszFName), nValue ); }
00408     void                SetField( const char *pszFName, GIntBig nValue )
00409                            { SetField( GetFieldIndex(pszFName), nValue ); }
00410     void                SetField( const char *pszFName, double dfValue )
00411                            { SetField( GetFieldIndex(pszFName), dfValue ); }
00412     void                SetField( const char *pszFName, const char * pszValue )
00413                            { SetField( GetFieldIndex(pszFName), pszValue ); }
00414     void                SetField( const char *pszFName, int nCount,
00415                                   int * panValues )
00416                          { SetField(GetFieldIndex(pszFName),nCount,panValues); }
00417     void                SetField( const char *pszFName, int nCount,
00418                                   const GIntBig * panValues )
00419                          { SetField(GetFieldIndex(pszFName),nCount,panValues); }
00420     void                SetField( const char *pszFName, int nCount,
00421                                   double * padfValues )
00422                          {SetField(GetFieldIndex(pszFName),nCount,padfValues); }
00423     void                SetField( const char *pszFName, char ** papszValues )
00424                            { SetField( GetFieldIndex(pszFName), papszValues); }
00425     void                SetField( const char *pszFName, OGRField * puValue )
00426                            { SetField( GetFieldIndex(pszFName), puValue ); }
00427     void                SetField( const char *pszFName,
00428                                   int nYear, int nMonth, int nDay,
00429                                   int nHour=0, int nMinute=0, float fSecond=0.f,
00430                                   int nTZFlag = 0 )
00431                            { SetField( GetFieldIndex(pszFName),
00432                                        nYear, nMonth, nDay,
00433                                        nHour, nMinute, fSecond, nTZFlag ); }
00434 
00435     GIntBig             GetFID() const { return nFID; }
00436     virtual OGRErr      SetFID( GIntBig nFIDIn );
00437 
00438     void                DumpReadable( FILE *, char** papszOptions = NULL );
00439 
00440     OGRErr              SetFrom( OGRFeature *, int = TRUE );
00441     OGRErr              SetFrom( OGRFeature *, int *, int = TRUE );
00442     OGRErr              SetFieldsFrom( OGRFeature *, int *, int = TRUE );
00443 
00445     OGRErr              RemapFields( OGRFeatureDefn *poNewDefn,
00446                                      int *panRemapSource );
00447     OGRErr              RemapGeomFields( OGRFeatureDefn *poNewDefn,
00448                                      int *panRemapSource );
00450 
00451     int                 Validate( int nValidateFlags,
00452                                   int bEmitError );
00453     void                FillUnsetWithDefault( int bNotNullableOnly,
00454                                               char** papszOptions );
00455 
00456     virtual const char *GetStyleString();
00457     virtual void        SetStyleString( const char * );
00458     virtual void        SetStyleStringDirectly( char * );
00459 
00463     virtual OGRStyleTable *GetStyleTable() { return m_poStyleTable; }
00464     virtual void        SetStyleTable( OGRStyleTable *poStyleTable );
00465     virtual void        SetStyleTableDirectly( OGRStyleTable *poStyleTable );
00466 
00467     const char         *GetNativeData() const { return m_pszNativeData; }
00468     const char         *GetNativeMediaType() const
00469         { return m_pszNativeMediaType; }
00470     void                SetNativeData( const char* pszNativeData );
00471     void                SetNativeMediaType( const char* pszNativeMediaType );
00472 
00473     static OGRFeature  *CreateFeature( OGRFeatureDefn * );
00474     static void         DestroyFeature( OGRFeature * );
00475 
00476   private:
00477     CPL_DISALLOW_COPY_ASSIGN(OGRFeature)
00478 };
00479 
00480 /************************************************************************/
00481 /*                           OGRFeatureQuery                            */
00482 /************************************************************************/
00483 
00485 class OGRLayer;
00486 class swq_expr_node;
00487 class swq_custom_func_registrar;
00488 
00489 class CPL_DLL OGRFeatureQuery
00490 {
00491   private:
00492     OGRFeatureDefn *poTargetDefn;
00493     void           *pSWQExpr;
00494 
00495     char      **FieldCollector( void *, char ** );
00496 
00497     GIntBig    *EvaluateAgainstIndices( swq_expr_node*, OGRLayer *,
00498                                            GIntBig& nFIDCount );
00499 
00500     int         CanUseIndex( swq_expr_node*, OGRLayer * );
00501 
00502   public:
00503                 OGRFeatureQuery();
00504                ~OGRFeatureQuery();
00505 
00506     OGRErr      Compile( OGRFeatureDefn *, const char *,
00507                          int bCheck = TRUE,
00508                          swq_custom_func_registrar*
00509                          poCustomFuncRegistrar = NULL );
00510     int         Evaluate( OGRFeature * );
00511 
00512     GIntBig    *EvaluateAgainstIndices( OGRLayer *, OGRErr * );
00513 
00514     int         CanUseIndex( OGRLayer * );
00515 
00516     char      **GetUsedFields();
00517 
00518     void       *GetSWQExpr() { return pSWQExpr; }
00519 };
00521 
00522 #endif /* ndef OGR_FEATURE_H_INCLUDED */

Generated for GDAL by doxygen 1.7.6.1.