OGR
ogr_feature.h
Go to the documentation of this file.
1 /******************************************************************************
2  * $Id: ogr_feature.h 28968 2015-04-21 19:00:02Z rouault $
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 
122 /************************************************************************/
123 /* OGRGeomFieldDefn */
124 /************************************************************************/
125 
140 class CPL_DLL OGRGeomFieldDefn
141 {
142 protected:
143  char *pszName;
144  OGRwkbGeometryType eGeomType; /* all values possible except wkbNone */
145  OGRSpatialReference* poSRS;
146 
147  int bIgnore;
148  int bNullable;
149 
150  void Initialize( const char *, OGRwkbGeometryType );
151 
152 public:
153  OGRGeomFieldDefn(const char *pszNameIn,
154  OGRwkbGeometryType eGeomTypeIn);
156  virtual ~OGRGeomFieldDefn();
157 
158  void SetName( const char * );
159  const char *GetNameRef() { return pszName; }
160 
161  OGRwkbGeometryType GetType() { return eGeomType; }
162  void SetType( OGRwkbGeometryType eTypeIn );
163 
164  virtual OGRSpatialReference* GetSpatialRef();
165  void SetSpatialRef(OGRSpatialReference* poSRSIn);
166 
167  int IsIgnored() { return bIgnore; }
168  void SetIgnored( int bIgnoreIn ) { bIgnore = bIgnoreIn; }
169 
170  int IsNullable() const { return bNullable; }
171  void SetNullable( int bNullableIn ) { bNullable = bNullableIn; }
172 
173  int IsSame( OGRGeomFieldDefn * );
174 };
175 
176 /************************************************************************/
177 /* OGRFeatureDefn */
178 /************************************************************************/
179 
200 class CPL_DLL OGRFeatureDefn
201 {
202  protected:
203  volatile int nRefCount;
204 
205  int nFieldCount;
206  OGRFieldDefn **papoFieldDefn;
207 
208  int nGeomFieldCount;
209  OGRGeomFieldDefn **papoGeomFieldDefn;
210 
211  char *pszFeatureClassName;
212 
213  int bIgnoreStyle;
214 
215  public:
216  OGRFeatureDefn( const char * pszName = NULL );
217  virtual ~OGRFeatureDefn();
218 
219  virtual const char *GetName();
220 
221  virtual int GetFieldCount();
222  virtual OGRFieldDefn *GetFieldDefn( int i );
223  virtual int GetFieldIndex( const char * );
224 
225  virtual void AddFieldDefn( OGRFieldDefn * );
226  virtual OGRErr DeleteFieldDefn( int iField );
227  virtual OGRErr ReorderFieldDefns( int* panMap );
228 
229  virtual int GetGeomFieldCount();
230  virtual OGRGeomFieldDefn *GetGeomFieldDefn( int i );
231  virtual int GetGeomFieldIndex( const char * );
232 
233  virtual void AddGeomFieldDefn( OGRGeomFieldDefn *, int bCopy = TRUE );
234  virtual OGRErr DeleteGeomFieldDefn( int iGeomField );
235 
236  virtual OGRwkbGeometryType GetGeomType();
237  virtual void SetGeomType( OGRwkbGeometryType );
238 
239  virtual OGRFeatureDefn *Clone();
240 
241  int Reference() { return CPLAtomicInc(&nRefCount); }
242  int Dereference() { return CPLAtomicDec(&nRefCount); }
243  int GetReferenceCount() { return nRefCount; }
244  void Release();
245 
246  virtual int IsGeometryIgnored();
247  virtual void SetGeometryIgnored( int bIgnore );
248  virtual int IsStyleIgnored() { return bIgnoreStyle; }
249  virtual void SetStyleIgnored( int bIgnore ) { bIgnoreStyle = bIgnore; }
250 
251  virtual int IsSame( OGRFeatureDefn * poOtherFeatureDefn );
252 
253  static OGRFeatureDefn *CreateFeatureDefn( const char *pszName = NULL );
254  static void DestroyFeatureDefn( OGRFeatureDefn * );
255 };
256 
257 /************************************************************************/
258 /* OGRFeature */
259 /************************************************************************/
260 
265 class CPL_DLL OGRFeature
266 {
267  private:
268 
269  GIntBig nFID;
270  OGRFeatureDefn *poDefn;
271  OGRGeometry **papoGeometries;
272  OGRField *pauFields;
273 
274  protected:
275  char * m_pszStyleString;
276  OGRStyleTable *m_poStyleTable;
277  char * m_pszTmpFieldValue;
278 
279  public:
281  virtual ~OGRFeature();
282 
283  OGRFeatureDefn *GetDefnRef() { return poDefn; }
284 
285  OGRErr SetGeometryDirectly( OGRGeometry * );
286  OGRErr SetGeometry( OGRGeometry * );
287  OGRGeometry *GetGeometryRef();
288  OGRGeometry *StealGeometry();
289 
291  { return poDefn->GetGeomFieldCount(); }
293  { return poDefn->GetGeomFieldDefn(iField); }
294  int GetGeomFieldIndex( const char * pszName)
295  { return poDefn->GetGeomFieldIndex(pszName); }
296 
297  OGRGeometry* GetGeomFieldRef(int iField);
298  OGRGeometry* StealGeometry(int iField);
299  OGRGeometry* GetGeomFieldRef(const char* pszFName);
300  OGRErr SetGeomFieldDirectly( int iField, OGRGeometry * );
301  OGRErr SetGeomField( int iField, OGRGeometry * );
302 
303  OGRFeature *Clone();
304  virtual OGRBoolean Equal( OGRFeature * poFeature );
305 
306  int GetFieldCount() { return poDefn->GetFieldCount(); }
308  { return poDefn->GetFieldDefn(iField); }
309  int GetFieldIndex( const char * pszName)
310  { return poDefn->GetFieldIndex(pszName);}
311 
312  int IsFieldSet( int iField );
313 
314  void UnsetField( int iField );
315 
316  OGRField *GetRawFieldRef( int i ) { return pauFields + i; }
317 
318  int GetFieldAsInteger( int i );
319  GIntBig GetFieldAsInteger64( int i );
320  double GetFieldAsDouble( int i );
321  const char *GetFieldAsString( int i );
322  const int *GetFieldAsIntegerList( int i, int *pnCount );
323  const GIntBig *GetFieldAsInteger64List( int i, int *pnCount );
324  const double *GetFieldAsDoubleList( int i, int *pnCount );
325  char **GetFieldAsStringList( int i );
326  GByte *GetFieldAsBinary( int i, int *pnCount );
327  int GetFieldAsDateTime( int i,
328  int *pnYear, int *pnMonth, int *pnDay,
329  int *pnHour, int *pnMinute, int *pnSecond,
330  int *pnTZFlag );
331  int GetFieldAsDateTime( int i,
332  int *pnYear, int *pnMonth, int *pnDay,
333  int *pnHour, int *pnMinute, float *pfSecond,
334  int *pnTZFlag );
335 
336  int GetFieldAsInteger( const char *pszFName )
337  { return GetFieldAsInteger( GetFieldIndex(pszFName) ); }
338  GIntBig GetFieldAsInteger64( const char *pszFName )
339  { return GetFieldAsInteger64( GetFieldIndex(pszFName) ); }
340  double GetFieldAsDouble( const char *pszFName )
341  { return GetFieldAsDouble( GetFieldIndex(pszFName) ); }
342  const char *GetFieldAsString( const char *pszFName )
343  { return GetFieldAsString( GetFieldIndex(pszFName) ); }
344  const int *GetFieldAsIntegerList( const char *pszFName,
345  int *pnCount )
346  { return GetFieldAsIntegerList( GetFieldIndex(pszFName),
347  pnCount ); }
348  const GIntBig *GetFieldAsInteger64List( const char *pszFName,
349  int *pnCount )
350  { return GetFieldAsInteger64List( GetFieldIndex(pszFName),
351  pnCount ); }
352  const double *GetFieldAsDoubleList( const char *pszFName,
353  int *pnCount )
354  { return GetFieldAsDoubleList( GetFieldIndex(pszFName),
355  pnCount ); }
356  char **GetFieldAsStringList( const char *pszFName )
357  { return GetFieldAsStringList(GetFieldIndex(pszFName)); }
358 
359  void SetField( int i, int nValue );
360  void SetField( int i, GIntBig nValue );
361  void SetField( int i, double dfValue );
362  void SetField( int i, const char * pszValue );
363  void SetField( int i, int nCount, int * panValues );
364  void SetField( int i, int nCount, const GIntBig * panValues );
365  void SetField( int i, int nCount, double * padfValues );
366  void SetField( int i, char ** papszValues );
367  void SetField( int i, OGRField * puValue );
368  void SetField( int i, int nCount, GByte * pabyBinary );
369  void SetField( int i, int nYear, int nMonth, int nDay,
370  int nHour=0, int nMinute=0, float fSecond=0.f,
371  int nTZFlag = 0 );
372 
373  void SetField( const char *pszFName, int nValue )
374  { SetField( GetFieldIndex(pszFName), nValue ); }
375  void SetField( const char *pszFName, GIntBig nValue )
376  { SetField( GetFieldIndex(pszFName), nValue ); }
377  void SetField( const char *pszFName, double dfValue )
378  { SetField( GetFieldIndex(pszFName), dfValue ); }
379  void SetField( const char *pszFName, const char * pszValue)
380  { SetField( GetFieldIndex(pszFName), pszValue ); }
381  void SetField( const char *pszFName, int nCount,
382  int * panValues )
383  { SetField(GetFieldIndex(pszFName),nCount,panValues);}
384  void SetField( const char *pszFName, int nCount,
385  const GIntBig * panValues )
386  { SetField(GetFieldIndex(pszFName),nCount,panValues);}
387  void SetField( const char *pszFName, int nCount,
388  double * padfValues )
389  {SetField(GetFieldIndex(pszFName),nCount,padfValues);}
390  void SetField( const char *pszFName, char ** papszValues )
391  { SetField( GetFieldIndex(pszFName), papszValues); }
392  void SetField( const char *pszFName, OGRField * puValue )
393  { SetField( GetFieldIndex(pszFName), puValue ); }
394  void SetField( const char *pszFName,
395  int nYear, int nMonth, int nDay,
396  int nHour=0, int nMinute=0, float fSecond=0.f,
397  int nTZFlag = 0 )
398  { SetField( GetFieldIndex(pszFName),
399  nYear, nMonth, nDay,
400  nHour, nMinute, fSecond, nTZFlag ); }
401 
402  GIntBig GetFID() { return nFID; }
403  virtual OGRErr SetFID( GIntBig nFIDIn );
404 
405  void DumpReadable( FILE *, char** papszOptions = NULL );
406 
407  OGRErr SetFrom( OGRFeature *, int = TRUE);
408  OGRErr SetFrom( OGRFeature *, int *, int = TRUE );
409  OGRErr SetFieldsFrom( OGRFeature *, int *, int = TRUE );
410 
411  OGRErr RemapFields( OGRFeatureDefn *poNewDefn,
412  int *panRemapSource );
413  OGRErr RemapGeomFields( OGRFeatureDefn *poNewDefn,
414  int *panRemapSource );
415 
416  int Validate( int nValidateFlags,
417  int bEmitError );
418  void FillUnsetWithDefault(int bNotNullableOnly,
419  char** papszOptions );
420 
421  virtual const char *GetStyleString();
422  virtual void SetStyleString( const char * );
423  virtual void SetStyleStringDirectly( char * );
424  virtual OGRStyleTable *GetStyleTable() { return m_poStyleTable; }
425  virtual void SetStyleTable(OGRStyleTable *poStyleTable);
426  virtual void SetStyleTableDirectly(OGRStyleTable *poStyleTable);
427 
428  static OGRFeature *CreateFeature( OGRFeatureDefn * );
429  static void DestroyFeature( OGRFeature * );
430 };
431 
432 /************************************************************************/
433 /* OGRFeatureQuery */
434 /************************************************************************/
435 
436 class OGRLayer;
437 class swq_expr_node;
439 
440 class CPL_DLL OGRFeatureQuery
441 {
442  private:
443  OGRFeatureDefn *poTargetDefn;
444  void *pSWQExpr;
445 
446  char **FieldCollector( void *, char ** );
447 
448  GIntBig *EvaluateAgainstIndices( swq_expr_node*, OGRLayer *, GIntBig& nFIDCount);
449 
450  int CanUseIndex( swq_expr_node*, OGRLayer * );
451 
452  public:
453  OGRFeatureQuery();
454  ~OGRFeatureQuery();
455 
456  OGRErr Compile( OGRFeatureDefn *, const char *,
457  int bCheck = TRUE, swq_custom_func_registrar* poCustomFuncRegistrar = NULL );
458  int Evaluate( OGRFeature * );
459 
460  GIntBig *EvaluateAgainstIndices( OGRLayer *, OGRErr * );
461 
462  int CanUseIndex( OGRLayer * );
463 
464  char **GetUsedFields();
465 
466  void *GetSWQExpr() { return pSWQExpr; }
467 };
468 
469 #endif /* ndef _OGR_FEATURE_H_INCLUDED */
int IsIgnored()
Return whether this field should be omitted when fetching features.
Definition: ogr_feature.h:167
int GetReferenceCount()
Fetch current reference count.
Definition: ogr_feature.h:243
OGRFieldSubType
Definition: ogr_core.h:540
OGRFieldSubType GetSubType()
Fetch subtype of this field.
Definition: ogr_feature.h:91
OGRField * GetRawFieldRef(int i)
Fetch a pointer to the internal field value given the index.
Definition: ogr_feature.h:316
const char * GetNameRef()
Fetch name of this field.
Definition: ogr_feature.h:159
void SetNullable(int bNullableIn)
Set whether this geometry field can receive null values.
Definition: ogr_feature.h:171
Definition: ogr_feature.h:140
int GetPrecision()
Get the formatting precision for this field. This should normally be zero for fields of types other t...
Definition: ogr_feature.h:102
virtual int GetGeomFieldCount()
Fetch number of geometry fields on this feature.
Definition: ogrfeaturedefn.cpp:573
virtual void SetStyleIgnored(int bIgnore)
Set whether the style can be omitted when fetching features.
Definition: ogr_feature.h:249
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:309
Definition: ogr_feature.h:200
virtual int GetGeomFieldIndex(const char *)
Find geometry field by name.
Definition: ogrfeaturedefn.cpp:823
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
Definition: ogr_core.h:309
OGRwkbGeometryType GetType()
Fetch geometry type of this field.
Definition: ogr_feature.h:161
virtual OGRGeomFieldDefn * GetGeomFieldDefn(int i)
Fetch geometry field definition.
Definition: ogrfeaturedefn.cpp:621
OGRFieldDefn * GetFieldDefnRef(int iField)
Fetch definition for this field.
Definition: ogr_feature.h:307
void SetPrecision(int nPrecisionIn)
Set the formatting precision for this field in characters.
Definition: ogr_feature.h:103
Definition: ogr_geometry.h:104
Definition: ogr_feature.h:440
int IsNullable() const
Return whether this field can receive null values.
Definition: ogr_feature.h:116
void SetWidth(int nWidthIn)
Set the formatting width for this field in characters.
Definition: ogr_feature.h:100
OGRJustification
Definition: ogr_core.h:556
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:241
OGRFieldType
Definition: ogr_core.h:512
Definition: ogr_spatialref.h:129
int GetGeomFieldIndex(const char *pszName)
Fetch the geometry field index given geometry field name.
Definition: ogr_feature.h:294
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. This will always be the same as the field count for the OGRFe...
Definition: ogr_feature.h:306
int Dereference()
Decrements the reference count by one.
Definition: ogr_feature.h:242
int GetGeomFieldCount()
Fetch number of geometry fields on this feature. This will always be the same as the geometry field c...
Definition: ogr_feature.h:290
Definition: swq.h:173
Definition: ogr_core.h:574
void SetIgnored(int bIgnoreIn)
Set whether this field should be omitted when fetching features.
Definition: ogr_feature.h:168
Definition: ogrsf_frmts.h:66
OGRGeomFieldDefn * GetGeomFieldDefnRef(int iField)
Fetch definition for this geometry field.
Definition: ogr_feature.h:292
Definition: ogr_feature.h:265
virtual int GetFieldCount()
Fetch number of fields on this feature.
Definition: ogrfeaturedefn.cpp:264
virtual OGRFieldDefn * GetFieldDefn(int i)
Fetch field definition.
Definition: ogrfeaturedefn.cpp:311
Definition: ogr_featurestyle.h:81
virtual int IsStyleIgnored()
Determine whether the style can be omitted when fetching features.
Definition: ogr_feature.h:248
void SetJustify(OGRJustification eJustifyIn)
Set the justification for this field.
Definition: ogr_feature.h:96
int IsNullable() const
Return whether this geometry field can receive null values.
Definition: ogr_feature.h:170
OGRFeatureDefn * GetDefnRef()
Fetch feature definition.
Definition: ogr_feature.h:283
Definition: swq.h:104
GIntBig GetFID()
Get feature identifier.
Definition: ogr_feature.h:402
virtual int GetFieldIndex(const char *)
Find field by name.
Definition: ogrfeaturedefn.cpp:1117
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.10.