OGR
ogr_feature.h
Go to the documentation of this file.
1 /******************************************************************************
2  * $Id: ogr_feature.h 27110 2014-03-28 21:29:20Z 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 
52 class CPL_DLL OGRFieldDefn
53 {
54  private:
55  char *pszName;
56  OGRFieldType eType;
57  OGRJustification eJustify;
58  int nWidth; /* zero is variable */
59  int nPrecision;
60  OGRField uDefault;
61 
62  int bIgnore;
63 
64  void Initialize( const char *, OGRFieldType );
65 
66  public:
67  OGRFieldDefn( const char *, OGRFieldType );
69  ~OGRFieldDefn();
70 
71  void SetName( const char * );
72  const char *GetNameRef() { return pszName; }
73 
74  OGRFieldType GetType() { return eType; }
75  void SetType( OGRFieldType eTypeIn ) { eType = eTypeIn;}
76  static const char *GetFieldTypeName( OGRFieldType );
77 
78  OGRJustification GetJustify() { return eJustify; }
79  void SetJustify( OGRJustification eJustifyIn )
80  { eJustify = eJustifyIn; }
81 
82  int GetWidth() { return nWidth; }
83  void SetWidth( int nWidthIn ) { nWidth = MAX(0,nWidthIn); }
84 
85  int GetPrecision() { return nPrecision; }
86  void SetPrecision( int nPrecisionIn )
87  { nPrecision = nPrecisionIn; }
88 
89  void Set( const char *, OGRFieldType, int = 0, int = 0,
90  OGRJustification = OJUndefined );
91 
92  void SetDefault( const OGRField * );
93  const OGRField *GetDefaultRef() { return &uDefault; }
94 
95  int IsIgnored() { return bIgnore; }
96  void SetIgnored( int bIgnore ) { this->bIgnore = bIgnore; }
97 
98  int IsSame( const OGRFieldDefn * ) const;
99 };
100 
101 /************************************************************************/
102 /* OGRGeomFieldDefn */
103 /************************************************************************/
104 
112 class CPL_DLL OGRGeomFieldDefn
113 {
114 protected:
115  char *pszName;
116  OGRwkbGeometryType eGeomType; /* all values possible except wkbNone */
117  OGRSpatialReference* poSRS;
118 
119  int bIgnore;
120 
121  void Initialize( const char *, OGRwkbGeometryType );
122 
123 public:
124  OGRGeomFieldDefn(const char *pszNameIn,
125  OGRwkbGeometryType eGeomTypeIn);
127  virtual ~OGRGeomFieldDefn();
128 
129  void SetName( const char * );
130  const char *GetNameRef() { return pszName; }
131 
132  OGRwkbGeometryType GetType() { return eGeomType; }
133  void SetType( OGRwkbGeometryType eTypeIn );
134 
135  virtual OGRSpatialReference* GetSpatialRef();
136  void SetSpatialRef(OGRSpatialReference* poSRS);
137 
138  int IsIgnored() { return bIgnore; }
139  void SetIgnored( int bIgnore ) { this->bIgnore = bIgnore; }
140 
141  int IsSame( OGRGeomFieldDefn * );
142 };
143 
144 /************************************************************************/
145 /* OGRFeatureDefn */
146 /************************************************************************/
147 
167 class CPL_DLL OGRFeatureDefn
168 {
169  protected:
170  volatile int nRefCount;
171 
172  int nFieldCount;
173  OGRFieldDefn **papoFieldDefn;
174 
175  int nGeomFieldCount;
176  OGRGeomFieldDefn **papoGeomFieldDefn;
177 
178  char *pszFeatureClassName;
179 
180  int bIgnoreStyle;
181 
182  public:
183  OGRFeatureDefn( const char * pszName = NULL );
184  virtual ~OGRFeatureDefn();
185 
186  virtual const char *GetName();
187 
188  virtual int GetFieldCount();
189  virtual OGRFieldDefn *GetFieldDefn( int i );
190  virtual int GetFieldIndex( const char * );
191 
192  virtual void AddFieldDefn( OGRFieldDefn * );
193  virtual OGRErr DeleteFieldDefn( int iField );
194  virtual OGRErr ReorderFieldDefns( int* panMap );
195 
196  virtual int GetGeomFieldCount();
197  virtual OGRGeomFieldDefn *GetGeomFieldDefn( int i );
198  virtual int GetGeomFieldIndex( const char * );
199 
200  virtual void AddGeomFieldDefn( OGRGeomFieldDefn *, int bCopy = TRUE );
201  virtual OGRErr DeleteGeomFieldDefn( int iGeomField );
202 
203  virtual OGRwkbGeometryType GetGeomType();
204  virtual void SetGeomType( OGRwkbGeometryType );
205 
206  virtual OGRFeatureDefn *Clone();
207 
208  int Reference() { return CPLAtomicInc(&nRefCount); }
209  int Dereference() { return CPLAtomicDec(&nRefCount); }
210  int GetReferenceCount() { return nRefCount; }
211  void Release();
212 
213  virtual int IsGeometryIgnored();
214  virtual void SetGeometryIgnored( int bIgnore );
215  virtual int IsStyleIgnored() { return bIgnoreStyle; }
216  virtual void SetStyleIgnored( int bIgnore ) { bIgnoreStyle = bIgnore; }
217 
218  virtual int IsSame( OGRFeatureDefn * poOtherFeatureDefn );
219 
220  static OGRFeatureDefn *CreateFeatureDefn( const char *pszName = NULL );
221  static void DestroyFeatureDefn( OGRFeatureDefn * );
222 };
223 
224 /************************************************************************/
225 /* OGRFeature */
226 /************************************************************************/
227 
232 class CPL_DLL OGRFeature
233 {
234  private:
235 
236  long nFID;
237  OGRFeatureDefn *poDefn;
238  OGRGeometry **papoGeometries;
239  OGRField *pauFields;
240 
241  protected:
242  char * m_pszStyleString;
243  OGRStyleTable *m_poStyleTable;
244  char * m_pszTmpFieldValue;
245 
246  public:
248  virtual ~OGRFeature();
249 
250  OGRFeatureDefn *GetDefnRef() { return poDefn; }
251 
252  OGRErr SetGeometryDirectly( OGRGeometry * );
253  OGRErr SetGeometry( OGRGeometry * );
254  OGRGeometry *GetGeometryRef();
255  OGRGeometry *StealGeometry();
256 
258  { return poDefn->GetGeomFieldCount(); }
260  { return poDefn->GetGeomFieldDefn(iField); }
261  int GetGeomFieldIndex( const char * pszName)
262  { return poDefn->GetGeomFieldIndex(pszName); }
263 
264  OGRGeometry* GetGeomFieldRef(int iField);
265  OGRGeometry* StealGeometry(int iField);
266  OGRGeometry* GetGeomFieldRef(const char* pszFName);
267  OGRErr SetGeomFieldDirectly( int iField, OGRGeometry * );
268  OGRErr SetGeomField( int iField, OGRGeometry * );
269 
270  OGRFeature *Clone();
271  virtual OGRBoolean Equal( OGRFeature * poFeature );
272 
273  int GetFieldCount() { return poDefn->GetFieldCount(); }
275  { return poDefn->GetFieldDefn(iField); }
276  int GetFieldIndex( const char * pszName)
277  { return poDefn->GetFieldIndex(pszName);}
278 
279  int IsFieldSet( int iField );
280 
281  void UnsetField( int iField );
282 
283  OGRField *GetRawFieldRef( int i ) { return pauFields + i; }
284 
285  int GetFieldAsInteger( int i );
286  double GetFieldAsDouble( int i );
287  const char *GetFieldAsString( int i );
288  const int *GetFieldAsIntegerList( int i, int *pnCount );
289  const double *GetFieldAsDoubleList( int i, int *pnCount );
290  char **GetFieldAsStringList( int i );
291  GByte *GetFieldAsBinary( int i, int *pnCount );
292  int GetFieldAsDateTime( int i,
293  int *pnYear, int *pnMonth, int *pnDay,
294  int *pnHour, int *pnMinute, int *pnSecond,
295  int *pnTZFlag );
296 
297  int GetFieldAsInteger( const char *pszFName )
298  { return GetFieldAsInteger( GetFieldIndex(pszFName) ); }
299  double GetFieldAsDouble( const char *pszFName )
300  { return GetFieldAsDouble( GetFieldIndex(pszFName) ); }
301  const char *GetFieldAsString( const char *pszFName )
302  { return GetFieldAsString( GetFieldIndex(pszFName) ); }
303  const int *GetFieldAsIntegerList( const char *pszFName,
304  int *pnCount )
305  { return GetFieldAsIntegerList( GetFieldIndex(pszFName),
306  pnCount ); }
307  const double *GetFieldAsDoubleList( const char *pszFName,
308  int *pnCount )
309  { return GetFieldAsDoubleList( GetFieldIndex(pszFName),
310  pnCount ); }
311  char **GetFieldAsStringList( const char *pszFName )
312  { return GetFieldAsStringList(GetFieldIndex(pszFName)); }
313 
314  void SetField( int i, int nValue );
315  void SetField( int i, double dfValue );
316  void SetField( int i, const char * pszValue );
317  void SetField( int i, int nCount, int * panValues );
318  void SetField( int i, int nCount, double * padfValues );
319  void SetField( int i, char ** papszValues );
320  void SetField( int i, OGRField * puValue );
321  void SetField( int i, int nCount, GByte * pabyBinary );
322  void SetField( int i, int nYear, int nMonth, int nDay,
323  int nHour=0, int nMinute=0, int nSecond=0,
324  int nTZFlag = 0 );
325 
326  void SetField( const char *pszFName, int nValue )
327  { SetField( GetFieldIndex(pszFName), nValue ); }
328  void SetField( const char *pszFName, double dfValue )
329  { SetField( GetFieldIndex(pszFName), dfValue ); }
330  void SetField( const char *pszFName, const char * pszValue)
331  { SetField( GetFieldIndex(pszFName), pszValue ); }
332  void SetField( const char *pszFName, int nCount,
333  int * panValues )
334  { SetField(GetFieldIndex(pszFName),nCount,panValues);}
335  void SetField( const char *pszFName, int nCount,
336  double * padfValues )
337  {SetField(GetFieldIndex(pszFName),nCount,padfValues);}
338  void SetField( const char *pszFName, char ** papszValues )
339  { SetField( GetFieldIndex(pszFName), papszValues); }
340  void SetField( const char *pszFName, OGRField * puValue )
341  { SetField( GetFieldIndex(pszFName), puValue ); }
342  void SetField( const char *pszFName,
343  int nYear, int nMonth, int nDay,
344  int nHour=0, int nMinute=0, int nSecond=0,
345  int nTZFlag = 0 )
346  { SetField( GetFieldIndex(pszFName),
347  nYear, nMonth, nDay,
348  nHour, nMinute, nSecond, nTZFlag ); }
349 
350  long GetFID() { return nFID; }
351  virtual OGRErr SetFID( long nFID );
352 
353  void DumpReadable( FILE *, char** papszOptions = NULL );
354 
355  OGRErr SetFrom( OGRFeature *, int = TRUE);
356  OGRErr SetFrom( OGRFeature *, int *, int = TRUE );
357  OGRErr SetFieldsFrom( OGRFeature *, int *, int = TRUE );
358 
359  OGRErr RemapFields( OGRFeatureDefn *poNewDefn,
360  int *panRemapSource );
361  OGRErr RemapGeomFields( OGRFeatureDefn *poNewDefn,
362  int *panRemapSource );
363 
364  virtual const char *GetStyleString();
365  virtual void SetStyleString( const char * );
366  virtual void SetStyleStringDirectly( char * );
367  virtual OGRStyleTable *GetStyleTable() { return m_poStyleTable; }
368  virtual void SetStyleTable(OGRStyleTable *poStyleTable);
369  virtual void SetStyleTableDirectly(OGRStyleTable *poStyleTable)
370  { if ( m_poStyleTable ) delete m_poStyleTable;
371  m_poStyleTable = poStyleTable; }
372 
373  static OGRFeature *CreateFeature( OGRFeatureDefn * );
374  static void DestroyFeature( OGRFeature * );
375 };
376 
377 /************************************************************************/
378 /* OGRFeatureQuery */
379 /************************************************************************/
380 
381 class OGRLayer;
382 class swq_expr_node;
383 
384 class CPL_DLL OGRFeatureQuery
385 {
386  private:
387  OGRFeatureDefn *poTargetDefn;
388  void *pSWQExpr;
389 
390  char **FieldCollector( void *, char ** );
391 
392  long *EvaluateAgainstIndices( swq_expr_node*, OGRLayer *, int& nFIDCount);
393 
394  int CanUseIndex( swq_expr_node*, OGRLayer * );
395 
396  public:
397  OGRFeatureQuery();
398  ~OGRFeatureQuery();
399 
400  OGRErr Compile( OGRFeatureDefn *, const char * );
401  int Evaluate( OGRFeature * );
402 
403  long *EvaluateAgainstIndices( OGRLayer *, OGRErr * );
404 
405  int CanUseIndex( OGRLayer * );
406 
407  char **GetUsedFields();
408 
409  void *GetSWGExpr() { return pSWQExpr; }
410 };
411 
412 #endif /* ndef _OGR_FEATURE_H_INCLUDED */
int IsIgnored()
Return whether this field should be omitted when fetching features.
Definition: ogr_feature.h:138
int GetReferenceCount()
Fetch current reference count.
Definition: ogr_feature.h:210
OGRField * GetRawFieldRef(int i)
Fetch a pointer to the internal field value given the index.
Definition: ogr_feature.h:283
const char * GetNameRef()
Fetch name of this field.
Definition: ogr_feature.h:130
Definition: ogr_feature.h:112
int GetPrecision()
Get the formatting precision for this field. This should normally be zero for fields of types other t...
Definition: ogr_feature.h:85
long GetFID()
Get feature identifier.
Definition: ogr_feature.h:350
virtual int GetGeomFieldCount()
Fetch number of geometry fields on this feature.
Definition: ogrfeaturedefn.cpp:561
virtual void SetStyleIgnored(int bIgnore)
Set whether the style can be omitted when fetching features.
Definition: ogr_feature.h:216
int GetWidth()
Get the formatting width for this field.
Definition: ogr_feature.h:82
int GetFieldIndex(const char *pszName)
Fetch the field index given field name.
Definition: ogr_feature.h:276
Definition: ogr_feature.h:167
virtual int GetGeomFieldIndex(const char *)
Find geometry field by name.
Definition: ogrfeaturedefn.cpp:798
void SetType(OGRFieldType eTypeIn)
Set the type of this field. This should never be done to an OGRFieldDefn that is already part of an O...
Definition: ogr_feature.h:75
Definition: ogr_feature.h:52
OGRFieldType GetType()
Fetch type of this field.
Definition: ogr_feature.h:74
const char * GetNameRef()
Fetch name of this field.
Definition: ogr_feature.h:72
OGRwkbGeometryType
Definition: ogr_core.h:308
OGRwkbGeometryType GetType()
Fetch geometry type of this field.
Definition: ogr_feature.h:132
virtual OGRGeomFieldDefn * GetGeomFieldDefn(int i)
Fetch geometry field definition.
Definition: ogrfeaturedefn.cpp:604
OGRFieldDefn * GetFieldDefnRef(int iField)
Fetch definition for this field.
Definition: ogr_feature.h:274
void SetPrecision(int nPrecisionIn)
Set the formatting precision for this field in characters.
Definition: ogr_feature.h:86
Definition: ogr_geometry.h:79
Definition: ogr_feature.h:384
void SetWidth(int nWidthIn)
Set the formatting width for this field in characters.
Definition: ogr_feature.h:83
OGRJustification
Definition: ogr_core.h:409
OGRJustification GetJustify()
Get the justification for this field.
Definition: ogr_feature.h:78
int Reference()
Increments the reference count by one.
Definition: ogr_feature.h:208
OGRFieldType
Definition: ogr_core.h:388
Definition: ogr_spatialref.h:129
int GetGeomFieldIndex(const char *pszName)
Fetch the geometry field index given geometry field name.
Definition: ogr_feature.h:261
int IsIgnored()
Return whether this field should be omitted when fetching features.
Definition: ogr_feature.h:95
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:273
void SetIgnored(int bIgnore)
Set whether this field should be omitted when fetching features.
Definition: ogr_feature.h:96
int Dereference()
Decrements the reference count by one.
Definition: ogr_feature.h:209
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:257
Definition: ogr_core.h:427
Definition: ogrsf_frmts.h:59
OGRGeomFieldDefn * GetGeomFieldDefnRef(int iField)
Fetch definition for this geometry field.
Definition: ogr_feature.h:259
Definition: ogr_feature.h:232
virtual int GetFieldCount()
Fetch number of fields on this feature.
Definition: ogrfeaturedefn.cpp:263
virtual OGRFieldDefn * GetFieldDefn(int i)
Fetch field definition.
Definition: ogrfeaturedefn.cpp:305
Definition: ogr_featurestyle.h:81
virtual int IsStyleIgnored()
Determine whether the style can be omitted when fetching features.
Definition: ogr_feature.h:215
void SetJustify(OGRJustification eJustifyIn)
Set the justification for this field.
Definition: ogr_feature.h:79
OGRFeatureDefn * GetDefnRef()
Fetch feature definition.
Definition: ogr_feature.h:250
Definition: swq.h:97
virtual int GetFieldIndex(const char *)
Find field by name.
Definition: ogrfeaturedefn.cpp:1074
void SetIgnored(int bIgnore)
Set whether this field should be omitted when fetching features.
Definition: ogr_feature.h:139

Generated for GDAL by doxygen 1.8.11.