Statistics
| Revision:

svn-gvsig-desktop / tags / v1_2_Build_1201 / libraries / libjni-gdal / include / ogr_feature.h @ 32257

History | View | Annotate | Download (14.8 KB)

1
/******************************************************************************
2
 * $Id: ogr_feature.h 7765 2006-10-03 07:05:18Z nacho $
3
 *
4
 * Project:  OpenGIS Simple Features Reference Implementation
5
 * Purpose:  Class for representing a whole feature, and layer schemas.
6
 * Author:   Frank Warmerdam, warmerda@home.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
 * $Log$
31
 * Revision 1.3  2006-10-03 07:05:18  nacho
32
 * *** empty log message ***
33
 *
34
 * Revision 1.1  2006/07/18 16:21:00  nacho
35
 * *** empty log message ***
36
 *
37
 * Revision 1.1  2006/06/29 16:23:27  nacho
38
 * *** empty log message ***
39
 *
40
 * Revision 1.2  2006/01/09 12:50:13  nacho
41
 * *** empty log message ***
42
 *
43
 * Revision 1.1  2005/07/27 08:22:55  igbrotru
44
 * *** empty log message ***
45
 *
46
 * Revision 1.1  2005/01/11 15:23:01  igbrotru
47
 * *** empty log message ***
48
 *
49
 * Revision 1.29  2004/02/23 21:47:23  warmerda
50
 * Added GetUsedFields() and GetSWGExpr() methods on OGRFeatureQuery class
51
 *
52
 * Revision 1.28  2003/05/28 19:16:42  warmerda
53
 * fixed up argument names and stuff for docs
54
 *
55
 * Revision 1.27  2003/04/08 20:57:28  warmerda
56
 * added RemapFields on OGRFeature
57
 *
58
 * Revision 1.26  2003/03/04 05:46:31  warmerda
59
 * added EvaluateAgainstIndices for OGRFeatureQuery
60
 *
61
 * Revision 1.25  2003/01/08 22:03:44  warmerda
62
 * added StealGeometry() method on OGRFeature
63
 *
64
 * Revision 1.24  2002/10/09 14:31:06  warmerda
65
 * dont permit negative widths to be assigned to field definition
66
 *
67
 * Revision 1.23  2002/09/26 18:13:17  warmerda
68
 * moved some defs to ogr_core.h for sharing with ogr_api.h
69
 *
70
 * Revision 1.22  2002/08/07 21:37:47  warmerda
71
 * added indirect OGRFeaturedefn constructor/destructor
72
 *
73
 * Revision 1.21  2001/11/01 16:54:16  warmerda
74
 * added DestroyFeature
75
 *
76
 * Revision 1.20  2001/07/19 18:25:07  warmerda
77
 * expanded tabs
78
 *
79
 * Revision 1.19  2001/06/19 15:48:36  warmerda
80
 * added feature attribute query support
81
 *
82
 * Revision 1.18  2001/06/01 14:33:00  warmerda
83
 * added CreateFeature factory method
84
 *
85
 * Revision 1.17  2001/02/06 17:10:28  warmerda
86
 * export entry points from DLL
87
 *
88
 * Revision 1.16  2001/01/19 21:10:47  warmerda
89
 * replaced tabs
90
 *
91
 * Revision 1.15  2000/12/07 03:40:13  danmo
92
 * Removed stray comma in OGRFieldType enum defn
93
 *
94
 * Revision 1.14  2000/10/03 19:19:56  danmo
95
 * Made m_pszStyleString protected (was private)
96
 *
97
 * Revision 1.13  2000/10/03 18:14:29  danmo
98
 * Made OGRFeature::Get/SetStyleString() virtual
99
 *
100
 * Revision 1.12  2000/08/18 21:26:53  svillene
101
 * Add representation
102
 *
103
 * Revision 1.11  1999/11/26 03:05:38  warmerda
104
 * added unset field support
105
 *
106
 * Revision 1.10  1999/11/18 19:02:20  warmerda
107
 * expanded tabs
108
 *
109
 * Revision 1.9  1999/11/04 21:05:49  warmerda
110
 * Added the Set() method on OGRFieldDefn to set all info in one call,
111
 * and the SetFrom() method on OGRFeature to copy the contents of one
112
 * feature to another, even if of a different OGRFeatureDefn.
113
 *
114
 * Revision 1.8  1999/10/01 14:47:05  warmerda
115
 * added full family of get/set field methods with field names
116
 *
117
 * Revision 1.7  1999/08/30 14:52:33  warmerda
118
 * added support for StringList fields
119
 *
120
 * Revision 1.6  1999/08/26 17:38:00  warmerda
121
 * added support for real and integer lists
122
 *
123
 * Revision 1.5  1999/07/27 00:47:37  warmerda
124
 * Added FID to OGRFeature class
125
 *
126
 * Revision 1.4  1999/07/07 04:23:07  danmo
127
 * Fixed typo in  #define _OGR_..._H_INCLUDED  line
128
 *
129
 * Revision 1.3  1999/07/05 17:18:39  warmerda
130
 * added docs
131
 *
132
 * Revision 1.2  1999/06/11 19:21:27  warmerda
133
 * Fleshed out operational definitions
134
 *
135
 * Revision 1.1  1999/05/31 17:14:53  warmerda
136
 * New
137
 *
138
 */
139

    
140
#ifndef _OGR_FEATURE_H_INCLUDED
141
#define _OGR_FEATURE_H_INCLUDED
142

    
143
#include "ogr_geometry.h"
144

    
145
class OGRStyleTable;
146

    
147
/**
148
 * \file ogr_feature.h
149
 *
150
 * Simple feature classes.
151
 */
152

    
153
/************************************************************************/
154
/*                             OGRFieldDefn                             */
155
/************************************************************************/
156

    
157
/**
158
 * Definition of an attribute of an OGRFeatureDefn.
159
 */
160

    
161
class CPL_DLL OGRFieldDefn
162
{
163
  private:
164
    char                *pszName;
165
    OGRFieldType        eType;                  
166
    OGRJustification    eJustify;               
167
    int                 nWidth;                 /* zero is variable */
168
    int                 nPrecision;
169
    OGRField            uDefault;
170

    
171
    void                Initialize( const char *, OGRFieldType );
172
    
173
  public:
174
                        OGRFieldDefn( const char *, OGRFieldType );
175
                        OGRFieldDefn( OGRFieldDefn * );
176
                        ~OGRFieldDefn();
177

    
178
    void                SetName( const char * );
179
    const char         *GetNameRef() { return pszName; }
180

    
181
    OGRFieldType        GetType() { return eType; }
182
    void                SetType( OGRFieldType eTypeIn ) { eType = eTypeIn;}
183
    static const char  *GetFieldTypeName( OGRFieldType );
184

    
185
    OGRJustification    GetJustify() { return eJustify; }
186
    void                SetJustify( OGRJustification eJustifyIn )
187
                                                { eJustify = eJustifyIn; }
188

    
189
    int                 GetWidth() { return nWidth; }
190
    void                SetWidth( int nWidthIn ) { nWidth = MAX(0,nWidthIn); }
191

    
192
    int                 GetPrecision() { return nPrecision; }
193
    void                SetPrecision( int nPrecisionIn )
194
                                                { nPrecision = nPrecisionIn; }
195

    
196
    void                Set( const char *, OGRFieldType, int = 0, int = 0,
197
                             OGRJustification = OJUndefined );
198

    
199
    void                SetDefault( const OGRField * );
200
    const OGRField     *GetDefaultRef() { return &uDefault; }
201
};
202

    
203
/************************************************************************/
204
/*                            OGRFeatureDefn                            */
205
/************************************************************************/
206

    
207
/**
208
 * Definition of a feature class or feature layer.
209
 *
210
 * This object contains schema information for a set of OGRFeatures.  In
211
 * table based systems, an OGRFeatureDefn is essentially a layer.  In more
212
 * object oriented approaches (such as SF CORBA) this can represent a class
213
 * of features but doesn't necessarily relate to all of a layer, or just one
214
 * layer.
215
 *
216
 * This object also can contain some other information such as a name, the
217
 * base geometry type and potentially other metadata.
218
 *
219
 * It is reasonable for different translators to derive classes from
220
 * OGRFeatureDefn with additional translator specific information. 
221
 */
222

    
223
class CPL_DLL OGRFeatureDefn
224
{
225
  private:
226
    int         nRefCount;
227
    
228
    int         nFieldCount;
229
    OGRFieldDefn **papoFieldDefn;
230

    
231
    OGRwkbGeometryType eGeomType;
232

    
233
    char        *pszFeatureClassName;
234
    
235
  public:
236
                OGRFeatureDefn( const char * pszName = NULL );
237
    virtual    ~OGRFeatureDefn();
238

    
239
    const char  *GetName() { return pszFeatureClassName; }
240

    
241
    int         GetFieldCount() { return nFieldCount; }
242
    OGRFieldDefn *GetFieldDefn( int i );
243
    int         GetFieldIndex( const char * );
244

    
245
    void        AddFieldDefn( OGRFieldDefn * );
246

    
247
    OGRwkbGeometryType GetGeomType() { return eGeomType; }
248
    void        SetGeomType( OGRwkbGeometryType );
249

    
250
    OGRFeatureDefn *Clone();
251

    
252
    int         Reference() { return ++nRefCount; }
253
    int         Dereference() { return --nRefCount; }
254
    int         GetReferenceCount() { return nRefCount; }
255

    
256
    static OGRFeatureDefn  *CreateFeatureDefn( const char *pszName = NULL );
257
    static void         DestroyFeatureDefn( OGRFeatureDefn * );
258
};
259

    
260
/************************************************************************/
261
/*                              OGRFeature                              */
262
/************************************************************************/
263

    
264
/**
265
 * A simple feature, including geometry and attributes.
266
 */
267

    
268
class CPL_DLL OGRFeature
269
{
270
  private:
271

    
272
    long                nFID;
273
    OGRFeatureDefn      *poDefn;
274
    OGRGeometry         *poGeometry;
275
    OGRField            *pauFields;
276

    
277
  protected: 
278
    char *              m_pszStyleString;
279
    OGRStyleTable       *m_poStyleTable;
280
    
281
    
282
  public:
283
                        OGRFeature( OGRFeatureDefn * );
284
    virtual            ~OGRFeature();                        
285

    
286
    OGRFeatureDefn     *GetDefnRef() { return poDefn; }
287
    
288
    OGRErr              SetGeometryDirectly( OGRGeometry * );
289
    OGRErr              SetGeometry( OGRGeometry * );
290
    OGRGeometry        *GetGeometryRef() { return poGeometry; }
291
    OGRGeometry        *StealGeometry();
292

    
293
    OGRFeature         *Clone();
294
    virtual OGRBoolean  Equal( OGRFeature * poFeature );
295

    
296
    int                 GetFieldCount() { return poDefn->GetFieldCount(); }
297
    OGRFieldDefn       *GetFieldDefnRef( int iField )
298
                                      { return poDefn->GetFieldDefn(iField); }
299
    int                 GetFieldIndex( const char * pszName)
300
                                      { return poDefn->GetFieldIndex(pszName);}
301

    
302
    int                 IsFieldSet( int iField )
303
                        { return
304
                              pauFields[iField].Set.nMarker1 != OGRUnsetMarker
305
                           || pauFields[iField].Set.nMarker2 != OGRUnsetMarker;
306
                              }
307
    
308
    void                UnsetField( int iField );
309
    
310
    OGRField           *GetRawFieldRef( int i ) { return pauFields + i; }
311

    
312
    int                 GetFieldAsInteger( int i );
313
    double              GetFieldAsDouble( int i );
314
    const char         *GetFieldAsString( int i );
315
    const int          *GetFieldAsIntegerList( int i, int *pnCount );
316
    const double       *GetFieldAsDoubleList( int i, int *pnCount );
317
    char              **GetFieldAsStringList( int i );
318

    
319
    int                 GetFieldAsInteger( const char *pszFName )
320
                      { return GetFieldAsInteger( GetFieldIndex(pszFName) ); }
321
    double              GetFieldAsDouble( const char *pszFName )
322
                      { return GetFieldAsDouble( GetFieldIndex(pszFName) ); }
323
    const char         *GetFieldAsString( const char *pszFName )
324
                      { return GetFieldAsString( GetFieldIndex(pszFName) ); }
325
    const int          *GetFieldAsIntegerList( const char *pszFName,
326
                                               int *pnCount )
327
                      { return GetFieldAsIntegerList( GetFieldIndex(pszFName),
328
                                                      pnCount ); }
329
    const double       *GetFieldAsDoubleList( const char *pszFName,
330
                                              int *pnCount )
331
                      { return GetFieldAsDoubleList( GetFieldIndex(pszFName),
332
                                                     pnCount ); }
333
    char              **GetFieldAsStringList( const char *pszFName )
334
                      { return GetFieldAsStringList(GetFieldIndex(pszFName)); }
335

    
336
    void                SetField( int i, int nValue );
337
    void                SetField( int i, double dfValue );
338
    void                SetField( int i, const char * pszValue );
339
    void                SetField( int i, int nCount, int * panValues );
340
    void                SetField( int i, int nCount, double * padfValues );
341
    void                SetField( int i, char ** papszValues );
342
    void                SetField( int i, OGRField * puValue );
343

    
344
    void                SetField( const char *pszFName, int nValue )
345
                           { SetField( GetFieldIndex(pszFName), nValue ); }
346
    void                SetField( const char *pszFName, double dfValue )
347
                           { SetField( GetFieldIndex(pszFName), dfValue ); }
348
    void                SetField( const char *pszFName, const char * pszValue)
349
                           { SetField( GetFieldIndex(pszFName), pszValue ); }
350
    void                SetField( const char *pszFName, int nCount,
351
                                  int * panValues )
352
                         { SetField(GetFieldIndex(pszFName),nCount,panValues);}
353
    void                SetField( const char *pszFName, int nCount,
354
                                  double * padfValues )
355
                         {SetField(GetFieldIndex(pszFName),nCount,padfValues);}
356
    void                SetField( const char *pszFName, char ** papszValues )
357
                           { SetField( GetFieldIndex(pszFName), papszValues); }
358
    void                SetField( const char *pszFName, OGRField * puValue )
359
                           { SetField( GetFieldIndex(pszFName), puValue ); }
360

    
361
    long                GetFID() { return nFID; }
362
    virtual OGRErr      SetFID( long nFID );
363

    
364
    void                DumpReadable( FILE * );
365

    
366
    OGRErr              SetFrom( OGRFeature *, int = TRUE);
367

    
368
    OGRErr              RemapFields( OGRFeatureDefn *poNewDefn, 
369
                                     int *panRemapSource );
370

    
371
    virtual const char *GetStyleString();
372
    virtual void        SetStyleString(const char *);
373
    virtual void        SetStyleTable(OGRStyleTable *poStyleTable);
374

    
375
    static OGRFeature  *CreateFeature( OGRFeatureDefn * );
376
    static void         DestroyFeature( OGRFeature * );
377
};
378

    
379
/************************************************************************/
380
/*                           OGRFeatureQuery                            */
381
/************************************************************************/
382

    
383
class OGRLayer;
384

    
385
class CPL_DLL OGRFeatureQuery
386
{
387
  private:
388
    OGRFeatureDefn *poTargetDefn;
389
    void           *pSWQExpr;
390

    
391
    char          **FieldCollector( void *, char ** );
392
    
393
  public:
394
                OGRFeatureQuery();
395
                ~OGRFeatureQuery();
396

    
397
    OGRErr      Compile( OGRFeatureDefn *, const char * );
398
    int         Evaluate( OGRFeature * );
399

    
400
    long       *EvaluateAgainstIndices( OGRLayer *, OGRErr * );
401

    
402
    char      **GetUsedFields();
403

    
404
    void       *GetSWGExpr() { return pSWQExpr; }
405
};
406

    
407
#endif /* ndef _OGR_FEATURE_H_INCLUDED */