Statistics
| Revision:

svn-gvsig-desktop / tags / v10_RC2c / libraries / libjni-gdal / include / ogr_spatialref.h @ 8745

History | View | Annotate | Download (21.3 KB)

1
/******************************************************************************
2
 * $Id: ogr_spatialref.h 8745 2006-11-14 13:14:23Z  $
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.2.10.1  2006-10-04 06:55:46  nacho
33
 * *** empty log message ***
34
 *
35
 * Revision 1.3  2006/10/03 07:05:18  nacho
36
 * *** empty log message ***
37
 *
38
 * Revision 1.1  2006/07/18 16:21:00  nacho
39
 * *** empty log message ***
40
 *
41
 * Revision 1.1  2006/06/29 16:23:27  nacho
42
 * *** empty log message ***
43
 *
44
 * Revision 1.2  2006/01/09 12:50:13  nacho
45
 * *** empty log message ***
46
 *
47
 * Revision 1.1  2005/07/27 08:22:55  igbrotru
48
 * *** empty log message ***
49
 *
50
 * Revision 1.1  2005/01/11 15:23:01  igbrotru
51
 * *** empty log message ***
52
 *
53
 * Revision 1.61  2004/05/10 17:05:14  warmerda
54
 * added AutoIdentifyEPSG()
55
 *
56
 * Revision 1.60  2004/03/04 18:04:45  warmerda
57
 * added importFromDict() support
58
 *
59
 * Revision 1.59  2004/02/07 17:31:21  dron
60
 * Added OSRExportToUSGS() method.
61
 *
62
 * Revision 1.58  2004/02/05 17:07:59  dron
63
 * Support for HOM projection, specified by two points on centerline.
64
 *
65
 * Revision 1.57  2004/02/01 14:24:09  dron
66
 * Added OGRSpatialReference::importFromUSGS().
67
 *
68
 * Revision 1.56  2004/01/24 09:34:59  warmerda
69
 * added TransformEx support to capture per point reprojection failure
70
 *
71
 * Revision 1.55  2003/10/07 04:20:50  warmerda
72
 * added WMS AUTO: support
73
 *
74
 * Revision 1.54  2003/09/09 07:49:19  dron
75
 * Added exportToPCI() method.
76
 *
77
 * Revision 1.53  2003/08/31 14:51:30  dron
78
 * Added importFromPCI() method.
79
 *
80
 * Revision 1.52  2003/08/18 13:26:01  warmerda
81
 * added SetTMVariant() and related definitions
82
 *
83
 * Revision 1.51  2003/05/30 15:39:53  warmerda
84
 * Added override units capability for SetStatePlane()
85
 *
86
 * Revision 1.50  2003/05/28 19:16:42  warmerda
87
 * fixed up argument names and stuff for docs
88
 *
89
 * Revision 1.49  2003/03/12 14:25:01  warmerda
90
 * added NeedsQuoting() method
91
 *
92
 * Revision 1.48  2003/02/25 04:53:51  warmerda
93
 * added CopyGeogCSFrom() method
94
 *
95
 * Revision 1.47  2003/02/06 04:53:12  warmerda
96
 * added Fixup() method
97
 *
98
 * Revision 1.46  2003/01/08 18:14:28  warmerda
99
 * added FixupOrdering()
100
 */
101

    
102
#ifndef _OGR_SPATIALREF_H_INCLUDED
103
#define _OGR_SPATIALREF_H_INCLUDED
104

    
105
#include "ogr_srs_api.h"
106

    
107
/**
108
 * \file ogr_spatialref.h
109
 *
110
 * Coordinate systems services.
111
 */
112

    
113
/************************************************************************/
114
/*                             OGR_SRSNode                              */
115
/************************************************************************/
116

    
117
/**
118
 * Objects of this class are used to represent value nodes in the parsed
119
 * representation of the WKT SRS format.  For instance UNIT["METER",1]
120
 * would be rendered into three OGR_SRSNodes.  The root node would have a
121
 * value of UNIT, and two children, the first with a value of METER, and the
122
 * second with a value of 1.
123
 *
124
 * Normally application code just interacts with the OGRSpatialReference
125
 * object, which uses the OGR_SRSNode to implement it's data structure;
126
 * however, this class is user accessable for detailed access to components
127
 * of an SRS definition.
128
 */
129

    
130
class CPL_DLL OGR_SRSNode
131
{
132
    char        *pszValue;
133

    
134
    int         nChildren;
135
    OGR_SRSNode **papoChildNodes;
136

    
137
    OGR_SRSNode *poParent;
138

    
139
    void        ClearChildren();
140
    int         NeedsQuoting() const;
141
    
142
  public:
143
                OGR_SRSNode(const char * = NULL);
144
                ~OGR_SRSNode();
145

    
146
    int         IsLeafNode() const { return nChildren == 0; }
147
    
148
    int         GetChildCount() const { return nChildren; }
149
    OGR_SRSNode *GetChild( int );
150
    const OGR_SRSNode *GetChild( int ) const;
151

    
152
    OGR_SRSNode *GetNode( const char * );
153
    const OGR_SRSNode *GetNode( const char * ) const;
154

    
155
    void        InsertChild( OGR_SRSNode *, int );
156
    void        AddChild( OGR_SRSNode * );
157
    int         FindChild( const char * ) const;
158
    void        DestroyChild( int );
159
    void        StripNodes( const char * );
160

    
161
    const char  *GetValue() const { return pszValue; }
162
    void        SetValue( const char * );
163

    
164
    void        MakeValueSafe();
165
    OGRErr      FixupOrdering();
166

    
167
    OGR_SRSNode *Clone() const;
168

    
169
    OGRErr      importFromWkt( char ** );
170
    OGRErr      exportToWkt( char ** ) const;
171
    OGRErr      exportToPrettyWkt( char **, int = 1) const;
172
    
173
    OGRErr      applyRemapper( const char *pszNode, 
174
                               char **papszSrcValues, 
175
                               char **papszDstValues, 
176
                               int nStepSize = 1,
177
                               int bChildOfHit = FALSE );
178
};
179

    
180
/************************************************************************/
181
/*                         OGRSpatialReference                          */
182
/************************************************************************/
183

    
184
/**
185
 * This class respresents a OpenGIS Spatial Reference System, and contains
186
 * methods for converting between this object organization and well known
187
 * text (WKT) format.  This object is reference counted as one instance of
188
 * the object is normally shared between many OGRGeometry objects.
189
 *
190
 * Normally application code can fetch needed parameter values for this
191
 * SRS using GetAttrValue(), but in special cases the underlying parse tree
192
 * (or OGR_SRSNode objects) can be accessed more directly.
193
 *
194
 * See <a href="osr_tutorial.html">the tutorial</a> for more information on
195
 * how to use this class.
196
 */
197

    
198
class CPL_DLL OGRSpatialReference
199
{
200
    int         nRefCount;
201

    
202
    OGR_SRSNode *poRoot;
203

    
204
    int         bNormInfoSet;
205
    double      dfFromGreenwich;
206
    double      dfToMeter;
207
    double      dfToDegrees;
208

    
209
    OGRErr      ValidateProjection();
210
    int         IsAliasFor( const char *, const char * );
211
    void        GetNormInfo() const;
212

    
213
  public:
214
                OGRSpatialReference(const OGRSpatialReference&);
215
                OGRSpatialReference(const char * = NULL);
216
                
217
    virtual    ~OGRSpatialReference();
218
                
219
    OGRSpatialReference &operator=(const OGRSpatialReference&);
220

    
221
    int         Reference();
222
    int         Dereference();
223
    int         GetReferenceCount() const { return nRefCount; }
224

    
225
    OGRSpatialReference *Clone() const;
226
    OGRSpatialReference *CloneGeogCS() const;
227

    
228
    OGRErr      exportToWkt( char ** );
229
    OGRErr      exportToPrettyWkt( char **, int = FALSE) const;
230
    OGRErr      exportToProj4( char ** ) const;
231
    OGRErr      exportToPCI( char **, char **, double ** ) const;
232
    OGRErr      exportToUSGS( long *, long *, double **, long * ) const;
233
    OGRErr      exportToXML( char **, const char * = NULL ) const;
234
    OGRErr      importFromWkt( char ** );
235
    OGRErr      importFromProj4( const char * );
236
    OGRErr      importFromEPSG( int );
237
    OGRErr      importFromESRI( char ** );
238
    OGRErr      importFromPCI( const char *pszProj,
239
                               const char *pszUnits = NULL,
240
                               double *padfPrjParams = NULL );
241
    OGRErr      importFromUSGS( long iProjsys, long iZone,
242
                                double *padfPrjParams, long iDatum );
243
    OGRErr      importFromWMSAUTO( const char *pszAutoDef );
244
    OGRErr      importFromXML( const char * );
245
    OGRErr      importFromDict( const char *pszDict, const char *pszCode );
246

    
247
    OGRErr      morphToESRI();
248
    OGRErr      morphFromESRI();
249

    
250
    OGRErr      Validate();
251
    OGRErr      StripCTParms( OGR_SRSNode * = NULL );
252
    OGRErr      FixupOrdering();
253
    OGRErr      Fixup();
254

    
255
    // Machinary for accessing parse nodes
256
    OGR_SRSNode *GetRoot() { return poRoot; }
257
    const OGR_SRSNode *GetRoot() const { return poRoot; }
258
    void        SetRoot( OGR_SRSNode * );
259
    
260
    OGR_SRSNode *GetAttrNode(const char *);
261
    const OGR_SRSNode *GetAttrNode(const char *) const;
262
    const char  *GetAttrValue(const char *, int = 0) const;
263

    
264
    OGRErr      SetNode( const char *, const char * );
265
    OGRErr      SetNode( const char *, double );
266

    
267
    OGRErr      SetLinearUnits( const char *pszName, double dfInMeters );
268
    double      GetLinearUnits( char ** = NULL ) const;
269

    
270
    OGRErr      SetAngularUnits( const char *pszName, double dfInRadians );
271
    double      GetAngularUnits( char ** = NULL ) const;
272

    
273
    double      GetPrimeMeridian( char ** = NULL ) const;
274

    
275
    int         IsGeographic() const;
276
    int         IsProjected() const;
277
    int         IsLocal() const;
278
    int         IsSameGeogCS( const OGRSpatialReference * ) const;
279
    int         IsSame( const OGRSpatialReference * ) const;
280

    
281
    void        Clear();
282
    OGRErr      SetLocalCS( const char * );
283
    OGRErr      SetProjCS( const char * );
284
    OGRErr      SetProjection( const char * );
285
    OGRErr      SetGeogCS( const char * pszGeogName,
286
                           const char * pszDatumName,
287
                           const char * pszEllipsoidName,
288
                           double dfSemiMajor, double dfInvFlattening,
289
                           const char * pszPMName = NULL,
290
                           double dfPMOffset = 0.0,
291
                           const char * pszUnits = NULL,
292
                           double dfConvertToRadians = 0.0 );
293
    OGRErr      SetWellKnownGeogCS( const char * );
294
    OGRErr      CopyGeogCSFrom( const OGRSpatialReference * poSrcSRS );
295

    
296
    OGRErr      SetFromUserInput( const char * );
297

    
298
    OGRErr      SetTOWGS84( double, double, double,
299
                            double = 0.0, double = 0.0, double = 0.0,
300
                            double = 0.0 );
301
    OGRErr      GetTOWGS84( double *padfCoef, int nCoeff = 7 ) const;
302
    
303
    double      GetSemiMajor( OGRErr * = NULL ) const;
304
    double      GetSemiMinor( OGRErr * = NULL ) const;
305
    double      GetInvFlattening( OGRErr * = NULL ) const;
306

    
307
    OGRErr      SetAuthority( const char * pszTargetKey, 
308
                              const char * pszAuthority, 
309
                              int nCode );
310

    
311
    OGRErr      AutoIdentifyEPSG();
312

    
313
    const char *GetAuthorityCode( const char * pszTargetKey ) const;
314
    const char *GetAuthorityName( const char * pszTargetKey ) const;
315
                           
316
    OGRErr      SetProjParm( const char *, double );
317
    double      GetProjParm( const char *, double =0.0, OGRErr* = NULL ) const;
318

    
319
    OGRErr      SetNormProjParm( const char *, double );
320
    double      GetNormProjParm( const char *, double=0.0, OGRErr* =NULL)const;
321

    
322
    static int  IsAngularParameter( const char * );
323
    static int  IsLongitudeParameter( const char * );
324
    static int  IsLinearParameter( const char * );
325

    
326
    /** Albers Conic Equal Area */
327
    OGRErr      SetACEA( double dfStdP1, double dfStdP2,
328
                         double dfCenterLat, double dfCenterLong,
329
                         double dfFalseEasting, double dfFalseNorthing );
330
    
331
    /** Azimuthal Equidistant */
332
    OGRErr      SetAE( double dfCenterLat, double dfCenterLong,
333
                       double dfFalseEasting, double dfFalseNorthing );
334

    
335
    /** Cylindrical Equal Area */
336
    OGRErr      SetCEA( double dfStdP1, double dfCentralMeridian,
337
                        double dfFalseEasting, double dfFalseNorthing );
338

    
339
    /** Cassini-Soldner */
340
    OGRErr      SetCS( double dfCenterLat, double dfCenterLong,
341
                       double dfFalseEasting, double dfFalseNorthing );
342

    
343
    /** Equidistant Conic */
344
    OGRErr      SetEC( double dfStdP1, double dfStdP2,
345
                       double dfCenterLat, double dfCenterLong,
346
                       double dfFalseEasting, double dfFalseNorthing );
347

    
348
    /** Eckert IV */
349
    OGRErr      SetEckertIV( double dfCentralMeridian,
350
                             double dfFalseEasting, double dfFalseNorthing );
351

    
352
    /** Eckert VI */
353
    OGRErr      SetEckertVI( double dfCentralMeridian,
354
                             double dfFalseEasting, double dfFalseNorthing );
355

    
356
    /** Equirectangular */
357
    OGRErr      SetEquirectangular(double dfCenterLat, double dfCenterLong,
358
                            double dfFalseEasting, double dfFalseNorthing );
359

    
360
    /** Gall Stereograpic */
361
    OGRErr      SetGS( double dfCentralMeridian,
362
                       double dfFalseEasting, double dfFalseNorthing );
363
    
364
    /** Gnomonic */
365
    OGRErr      SetGnomonic(double dfCenterLat, double dfCenterLong,
366
                            double dfFalseEasting, double dfFalseNorthing );
367

    
368
    OGRErr      SetHOM( double dfCenterLat, double dfCenterLong,
369
                        double dfAzimuth, double dfRectToSkew,
370
                        double dfScale,
371
                        double dfFalseEasting, double dfFalseNorthing );
372

    
373
    OGRErr      SetHOM2PNO( double dfCenterLat,
374
                            double dfLat1, double dfLong1,
375
                            double dfLat2, double dfLong2,
376
                            double dfScale,
377
                            double dfFalseEasting, double dfFalseNorthing );
378

    
379
    /** Krovak Oblique Conic Conformal */
380
    OGRErr      SetKrovak( double dfCenterLat, double dfCenterLong,
381
                           double dfAzimuth, double dfPseudoStdParallelLat,
382
                           double dfScale, 
383
                           double dfFalseEasting, double dfFalseNorthing );
384

    
385
    /** Lambert Azimuthal Equal-Area */
386
    OGRErr      SetLAEA( double dfCenterLat, double dfCenterLong,
387
                         double dfFalseEasting, double dfFalseNorthing );
388

    
389
    /** Lambert Conformal Conic */
390
    OGRErr      SetLCC( double dfStdP1, double dfStdP2,
391
                        double dfCenterLat, double dfCenterLong,
392
                        double dfFalseEasting, double dfFalseNorthing );
393

    
394
    /** Lambert Conformal Conic 1SP */
395
    OGRErr      SetLCC1SP( double dfCenterLat, double dfCenterLong,
396
                           double dfScale,
397
                           double dfFalseEasting, double dfFalseNorthing );
398

    
399
    /** Lambert Conformal Conic (Belgium) */
400
    OGRErr      SetLCCB( double dfStdP1, double dfStdP2,
401
                         double dfCenterLat, double dfCenterLong,
402
                         double dfFalseEasting, double dfFalseNorthing );
403
    
404
    /** Miller Cylindrical */
405
    OGRErr      SetMC( double dfCenterLat, double dfCenterLong,
406
                       double dfFalseEasting, double dfFalseNorthing );
407

    
408
    /** Mercator */
409
    OGRErr      SetMercator( double dfCenterLat, double dfCenterLong,
410
                             double dfScale, 
411
                             double dfFalseEasting, double dfFalseNorthing );
412

    
413
    /** Mollweide */
414
    OGRErr      SetMollweide( double dfCentralMeridian,
415
                              double dfFalseEasting, double dfFalseNorthing );
416

    
417
    /** New Zealand Map Grid */
418
    OGRErr      SetNZMG( double dfCenterLat, double dfCenterLong,
419
                         double dfFalseEasting, double dfFalseNorthing );
420

    
421
    /** Oblique Stereographic */
422
    OGRErr      SetOS( double dfOriginLat, double dfCMeridian,
423
                       double dfScale,
424
                       double dfFalseEasting,double dfFalseNorthing);
425
    
426
    /** Orthographic */
427
    OGRErr      SetOrthographic( double dfCenterLat, double dfCenterLong,
428
                                 double dfFalseEasting,double dfFalseNorthing);
429

    
430
    /** Polyconic */
431
    OGRErr      SetPolyconic( double dfCenterLat, double dfCenterLong,
432
                              double dfFalseEasting, double dfFalseNorthing );
433

    
434
    /** Polar Stereographic */
435
    OGRErr      SetPS( double dfCenterLat, double dfCenterLong,
436
                       double dfScale,
437
                       double dfFalseEasting, double dfFalseNorthing);
438
    
439
    /** Robinson */
440
    OGRErr      SetRobinson( double dfCenterLong, 
441
                             double dfFalseEasting, double dfFalseNorthing );
442
    
443
    /** Sinusoidal */
444
    OGRErr      SetSinusoidal( double dfCenterLong, 
445
                               double dfFalseEasting, double dfFalseNorthing );
446
    
447
    /** Stereographic */
448
    OGRErr      SetStereographic( double dfCenterLat, double dfCenterLong,
449
                                  double dfScale,
450
                                 double dfFalseEasting,double dfFalseNorthing);
451
    
452
    /** Swiss Oblique Cylindrical */
453
    OGRErr      SetSOC( double dfLatitudeOfOrigin, double dfCentralMeridian,
454
                        double dfFalseEasting, double dfFalseNorthing );
455
    
456
    /** Transverse Mercator */
457
    OGRErr      SetTM( double dfCenterLat, double dfCenterLong,
458
                       double dfScale,
459
                       double dfFalseEasting, double dfFalseNorthing );
460

    
461
    /** Transverse Mercator variants. */
462
    OGRErr      SetTMVariant( const char *pszVariantName, 
463
                              double dfCenterLat, double dfCenterLong,
464
                              double dfScale,
465
                              double dfFalseEasting, double dfFalseNorthing );
466

    
467
    /** Tunesia Mining Grid  */
468
    OGRErr      SetTMG( double dfCenterLat, double dfCenterLong, 
469
                        double dfFalseEasting, double dfFalseNorthing );
470

    
471
    /** Transverse Mercator (South Oriented) */
472
    OGRErr      SetTMSO( double dfCenterLat, double dfCenterLong,
473
                         double dfScale,
474
                         double dfFalseEasting, double dfFalseNorthing );
475

    
476
    /** VanDerGrinten */
477
    OGRErr      SetVDG( double dfCenterLong,
478
                        double dfFalseEasting, double dfFalseNorthing );
479

    
480
    /** Universal Transverse Mercator */
481
    OGRErr      SetUTM( int nZone, int bNorth = TRUE );
482
    int         GetUTMZone( int *pbNorth = NULL ) const;
483

    
484
    /** State Plane */
485
    OGRErr      SetStatePlane( int nZone, int bNAD83 = TRUE,
486
                               const char *pszOverrideUnitName = NULL,
487
                               double dfOverrideUnit = 0.0 );
488
};
489

    
490
/************************************************************************/
491
/*                     OGRCoordinateTransformation                      */
492
/*                                                                      */
493
/*      This is really just used as a base class for a private          */
494
/*      implementation.                                                 */
495
/************************************************************************/
496

    
497
/**
498
 * Object for transforming between coordinate systems.
499
 *
500
 * Also, see OGRCreateSpatialReference() for creating transformations.
501
 */
502
 
503
class CPL_DLL OGRCoordinateTransformation
504
{
505
public:
506
    virtual ~OGRCoordinateTransformation() {}
507

    
508
    // From CT_CoordinateTransformation
509

    
510
    /** Fetch internal source coordinate system. */
511
    virtual OGRSpatialReference *GetSourceCS() = 0;
512

    
513
    /** Fetch internal target coordinate system. */
514
    virtual OGRSpatialReference *GetTargetCS() = 0;
515

    
516
    // From CT_MathTransform
517

    
518
    /**
519
     * Transform points from source to destination space.
520
     *
521
     * This method is the same as the C function OCTTransform().
522
     *
523
     * The method TransformEx() allows extended success information to 
524
     * be captured indicating which points failed to transform. 
525
     *
526
     * @param nCount number of points to transform.
527
     * @param x array of nCount X vertices, modified in place.
528
     * @param y array of nCount Y vertices, modified in place.
529
     * @param z array of nCount Z vertices, modified in place.
530
     * @return TRUE on success, or FALSE if some or all points fail to
531
     * transform.
532
     */
533
    virtual int Transform( int nCount, 
534
                           double *x, double *y, double *z = NULL ) = 0;
535

    
536
    /**
537
     * Transform points from source to destination space.
538
     *
539
     * This method is the same as the C function OCTTransformEx().
540
     *
541
     * @param nCount number of points to transform.
542
     * @param x array of nCount X vertices, modified in place.
543
     * @param y array of nCount Y vertices, modified in place.
544
     * @param z array of nCount Z vertices, modified in place.
545
     * @param pabSuccess array of per-point flags set to TRUE if that point 
546
     * transforms, or FALSE if it does not.
547
     *
548
     * @return TRUE if some or all points transform successfully, or FALSE if 
549
     * if none transform.
550
     */
551
    virtual int TransformEx( int nCount, 
552
                             double *x, double *y, double *z = NULL,
553
                             int *pabSuccess = NULL ) = 0;
554

    
555
};
556

    
557
OGRCoordinateTransformation CPL_DLL *
558
OGRCreateCoordinateTransformation( OGRSpatialReference *poSource, 
559
                                   OGRSpatialReference *poTarget );
560

    
561
#endif /* ndef _OGR_SPATIALREF_H_INCLUDED */