GDAL
|
00001 /****************************************************************************** 00002 * $Id: ogr_feature.h 28968 2015-04-21 19:00:02Z 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 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 void Initialize( const char *, OGRFieldType ); 00078 00079 public: 00080 OGRFieldDefn( const char *, OGRFieldType ); 00081 OGRFieldDefn( OGRFieldDefn * ); 00082 ~OGRFieldDefn(); 00083 00084 void SetName( const char * ); 00085 const char *GetNameRef() { return pszName; } 00086 00087 OGRFieldType GetType() { return eType; } 00088 void SetType( OGRFieldType eTypeIn ); 00089 static const char *GetFieldTypeName( OGRFieldType ); 00090 00091 OGRFieldSubType GetSubType() { return eSubType; } 00092 void SetSubType( OGRFieldSubType eSubTypeIn ); 00093 static const char *GetFieldSubTypeName( OGRFieldSubType ); 00094 00095 OGRJustification GetJustify() { return eJustify; } 00096 void SetJustify( OGRJustification eJustifyIn ) 00097 { eJustify = eJustifyIn; } 00098 00099 int GetWidth() { return nWidth; } 00100 void SetWidth( int nWidthIn ) { nWidth = MAX(0,nWidthIn); } 00101 00102 int GetPrecision() { return nPrecision; } 00103 void SetPrecision( int nPrecisionIn ) 00104 { nPrecision = nPrecisionIn; } 00105 00106 void Set( const char *, OGRFieldType, int = 0, int = 0, 00107 OGRJustification = OJUndefined ); 00108 00109 void SetDefault( const char* ); 00110 const char *GetDefault() const; 00111 int IsDefaultDriverSpecific() const; 00112 00113 int IsIgnored() { return bIgnore; } 00114 void SetIgnored( int bIgnoreIn ) { bIgnore = bIgnoreIn; } 00115 00116 int IsNullable() const { return bNullable; } 00117 void SetNullable( int bNullableIn ) { bNullable = bNullableIn; } 00118 00119 int IsSame( const OGRFieldDefn * ) const; 00120 }; 00121 00122 /************************************************************************/ 00123 /* OGRGeomFieldDefn */ 00124 /************************************************************************/ 00125 00140 class CPL_DLL OGRGeomFieldDefn 00141 { 00142 protected: 00143 char *pszName; 00144 OGRwkbGeometryType eGeomType; /* all values possible except wkbNone */ 00145 OGRSpatialReference* poSRS; 00146 00147 int bIgnore; 00148 int bNullable; 00149 00150 void Initialize( const char *, OGRwkbGeometryType ); 00151 00152 public: 00153 OGRGeomFieldDefn(const char *pszNameIn, 00154 OGRwkbGeometryType eGeomTypeIn); 00155 OGRGeomFieldDefn( OGRGeomFieldDefn * ); 00156 virtual ~OGRGeomFieldDefn(); 00157 00158 void SetName( const char * ); 00159 const char *GetNameRef() { return pszName; } 00160 00161 OGRwkbGeometryType GetType() { return eGeomType; } 00162 void SetType( OGRwkbGeometryType eTypeIn ); 00163 00164 virtual OGRSpatialReference* GetSpatialRef(); 00165 void SetSpatialRef(OGRSpatialReference* poSRSIn); 00166 00167 int IsIgnored() { return bIgnore; } 00168 void SetIgnored( int bIgnoreIn ) { bIgnore = bIgnoreIn; } 00169 00170 int IsNullable() const { return bNullable; } 00171 void SetNullable( int bNullableIn ) { bNullable = bNullableIn; } 00172 00173 int IsSame( OGRGeomFieldDefn * ); 00174 }; 00175 00176 /************************************************************************/ 00177 /* OGRFeatureDefn */ 00178 /************************************************************************/ 00179 00200 class CPL_DLL OGRFeatureDefn 00201 { 00202 protected: 00203 volatile int nRefCount; 00204 00205 int nFieldCount; 00206 OGRFieldDefn **papoFieldDefn; 00207 00208 int nGeomFieldCount; 00209 OGRGeomFieldDefn **papoGeomFieldDefn; 00210 00211 char *pszFeatureClassName; 00212 00213 int bIgnoreStyle; 00214 00215 public: 00216 OGRFeatureDefn( const char * pszName = NULL ); 00217 virtual ~OGRFeatureDefn(); 00218 00219 virtual const char *GetName(); 00220 00221 virtual int GetFieldCount(); 00222 virtual OGRFieldDefn *GetFieldDefn( int i ); 00223 virtual int GetFieldIndex( const char * ); 00224 00225 virtual void AddFieldDefn( OGRFieldDefn * ); 00226 virtual OGRErr DeleteFieldDefn( int iField ); 00227 virtual OGRErr ReorderFieldDefns( int* panMap ); 00228 00229 virtual int GetGeomFieldCount(); 00230 virtual OGRGeomFieldDefn *GetGeomFieldDefn( int i ); 00231 virtual int GetGeomFieldIndex( const char * ); 00232 00233 virtual void AddGeomFieldDefn( OGRGeomFieldDefn *, int bCopy = TRUE ); 00234 virtual OGRErr DeleteGeomFieldDefn( int iGeomField ); 00235 00236 virtual OGRwkbGeometryType GetGeomType(); 00237 virtual void SetGeomType( OGRwkbGeometryType ); 00238 00239 virtual OGRFeatureDefn *Clone(); 00240 00241 int Reference() { return CPLAtomicInc(&nRefCount); } 00242 int Dereference() { return CPLAtomicDec(&nRefCount); } 00243 int GetReferenceCount() { return nRefCount; } 00244 void Release(); 00245 00246 virtual int IsGeometryIgnored(); 00247 virtual void SetGeometryIgnored( int bIgnore ); 00248 virtual int IsStyleIgnored() { return bIgnoreStyle; } 00249 virtual void SetStyleIgnored( int bIgnore ) { bIgnoreStyle = bIgnore; } 00250 00251 virtual int IsSame( OGRFeatureDefn * poOtherFeatureDefn ); 00252 00253 static OGRFeatureDefn *CreateFeatureDefn( const char *pszName = NULL ); 00254 static void DestroyFeatureDefn( OGRFeatureDefn * ); 00255 }; 00256 00257 /************************************************************************/ 00258 /* OGRFeature */ 00259 /************************************************************************/ 00260 00265 class CPL_DLL OGRFeature 00266 { 00267 private: 00268 00269 GIntBig nFID; 00270 OGRFeatureDefn *poDefn; 00271 OGRGeometry **papoGeometries; 00272 OGRField *pauFields; 00273 00274 protected: 00275 char * m_pszStyleString; 00276 OGRStyleTable *m_poStyleTable; 00277 char * m_pszTmpFieldValue; 00278 00279 public: 00280 OGRFeature( OGRFeatureDefn * ); 00281 virtual ~OGRFeature(); 00282 00283 OGRFeatureDefn *GetDefnRef() { return poDefn; } 00284 00285 OGRErr SetGeometryDirectly( OGRGeometry * ); 00286 OGRErr SetGeometry( OGRGeometry * ); 00287 OGRGeometry *GetGeometryRef(); 00288 OGRGeometry *StealGeometry(); 00289 00290 int GetGeomFieldCount() 00291 { return poDefn->GetGeomFieldCount(); } 00292 OGRGeomFieldDefn *GetGeomFieldDefnRef( int iField ) 00293 { return poDefn->GetGeomFieldDefn(iField); } 00294 int GetGeomFieldIndex( const char * pszName) 00295 { return poDefn->GetGeomFieldIndex(pszName); } 00296 00297 OGRGeometry* GetGeomFieldRef(int iField); 00298 OGRGeometry* StealGeometry(int iField); 00299 OGRGeometry* GetGeomFieldRef(const char* pszFName); 00300 OGRErr SetGeomFieldDirectly( int iField, OGRGeometry * ); 00301 OGRErr SetGeomField( int iField, OGRGeometry * ); 00302 00303 OGRFeature *Clone(); 00304 virtual OGRBoolean Equal( OGRFeature * poFeature ); 00305 00306 int GetFieldCount() { return poDefn->GetFieldCount(); } 00307 OGRFieldDefn *GetFieldDefnRef( int iField ) 00308 { return poDefn->GetFieldDefn(iField); } 00309 int GetFieldIndex( const char * pszName) 00310 { return poDefn->GetFieldIndex(pszName);} 00311 00312 int IsFieldSet( int iField ); 00313 00314 void UnsetField( int iField ); 00315 00316 OGRField *GetRawFieldRef( int i ) { return pauFields + i; } 00317 00318 int GetFieldAsInteger( int i ); 00319 GIntBig GetFieldAsInteger64( int i ); 00320 double GetFieldAsDouble( int i ); 00321 const char *GetFieldAsString( int i ); 00322 const int *GetFieldAsIntegerList( int i, int *pnCount ); 00323 const GIntBig *GetFieldAsInteger64List( int i, int *pnCount ); 00324 const double *GetFieldAsDoubleList( int i, int *pnCount ); 00325 char **GetFieldAsStringList( int i ); 00326 GByte *GetFieldAsBinary( int i, int *pnCount ); 00327 int GetFieldAsDateTime( int i, 00328 int *pnYear, int *pnMonth, int *pnDay, 00329 int *pnHour, int *pnMinute, int *pnSecond, 00330 int *pnTZFlag ); 00331 int GetFieldAsDateTime( int i, 00332 int *pnYear, int *pnMonth, int *pnDay, 00333 int *pnHour, int *pnMinute, float *pfSecond, 00334 int *pnTZFlag ); 00335 00336 int GetFieldAsInteger( const char *pszFName ) 00337 { return GetFieldAsInteger( GetFieldIndex(pszFName) ); } 00338 GIntBig GetFieldAsInteger64( const char *pszFName ) 00339 { return GetFieldAsInteger64( GetFieldIndex(pszFName) ); } 00340 double GetFieldAsDouble( const char *pszFName ) 00341 { return GetFieldAsDouble( GetFieldIndex(pszFName) ); } 00342 const char *GetFieldAsString( const char *pszFName ) 00343 { return GetFieldAsString( GetFieldIndex(pszFName) ); } 00344 const int *GetFieldAsIntegerList( const char *pszFName, 00345 int *pnCount ) 00346 { return GetFieldAsIntegerList( GetFieldIndex(pszFName), 00347 pnCount ); } 00348 const GIntBig *GetFieldAsInteger64List( const char *pszFName, 00349 int *pnCount ) 00350 { return GetFieldAsInteger64List( GetFieldIndex(pszFName), 00351 pnCount ); } 00352 const double *GetFieldAsDoubleList( const char *pszFName, 00353 int *pnCount ) 00354 { return GetFieldAsDoubleList( GetFieldIndex(pszFName), 00355 pnCount ); } 00356 char **GetFieldAsStringList( const char *pszFName ) 00357 { return GetFieldAsStringList(GetFieldIndex(pszFName)); } 00358 00359 void SetField( int i, int nValue ); 00360 void SetField( int i, GIntBig nValue ); 00361 void SetField( int i, double dfValue ); 00362 void SetField( int i, const char * pszValue ); 00363 void SetField( int i, int nCount, int * panValues ); 00364 void SetField( int i, int nCount, const GIntBig * panValues ); 00365 void SetField( int i, int nCount, double * padfValues ); 00366 void SetField( int i, char ** papszValues ); 00367 void SetField( int i, OGRField * puValue ); 00368 void SetField( int i, int nCount, GByte * pabyBinary ); 00369 void SetField( int i, int nYear, int nMonth, int nDay, 00370 int nHour=0, int nMinute=0, float fSecond=0.f, 00371 int nTZFlag = 0 ); 00372 00373 void SetField( const char *pszFName, int nValue ) 00374 { SetField( GetFieldIndex(pszFName), nValue ); } 00375 void SetField( const char *pszFName, GIntBig nValue ) 00376 { SetField( GetFieldIndex(pszFName), nValue ); } 00377 void SetField( const char *pszFName, double dfValue ) 00378 { SetField( GetFieldIndex(pszFName), dfValue ); } 00379 void SetField( const char *pszFName, const char * pszValue) 00380 { SetField( GetFieldIndex(pszFName), pszValue ); } 00381 void SetField( const char *pszFName, int nCount, 00382 int * panValues ) 00383 { SetField(GetFieldIndex(pszFName),nCount,panValues);} 00384 void SetField( const char *pszFName, int nCount, 00385 const GIntBig * panValues ) 00386 { SetField(GetFieldIndex(pszFName),nCount,panValues);} 00387 void SetField( const char *pszFName, int nCount, 00388 double * padfValues ) 00389 {SetField(GetFieldIndex(pszFName),nCount,padfValues);} 00390 void SetField( const char *pszFName, char ** papszValues ) 00391 { SetField( GetFieldIndex(pszFName), papszValues); } 00392 void SetField( const char *pszFName, OGRField * puValue ) 00393 { SetField( GetFieldIndex(pszFName), puValue ); } 00394 void SetField( const char *pszFName, 00395 int nYear, int nMonth, int nDay, 00396 int nHour=0, int nMinute=0, float fSecond=0.f, 00397 int nTZFlag = 0 ) 00398 { SetField( GetFieldIndex(pszFName), 00399 nYear, nMonth, nDay, 00400 nHour, nMinute, fSecond, nTZFlag ); } 00401 00402 GIntBig GetFID() { return nFID; } 00403 virtual OGRErr SetFID( GIntBig nFIDIn ); 00404 00405 void DumpReadable( FILE *, char** papszOptions = NULL ); 00406 00407 OGRErr SetFrom( OGRFeature *, int = TRUE); 00408 OGRErr SetFrom( OGRFeature *, int *, int = TRUE ); 00409 OGRErr SetFieldsFrom( OGRFeature *, int *, int = TRUE ); 00410 00411 OGRErr RemapFields( OGRFeatureDefn *poNewDefn, 00412 int *panRemapSource ); 00413 OGRErr RemapGeomFields( OGRFeatureDefn *poNewDefn, 00414 int *panRemapSource ); 00415 00416 int Validate( int nValidateFlags, 00417 int bEmitError ); 00418 void FillUnsetWithDefault(int bNotNullableOnly, 00419 char** papszOptions ); 00420 00421 virtual const char *GetStyleString(); 00422 virtual void SetStyleString( const char * ); 00423 virtual void SetStyleStringDirectly( char * ); 00424 virtual OGRStyleTable *GetStyleTable() { return m_poStyleTable; } 00425 virtual void SetStyleTable(OGRStyleTable *poStyleTable); 00426 virtual void SetStyleTableDirectly(OGRStyleTable *poStyleTable); 00427 00428 static OGRFeature *CreateFeature( OGRFeatureDefn * ); 00429 static void DestroyFeature( OGRFeature * ); 00430 }; 00431 00432 /************************************************************************/ 00433 /* OGRFeatureQuery */ 00434 /************************************************************************/ 00435 00436 class OGRLayer; 00437 class swq_expr_node; 00438 class swq_custom_func_registrar; 00439 00440 class CPL_DLL OGRFeatureQuery 00441 { 00442 private: 00443 OGRFeatureDefn *poTargetDefn; 00444 void *pSWQExpr; 00445 00446 char **FieldCollector( void *, char ** ); 00447 00448 GIntBig *EvaluateAgainstIndices( swq_expr_node*, OGRLayer *, GIntBig& nFIDCount); 00449 00450 int CanUseIndex( swq_expr_node*, OGRLayer * ); 00451 00452 public: 00453 OGRFeatureQuery(); 00454 ~OGRFeatureQuery(); 00455 00456 OGRErr Compile( OGRFeatureDefn *, const char *, 00457 int bCheck = TRUE, swq_custom_func_registrar* poCustomFuncRegistrar = NULL ); 00458 int Evaluate( OGRFeature * ); 00459 00460 GIntBig *EvaluateAgainstIndices( OGRLayer *, OGRErr * ); 00461 00462 int CanUseIndex( OGRLayer * ); 00463 00464 char **GetUsedFields(); 00465 00466 void *GetSWQExpr() { return pSWQExpr; } 00467 }; 00468 00469 #endif /* ndef _OGR_FEATURE_H_INCLUDED */