00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
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
00046
00047
00062 class CPL_DLL OGRFieldDefn
00063 {
00064 private:
00065 char *pszName;
00066 OGRFieldType eType;
00067 OGRJustification eJustify;
00068 int nWidth;
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 private:
00122 CPL_DISALLOW_COPY_ASSIGN(OGRFieldDefn);
00123 };
00124
00125
00126
00127
00128
00143 class CPL_DLL OGRGeomFieldDefn
00144 {
00145 protected:
00146 char *pszName;
00147 OGRwkbGeometryType eGeomType;
00148 OGRSpatialReference* poSRS;
00149
00150 int bIgnore;
00151 int bNullable;
00152
00153 void Initialize( const char *, OGRwkbGeometryType );
00154
00155 public:
00156 OGRGeomFieldDefn(const char *pszNameIn,
00157 OGRwkbGeometryType eGeomTypeIn);
00158 OGRGeomFieldDefn( OGRGeomFieldDefn * );
00159 virtual ~OGRGeomFieldDefn();
00160
00161 void SetName( const char * );
00162 const char *GetNameRef() { return pszName; }
00163
00164 OGRwkbGeometryType GetType() { return eGeomType; }
00165 void SetType( OGRwkbGeometryType eTypeIn );
00166
00167 virtual OGRSpatialReference* GetSpatialRef();
00168 void SetSpatialRef(OGRSpatialReference* poSRSIn);
00169
00170 int IsIgnored() { return bIgnore; }
00171 void SetIgnored( int bIgnoreIn ) { bIgnore = bIgnoreIn; }
00172
00173 int IsNullable() const { return bNullable; }
00174 void SetNullable( int bNullableIn ) { bNullable = bNullableIn; }
00175
00176 int IsSame( OGRGeomFieldDefn * );
00177
00178 private:
00179 CPL_DISALLOW_COPY_ASSIGN(OGRGeomFieldDefn);
00180 };
00181
00182
00183
00184
00185
00206 class CPL_DLL OGRFeatureDefn
00207 {
00208 protected:
00209 volatile int nRefCount;
00210
00211 int nFieldCount;
00212 OGRFieldDefn **papoFieldDefn;
00213
00214 int nGeomFieldCount;
00215 OGRGeomFieldDefn **papoGeomFieldDefn;
00216
00217 char *pszFeatureClassName;
00218
00219 int bIgnoreStyle;
00220
00221 public:
00222 OGRFeatureDefn( const char * pszName = NULL );
00223 virtual ~OGRFeatureDefn();
00224
00225 virtual const char *GetName();
00226
00227 virtual int GetFieldCount();
00228 virtual OGRFieldDefn *GetFieldDefn( int i );
00229 virtual int GetFieldIndex( const char * );
00230
00231 virtual void AddFieldDefn( OGRFieldDefn * );
00232 virtual OGRErr DeleteFieldDefn( int iField );
00233 virtual OGRErr ReorderFieldDefns( int* panMap );
00234
00235 virtual int GetGeomFieldCount();
00236 virtual OGRGeomFieldDefn *GetGeomFieldDefn( int i );
00237 virtual int GetGeomFieldIndex( const char * );
00238
00239 virtual void AddGeomFieldDefn( OGRGeomFieldDefn *, int bCopy = TRUE );
00240 virtual OGRErr DeleteGeomFieldDefn( int iGeomField );
00241
00242 virtual OGRwkbGeometryType GetGeomType();
00243 virtual void SetGeomType( OGRwkbGeometryType );
00244
00245 virtual OGRFeatureDefn *Clone();
00246
00247 int Reference() { return CPLAtomicInc(&nRefCount); }
00248 int Dereference() { return CPLAtomicDec(&nRefCount); }
00249 int GetReferenceCount() { return nRefCount; }
00250 void Release();
00251
00252 virtual int IsGeometryIgnored();
00253 virtual void SetGeometryIgnored( int bIgnore );
00254 virtual int IsStyleIgnored() { return bIgnoreStyle; }
00255 virtual void SetStyleIgnored( int bIgnore ) { bIgnoreStyle = bIgnore; }
00256
00257 virtual int IsSame( OGRFeatureDefn * poOtherFeatureDefn );
00258
00259 static OGRFeatureDefn *CreateFeatureDefn( const char *pszName = NULL );
00260 static void DestroyFeatureDefn( OGRFeatureDefn * );
00261
00262 private:
00263 CPL_DISALLOW_COPY_ASSIGN(OGRFeatureDefn);
00264 };
00265
00266
00267
00268
00269
00274 class CPL_DLL OGRFeature
00275 {
00276 private:
00277
00278 GIntBig nFID;
00279 OGRFeatureDefn *poDefn;
00280 OGRGeometry **papoGeometries;
00281 OGRField *pauFields;
00282 char *m_pszNativeData;
00283 char *m_pszNativeMediaType;
00284
00285 bool SetFieldInternal( int i, OGRField * puValue );
00286
00287 protected:
00288 char * m_pszStyleString;
00289 OGRStyleTable *m_poStyleTable;
00290 char * m_pszTmpFieldValue;
00291
00292 public:
00293 OGRFeature( OGRFeatureDefn * );
00294 virtual ~OGRFeature();
00295
00296 OGRFeatureDefn *GetDefnRef() { return poDefn; }
00297
00298 OGRErr SetGeometryDirectly( OGRGeometry * );
00299 OGRErr SetGeometry( OGRGeometry * );
00300 OGRGeometry *GetGeometryRef();
00301 OGRGeometry *StealGeometry() CPL_WARN_UNUSED_RESULT;
00302
00303 int GetGeomFieldCount()
00304 { return poDefn->GetGeomFieldCount(); }
00305 OGRGeomFieldDefn *GetGeomFieldDefnRef( int iField )
00306 { return poDefn->GetGeomFieldDefn(iField); }
00307 int GetGeomFieldIndex( const char * pszName)
00308 { return poDefn->GetGeomFieldIndex(pszName); }
00309
00310 OGRGeometry* GetGeomFieldRef(int iField);
00311 OGRGeometry* StealGeometry(int iField);
00312 OGRGeometry* GetGeomFieldRef(const char* pszFName);
00313 OGRErr SetGeomFieldDirectly( int iField, OGRGeometry * );
00314 OGRErr SetGeomField( int iField, OGRGeometry * );
00315
00316 OGRFeature *Clone() CPL_WARN_UNUSED_RESULT;
00317 virtual OGRBoolean Equal( OGRFeature * poFeature );
00318
00319 int GetFieldCount() { return poDefn->GetFieldCount(); }
00320 OGRFieldDefn *GetFieldDefnRef( int iField )
00321 { return poDefn->GetFieldDefn(iField); }
00322 int GetFieldIndex( const char * pszName)
00323 { return poDefn->GetFieldIndex(pszName);}
00324
00325 int IsFieldSet( int iField );
00326
00327 void UnsetField( int iField );
00328
00329 OGRField *GetRawFieldRef( int i ) { return pauFields + i; }
00330
00331 int GetFieldAsInteger( int i );
00332 GIntBig GetFieldAsInteger64( int i );
00333 double GetFieldAsDouble( int i );
00334 const char *GetFieldAsString( int i );
00335 const int *GetFieldAsIntegerList( int i, int *pnCount );
00336 const GIntBig *GetFieldAsInteger64List( int i, int *pnCount );
00337 const double *GetFieldAsDoubleList( int i, int *pnCount );
00338 char **GetFieldAsStringList( int i );
00339 GByte *GetFieldAsBinary( int i, int *pnCount );
00340 int GetFieldAsDateTime( int i,
00341 int *pnYear, int *pnMonth, int *pnDay,
00342 int *pnHour, int *pnMinute, int *pnSecond,
00343 int *pnTZFlag );
00344 int GetFieldAsDateTime( int i,
00345 int *pnYear, int *pnMonth, int *pnDay,
00346 int *pnHour, int *pnMinute, float *pfSecond,
00347 int *pnTZFlag );
00348
00349 int GetFieldAsInteger( const char *pszFName )
00350 { return GetFieldAsInteger( GetFieldIndex(pszFName) ); }
00351 GIntBig GetFieldAsInteger64( const char *pszFName )
00352 { return GetFieldAsInteger64( GetFieldIndex(pszFName) ); }
00353 double GetFieldAsDouble( const char *pszFName )
00354 { return GetFieldAsDouble( GetFieldIndex(pszFName) ); }
00355 const char *GetFieldAsString( const char *pszFName )
00356 { return GetFieldAsString( GetFieldIndex(pszFName) ); }
00357 const int *GetFieldAsIntegerList( const char *pszFName,
00358 int *pnCount )
00359 { return GetFieldAsIntegerList( GetFieldIndex(pszFName),
00360 pnCount ); }
00361 const GIntBig *GetFieldAsInteger64List( const char *pszFName,
00362 int *pnCount )
00363 { return GetFieldAsInteger64List( GetFieldIndex(pszFName),
00364 pnCount ); }
00365 const double *GetFieldAsDoubleList( const char *pszFName,
00366 int *pnCount )
00367 { return GetFieldAsDoubleList( GetFieldIndex(pszFName),
00368 pnCount ); }
00369 char **GetFieldAsStringList( const char *pszFName )
00370 { return GetFieldAsStringList(GetFieldIndex(pszFName)); }
00371
00372 void SetField( int i, int nValue );
00373 void SetField( int i, GIntBig nValue );
00374 void SetField( int i, double dfValue );
00375 void SetField( int i, const char * pszValue );
00376 void SetField( int i, int nCount, int * panValues );
00377 void SetField( int i, int nCount, const GIntBig * panValues );
00378 void SetField( int i, int nCount, double * padfValues );
00379 void SetField( int i, char ** papszValues );
00380 void SetField( int i, OGRField * puValue );
00381 void SetField( int i, int nCount, GByte * pabyBinary );
00382 void SetField( int i, int nYear, int nMonth, int nDay,
00383 int nHour=0, int nMinute=0, float fSecond=0.f,
00384 int nTZFlag = 0 );
00385
00386 void SetField( const char *pszFName, int nValue )
00387 { SetField( GetFieldIndex(pszFName), nValue ); }
00388 void SetField( const char *pszFName, GIntBig nValue )
00389 { SetField( GetFieldIndex(pszFName), nValue ); }
00390 void SetField( const char *pszFName, double dfValue )
00391 { SetField( GetFieldIndex(pszFName), dfValue ); }
00392 void SetField( const char *pszFName, const char * pszValue)
00393 { SetField( GetFieldIndex(pszFName), pszValue ); }
00394 void SetField( const char *pszFName, int nCount,
00395 int * panValues )
00396 { SetField(GetFieldIndex(pszFName),nCount,panValues);}
00397 void SetField( const char *pszFName, int nCount,
00398 const GIntBig * panValues )
00399 { SetField(GetFieldIndex(pszFName),nCount,panValues);}
00400 void SetField( const char *pszFName, int nCount,
00401 double * padfValues )
00402 {SetField(GetFieldIndex(pszFName),nCount,padfValues);}
00403 void SetField( const char *pszFName, char ** papszValues )
00404 { SetField( GetFieldIndex(pszFName), papszValues); }
00405 void SetField( const char *pszFName, OGRField * puValue )
00406 { SetField( GetFieldIndex(pszFName), puValue ); }
00407 void SetField( const char *pszFName,
00408 int nYear, int nMonth, int nDay,
00409 int nHour=0, int nMinute=0, float fSecond=0.f,
00410 int nTZFlag = 0 )
00411 { SetField( GetFieldIndex(pszFName),
00412 nYear, nMonth, nDay,
00413 nHour, nMinute, fSecond, nTZFlag ); }
00414
00415 GIntBig GetFID() { return nFID; }
00416 virtual OGRErr SetFID( GIntBig nFIDIn );
00417
00418 void DumpReadable( FILE *, char** papszOptions = NULL );
00419
00420 OGRErr SetFrom( OGRFeature *, int = TRUE);
00421 OGRErr SetFrom( OGRFeature *, int *, int = TRUE );
00422 OGRErr SetFieldsFrom( OGRFeature *, int *, int = TRUE );
00423
00424 OGRErr RemapFields( OGRFeatureDefn *poNewDefn,
00425 int *panRemapSource );
00426 OGRErr RemapGeomFields( OGRFeatureDefn *poNewDefn,
00427 int *panRemapSource );
00428
00429 int Validate( int nValidateFlags,
00430 int bEmitError );
00431 void FillUnsetWithDefault(int bNotNullableOnly,
00432 char** papszOptions );
00433
00434 virtual const char *GetStyleString();
00435 virtual void SetStyleString( const char * );
00436 virtual void SetStyleStringDirectly( char * );
00437 virtual OGRStyleTable *GetStyleTable() { return m_poStyleTable; }
00438 virtual void SetStyleTable(OGRStyleTable *poStyleTable);
00439 virtual void SetStyleTableDirectly(OGRStyleTable *poStyleTable);
00440
00441 const char *GetNativeData() const { return m_pszNativeData; }
00442 const char *GetNativeMediaType() const { return m_pszNativeMediaType; }
00443 void SetNativeData( const char* pszNativeData );
00444 void SetNativeMediaType( const char* pszNativeMediaType );
00445
00446 static OGRFeature *CreateFeature( OGRFeatureDefn * );
00447 static void DestroyFeature( OGRFeature * );
00448
00449 private:
00450 CPL_DISALLOW_COPY_ASSIGN(OGRFeature);
00451 };
00452
00453
00454
00455
00456
00457 class OGRLayer;
00458 class swq_expr_node;
00459 class swq_custom_func_registrar;
00460
00461 class CPL_DLL OGRFeatureQuery
00462 {
00463 private:
00464 OGRFeatureDefn *poTargetDefn;
00465 void *pSWQExpr;
00466
00467 char **FieldCollector( void *, char ** );
00468
00469 GIntBig *EvaluateAgainstIndices( swq_expr_node*, OGRLayer *, GIntBig& nFIDCount);
00470
00471 int CanUseIndex( swq_expr_node*, OGRLayer * );
00472
00473 public:
00474 OGRFeatureQuery();
00475 ~OGRFeatureQuery();
00476
00477 OGRErr Compile( OGRFeatureDefn *, const char *,
00478 int bCheck = TRUE, swq_custom_func_registrar* poCustomFuncRegistrar = NULL );
00479 int Evaluate( OGRFeature * );
00480
00481 GIntBig *EvaluateAgainstIndices( OGRLayer *, OGRErr * );
00482
00483 int CanUseIndex( OGRLayer * );
00484
00485 char **GetUsedFields();
00486
00487 void *GetSWQExpr() { return pSWQExpr; }
00488 };
00489
00490 #endif