GDAL
ogr_feature.h
Go to the documentation of this file.
1 /******************************************************************************
2  * $Id: ogr_feature.h 33631 2016-03-04 06:28:09Z goatbar $
3  *
4  * Project: OpenGIS Simple Features Reference Implementation
5  * Purpose: Class for representing a whole feature, and layer schemas.
6  * Author: Frank Warmerdam, warmerdam@pobox.com
7  *
8  ******************************************************************************
9  * Copyright (c) 1999, Les Technologies SoftMap Inc.
10  * Copyright (c) 2008-2013, Even Rouault <even dot rouault at mines-paris dot org>
11  *
12  * Permission is hereby granted, free of charge, to any person obtaining a
13  * copy of this software and associated documentation files (the "Software"),
14  * to deal in the Software without restriction, including without limitation
15  * the rights to use, copy, modify, merge, publish, distribute, sublicense,
16  * and/or sell copies of the Software, and to permit persons to whom the
17  * Software is furnished to do so, subject to the following conditions:
18  *
19  * The above copyright notice and this permission notice shall be included
20  * in all copies or substantial portions of the Software.
21  *
22  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
23  * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
24  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
25  * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
26  * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
27  * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
28  * DEALINGS IN THE SOFTWARE.
29  ****************************************************************************/
30 
31 #ifndef OGR_FEATURE_H_INCLUDED
32 #define OGR_FEATURE_H_INCLUDED
33 
34 #include "ogr_geometry.h"
35 #include "ogr_featurestyle.h"
36 #include "cpl_atomic_ops.h"
37 
44 /************************************************************************/
45 /* OGRFieldDefn */
46 /************************************************************************/
47 
62 class CPL_DLL OGRFieldDefn
63 {
64  private:
65  char *pszName;
66  OGRFieldType eType;
67  OGRJustification eJustify;
68  int nWidth; /* zero is variable */
69  int nPrecision;
70  char *pszDefault;
71 
72  int bIgnore;
73  OGRFieldSubType eSubType;
74 
75  int bNullable;
76 
77  void Initialize( const char *, OGRFieldType );
78 
79  public:
80  OGRFieldDefn( const char *, OGRFieldType );
82  ~OGRFieldDefn();
83 
84  void SetName( const char * );
85  const char *GetNameRef() { return pszName; }
86 
87  OGRFieldType GetType() { return eType; }
88  void SetType( OGRFieldType eTypeIn );
89  static const char *GetFieldTypeName( OGRFieldType );
90 
91  OGRFieldSubType GetSubType() { return eSubType; }
92  void SetSubType( OGRFieldSubType eSubTypeIn );
93  static const char *GetFieldSubTypeName( OGRFieldSubType );
94 
95  OGRJustification GetJustify() { return eJustify; }
96  void SetJustify( OGRJustification eJustifyIn )
97  { eJustify = eJustifyIn; }
98 
99  int GetWidth() { return nWidth; }
100  void SetWidth( int nWidthIn ) { nWidth = MAX(0,nWidthIn); }
101 
102  int GetPrecision() { return nPrecision; }
103  void SetPrecision( int nPrecisionIn )
104  { nPrecision = nPrecisionIn; }
105 
106  void Set( const char *, OGRFieldType, int = 0, int = 0,
107  OGRJustification = OJUndefined );
108 
109  void SetDefault( const char* );
110  const char *GetDefault() const;
111  int IsDefaultDriverSpecific() const;
112 
113  int IsIgnored() { return bIgnore; }
114  void SetIgnored( int bIgnoreIn ) { bIgnore = bIgnoreIn; }
115 
116  int IsNullable() const { return bNullable; }
117  void SetNullable( int bNullableIn ) { bNullable = bNullableIn; }
118 
119  int IsSame( const OGRFieldDefn * ) const;
120 
121  private:
122  CPL_DISALLOW_COPY_ASSIGN(OGRFieldDefn);
123 };
124 
125 /************************************************************************/
126 /* OGRGeomFieldDefn */
127 /************************************************************************/
128 
143 class CPL_DLL OGRGeomFieldDefn
144 {
145 protected:
146  char *pszName;
147  OGRwkbGeometryType eGeomType; /* all values possible except wkbNone */
148  OGRSpatialReference* poSRS;
149 
150  int bIgnore;
151  int bNullable;
152 
153  void Initialize( const char *, OGRwkbGeometryType );
154 
155 public:
156  OGRGeomFieldDefn(const char *pszNameIn,
157  OGRwkbGeometryType eGeomTypeIn);
159  virtual ~OGRGeomFieldDefn();
160 
161  void SetName( const char * );
162  const char *GetNameRef() { return pszName; }
163 
164  OGRwkbGeometryType GetType() { return eGeomType; }
165  void SetType( OGRwkbGeometryType eTypeIn );
166 
167  virtual OGRSpatialReference* GetSpatialRef();
168  void SetSpatialRef(OGRSpatialReference* poSRSIn);
169 
170  int IsIgnored() { return bIgnore; }
171  void SetIgnored( int bIgnoreIn ) { bIgnore = bIgnoreIn; }
172 
173  int IsNullable() const { return bNullable; }
174  void SetNullable( int bNullableIn ) { bNullable = bNullableIn; }
175 
176  int IsSame( OGRGeomFieldDefn * );
177 
178  private:
179  CPL_DISALLOW_COPY_ASSIGN(OGRGeomFieldDefn);
180 };
181 
182 /************************************************************************/
183 /* OGRFeatureDefn */
184 /************************************************************************/
185 
206 class CPL_DLL OGRFeatureDefn
207 {
208  protected:
209  volatile int nRefCount;
210 
211  int nFieldCount;
212  OGRFieldDefn **papoFieldDefn;
213 
214  int nGeomFieldCount;
215  OGRGeomFieldDefn **papoGeomFieldDefn;
216 
217  char *pszFeatureClassName;
218 
219  int bIgnoreStyle;
220 
221  public:
222  OGRFeatureDefn( const char * pszName = NULL );
223  virtual ~OGRFeatureDefn();
224 
225  virtual const char *GetName();
226 
227  virtual int GetFieldCount();
228  virtual OGRFieldDefn *GetFieldDefn( int i );
229  virtual int GetFieldIndex( const char * );
230 
231  virtual void AddFieldDefn( OGRFieldDefn * );
232  virtual OGRErr DeleteFieldDefn( int iField );
233  virtual OGRErr ReorderFieldDefns( int* panMap );
234 
235  virtual int GetGeomFieldCount();
236  virtual OGRGeomFieldDefn *GetGeomFieldDefn( int i );
237  virtual int GetGeomFieldIndex( const char * );
238 
239  virtual void AddGeomFieldDefn( OGRGeomFieldDefn *, int bCopy = TRUE );
240  virtual OGRErr DeleteGeomFieldDefn( int iGeomField );
241 
242  virtual OGRwkbGeometryType GetGeomType();
243  virtual void SetGeomType( OGRwkbGeometryType );
244 
245  virtual OGRFeatureDefn *Clone();
246 
247  int Reference() { return CPLAtomicInc(&nRefCount); }
248  int Dereference() { return CPLAtomicDec(&nRefCount); }
249  int GetReferenceCount() { return nRefCount; }
250  void Release();
251 
252  virtual int IsGeometryIgnored();
253  virtual void SetGeometryIgnored( int bIgnore );
254  virtual int IsStyleIgnored() { return bIgnoreStyle; }
255  virtual void SetStyleIgnored( int bIgnore ) { bIgnoreStyle = bIgnore; }
256 
257  virtual int IsSame( OGRFeatureDefn * poOtherFeatureDefn );
258 
259  static OGRFeatureDefn *CreateFeatureDefn( const char *pszName = NULL );
260  static void DestroyFeatureDefn( OGRFeatureDefn * );
261 
262  private:
263  CPL_DISALLOW_COPY_ASSIGN(OGRFeatureDefn);
264 };
265 
266 /************************************************************************/
267 /* OGRFeature */
268 /************************************************************************/
269 
274 class CPL_DLL OGRFeature
275 {
276  private:
277 
278  GIntBig nFID;
279  OGRFeatureDefn *poDefn;
280  OGRGeometry **papoGeometries;
281  OGRField *pauFields;
282  char *m_pszNativeData;
283  char *m_pszNativeMediaType;
284 
285  bool SetFieldInternal( int i, OGRField * puValue );
286 
287  protected:
288  char * m_pszStyleString;
289  OGRStyleTable *m_poStyleTable;
290  char * m_pszTmpFieldValue;
291 
292  public:
294  virtual ~OGRFeature();
295 
296  OGRFeatureDefn *GetDefnRef() { return poDefn; }
297 
298  OGRErr SetGeometryDirectly( OGRGeometry * );
299  OGRErr SetGeometry( OGRGeometry * );
300  OGRGeometry *GetGeometryRef();
301  OGRGeometry *StealGeometry() CPL_WARN_UNUSED_RESULT;
302 
304  { return poDefn->GetGeomFieldCount(); }
306  { return poDefn->GetGeomFieldDefn(iField); }
307  int GetGeomFieldIndex( const char * pszName)
308  { return poDefn->GetGeomFieldIndex(pszName); }
309 
310  OGRGeometry* GetGeomFieldRef(int iField);
311  OGRGeometry* StealGeometry(int iField);
312  OGRGeometry* GetGeomFieldRef(const char* pszFName);
313  OGRErr SetGeomFieldDirectly( int iField, OGRGeometry * );
314  OGRErr SetGeomField( int iField, OGRGeometry * );
315 
316  OGRFeature *Clone() CPL_WARN_UNUSED_RESULT;
317  virtual OGRBoolean Equal( OGRFeature * poFeature );
318 
319  int GetFieldCount() { return poDefn->GetFieldCount(); }
321  { return poDefn->GetFieldDefn(iField); }
322  int GetFieldIndex( const char * pszName)
323  { return poDefn->GetFieldIndex(pszName);}
324 
325  int IsFieldSet( int iField );
326 
327  void UnsetField( int iField );
328 
329  OGRField *GetRawFieldRef( int i ) { return pauFields + i; }
330 
331  int GetFieldAsInteger( int i );
332  GIntBig GetFieldAsInteger64( int i );
333  double GetFieldAsDouble( int i );
334  const char *GetFieldAsString( int i );
335  const int *GetFieldAsIntegerList( int i, int *pnCount );
336  const GIntBig *GetFieldAsInteger64List( int i, int *pnCount );
337  const double *GetFieldAsDoubleList( int i, int *pnCount );
338  char **GetFieldAsStringList( int i );
339  GByte *GetFieldAsBinary( int i, int *pnCount );
340  int GetFieldAsDateTime( int i,
341  int *pnYear, int *pnMonth, int *pnDay,
342  int *pnHour, int *pnMinute, int *pnSecond,
343  int *pnTZFlag );
344  int GetFieldAsDateTime( int i,
345  int *pnYear, int *pnMonth, int *pnDay,
346  int *pnHour, int *pnMinute, float *pfSecond,
347  int *pnTZFlag );
348 
349  int GetFieldAsInteger( const char *pszFName )
350  { return GetFieldAsInteger( GetFieldIndex(pszFName) ); }
351  GIntBig GetFieldAsInteger64( const char *pszFName )
352  { return GetFieldAsInteger64( GetFieldIndex(pszFName) ); }
353  double GetFieldAsDouble( const char *pszFName )
354  { return GetFieldAsDouble( GetFieldIndex(pszFName) ); }
355  const char *GetFieldAsString( const char *pszFName )
356  { return GetFieldAsString( GetFieldIndex(pszFName) ); }
357  const int *GetFieldAsIntegerList( const char *pszFName,
358  int *pnCount )
359  { return GetFieldAsIntegerList( GetFieldIndex(pszFName),
360  pnCount ); }
361  const GIntBig *GetFieldAsInteger64List( const char *pszFName,
362  int *pnCount )
363  { return GetFieldAsInteger64List( GetFieldIndex(pszFName),
364  pnCount ); }
365  const double *GetFieldAsDoubleList( const char *pszFName,
366  int *pnCount )
367  { return GetFieldAsDoubleList( GetFieldIndex(pszFName),
368  pnCount ); }
369  char **GetFieldAsStringList( const char *pszFName )
370  { return GetFieldAsStringList(GetFieldIndex(pszFName)); }
371 
372  void SetField( int i, int nValue );
373  void SetField( int i, GIntBig nValue );
374  void SetField( int i, double dfValue );
375  void SetField( int i, const char * pszValue );
376  void SetField( int i, int nCount, int * panValues );
377  void SetField( int i, int nCount, const GIntBig * panValues );
378  void SetField( int i, int nCount, double * padfValues );
379  void SetField( int i, char ** papszValues );
380  void SetField( int i, OGRField * puValue );
381  void SetField( int i, int nCount, GByte * pabyBinary );
382  void SetField( int i, int nYear, int nMonth, int nDay,
383  int nHour=0, int nMinute=0, float fSecond=0.f,
384  int nTZFlag = 0 );
385 
386  void SetField( const char *pszFName, int nValue )
387  { SetField( GetFieldIndex(pszFName), nValue ); }
388  void SetField( const char *pszFName, GIntBig nValue )
389  { SetField( GetFieldIndex(pszFName), nValue ); }
390  void SetField( const char *pszFName, double dfValue )
391  { SetField( GetFieldIndex(pszFName), dfValue ); }
392  void SetField( const char *pszFName, const char * pszValue)
393  { SetField( GetFieldIndex(pszFName), pszValue ); }
394  void SetField( const char *pszFName, int nCount,
395  int * panValues )
396  { SetField(GetFieldIndex(pszFName),nCount,panValues);}
397  void SetField( const char *pszFName, int nCount,
398  const GIntBig * panValues )
399  { SetField(GetFieldIndex(pszFName),nCount,panValues);}
400  void SetField( const char *pszFName, int nCount,
401  double * padfValues )
402  {SetField(GetFieldIndex(pszFName),nCount,padfValues);}
403  void SetField( const char *pszFName, char ** papszValues )
404  { SetField( GetFieldIndex(pszFName), papszValues); }
405  void SetField( const char *pszFName, OGRField * puValue )
406  { SetField( GetFieldIndex(pszFName), puValue ); }
407  void SetField( const char *pszFName,
408  int nYear, int nMonth, int nDay,
409  int nHour=0, int nMinute=0, float fSecond=0.f,
410  int nTZFlag = 0 )
411  { SetField( GetFieldIndex(pszFName),
412  nYear, nMonth, nDay,
413  nHour, nMinute, fSecond, nTZFlag ); }
414 
415  GIntBig GetFID() { return nFID; }
416  virtual OGRErr SetFID( GIntBig nFIDIn );
417 
418  void DumpReadable( FILE *, char** papszOptions = NULL );
419 
420  OGRErr SetFrom( OGRFeature *, int = TRUE);
421  OGRErr SetFrom( OGRFeature *, int *, int = TRUE );
422  OGRErr SetFieldsFrom( OGRFeature *, int *, int = TRUE );
423 
424  OGRErr RemapFields( OGRFeatureDefn *poNewDefn,
425  int *panRemapSource );
426  OGRErr RemapGeomFields( OGRFeatureDefn *poNewDefn,
427  int *panRemapSource );
428 
429  int Validate( int nValidateFlags,
430  int bEmitError );
431  void FillUnsetWithDefault(int bNotNullableOnly,
432  char** papszOptions );
433 
434  virtual const char *GetStyleString();
435  virtual void SetStyleString( const char * );
436  virtual void SetStyleStringDirectly( char * );
437  virtual OGRStyleTable *GetStyleTable() { return m_poStyleTable; }
438  virtual void SetStyleTable(OGRStyleTable *poStyleTable);
439  virtual void SetStyleTableDirectly(OGRStyleTable *poStyleTable);
440 
441  const char *GetNativeData() const { return m_pszNativeData; }
442  const char *GetNativeMediaType() const { return m_pszNativeMediaType; }
443  void SetNativeData( const char* pszNativeData );
444  void SetNativeMediaType( const char* pszNativeMediaType );
445 
446  static OGRFeature *CreateFeature( OGRFeatureDefn * );
447  static void DestroyFeature( OGRFeature * );
448 
449  private:
450  CPL_DISALLOW_COPY_ASSIGN(OGRFeature);
451 };
452 
453 /************************************************************************/
454 /* OGRFeatureQuery */
455 /************************************************************************/
456 
457 class OGRLayer;
458 class swq_expr_node;
460 
461 class CPL_DLL OGRFeatureQuery
462 {
463  private:
464  OGRFeatureDefn *poTargetDefn;
465  void *pSWQExpr;
466 
467  char **FieldCollector( void *, char ** );
468 
469  GIntBig *EvaluateAgainstIndices( swq_expr_node*, OGRLayer *, GIntBig& nFIDCount);
470 
471  int CanUseIndex( swq_expr_node*, OGRLayer * );
472 
473  public:
474  OGRFeatureQuery();
475  ~OGRFeatureQuery();
476 
477  OGRErr Compile( OGRFeatureDefn *, const char *,
478  int bCheck = TRUE, swq_custom_func_registrar* poCustomFuncRegistrar = NULL );
479  int Evaluate( OGRFeature * );
480 
481  GIntBig *EvaluateAgainstIndices( OGRLayer *, OGRErr * );
482 
483  int CanUseIndex( OGRLayer * );
484 
485  char **GetUsedFields();
486 
487  void *GetSWQExpr() { return pSWQExpr; }
488 };
489 
490 #endif /* ndef OGR_FEATURE_H_INCLUDED */
int IsIgnored()
Return whether this field should be omitted when fetching features.
Definition: ogr_feature.h:170
int GetReferenceCount()
Fetch current reference count.
Definition: ogr_feature.h:249
OGRFieldSubType
List of field subtypes.
Definition: ogr_core.h:628
OGRFieldSubType GetSubType()
Fetch subtype of this field.
Definition: ogr_feature.h:91
int IsNullable() const
Return whether this geometry field can receive null values.
Definition: ogr_feature.h:173
OGRField * GetRawFieldRef(int i)
Fetch a pointer to the internal field value given the index.
Definition: ogr_feature.h:329
const char * GetNameRef()
Fetch name of this field.
Definition: ogr_feature.h:162
void SetNullable(int bNullableIn)
Set whether this geometry field can receive null values.
Definition: ogr_feature.h:174
Definition of a geometry field of an OGRFeatureDefn.
Definition: ogr_feature.h:143
int GetPrecision()
Get the formatting precision for this field.
Definition: ogr_feature.h:102
virtual int GetGeomFieldCount()
Fetch number of geometry fields on this feature.
Definition: ogrfeaturedefn.cpp:575
virtual void SetStyleIgnored(int bIgnore)
Set whether the style can be omitted when fetching features.
Definition: ogr_feature.h:255
int GetWidth()
Get the formatting width for this field.
Definition: ogr_feature.h:99
int GetFieldIndex(const char *pszName)
Fetch the field index given field name.
Definition: ogr_feature.h:322
const char * GetNativeMediaType() const
Returns the native media type for the feature.
Definition: ogr_feature.h:442
Definition of a feature class or feature layer.
Definition: ogr_feature.h:206
virtual int GetGeomFieldIndex(const char *)
Find geometry field by name.
Definition: ogrfeaturedefn.cpp:829
Simple feature style classes.
Definition of an attribute of an OGRFeatureDefn.
Definition: ogr_feature.h:62
OGRFieldType GetType()
Fetch type of this field.
Definition: ogr_feature.h:87
const char * GetNameRef()
Fetch name of this field.
Definition: ogr_feature.h:85
OGRwkbGeometryType
List of well known binary geometry types.
Definition: ogr_core.h:333
OGRwkbGeometryType GetType()
Fetch geometry type of this field.
Definition: ogr_feature.h:164
virtual OGRGeomFieldDefn * GetGeomFieldDefn(int i)
Fetch geometry field definition.
Definition: ogrfeaturedefn.cpp:623
OGRFieldDefn * GetFieldDefnRef(int iField)
Fetch definition for this field.
Definition: ogr_feature.h:320
const char * GetNativeData() const
Returns the native data for the feature.
Definition: ogr_feature.h:441
void SetPrecision(int nPrecisionIn)
Set the formatting precision for this field in characters.
Definition: ogr_feature.h:103
Abstract base class for all geometry classes.
Definition: ogr_geometry.h:104
Definition: ogr_feature.h:461
void SetWidth(int nWidthIn)
Set the formatting width for this field in characters.
Definition: ogr_feature.h:100
OGRJustification
Display justification for field values.
Definition: ogr_core.h:644
OGRJustification GetJustify()
Get the justification for this field.
Definition: ogr_feature.h:95
int Reference()
Increments the reference count by one.
Definition: ogr_feature.h:247
int IsNullable() const
Return whether this field can receive null values.
Definition: ogr_feature.h:116
OGRFieldType
List of feature field types.
Definition: ogr_core.h:600
This class represents an OpenGIS Spatial Reference System, and contains methods for converting betwee...
Definition: ogr_spatialref.h:129
int GetGeomFieldIndex(const char *pszName)
Fetch the geometry field index given geometry field name.
Definition: ogr_feature.h:307
int IsIgnored()
Return whether this field should be omitted when fetching features.
Definition: ogr_feature.h:113
int GetFieldCount()
Fetch number of fields on this feature.
Definition: ogr_feature.h:319
int Dereference()
Decrements the reference count by one.
Definition: ogr_feature.h:248
int GetGeomFieldCount()
Fetch number of geometry fields on this feature.
Definition: ogr_feature.h:303
Definition: swq.h:170
OGRFeature field attribute value union.
Definition: ogr_core.h:662
void SetIgnored(int bIgnoreIn)
Set whether this field should be omitted when fetching features.
Definition: ogr_feature.h:171
This class represents a layer of simple features, with access methods.
Definition: ogrsf_frmts.h:66
OGRGeomFieldDefn * GetGeomFieldDefnRef(int iField)
Fetch definition for this geometry field.
Definition: ogr_feature.h:305
A simple feature, including geometry and attributes.
Definition: ogr_feature.h:274
virtual int GetFieldCount()
Fetch number of fields on this feature.
Definition: ogrfeaturedefn.cpp:265
virtual OGRFieldDefn * GetFieldDefn(int i)
Fetch field definition.
Definition: ogrfeaturedefn.cpp:312
This class represents a style table.
Definition: ogr_featurestyle.h:82
virtual int IsStyleIgnored()
Determine whether the style can be omitted when fetching features.
Definition: ogr_feature.h:254
Simple feature geometry classes.
void SetJustify(OGRJustification eJustifyIn)
Set the justification for this field.
Definition: ogr_feature.h:96
OGRFeatureDefn * GetDefnRef()
Fetch feature definition.
Definition: ogr_feature.h:296
Definition: swq.h:102
GIntBig GetFID()
Get feature identifier.
Definition: ogr_feature.h:415
virtual int GetFieldIndex(const char *)
Find field by name.
Definition: ogrfeaturedefn.cpp:1127
void SetIgnored(int bIgnoreIn)
Set whether this field should be omitted when fetching features.
Definition: ogr_feature.h:114
void SetNullable(int bNullableIn)
Set whether this field can receive null values.
Definition: ogr_feature.h:117

Generated for GDAL by doxygen 1.8.12.