Statistics
| Revision:

svn-gvsig-desktop / branches / v10 / libraries / libjni-gdal-macosx / include / ogr_feature.h @ 18727

History | View | Annotate | Download (15 KB)

1 8219 nacho
/******************************************************************************
2
 * $Id$
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 13023 mija
 * Revision 1.1.2.2  2007-08-12 19:32:52  mija
32
 * Tentatively brought up-to-date to latest version of jgdal
33
 *
34
 * Revision 1.2.10.2  2006/11/15 00:08:29  jjdelcerro
35 8219 nacho
 * *** empty log message ***
36
 *
37 13023 mija
 * Revision 1.3  2006/10/03 07:05:18  nacho
38 8767 jjdelcerro
 * *** empty log message ***
39
 *
40 13023 mija
 * Revision 1.1  2006/07/18 16:21:00  nacho
41
 * *** empty log message ***
42
 *
43 8219 nacho
 * Revision 1.1  2006/06/29 16:23:27  nacho
44
 * *** empty log message ***
45
 *
46
 * Revision 1.2  2006/01/09 12:50:13  nacho
47
 * *** empty log message ***
48
 *
49
 * Revision 1.1  2005/07/27 08:22:55  igbrotru
50
 * *** empty log message ***
51
 *
52
 * Revision 1.1  2005/01/11 15:23:01  igbrotru
53
 * *** empty log message ***
54
 *
55
 * Revision 1.29  2004/02/23 21:47:23  warmerda
56
 * Added GetUsedFields() and GetSWGExpr() methods on OGRFeatureQuery class
57
 *
58
 * Revision 1.28  2003/05/28 19:16:42  warmerda
59
 * fixed up argument names and stuff for docs
60
 *
61
 * Revision 1.27  2003/04/08 20:57:28  warmerda
62
 * added RemapFields on OGRFeature
63
 *
64
 * Revision 1.26  2003/03/04 05:46:31  warmerda
65
 * added EvaluateAgainstIndices for OGRFeatureQuery
66
 *
67
 * Revision 1.25  2003/01/08 22:03:44  warmerda
68
 * added StealGeometry() method on OGRFeature
69
 *
70
 * Revision 1.24  2002/10/09 14:31:06  warmerda
71
 * dont permit negative widths to be assigned to field definition
72
 *
73
 * Revision 1.23  2002/09/26 18:13:17  warmerda
74
 * moved some defs to ogr_core.h for sharing with ogr_api.h
75
 *
76
 * Revision 1.22  2002/08/07 21:37:47  warmerda
77
 * added indirect OGRFeaturedefn constructor/destructor
78
 *
79
 * Revision 1.21  2001/11/01 16:54:16  warmerda
80
 * added DestroyFeature
81
 *
82
 * Revision 1.20  2001/07/19 18:25:07  warmerda
83
 * expanded tabs
84
 *
85
 * Revision 1.19  2001/06/19 15:48:36  warmerda
86
 * added feature attribute query support
87
 *
88
 * Revision 1.18  2001/06/01 14:33:00  warmerda
89
 * added CreateFeature factory method
90
 *
91
 * Revision 1.17  2001/02/06 17:10:28  warmerda
92
 * export entry points from DLL
93
 *
94
 * Revision 1.16  2001/01/19 21:10:47  warmerda
95
 * replaced tabs
96
 *
97
 * Revision 1.15  2000/12/07 03:40:13  danmo
98
 * Removed stray comma in OGRFieldType enum defn
99
 *
100
 * Revision 1.14  2000/10/03 19:19:56  danmo
101
 * Made m_pszStyleString protected (was private)
102
 *
103
 * Revision 1.13  2000/10/03 18:14:29  danmo
104
 * Made OGRFeature::Get/SetStyleString() virtual
105
 *
106
 * Revision 1.12  2000/08/18 21:26:53  svillene
107
 * Add representation
108
 *
109
 * Revision 1.11  1999/11/26 03:05:38  warmerda
110
 * added unset field support
111
 *
112
 * Revision 1.10  1999/11/18 19:02:20  warmerda
113
 * expanded tabs
114
 *
115
 * Revision 1.9  1999/11/04 21:05:49  warmerda
116
 * Added the Set() method on OGRFieldDefn to set all info in one call,
117
 * and the SetFrom() method on OGRFeature to copy the contents of one
118
 * feature to another, even if of a different OGRFeatureDefn.
119
 *
120
 * Revision 1.8  1999/10/01 14:47:05  warmerda
121
 * added full family of get/set field methods with field names
122
 *
123
 * Revision 1.7  1999/08/30 14:52:33  warmerda
124
 * added support for StringList fields
125
 *
126
 * Revision 1.6  1999/08/26 17:38:00  warmerda
127
 * added support for real and integer lists
128
 *
129
 * Revision 1.5  1999/07/27 00:47:37  warmerda
130
 * Added FID to OGRFeature class
131
 *
132
 * Revision 1.4  1999/07/07 04:23:07  danmo
133
 * Fixed typo in  #define _OGR_..._H_INCLUDED  line
134
 *
135
 * Revision 1.3  1999/07/05 17:18:39  warmerda
136
 * added docs
137
 *
138
 * Revision 1.2  1999/06/11 19:21:27  warmerda
139
 * Fleshed out operational definitions
140
 *
141
 * Revision 1.1  1999/05/31 17:14:53  warmerda
142
 * New
143
 *
144
 */
145
146
#ifndef _OGR_FEATURE_H_INCLUDED
147
#define _OGR_FEATURE_H_INCLUDED
148
149
#include "ogr_geometry.h"
150
151
class OGRStyleTable;
152
153
/**
154
 * \file ogr_feature.h
155
 *
156
 * Simple feature classes.
157
 */
158
159
/************************************************************************/
160
/*                             OGRFieldDefn                             */
161
/************************************************************************/
162
163
/**
164
 * Definition of an attribute of an OGRFeatureDefn.
165
 */
166
167
class CPL_DLL OGRFieldDefn
168
{
169
  private:
170
    char                *pszName;
171
    OGRFieldType        eType;
172
    OGRJustification    eJustify;
173
    int                 nWidth;                 /* zero is variable */
174
    int                 nPrecision;
175
    OGRField            uDefault;
176
177
    void                Initialize( const char *, OGRFieldType );
178
179
  public:
180
                        OGRFieldDefn( const char *, OGRFieldType );
181
                        OGRFieldDefn( OGRFieldDefn * );
182
                        ~OGRFieldDefn();
183
184
    void                SetName( const char * );
185
    const char         *GetNameRef() { return pszName; }
186
187
    OGRFieldType        GetType() { return eType; }
188
    void                SetType( OGRFieldType eTypeIn ) { eType = eTypeIn;}
189
    static const char  *GetFieldTypeName( OGRFieldType );
190
191
    OGRJustification    GetJustify() { return eJustify; }
192
    void                SetJustify( OGRJustification eJustifyIn )
193
                                                { eJustify = eJustifyIn; }
194
195
    int                 GetWidth() { return nWidth; }
196
    void                SetWidth( int nWidthIn ) { nWidth = MAX(0,nWidthIn); }
197
198
    int                 GetPrecision() { return nPrecision; }
199
    void                SetPrecision( int nPrecisionIn )
200
                                                { nPrecision = nPrecisionIn; }
201
202
    void                Set( const char *, OGRFieldType, int = 0, int = 0,
203
                             OGRJustification = OJUndefined );
204
205
    void                SetDefault( const OGRField * );
206
    const OGRField     *GetDefaultRef() { return &uDefault; }
207
};
208
209
/************************************************************************/
210
/*                            OGRFeatureDefn                            */
211
/************************************************************************/
212
213
/**
214
 * Definition of a feature class or feature layer.
215
 *
216
 * This object contains schema information for a set of OGRFeatures.  In
217
 * table based systems, an OGRFeatureDefn is essentially a layer.  In more
218
 * object oriented approaches (such as SF CORBA) this can represent a class
219
 * of features but doesn't necessarily relate to all of a layer, or just one
220
 * layer.
221
 *
222
 * This object also can contain some other information such as a name, the
223
 * base geometry type and potentially other metadata.
224
 *
225
 * It is reasonable for different translators to derive classes from
226
 * OGRFeatureDefn with additional translator specific information.
227
 */
228
229
class CPL_DLL OGRFeatureDefn
230
{
231
  private:
232
    int         nRefCount;
233
234
    int         nFieldCount;
235
    OGRFieldDefn **papoFieldDefn;
236
237
    OGRwkbGeometryType eGeomType;
238
239
    char        *pszFeatureClassName;
240
241
  public:
242
                OGRFeatureDefn( const char * pszName = NULL );
243
    virtual    ~OGRFeatureDefn();
244
245
    const char  *GetName() { return pszFeatureClassName; }
246
247
    int         GetFieldCount() { return nFieldCount; }
248
    OGRFieldDefn *GetFieldDefn( int i );
249
    int         GetFieldIndex( const char * );
250
251
    void        AddFieldDefn( OGRFieldDefn * );
252
253
    OGRwkbGeometryType GetGeomType() { return eGeomType; }
254
    void        SetGeomType( OGRwkbGeometryType );
255
256
    OGRFeatureDefn *Clone();
257
258
    int         Reference() { return ++nRefCount; }
259
    int         Dereference() { return --nRefCount; }
260
    int         GetReferenceCount() { return nRefCount; }
261
262
    static OGRFeatureDefn  *CreateFeatureDefn( const char *pszName = NULL );
263
    static void         DestroyFeatureDefn( OGRFeatureDefn * );
264
};
265
266
/************************************************************************/
267
/*                              OGRFeature                              */
268
/************************************************************************/
269
270
/**
271
 * A simple feature, including geometry and attributes.
272
 */
273
274
class CPL_DLL OGRFeature
275
{
276
  private:
277
278
    long                nFID;
279
    OGRFeatureDefn      *poDefn;
280
    OGRGeometry         *poGeometry;
281
    OGRField            *pauFields;
282
283
  protected:
284
    char *              m_pszStyleString;
285
    OGRStyleTable       *m_poStyleTable;
286
287
288
  public:
289
                        OGRFeature( OGRFeatureDefn * );
290
    virtual            ~OGRFeature();
291
292
    OGRFeatureDefn     *GetDefnRef() { return poDefn; }
293
294
    OGRErr              SetGeometryDirectly( OGRGeometry * );
295
    OGRErr              SetGeometry( OGRGeometry * );
296
    OGRGeometry        *GetGeometryRef() { return poGeometry; }
297
    OGRGeometry        *StealGeometry();
298
299
    OGRFeature         *Clone();
300
    virtual OGRBoolean  Equal( OGRFeature * poFeature );
301
302
    int                 GetFieldCount() { return poDefn->GetFieldCount(); }
303
    OGRFieldDefn       *GetFieldDefnRef( int iField )
304
                                      { return poDefn->GetFieldDefn(iField); }
305
    int                 GetFieldIndex( const char * pszName)
306
                                      { return poDefn->GetFieldIndex(pszName);}
307
308
    int                 IsFieldSet( int iField )
309
                        { return
310
                              pauFields[iField].Set.nMarker1 != OGRUnsetMarker
311
                           || pauFields[iField].Set.nMarker2 != OGRUnsetMarker;
312
                              }
313
314
    void                UnsetField( int iField );
315
316
    OGRField           *GetRawFieldRef( int i ) { return pauFields + i; }
317
318
    int                 GetFieldAsInteger( int i );
319
    double              GetFieldAsDouble( int i );
320
    const char         *GetFieldAsString( int i );
321
    const int          *GetFieldAsIntegerList( int i, int *pnCount );
322
    const double       *GetFieldAsDoubleList( int i, int *pnCount );
323
    char              **GetFieldAsStringList( int i );
324
325
    int                 GetFieldAsInteger( const char *pszFName )
326
                      { return GetFieldAsInteger( GetFieldIndex(pszFName) ); }
327
    double              GetFieldAsDouble( const char *pszFName )
328
                      { return GetFieldAsDouble( GetFieldIndex(pszFName) ); }
329
    const char         *GetFieldAsString( const char *pszFName )
330
                      { return GetFieldAsString( GetFieldIndex(pszFName) ); }
331
    const int          *GetFieldAsIntegerList( const char *pszFName,
332
                                               int *pnCount )
333
                      { return GetFieldAsIntegerList( GetFieldIndex(pszFName),
334
                                                      pnCount ); }
335
    const double       *GetFieldAsDoubleList( const char *pszFName,
336
                                              int *pnCount )
337
                      { return GetFieldAsDoubleList( GetFieldIndex(pszFName),
338
                                                     pnCount ); }
339
    char              **GetFieldAsStringList( const char *pszFName )
340
                      { return GetFieldAsStringList(GetFieldIndex(pszFName)); }
341
342
    void                SetField( int i, int nValue );
343
    void                SetField( int i, double dfValue );
344
    void                SetField( int i, const char * pszValue );
345
    void                SetField( int i, int nCount, int * panValues );
346
    void                SetField( int i, int nCount, double * padfValues );
347
    void                SetField( int i, char ** papszValues );
348
    void                SetField( int i, OGRField * puValue );
349
350
    void                SetField( const char *pszFName, int nValue )
351
                           { SetField( GetFieldIndex(pszFName), nValue ); }
352
    void                SetField( const char *pszFName, double dfValue )
353
                           { SetField( GetFieldIndex(pszFName), dfValue ); }
354
    void                SetField( const char *pszFName, const char * pszValue)
355
                           { SetField( GetFieldIndex(pszFName), pszValue ); }
356
    void                SetField( const char *pszFName, int nCount,
357
                                  int * panValues )
358
                         { SetField(GetFieldIndex(pszFName),nCount,panValues);}
359
    void                SetField( const char *pszFName, int nCount,
360
                                  double * padfValues )
361
                         {SetField(GetFieldIndex(pszFName),nCount,padfValues);}
362
    void                SetField( const char *pszFName, char ** papszValues )
363
                           { SetField( GetFieldIndex(pszFName), papszValues); }
364
    void                SetField( const char *pszFName, OGRField * puValue )
365
                           { SetField( GetFieldIndex(pszFName), puValue ); }
366
367
    long                GetFID() { return nFID; }
368
    virtual OGRErr      SetFID( long nFID );
369
370
    void                DumpReadable( FILE * );
371
372
    OGRErr              SetFrom( OGRFeature *, int = TRUE);
373
374
    OGRErr              RemapFields( OGRFeatureDefn *poNewDefn,
375
                                     int *panRemapSource );
376
377
    virtual const char *GetStyleString();
378
    virtual void        SetStyleString(const char *);
379
    virtual void        SetStyleTable(OGRStyleTable *poStyleTable);
380
381
    static OGRFeature  *CreateFeature( OGRFeatureDefn * );
382
    static void         DestroyFeature( OGRFeature * );
383
};
384
385
/************************************************************************/
386
/*                           OGRFeatureQuery                            */
387
/************************************************************************/
388
389
class OGRLayer;
390
391
class CPL_DLL OGRFeatureQuery
392
{
393
  private:
394
    OGRFeatureDefn *poTargetDefn;
395
    void           *pSWQExpr;
396
397
    char          **FieldCollector( void *, char ** );
398
399
  public:
400
                OGRFeatureQuery();
401
                ~OGRFeatureQuery();
402
403
    OGRErr      Compile( OGRFeatureDefn *, const char * );
404
    int         Evaluate( OGRFeature * );
405
406
    long       *EvaluateAgainstIndices( OGRLayer *, OGRErr * );
407
408
    char      **GetUsedFields();
409
410
    void       *GetSWGExpr() { return pSWQExpr; }
411
};
412
413
#endif /* ndef _OGR_FEATURE_H_INCLUDED */