1 : /******************************************************************************
2 : * $Id: ogr_feature.h 24286 2012-04-21 19:17:26Z 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 :
37 : /**
38 : * \file ogr_feature.h
39 : *
40 : * Simple feature classes.
41 : */
42 :
43 : /************************************************************************/
44 : /* OGRFieldDefn */
45 : /************************************************************************/
46 :
47 : /**
48 : * Definition of an attribute of an OGRFeatureDefn.
49 : */
50 :
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 );
67 : OGRFieldDefn( OGRFieldDefn * );
68 : ~OGRFieldDefn();
69 :
70 : void SetName( const char * );
71 350542190 : const char *GetNameRef() { return pszName; }
72 :
73 78122798 : OGRFieldType GetType() { return eType; }
74 35980 : void SetType( OGRFieldType eTypeIn ) { eType = eTypeIn;}
75 : static const char *GetFieldTypeName( OGRFieldType );
76 :
77 73406 : OGRJustification GetJustify() { return eJustify; }
78 83282 : void SetJustify( OGRJustification eJustifyIn )
79 83282 : { eJustify = eJustifyIn; }
80 :
81 115712 : int GetWidth() { return nWidth; }
82 110578 : void SetWidth( int nWidthIn ) { nWidth = MAX(0,nWidthIn); }
83 :
84 78784 : int GetPrecision() { return nPrecision; }
85 106580 : void SetPrecision( int nPrecisionIn )
86 106580 : { 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 108206 : int IsIgnored() { return bIgnore; }
95 7764 : void SetIgnored( int bIgnore ) { this->bIgnore = bIgnore; }
96 :
97 : int IsSame( const OGRFieldDefn * ) const;
98 : };
99 :
100 : /************************************************************************/
101 : /* OGRFeatureDefn */
102 : /************************************************************************/
103 :
104 : /**
105 : * Definition of a feature class or feature layer.
106 : *
107 : * This object contains schema information for a set of OGRFeatures. In
108 : * table based systems, an OGRFeatureDefn is essentially a layer. In more
109 : * object oriented approaches (such as SF CORBA) this can represent a class
110 : * of features but doesn't necessarily relate to all of a layer, or just one
111 : * layer.
112 : *
113 : * This object also can contain some other information such as a name, the
114 : * base geometry type and potentially other metadata.
115 : *
116 : * It is reasonable for different translators to derive classes from
117 : * OGRFeatureDefn with additional translator specific information.
118 : */
119 :
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 2128616 : const char *GetName() { return pszFeatureClassName; }
140 :
141 185165262 : 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 49340 : OGRwkbGeometryType GetGeomType() { return eGeomType; }
150 : void SetGeomType( OGRwkbGeometryType );
151 :
152 : OGRFeatureDefn *Clone();
153 :
154 2858476 : int Reference() { return CPLAtomicInc(&nRefCount); }
155 2858476 : int Dereference() { return CPLAtomicDec(&nRefCount); }
156 0 : int GetReferenceCount() { return nRefCount; }
157 : void Release();
158 :
159 96994 : int IsGeometryIgnored() { return bIgnoreGeometry; }
160 2428 : void SetGeometryIgnored( int bIgnore ) { bIgnoreGeometry = bIgnore; }
161 4 : int IsStyleIgnored() { return bIgnoreStyle; }
162 1442 : 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 :
174 : /**
175 : * A simple feature, including geometry and attributes.
176 : */
177 :
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:
193 : OGRFeature( OGRFeatureDefn * );
194 : virtual ~OGRFeature();
195 :
196 320958 : OGRFeatureDefn *GetDefnRef() { return poDefn; }
197 :
198 : OGRErr SetGeometryDirectly( OGRGeometry * );
199 : OGRErr SetGeometry( OGRGeometry * );
200 4067908 : OGRGeometry *GetGeometryRef() { return poGeometry; }
201 : OGRGeometry *StealGeometry();
202 :
203 : OGRFeature *Clone();
204 : virtual OGRBoolean Equal( OGRFeature * poFeature );
205 :
206 8630766 : int GetFieldCount() { return poDefn->GetFieldCount(); }
207 7369138 : OGRFieldDefn *GetFieldDefnRef( int iField )
208 7369138 : { return poDefn->GetFieldDefn(iField); }
209 20485936 : int GetFieldIndex( const char * pszName)
210 20485936 : { return poDefn->GetFieldIndex(pszName);}
211 :
212 : int IsFieldSet( int iField ) const;
213 :
214 : void UnsetField( int iField );
215 :
216 738832 : 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 424494 : int GetFieldAsInteger( const char *pszFName )
231 424494 : { return GetFieldAsInteger( GetFieldIndex(pszFName) ); }
232 36 : double GetFieldAsDouble( const char *pszFName )
233 36 : { return GetFieldAsDouble( GetFieldIndex(pszFName) ); }
234 250408 : const char *GetFieldAsString( const char *pszFName )
235 250408 : { 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 0 : void SetField( const char *pszFName, const char * pszValue)
264 0 : { 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 553418 : 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 :
291 : OGRErr RemapFields( OGRFeatureDefn *poNewDefn,
292 : int *panRemapSource );
293 :
294 : virtual const char *GetStyleString();
295 : virtual void SetStyleString( const char * );
296 : virtual void SetStyleStringDirectly( char * );
297 54 : virtual OGRStyleTable *GetStyleTable() { return m_poStyleTable; }
298 : virtual void SetStyleTable(OGRStyleTable *poStyleTable);
299 0 : virtual void SetStyleTableDirectly(OGRStyleTable *poStyleTable)
300 0 : { if ( m_poStyleTable ) delete m_poStyleTable;
301 0 : m_poStyleTable = poStyleTable; }
302 :
303 : static OGRFeature *CreateFeature( OGRFeatureDefn * );
304 : static void DestroyFeature( OGRFeature * );
305 : };
306 :
307 : /************************************************************************/
308 : /* OGRFeatureQuery */
309 : /************************************************************************/
310 :
311 : class OGRLayer;
312 : class swq_expr_node;
313 :
314 : class CPL_DLL OGRFeatureQuery
315 : {
316 : private:
317 : OGRFeatureDefn *poTargetDefn;
318 : void *pSWQExpr;
319 :
320 : char **FieldCollector( void *, char ** );
321 :
322 : long *EvaluateAgainstIndices( swq_expr_node*, OGRLayer *, int& nFIDCount);
323 :
324 : public:
325 : OGRFeatureQuery();
326 : ~OGRFeatureQuery();
327 :
328 : OGRErr Compile( OGRFeatureDefn *, const char * );
329 : int Evaluate( OGRFeature * );
330 :
331 : long *EvaluateAgainstIndices( OGRLayer *, OGRErr * );
332 :
333 : char **GetUsedFields();
334 :
335 : void *GetSWGExpr() { return pSWQExpr; }
336 : };
337 :
338 : #endif /* ndef _OGR_FEATURE_H_INCLUDED */
|