Statistics
| Revision:

root / trunk / libraries / libjni-gdal / include / ogr_spatialref.h @ 2223

History | View | Annotate | Download (20.9 KB)

1 879 igbrotru
/******************************************************************************
2
 * $Id$
3
 *
4
 * Project:  OpenGIS Simple Features Reference Implementation
5
 * Purpose:  Classes for manipulating spatial reference systems in a
6
 *           platform non-specific manner.
7
 * Author:   Frank Warmerdam, warmerdam@pobox.com
8
 *
9
 ******************************************************************************
10
 * Copyright (c) 1999,  Les Technologies SoftMap Inc.
11
 *
12
 * Permission is hereby granted, free of charge, to any person obtaining a
13
 * copy of this software and associated documentation files (the "Software"),
14
 * to deal in the Software without restriction, including without limitation
15
 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
16
 * and/or sell copies of the Software, and to permit persons to whom the
17
 * Software is furnished to do so, subject to the following conditions:
18
 *
19
 * The above copyright notice and this permission notice shall be included
20
 * in all copies or substantial portions of the Software.
21
 *
22
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
23
 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
24
 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
25
 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
26
 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
27
 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
28
 * DEALINGS IN THE SOFTWARE.
29
 ******************************************************************************
30
 *
31
 * $Log$
32
 * Revision 1.1  2005-01-11 15:23:01  igbrotru
33
 * *** empty log message ***
34
 *
35
 * Revision 1.61  2004/05/10 17:05:14  warmerda
36
 * added AutoIdentifyEPSG()
37
 *
38
 * Revision 1.60  2004/03/04 18:04:45  warmerda
39
 * added importFromDict() support
40
 *
41
 * Revision 1.59  2004/02/07 17:31:21  dron
42
 * Added OSRExportToUSGS() method.
43
 *
44
 * Revision 1.58  2004/02/05 17:07:59  dron
45
 * Support for HOM projection, specified by two points on centerline.
46
 *
47
 * Revision 1.57  2004/02/01 14:24:09  dron
48
 * Added OGRSpatialReference::importFromUSGS().
49
 *
50
 * Revision 1.56  2004/01/24 09:34:59  warmerda
51
 * added TransformEx support to capture per point reprojection failure
52
 *
53
 * Revision 1.55  2003/10/07 04:20:50  warmerda
54
 * added WMS AUTO: support
55
 *
56
 * Revision 1.54  2003/09/09 07:49:19  dron
57
 * Added exportToPCI() method.
58
 *
59
 * Revision 1.53  2003/08/31 14:51:30  dron
60
 * Added importFromPCI() method.
61
 *
62
 * Revision 1.52  2003/08/18 13:26:01  warmerda
63
 * added SetTMVariant() and related definitions
64
 *
65
 * Revision 1.51  2003/05/30 15:39:53  warmerda
66
 * Added override units capability for SetStatePlane()
67
 *
68
 * Revision 1.50  2003/05/28 19:16:42  warmerda
69
 * fixed up argument names and stuff for docs
70
 *
71
 * Revision 1.49  2003/03/12 14:25:01  warmerda
72
 * added NeedsQuoting() method
73
 *
74
 * Revision 1.48  2003/02/25 04:53:51  warmerda
75
 * added CopyGeogCSFrom() method
76
 *
77
 * Revision 1.47  2003/02/06 04:53:12  warmerda
78
 * added Fixup() method
79
 *
80
 * Revision 1.46  2003/01/08 18:14:28  warmerda
81
 * added FixupOrdering()
82
 */
83
84
#ifndef _OGR_SPATIALREF_H_INCLUDED
85
#define _OGR_SPATIALREF_H_INCLUDED
86
87
#include "ogr_srs_api.h"
88
89
/**
90
 * \file ogr_spatialref.h
91
 *
92
 * Coordinate systems services.
93
 */
94
95
/************************************************************************/
96
/*                             OGR_SRSNode                              */
97
/************************************************************************/
98
99
/**
100
 * Objects of this class are used to represent value nodes in the parsed
101
 * representation of the WKT SRS format.  For instance UNIT["METER",1]
102
 * would be rendered into three OGR_SRSNodes.  The root node would have a
103
 * value of UNIT, and two children, the first with a value of METER, and the
104
 * second with a value of 1.
105
 *
106
 * Normally application code just interacts with the OGRSpatialReference
107
 * object, which uses the OGR_SRSNode to implement it's data structure;
108
 * however, this class is user accessable for detailed access to components
109
 * of an SRS definition.
110
 */
111
112
class CPL_DLL OGR_SRSNode
113
{
114
    char        *pszValue;
115
116
    int         nChildren;
117
    OGR_SRSNode **papoChildNodes;
118
119
    OGR_SRSNode *poParent;
120
121
    void        ClearChildren();
122
    int         NeedsQuoting() const;
123
124
  public:
125
                OGR_SRSNode(const char * = NULL);
126
                ~OGR_SRSNode();
127
128
    int         IsLeafNode() const { return nChildren == 0; }
129
130
    int         GetChildCount() const { return nChildren; }
131
    OGR_SRSNode *GetChild( int );
132
    const OGR_SRSNode *GetChild( int ) const;
133
134
    OGR_SRSNode *GetNode( const char * );
135
    const OGR_SRSNode *GetNode( const char * ) const;
136
137
    void        InsertChild( OGR_SRSNode *, int );
138
    void        AddChild( OGR_SRSNode * );
139
    int         FindChild( const char * ) const;
140
    void        DestroyChild( int );
141
    void        StripNodes( const char * );
142
143
    const char  *GetValue() const { return pszValue; }
144
    void        SetValue( const char * );
145
146
    void        MakeValueSafe();
147
    OGRErr      FixupOrdering();
148
149
    OGR_SRSNode *Clone() const;
150
151
    OGRErr      importFromWkt( char ** );
152
    OGRErr      exportToWkt( char ** ) const;
153
    OGRErr      exportToPrettyWkt( char **, int = 1) const;
154
155
    OGRErr      applyRemapper( const char *pszNode,
156
                               char **papszSrcValues,
157
                               char **papszDstValues,
158
                               int nStepSize = 1,
159
                               int bChildOfHit = FALSE );
160
};
161
162
/************************************************************************/
163
/*                         OGRSpatialReference                          */
164
/************************************************************************/
165
166
/**
167
 * This class respresents a OpenGIS Spatial Reference System, and contains
168
 * methods for converting between this object organization and well known
169
 * text (WKT) format.  This object is reference counted as one instance of
170
 * the object is normally shared between many OGRGeometry objects.
171
 *
172
 * Normally application code can fetch needed parameter values for this
173
 * SRS using GetAttrValue(), but in special cases the underlying parse tree
174
 * (or OGR_SRSNode objects) can be accessed more directly.
175
 *
176
 * See <a href="osr_tutorial.html">the tutorial</a> for more information on
177
 * how to use this class.
178
 */
179
180
class CPL_DLL OGRSpatialReference
181
{
182
    int         nRefCount;
183
184
    OGR_SRSNode *poRoot;
185
186
    int         bNormInfoSet;
187
    double      dfFromGreenwich;
188
    double      dfToMeter;
189
    double      dfToDegrees;
190
191
    OGRErr      ValidateProjection();
192
    int         IsAliasFor( const char *, const char * );
193
    void        GetNormInfo() const;
194
195
  public:
196
                OGRSpatialReference(const OGRSpatialReference&);
197
                OGRSpatialReference(const char * = NULL);
198
199
    virtual    ~OGRSpatialReference();
200
201
    OGRSpatialReference &operator=(const OGRSpatialReference&);
202
203
    int         Reference();
204
    int         Dereference();
205
    int         GetReferenceCount() const { return nRefCount; }
206
207
    OGRSpatialReference *Clone() const;
208
    OGRSpatialReference *CloneGeogCS() const;
209
210
    OGRErr      exportToWkt( char ** );
211
    OGRErr      exportToPrettyWkt( char **, int = FALSE) const;
212
    OGRErr      exportToProj4( char ** ) const;
213
    OGRErr      exportToPCI( char **, char **, double ** ) const;
214
    OGRErr      exportToUSGS( long *, long *, double **, long * ) const;
215
    OGRErr      exportToXML( char **, const char * = NULL ) const;
216
    OGRErr      importFromWkt( char ** );
217
    OGRErr      importFromProj4( const char * );
218
    OGRErr      importFromEPSG( int );
219
    OGRErr      importFromESRI( char ** );
220
    OGRErr      importFromPCI( const char *pszProj,
221
                               const char *pszUnits = NULL,
222
                               double *padfPrjParams = NULL );
223
    OGRErr      importFromUSGS( long iProjsys, long iZone,
224
                                double *padfPrjParams, long iDatum );
225
    OGRErr      importFromWMSAUTO( const char *pszAutoDef );
226
    OGRErr      importFromXML( const char * );
227
    OGRErr      importFromDict( const char *pszDict, const char *pszCode );
228
229
    OGRErr      morphToESRI();
230
    OGRErr      morphFromESRI();
231
232
    OGRErr      Validate();
233
    OGRErr      StripCTParms( OGR_SRSNode * = NULL );
234
    OGRErr      FixupOrdering();
235
    OGRErr      Fixup();
236
237
    // Machinary for accessing parse nodes
238
    OGR_SRSNode *GetRoot() { return poRoot; }
239
    const OGR_SRSNode *GetRoot() const { return poRoot; }
240
    void        SetRoot( OGR_SRSNode * );
241
242
    OGR_SRSNode *GetAttrNode(const char *);
243
    const OGR_SRSNode *GetAttrNode(const char *) const;
244
    const char  *GetAttrValue(const char *, int = 0) const;
245
246
    OGRErr      SetNode( const char *, const char * );
247
    OGRErr      SetNode( const char *, double );
248
249
    OGRErr      SetLinearUnits( const char *pszName, double dfInMeters );
250
    double      GetLinearUnits( char ** = NULL ) const;
251
252
    OGRErr      SetAngularUnits( const char *pszName, double dfInRadians );
253
    double      GetAngularUnits( char ** = NULL ) const;
254
255
    double      GetPrimeMeridian( char ** = NULL ) const;
256
257
    int         IsGeographic() const;
258
    int         IsProjected() const;
259
    int         IsLocal() const;
260
    int         IsSameGeogCS( const OGRSpatialReference * ) const;
261
    int         IsSame( const OGRSpatialReference * ) const;
262
263
    void        Clear();
264
    OGRErr      SetLocalCS( const char * );
265
    OGRErr      SetProjCS( const char * );
266
    OGRErr      SetProjection( const char * );
267
    OGRErr      SetGeogCS( const char * pszGeogName,
268
                           const char * pszDatumName,
269
                           const char * pszEllipsoidName,
270
                           double dfSemiMajor, double dfInvFlattening,
271
                           const char * pszPMName = NULL,
272
                           double dfPMOffset = 0.0,
273
                           const char * pszUnits = NULL,
274
                           double dfConvertToRadians = 0.0 );
275
    OGRErr      SetWellKnownGeogCS( const char * );
276
    OGRErr      CopyGeogCSFrom( const OGRSpatialReference * poSrcSRS );
277
278
    OGRErr      SetFromUserInput( const char * );
279
280
    OGRErr      SetTOWGS84( double, double, double,
281
                            double = 0.0, double = 0.0, double = 0.0,
282
                            double = 0.0 );
283
    OGRErr      GetTOWGS84( double *padfCoef, int nCoeff = 7 ) const;
284
285
    double      GetSemiMajor( OGRErr * = NULL ) const;
286
    double      GetSemiMinor( OGRErr * = NULL ) const;
287
    double      GetInvFlattening( OGRErr * = NULL ) const;
288
289
    OGRErr      SetAuthority( const char * pszTargetKey,
290
                              const char * pszAuthority,
291
                              int nCode );
292
293
    OGRErr      AutoIdentifyEPSG();
294
295
    const char *GetAuthorityCode( const char * pszTargetKey ) const;
296
    const char *GetAuthorityName( const char * pszTargetKey ) const;
297
298
    OGRErr      SetProjParm( const char *, double );
299
    double      GetProjParm( const char *, double =0.0, OGRErr* = NULL ) const;
300
301
    OGRErr      SetNormProjParm( const char *, double );
302
    double      GetNormProjParm( const char *, double=0.0, OGRErr* =NULL)const;
303
304
    static int  IsAngularParameter( const char * );
305
    static int  IsLongitudeParameter( const char * );
306
    static int  IsLinearParameter( const char * );
307
308
    /** Albers Conic Equal Area */
309
    OGRErr      SetACEA( double dfStdP1, double dfStdP2,
310
                         double dfCenterLat, double dfCenterLong,
311
                         double dfFalseEasting, double dfFalseNorthing );
312
313
    /** Azimuthal Equidistant */
314
    OGRErr      SetAE( double dfCenterLat, double dfCenterLong,
315
                       double dfFalseEasting, double dfFalseNorthing );
316
317
    /** Cylindrical Equal Area */
318
    OGRErr      SetCEA( double dfStdP1, double dfCentralMeridian,
319
                        double dfFalseEasting, double dfFalseNorthing );
320
321
    /** Cassini-Soldner */
322
    OGRErr      SetCS( double dfCenterLat, double dfCenterLong,
323
                       double dfFalseEasting, double dfFalseNorthing );
324
325
    /** Equidistant Conic */
326
    OGRErr      SetEC( double dfStdP1, double dfStdP2,
327
                       double dfCenterLat, double dfCenterLong,
328
                       double dfFalseEasting, double dfFalseNorthing );
329
330
    /** Eckert IV */
331
    OGRErr      SetEckertIV( double dfCentralMeridian,
332
                             double dfFalseEasting, double dfFalseNorthing );
333
334
    /** Eckert VI */
335
    OGRErr      SetEckertVI( double dfCentralMeridian,
336
                             double dfFalseEasting, double dfFalseNorthing );
337
338
    /** Equirectangular */
339
    OGRErr      SetEquirectangular(double dfCenterLat, double dfCenterLong,
340
                            double dfFalseEasting, double dfFalseNorthing );
341
342
    /** Gall Stereograpic */
343
    OGRErr      SetGS( double dfCentralMeridian,
344
                       double dfFalseEasting, double dfFalseNorthing );
345
346
    /** Gnomonic */
347
    OGRErr      SetGnomonic(double dfCenterLat, double dfCenterLong,
348
                            double dfFalseEasting, double dfFalseNorthing );
349
350
    OGRErr      SetHOM( double dfCenterLat, double dfCenterLong,
351
                        double dfAzimuth, double dfRectToSkew,
352
                        double dfScale,
353
                        double dfFalseEasting, double dfFalseNorthing );
354
355
    OGRErr      SetHOM2PNO( double dfCenterLat,
356
                            double dfLat1, double dfLong1,
357
                            double dfLat2, double dfLong2,
358
                            double dfScale,
359
                            double dfFalseEasting, double dfFalseNorthing );
360
361
    /** Krovak Oblique Conic Conformal */
362
    OGRErr      SetKrovak( double dfCenterLat, double dfCenterLong,
363
                           double dfAzimuth, double dfPseudoStdParallelLat,
364
                           double dfScale,
365
                           double dfFalseEasting, double dfFalseNorthing );
366
367
    /** Lambert Azimuthal Equal-Area */
368
    OGRErr      SetLAEA( double dfCenterLat, double dfCenterLong,
369
                         double dfFalseEasting, double dfFalseNorthing );
370
371
    /** Lambert Conformal Conic */
372
    OGRErr      SetLCC( double dfStdP1, double dfStdP2,
373
                        double dfCenterLat, double dfCenterLong,
374
                        double dfFalseEasting, double dfFalseNorthing );
375
376
    /** Lambert Conformal Conic 1SP */
377
    OGRErr      SetLCC1SP( double dfCenterLat, double dfCenterLong,
378
                           double dfScale,
379
                           double dfFalseEasting, double dfFalseNorthing );
380
381
    /** Lambert Conformal Conic (Belgium) */
382
    OGRErr      SetLCCB( double dfStdP1, double dfStdP2,
383
                         double dfCenterLat, double dfCenterLong,
384
                         double dfFalseEasting, double dfFalseNorthing );
385
386
    /** Miller Cylindrical */
387
    OGRErr      SetMC( double dfCenterLat, double dfCenterLong,
388
                       double dfFalseEasting, double dfFalseNorthing );
389
390
    /** Mercator */
391
    OGRErr      SetMercator( double dfCenterLat, double dfCenterLong,
392
                             double dfScale,
393
                             double dfFalseEasting, double dfFalseNorthing );
394
395
    /** Mollweide */
396
    OGRErr      SetMollweide( double dfCentralMeridian,
397
                              double dfFalseEasting, double dfFalseNorthing );
398
399
    /** New Zealand Map Grid */
400
    OGRErr      SetNZMG( double dfCenterLat, double dfCenterLong,
401
                         double dfFalseEasting, double dfFalseNorthing );
402
403
    /** Oblique Stereographic */
404
    OGRErr      SetOS( double dfOriginLat, double dfCMeridian,
405
                       double dfScale,
406
                       double dfFalseEasting,double dfFalseNorthing);
407
408
    /** Orthographic */
409
    OGRErr      SetOrthographic( double dfCenterLat, double dfCenterLong,
410
                                 double dfFalseEasting,double dfFalseNorthing);
411
412
    /** Polyconic */
413
    OGRErr      SetPolyconic( double dfCenterLat, double dfCenterLong,
414
                              double dfFalseEasting, double dfFalseNorthing );
415
416
    /** Polar Stereographic */
417
    OGRErr      SetPS( double dfCenterLat, double dfCenterLong,
418
                       double dfScale,
419
                       double dfFalseEasting, double dfFalseNorthing);
420
421
    /** Robinson */
422
    OGRErr      SetRobinson( double dfCenterLong,
423
                             double dfFalseEasting, double dfFalseNorthing );
424
425
    /** Sinusoidal */
426
    OGRErr      SetSinusoidal( double dfCenterLong,
427
                               double dfFalseEasting, double dfFalseNorthing );
428
429
    /** Stereographic */
430
    OGRErr      SetStereographic( double dfCenterLat, double dfCenterLong,
431
                                  double dfScale,
432
                                 double dfFalseEasting,double dfFalseNorthing);
433
434
    /** Swiss Oblique Cylindrical */
435
    OGRErr      SetSOC( double dfLatitudeOfOrigin, double dfCentralMeridian,
436
                        double dfFalseEasting, double dfFalseNorthing );
437
438
    /** Transverse Mercator */
439
    OGRErr      SetTM( double dfCenterLat, double dfCenterLong,
440
                       double dfScale,
441
                       double dfFalseEasting, double dfFalseNorthing );
442
443
    /** Transverse Mercator variants. */
444
    OGRErr      SetTMVariant( const char *pszVariantName,
445
                              double dfCenterLat, double dfCenterLong,
446
                              double dfScale,
447
                              double dfFalseEasting, double dfFalseNorthing );
448
449
    /** Tunesia Mining Grid  */
450
    OGRErr      SetTMG( double dfCenterLat, double dfCenterLong,
451
                        double dfFalseEasting, double dfFalseNorthing );
452
453
    /** Transverse Mercator (South Oriented) */
454
    OGRErr      SetTMSO( double dfCenterLat, double dfCenterLong,
455
                         double dfScale,
456
                         double dfFalseEasting, double dfFalseNorthing );
457
458
    /** VanDerGrinten */
459
    OGRErr      SetVDG( double dfCenterLong,
460
                        double dfFalseEasting, double dfFalseNorthing );
461
462
    /** Universal Transverse Mercator */
463
    OGRErr      SetUTM( int nZone, int bNorth = TRUE );
464
    int         GetUTMZone( int *pbNorth = NULL ) const;
465
466
    /** State Plane */
467
    OGRErr      SetStatePlane( int nZone, int bNAD83 = TRUE,
468
                               const char *pszOverrideUnitName = NULL,
469
                               double dfOverrideUnit = 0.0 );
470
};
471
472
/************************************************************************/
473
/*                     OGRCoordinateTransformation                      */
474
/*                                                                      */
475
/*      This is really just used as a base class for a private          */
476
/*      implementation.                                                 */
477
/************************************************************************/
478
479
/**
480
 * Object for transforming between coordinate systems.
481
 *
482
 * Also, see OGRCreateSpatialReference() for creating transformations.
483
 */
484
485
class CPL_DLL OGRCoordinateTransformation
486
{
487
public:
488
    virtual ~OGRCoordinateTransformation() {}
489
490
    // From CT_CoordinateTransformation
491
492
    /** Fetch internal source coordinate system. */
493
    virtual OGRSpatialReference *GetSourceCS() = 0;
494
495
    /** Fetch internal target coordinate system. */
496
    virtual OGRSpatialReference *GetTargetCS() = 0;
497
498
    // From CT_MathTransform
499
500
    /**
501
     * Transform points from source to destination space.
502
     *
503
     * This method is the same as the C function OCTTransform().
504
     *
505
     * The method TransformEx() allows extended success information to
506
     * be captured indicating which points failed to transform.
507
     *
508
     * @param nCount number of points to transform.
509
     * @param x array of nCount X vertices, modified in place.
510
     * @param y array of nCount Y vertices, modified in place.
511
     * @param z array of nCount Z vertices, modified in place.
512
     * @return TRUE on success, or FALSE if some or all points fail to
513
     * transform.
514
     */
515
    virtual int Transform( int nCount,
516
                           double *x, double *y, double *z = NULL ) = 0;
517
518
    /**
519
     * Transform points from source to destination space.
520
     *
521
     * This method is the same as the C function OCTTransformEx().
522
     *
523
     * @param nCount number of points to transform.
524
     * @param x array of nCount X vertices, modified in place.
525
     * @param y array of nCount Y vertices, modified in place.
526
     * @param z array of nCount Z vertices, modified in place.
527
     * @param pabSuccess array of per-point flags set to TRUE if that point
528
     * transforms, or FALSE if it does not.
529
     *
530
     * @return TRUE if some or all points transform successfully, or FALSE if
531
     * if none transform.
532
     */
533
    virtual int TransformEx( int nCount,
534
                             double *x, double *y, double *z = NULL,
535
                             int *pabSuccess = NULL ) = 0;
536
537
};
538
539
OGRCoordinateTransformation CPL_DLL *
540
OGRCreateCoordinateTransformation( OGRSpatialReference *poSource,
541
                                   OGRSpatialReference *poTarget );
542
543
#endif /* ndef _OGR_SPATIALREF_H_INCLUDED */