OGR
ogr_feature.h
Go to the documentation of this file.
1 /******************************************************************************
2  * $Id: ogr_feature.h 22368 2011-05-13 17:59:41Z 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 
98 /************************************************************************/
99 /* OGRFeatureDefn */
100 /************************************************************************/
101 
118 class CPL_DLL OGRFeatureDefn
119 {
120  private:
121  volatile int nRefCount;
122 
123  int nFieldCount;
124  OGRFieldDefn **papoFieldDefn;
125 
126  OGRwkbGeometryType eGeomType;
127 
128  char *pszFeatureClassName;
129 
130  int bIgnoreGeometry;
131  int bIgnoreStyle;
132 
133  public:
134  OGRFeatureDefn( const char * pszName = NULL );
135  virtual ~OGRFeatureDefn();
136 
137  const char *GetName() { return pszFeatureClassName; }
138 
139  int GetFieldCount() { return nFieldCount; }
140  OGRFieldDefn *GetFieldDefn( int i );
141  int GetFieldIndex( const char * );
142 
143  void AddFieldDefn( OGRFieldDefn * );
144  OGRErr DeleteFieldDefn( int iField );
145  OGRErr ReorderFieldDefns( int* panMap );
146 
147  OGRwkbGeometryType GetGeomType() { return eGeomType; }
148  void SetGeomType( OGRwkbGeometryType );
149 
150  OGRFeatureDefn *Clone();
151 
152  int Reference() { return CPLAtomicInc(&nRefCount); }
153  int Dereference() { return CPLAtomicDec(&nRefCount); }
154  int GetReferenceCount() { return nRefCount; }
155  void Release();
156 
157  int IsGeometryIgnored() { return bIgnoreGeometry; }
158  void SetGeometryIgnored( int bIgnore ) { bIgnoreGeometry = bIgnore; }
159  int IsStyleIgnored() { return bIgnoreStyle; }
160  void SetStyleIgnored( int bIgnore ) { bIgnoreStyle = bIgnore; }
161 
162  static OGRFeatureDefn *CreateFeatureDefn( const char *pszName = NULL );
163  static void DestroyFeatureDefn( OGRFeatureDefn * );
164 };
165 
166 /************************************************************************/
167 /* OGRFeature */
168 /************************************************************************/
169 
174 class CPL_DLL OGRFeature
175 {
176  private:
177 
178  long nFID;
179  OGRFeatureDefn *poDefn;
180  OGRGeometry *poGeometry;
181  OGRField *pauFields;
182 
183  protected:
184  char * m_pszStyleString;
185  OGRStyleTable *m_poStyleTable;
186  char * m_pszTmpFieldValue;
187 
188  public:
190  virtual ~OGRFeature();
191 
192  OGRFeatureDefn *GetDefnRef() { return poDefn; }
193 
194  OGRErr SetGeometryDirectly( OGRGeometry * );
195  OGRErr SetGeometry( OGRGeometry * );
196  OGRGeometry *GetGeometryRef() { return poGeometry; }
197  OGRGeometry *StealGeometry();
198 
199  OGRFeature *Clone();
200  virtual OGRBoolean Equal( OGRFeature * poFeature );
201 
202  int GetFieldCount() { return poDefn->GetFieldCount(); }
203  OGRFieldDefn *GetFieldDefnRef( int iField )
204  { return poDefn->GetFieldDefn(iField); }
205  int GetFieldIndex( const char * pszName)
206  { return poDefn->GetFieldIndex(pszName);}
207 
208  int IsFieldSet( int iField ) const;
209 
210  void UnsetField( int iField );
211 
212  OGRField *GetRawFieldRef( int i ) { return pauFields + i; }
213 
214  int GetFieldAsInteger( int i );
215  double GetFieldAsDouble( int i );
216  const char *GetFieldAsString( int i );
217  const int *GetFieldAsIntegerList( int i, int *pnCount );
218  const double *GetFieldAsDoubleList( int i, int *pnCount );
219  char **GetFieldAsStringList( int i ) const;
220  GByte *GetFieldAsBinary( int i, int *pnCount );
221  int GetFieldAsDateTime( int i,
222  int *pnYear, int *pnMonth, int *pnDay,
223  int *pnHour, int *pnMinute, int *pnSecond,
224  int *pnTZFlag );
225 
226  int GetFieldAsInteger( const char *pszFName )
227  { return GetFieldAsInteger( GetFieldIndex(pszFName) ); }
228  double GetFieldAsDouble( const char *pszFName )
229  { return GetFieldAsDouble( GetFieldIndex(pszFName) ); }
230  const char *GetFieldAsString( const char *pszFName )
231  { return GetFieldAsString( GetFieldIndex(pszFName) ); }
232  const int *GetFieldAsIntegerList( const char *pszFName,
233  int *pnCount )
234  { return GetFieldAsIntegerList( GetFieldIndex(pszFName),
235  pnCount ); }
236  const double *GetFieldAsDoubleList( const char *pszFName,
237  int *pnCount )
238  { return GetFieldAsDoubleList( GetFieldIndex(pszFName),
239  pnCount ); }
240  char **GetFieldAsStringList( const char *pszFName )
241  { return GetFieldAsStringList(GetFieldIndex(pszFName)); }
242 
243  void SetField( int i, int nValue );
244  void SetField( int i, double dfValue );
245  void SetField( int i, const char * pszValue );
246  void SetField( int i, int nCount, int * panValues );
247  void SetField( int i, int nCount, double * padfValues );
248  void SetField( int i, char ** papszValues );
249  void SetField( int i, OGRField * puValue );
250  void SetField( int i, int nCount, GByte * pabyBinary );
251  void SetField( int i, int nYear, int nMonth, int nDay,
252  int nHour=0, int nMinute=0, int nSecond=0,
253  int nTZFlag = 0 );
254 
255  void SetField( const char *pszFName, int nValue )
256  { SetField( GetFieldIndex(pszFName), nValue ); }
257  void SetField( const char *pszFName, double dfValue )
258  { SetField( GetFieldIndex(pszFName), dfValue ); }
259  void SetField( const char *pszFName, const char * pszValue)
260  { SetField( GetFieldIndex(pszFName), pszValue ); }
261  void SetField( const char *pszFName, int nCount,
262  int * panValues )
263  { SetField(GetFieldIndex(pszFName),nCount,panValues);}
264  void SetField( const char *pszFName, int nCount,
265  double * padfValues )
266  {SetField(GetFieldIndex(pszFName),nCount,padfValues);}
267  void SetField( const char *pszFName, char ** papszValues )
268  { SetField( GetFieldIndex(pszFName), papszValues); }
269  void SetField( const char *pszFName, OGRField * puValue )
270  { SetField( GetFieldIndex(pszFName), puValue ); }
271  void SetField( const char *pszFName,
272  int nYear, int nMonth, int nDay,
273  int nHour=0, int nMinute=0, int nSecond=0,
274  int nTZFlag = 0 )
275  { SetField( GetFieldIndex(pszFName),
276  nYear, nMonth, nDay,
277  nHour, nMinute, nSecond, nTZFlag ); }
278 
279  long GetFID() { return nFID; }
280  virtual OGRErr SetFID( long nFID );
281 
282  void DumpReadable( FILE *, char** papszOptions = NULL );
283 
284  OGRErr SetFrom( OGRFeature *, int = TRUE);
285  OGRErr SetFrom( OGRFeature *, int *, int = TRUE );
286 
287  OGRErr RemapFields( OGRFeatureDefn *poNewDefn,
288  int *panRemapSource );
289 
290  virtual const char *GetStyleString();
291  virtual void SetStyleString( const char * );
292  virtual void SetStyleStringDirectly( char * );
293  virtual OGRStyleTable *GetStyleTable() { return m_poStyleTable; }
294  virtual void SetStyleTable(OGRStyleTable *poStyleTable);
295  virtual void SetStyleTableDirectly(OGRStyleTable *poStyleTable)
296  { if ( m_poStyleTable ) delete m_poStyleTable;
297  m_poStyleTable = poStyleTable; }
298 
299  static OGRFeature *CreateFeature( OGRFeatureDefn * );
300  static void DestroyFeature( OGRFeature * );
301 };
302 
303 /************************************************************************/
304 /* OGRFeatureQuery */
305 /************************************************************************/
306 
307 class OGRLayer;
308 
309 class CPL_DLL OGRFeatureQuery
310 {
311  private:
312  OGRFeatureDefn *poTargetDefn;
313  void *pSWQExpr;
314 
315  char **FieldCollector( void *, char ** );
316 
317  public:
318  OGRFeatureQuery();
319  ~OGRFeatureQuery();
320 
321  OGRErr Compile( OGRFeatureDefn *, const char * );
322  int Evaluate( OGRFeature * );
323 
324  long *EvaluateAgainstIndices( OGRLayer *, OGRErr * );
325 
326  char **GetUsedFields();
327 
328  void *GetSWGExpr() { return pSWQExpr; }
329 };
330 
331 #endif /* ndef _OGR_FEATURE_H_INCLUDED */

Generated for GDAL by doxygen 1.8.1.1.