OGR
ogr_feature.h
Go to the documentation of this file.
1 /******************************************************************************
2  * $Id: ogr_feature.h 24849 2012-08-25 12:22:05Z 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  *
11  * Permission is hereby granted, free of charge, to any person obtaining a
12  * copy of this software and associated documentation files (the "Software"),
13  * to deal in the Software without restriction, including without limitation
14  * the rights to use, copy, modify, merge, publish, distribute, sublicense,
15  * and/or sell copies of the Software, and to permit persons to whom the
16  * Software is furnished to do so, subject to the following conditions:
17  *
18  * The above copyright notice and this permission notice shall be included
19  * in all copies or substantial portions of the Software.
20  *
21  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
22  * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
23  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
24  * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
25  * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
26  * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
27  * DEALINGS IN THE SOFTWARE.
28  ****************************************************************************/
29 
30 #ifndef _OGR_FEATURE_H_INCLUDED
31 #define _OGR_FEATURE_H_INCLUDED
32 
33 #include "ogr_geometry.h"
34 #include "ogr_featurestyle.h"
35 #include "cpl_atomic_ops.h"
36 
43 /************************************************************************/
44 /* OGRFieldDefn */
45 /************************************************************************/
46 
51 class CPL_DLL OGRFieldDefn
52 {
53  private:
54  char *pszName;
55  OGRFieldType eType;
56  OGRJustification eJustify;
57  int nWidth; /* zero is variable */
58  int nPrecision;
59  OGRField uDefault;
60 
61  int bIgnore;
62 
63  void Initialize( const char *, OGRFieldType );
64 
65  public:
66  OGRFieldDefn( const char *, OGRFieldType );
68  ~OGRFieldDefn();
69 
70  void SetName( const char * );
71  const char *GetNameRef() { return pszName; }
72 
73  OGRFieldType GetType() { return eType; }
74  void SetType( OGRFieldType eTypeIn ) { eType = eTypeIn;}
75  static const char *GetFieldTypeName( OGRFieldType );
76 
77  OGRJustification GetJustify() { return eJustify; }
78  void SetJustify( OGRJustification eJustifyIn )
79  { eJustify = eJustifyIn; }
80 
81  int GetWidth() { return nWidth; }
82  void SetWidth( int nWidthIn ) { nWidth = MAX(0,nWidthIn); }
83 
84  int GetPrecision() { return nPrecision; }
85  void SetPrecision( int nPrecisionIn )
86  { nPrecision = nPrecisionIn; }
87 
88  void Set( const char *, OGRFieldType, int = 0, int = 0,
89  OGRJustification = OJUndefined );
90 
91  void SetDefault( const OGRField * );
92  const OGRField *GetDefaultRef() { return &uDefault; }
93 
94  int IsIgnored() { return bIgnore; }
95  void SetIgnored( int bIgnore ) { this->bIgnore = bIgnore; }
96 
97  int IsSame( const OGRFieldDefn * ) const;
98 };
99 
100 /************************************************************************/
101 /* OGRFeatureDefn */
102 /************************************************************************/
103 
120 class CPL_DLL OGRFeatureDefn
121 {
122  private:
123  volatile int nRefCount;
124 
125  int nFieldCount;
126  OGRFieldDefn **papoFieldDefn;
127 
128  OGRwkbGeometryType eGeomType;
129 
130  char *pszFeatureClassName;
131 
132  int bIgnoreGeometry;
133  int bIgnoreStyle;
134 
135  public:
136  OGRFeatureDefn( const char * pszName = NULL );
137  virtual ~OGRFeatureDefn();
138 
139  const char *GetName() { return pszFeatureClassName; }
140 
141  int GetFieldCount() { return nFieldCount; }
142  OGRFieldDefn *GetFieldDefn( int i );
143  int GetFieldIndex( const char * );
144 
145  void AddFieldDefn( OGRFieldDefn * );
146  OGRErr DeleteFieldDefn( int iField );
147  OGRErr ReorderFieldDefns( int* panMap );
148 
149  OGRwkbGeometryType GetGeomType() { return eGeomType; }
150  void SetGeomType( OGRwkbGeometryType );
151 
152  OGRFeatureDefn *Clone();
153 
154  int Reference() { return CPLAtomicInc(&nRefCount); }
155  int Dereference() { return CPLAtomicDec(&nRefCount); }
156  int GetReferenceCount() { return nRefCount; }
157  void Release();
158 
159  int IsGeometryIgnored() { return bIgnoreGeometry; }
160  void SetGeometryIgnored( int bIgnore ) { bIgnoreGeometry = bIgnore; }
161  int IsStyleIgnored() { return bIgnoreStyle; }
162  void SetStyleIgnored( int bIgnore ) { bIgnoreStyle = bIgnore; }
163 
164  int IsSame( const OGRFeatureDefn * poOtherFeatureDefn ) const;
165 
166  static OGRFeatureDefn *CreateFeatureDefn( const char *pszName = NULL );
167  static void DestroyFeatureDefn( OGRFeatureDefn * );
168 };
169 
170 /************************************************************************/
171 /* OGRFeature */
172 /************************************************************************/
173 
178 class CPL_DLL OGRFeature
179 {
180  private:
181 
182  long nFID;
183  OGRFeatureDefn *poDefn;
184  OGRGeometry *poGeometry;
185  OGRField *pauFields;
186 
187  protected:
188  char * m_pszStyleString;
189  OGRStyleTable *m_poStyleTable;
190  char * m_pszTmpFieldValue;
191 
192  public:
194  virtual ~OGRFeature();
195 
196  OGRFeatureDefn *GetDefnRef() { return poDefn; }
197 
198  OGRErr SetGeometryDirectly( OGRGeometry * );
199  OGRErr SetGeometry( OGRGeometry * );
200  OGRGeometry *GetGeometryRef() { return poGeometry; }
201  OGRGeometry *StealGeometry();
202 
203  OGRFeature *Clone();
204  virtual OGRBoolean Equal( OGRFeature * poFeature );
205 
206  int GetFieldCount() { return poDefn->GetFieldCount(); }
208  { return poDefn->GetFieldDefn(iField); }
209  int GetFieldIndex( const char * pszName)
210  { return poDefn->GetFieldIndex(pszName);}
211 
212  int IsFieldSet( int iField ) const;
213 
214  void UnsetField( int iField );
215 
216  OGRField *GetRawFieldRef( int i ) { return pauFields + i; }
217 
218  int GetFieldAsInteger( int i );
219  double GetFieldAsDouble( int i );
220  const char *GetFieldAsString( int i );
221  const int *GetFieldAsIntegerList( int i, int *pnCount );
222  const double *GetFieldAsDoubleList( int i, int *pnCount );
223  char **GetFieldAsStringList( int i ) const;
224  GByte *GetFieldAsBinary( int i, int *pnCount );
225  int GetFieldAsDateTime( int i,
226  int *pnYear, int *pnMonth, int *pnDay,
227  int *pnHour, int *pnMinute, int *pnSecond,
228  int *pnTZFlag );
229 
230  int GetFieldAsInteger( const char *pszFName )
231  { return GetFieldAsInteger( GetFieldIndex(pszFName) ); }
232  double GetFieldAsDouble( const char *pszFName )
233  { return GetFieldAsDouble( GetFieldIndex(pszFName) ); }
234  const char *GetFieldAsString( const char *pszFName )
235  { return GetFieldAsString( GetFieldIndex(pszFName) ); }
236  const int *GetFieldAsIntegerList( const char *pszFName,
237  int *pnCount )
238  { return GetFieldAsIntegerList( GetFieldIndex(pszFName),
239  pnCount ); }
240  const double *GetFieldAsDoubleList( const char *pszFName,
241  int *pnCount )
242  { return GetFieldAsDoubleList( GetFieldIndex(pszFName),
243  pnCount ); }
244  char **GetFieldAsStringList( const char *pszFName )
245  { return GetFieldAsStringList(GetFieldIndex(pszFName)); }
246 
247  void SetField( int i, int nValue );
248  void SetField( int i, double dfValue );
249  void SetField( int i, const char * pszValue );
250  void SetField( int i, int nCount, int * panValues );
251  void SetField( int i, int nCount, double * padfValues );
252  void SetField( int i, char ** papszValues );
253  void SetField( int i, OGRField * puValue );
254  void SetField( int i, int nCount, GByte * pabyBinary );
255  void SetField( int i, int nYear, int nMonth, int nDay,
256  int nHour=0, int nMinute=0, int nSecond=0,
257  int nTZFlag = 0 );
258 
259  void SetField( const char *pszFName, int nValue )
260  { SetField( GetFieldIndex(pszFName), nValue ); }
261  void SetField( const char *pszFName, double dfValue )
262  { SetField( GetFieldIndex(pszFName), dfValue ); }
263  void SetField( const char *pszFName, const char * pszValue)
264  { SetField( GetFieldIndex(pszFName), pszValue ); }
265  void SetField( const char *pszFName, int nCount,
266  int * panValues )
267  { SetField(GetFieldIndex(pszFName),nCount,panValues);}
268  void SetField( const char *pszFName, int nCount,
269  double * padfValues )
270  {SetField(GetFieldIndex(pszFName),nCount,padfValues);}
271  void SetField( const char *pszFName, char ** papszValues )
272  { SetField( GetFieldIndex(pszFName), papszValues); }
273  void SetField( const char *pszFName, OGRField * puValue )
274  { SetField( GetFieldIndex(pszFName), puValue ); }
275  void SetField( const char *pszFName,
276  int nYear, int nMonth, int nDay,
277  int nHour=0, int nMinute=0, int nSecond=0,
278  int nTZFlag = 0 )
279  { SetField( GetFieldIndex(pszFName),
280  nYear, nMonth, nDay,
281  nHour, nMinute, nSecond, nTZFlag ); }
282 
283  long GetFID() { return nFID; }
284  virtual OGRErr SetFID( long nFID );
285 
286  void DumpReadable( FILE *, char** papszOptions = NULL );
287 
288  OGRErr SetFrom( OGRFeature *, int = TRUE);
289  OGRErr SetFrom( OGRFeature *, int *, int = TRUE );
290  OGRErr SetFieldsFrom( OGRFeature *, int *, int = TRUE );
291 
292  OGRErr RemapFields( OGRFeatureDefn *poNewDefn,
293  int *panRemapSource );
294 
295  virtual const char *GetStyleString();
296  virtual void SetStyleString( const char * );
297  virtual void SetStyleStringDirectly( char * );
298  virtual OGRStyleTable *GetStyleTable() { return m_poStyleTable; }
299  virtual void SetStyleTable(OGRStyleTable *poStyleTable);
300  virtual void SetStyleTableDirectly(OGRStyleTable *poStyleTable)
301  { if ( m_poStyleTable ) delete m_poStyleTable;
302  m_poStyleTable = poStyleTable; }
303 
304  static OGRFeature *CreateFeature( OGRFeatureDefn * );
305  static void DestroyFeature( OGRFeature * );
306 };
307 
308 /************************************************************************/
309 /* OGRFeatureQuery */
310 /************************************************************************/
311 
312 class OGRLayer;
313 class swq_expr_node;
314 
315 class CPL_DLL OGRFeatureQuery
316 {
317  private:
318  OGRFeatureDefn *poTargetDefn;
319  void *pSWQExpr;
320 
321  char **FieldCollector( void *, char ** );
322 
323  long *EvaluateAgainstIndices( swq_expr_node*, OGRLayer *, int& nFIDCount);
324 
325  int CanUseIndex( swq_expr_node*, OGRLayer * );
326 
327  public:
328  OGRFeatureQuery();
329  ~OGRFeatureQuery();
330 
331  OGRErr Compile( OGRFeatureDefn *, const char * );
332  int Evaluate( OGRFeature * );
333 
334  long *EvaluateAgainstIndices( OGRLayer *, OGRErr * );
335 
336  int CanUseIndex( OGRLayer * );
337 
338  char **GetUsedFields();
339 
340  void *GetSWGExpr() { return pSWQExpr; }
341 };
342 
343 #endif /* ndef _OGR_FEATURE_H_INCLUDED */
int GetReferenceCount()
Fetch current reference count.
Definition: ogr_feature.h:156
OGRField * GetRawFieldRef(int i)
Fetch a pointer to the internal field value given the index.
Definition: ogr_feature.h:216
int GetPrecision()
Get the formatting precision for this field. This should normally be zero for fields of types other t...
Definition: ogr_feature.h:84
long GetFID()
Get feature identifier.
Definition: ogr_feature.h:283
void SetStyleIgnored(int bIgnore)
Set whether the style can be omitted when fetching features.
Definition: ogr_feature.h:162
void SetGeometryIgnored(int bIgnore)
Set whether the geometry can be omitted when fetching features.
Definition: ogr_feature.h:160
int GetWidth()
Get the formatting width for this field.
Definition: ogr_feature.h:81
int GetFieldIndex(const char *pszName)
Fetch the field index given field name.
Definition: ogr_feature.h:209
Definition: ogr_feature.h:120
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:74
Definition: ogr_feature.h:51
OGRFieldType GetType()
Fetch type of this field.
Definition: ogr_feature.h:73
const char * GetNameRef()
Fetch name of this field.
Definition: ogr_feature.h:71
OGRwkbGeometryType
Definition: ogr_core.h:297
const char * GetName()
Get name of this OGRFeatureDefn.
Definition: ogr_feature.h:139
OGRFieldDefn * GetFieldDefnRef(int iField)
Fetch definition for this field.
Definition: ogr_feature.h:207
void SetPrecision(int nPrecisionIn)
Set the formatting precision for this field in characters.
Definition: ogr_feature.h:85
Definition: ogr_geometry.h:77
Definition: ogr_feature.h:315
void SetWidth(int nWidthIn)
Set the formatting width for this field in characters.
Definition: ogr_feature.h:82
OGRJustification
Definition: ogr_core.h:385
OGRJustification GetJustify()
Get the justification for this field.
Definition: ogr_feature.h:77
int Reference()
Increments the reference count by one.
Definition: ogr_feature.h:154
OGRFieldType
Definition: ogr_core.h:364
int IsIgnored()
Return whether this field should be omitted when fetching features.
Definition: ogr_feature.h:94
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:206
int IsGeometryIgnored()
Determine whether the geometry can be omitted when fetching features.
Definition: ogr_feature.h:159
void SetIgnored(int bIgnore)
Set whether this field should be omitted when fetching features.
Definition: ogr_feature.h:95
OGRwkbGeometryType GetGeomType()
Fetch the geometry base type.
Definition: ogr_feature.h:149
int Dereference()
Decrements the reference count by one.
Definition: ogr_feature.h:155
Definition: ogr_core.h:403
Definition: ogrsf_frmts.h:58
OGRGeometry * GetGeometryRef()
Fetch pointer to feature geometry.
Definition: ogr_feature.h:200
Definition: ogr_feature.h:178
int GetFieldCount()
Fetch number of fields on this feature.
Definition: ogr_feature.h:141
Definition: ogr_featurestyle.h:81
int IsStyleIgnored()
Determine whether the style can be omitted when fetching features.
Definition: ogr_feature.h:161
void SetJustify(OGRJustification eJustifyIn)
Set the justification for this field.
Definition: ogr_feature.h:78
OGRFeatureDefn * GetDefnRef()
Fetch feature definition.
Definition: ogr_feature.h:196
Definition: swq.h:93

Generated for GDAL by doxygen 1.8.7.