OGR
|
00001 /****************************************************************************** 00002 * $Id: ogr_feature.h 24849 2012-08-25 12:22:05Z 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 int IsSame( const OGRFieldDefn * ) const; 00098 }; 00099 00100 /************************************************************************/ 00101 /* OGRFeatureDefn */ 00102 /************************************************************************/ 00103 00120 class CPL_DLL OGRFeatureDefn 00121 { 00122 private: 00123 volatile int nRefCount; 00124 00125 int nFieldCount; 00126 OGRFieldDefn **papoFieldDefn; 00127 00128 OGRwkbGeometryType eGeomType; 00129 00130 char *pszFeatureClassName; 00131 00132 int bIgnoreGeometry; 00133 int bIgnoreStyle; 00134 00135 public: 00136 OGRFeatureDefn( const char * pszName = NULL ); 00137 virtual ~OGRFeatureDefn(); 00138 00139 const char *GetName() { return pszFeatureClassName; } 00140 00141 int GetFieldCount() { return nFieldCount; } 00142 OGRFieldDefn *GetFieldDefn( int i ); 00143 int GetFieldIndex( const char * ); 00144 00145 void AddFieldDefn( OGRFieldDefn * ); 00146 OGRErr DeleteFieldDefn( int iField ); 00147 OGRErr ReorderFieldDefns( int* panMap ); 00148 00149 OGRwkbGeometryType GetGeomType() { return eGeomType; } 00150 void SetGeomType( OGRwkbGeometryType ); 00151 00152 OGRFeatureDefn *Clone(); 00153 00154 int Reference() { return CPLAtomicInc(&nRefCount); } 00155 int Dereference() { return CPLAtomicDec(&nRefCount); } 00156 int GetReferenceCount() { return nRefCount; } 00157 void Release(); 00158 00159 int IsGeometryIgnored() { return bIgnoreGeometry; } 00160 void SetGeometryIgnored( int bIgnore ) { bIgnoreGeometry = bIgnore; } 00161 int IsStyleIgnored() { return bIgnoreStyle; } 00162 void SetStyleIgnored( int bIgnore ) { bIgnoreStyle = bIgnore; } 00163 00164 int IsSame( const OGRFeatureDefn * poOtherFeatureDefn ) const; 00165 00166 static OGRFeatureDefn *CreateFeatureDefn( const char *pszName = NULL ); 00167 static void DestroyFeatureDefn( OGRFeatureDefn * ); 00168 }; 00169 00170 /************************************************************************/ 00171 /* OGRFeature */ 00172 /************************************************************************/ 00173 00178 class CPL_DLL OGRFeature 00179 { 00180 private: 00181 00182 long nFID; 00183 OGRFeatureDefn *poDefn; 00184 OGRGeometry *poGeometry; 00185 OGRField *pauFields; 00186 00187 protected: 00188 char * m_pszStyleString; 00189 OGRStyleTable *m_poStyleTable; 00190 char * m_pszTmpFieldValue; 00191 00192 public: 00193 OGRFeature( OGRFeatureDefn * ); 00194 virtual ~OGRFeature(); 00195 00196 OGRFeatureDefn *GetDefnRef() { return poDefn; } 00197 00198 OGRErr SetGeometryDirectly( OGRGeometry * ); 00199 OGRErr SetGeometry( OGRGeometry * ); 00200 OGRGeometry *GetGeometryRef() { return poGeometry; } 00201 OGRGeometry *StealGeometry(); 00202 00203 OGRFeature *Clone(); 00204 virtual OGRBoolean Equal( OGRFeature * poFeature ); 00205 00206 int GetFieldCount() { return poDefn->GetFieldCount(); } 00207 OGRFieldDefn *GetFieldDefnRef( int iField ) 00208 { return poDefn->GetFieldDefn(iField); } 00209 int GetFieldIndex( const char * pszName) 00210 { return poDefn->GetFieldIndex(pszName);} 00211 00212 int IsFieldSet( int iField ) const; 00213 00214 void UnsetField( int iField ); 00215 00216 OGRField *GetRawFieldRef( int i ) { return pauFields + i; } 00217 00218 int GetFieldAsInteger( int i ); 00219 double GetFieldAsDouble( int i ); 00220 const char *GetFieldAsString( int i ); 00221 const int *GetFieldAsIntegerList( int i, int *pnCount ); 00222 const double *GetFieldAsDoubleList( int i, int *pnCount ); 00223 char **GetFieldAsStringList( int i ) const; 00224 GByte *GetFieldAsBinary( int i, int *pnCount ); 00225 int GetFieldAsDateTime( int i, 00226 int *pnYear, int *pnMonth, int *pnDay, 00227 int *pnHour, int *pnMinute, int *pnSecond, 00228 int *pnTZFlag ); 00229 00230 int GetFieldAsInteger( const char *pszFName ) 00231 { return GetFieldAsInteger( GetFieldIndex(pszFName) ); } 00232 double GetFieldAsDouble( const char *pszFName ) 00233 { return GetFieldAsDouble( GetFieldIndex(pszFName) ); } 00234 const char *GetFieldAsString( const char *pszFName ) 00235 { return GetFieldAsString( GetFieldIndex(pszFName) ); } 00236 const int *GetFieldAsIntegerList( const char *pszFName, 00237 int *pnCount ) 00238 { return GetFieldAsIntegerList( GetFieldIndex(pszFName), 00239 pnCount ); } 00240 const double *GetFieldAsDoubleList( const char *pszFName, 00241 int *pnCount ) 00242 { return GetFieldAsDoubleList( GetFieldIndex(pszFName), 00243 pnCount ); } 00244 char **GetFieldAsStringList( const char *pszFName ) 00245 { return GetFieldAsStringList(GetFieldIndex(pszFName)); } 00246 00247 void SetField( int i, int nValue ); 00248 void SetField( int i, double dfValue ); 00249 void SetField( int i, const char * pszValue ); 00250 void SetField( int i, int nCount, int * panValues ); 00251 void SetField( int i, int nCount, double * padfValues ); 00252 void SetField( int i, char ** papszValues ); 00253 void SetField( int i, OGRField * puValue ); 00254 void SetField( int i, int nCount, GByte * pabyBinary ); 00255 void SetField( int i, int nYear, int nMonth, int nDay, 00256 int nHour=0, int nMinute=0, int nSecond=0, 00257 int nTZFlag = 0 ); 00258 00259 void SetField( const char *pszFName, int nValue ) 00260 { SetField( GetFieldIndex(pszFName), nValue ); } 00261 void SetField( const char *pszFName, double dfValue ) 00262 { SetField( GetFieldIndex(pszFName), dfValue ); } 00263 void SetField( const char *pszFName, const char * pszValue) 00264 { SetField( GetFieldIndex(pszFName), pszValue ); } 00265 void SetField( const char *pszFName, int nCount, 00266 int * panValues ) 00267 { SetField(GetFieldIndex(pszFName),nCount,panValues);} 00268 void SetField( const char *pszFName, int nCount, 00269 double * padfValues ) 00270 {SetField(GetFieldIndex(pszFName),nCount,padfValues);} 00271 void SetField( const char *pszFName, char ** papszValues ) 00272 { SetField( GetFieldIndex(pszFName), papszValues); } 00273 void SetField( const char *pszFName, OGRField * puValue ) 00274 { SetField( GetFieldIndex(pszFName), puValue ); } 00275 void SetField( const char *pszFName, 00276 int nYear, int nMonth, int nDay, 00277 int nHour=0, int nMinute=0, int nSecond=0, 00278 int nTZFlag = 0 ) 00279 { SetField( GetFieldIndex(pszFName), 00280 nYear, nMonth, nDay, 00281 nHour, nMinute, nSecond, nTZFlag ); } 00282 00283 long GetFID() { return nFID; } 00284 virtual OGRErr SetFID( long nFID ); 00285 00286 void DumpReadable( FILE *, char** papszOptions = NULL ); 00287 00288 OGRErr SetFrom( OGRFeature *, int = TRUE); 00289 OGRErr SetFrom( OGRFeature *, int *, int = TRUE ); 00290 OGRErr SetFieldsFrom( OGRFeature *, int *, int = TRUE ); 00291 00292 OGRErr RemapFields( OGRFeatureDefn *poNewDefn, 00293 int *panRemapSource ); 00294 00295 virtual const char *GetStyleString(); 00296 virtual void SetStyleString( const char * ); 00297 virtual void SetStyleStringDirectly( char * ); 00298 virtual OGRStyleTable *GetStyleTable() { return m_poStyleTable; } 00299 virtual void SetStyleTable(OGRStyleTable *poStyleTable); 00300 virtual void SetStyleTableDirectly(OGRStyleTable *poStyleTable) 00301 { if ( m_poStyleTable ) delete m_poStyleTable; 00302 m_poStyleTable = poStyleTable; } 00303 00304 static OGRFeature *CreateFeature( OGRFeatureDefn * ); 00305 static void DestroyFeature( OGRFeature * ); 00306 }; 00307 00308 /************************************************************************/ 00309 /* OGRFeatureQuery */ 00310 /************************************************************************/ 00311 00312 class OGRLayer; 00313 class swq_expr_node; 00314 00315 class CPL_DLL OGRFeatureQuery 00316 { 00317 private: 00318 OGRFeatureDefn *poTargetDefn; 00319 void *pSWQExpr; 00320 00321 char **FieldCollector( void *, char ** ); 00322 00323 long *EvaluateAgainstIndices( swq_expr_node*, OGRLayer *, int& nFIDCount); 00324 00325 int CanUseIndex( swq_expr_node*, OGRLayer * ); 00326 00327 public: 00328 OGRFeatureQuery(); 00329 ~OGRFeatureQuery(); 00330 00331 OGRErr Compile( OGRFeatureDefn *, const char * ); 00332 int Evaluate( OGRFeature * ); 00333 00334 long *EvaluateAgainstIndices( OGRLayer *, OGRErr * ); 00335 00336 int CanUseIndex( OGRLayer * ); 00337 00338 char **GetUsedFields(); 00339 00340 void *GetSWGExpr() { return pSWQExpr; } 00341 }; 00342 00343 #endif /* ndef _OGR_FEATURE_H_INCLUDED */