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