LCOV - code coverage report
Current view: directory - ogr - ogr_srs_panorama.cpp (source / functions) Found Hit Coverage
Test: gdal_filtered.info Lines: 274 65 23.7 %
Date: 2010-01-09 Functions: 4 2 50.0 %

       1                 : /******************************************************************************
       2                 :  * $Id: ogr_srs_panorama.cpp 17681 2009-09-25 08:41:18Z dron $
       3                 :  *
       4                 :  * Project:  OpenGIS Simple Features Reference Implementation
       5                 :  * Purpose:  OGRSpatialReference translation to/from "Panorama" GIS
       6                 :  *           georeferencing information (also know as GIS "Integration").
       7                 :  * Author:   Andrey Kiselev, dron@ak4719.spb.edu
       8                 :  *
       9                 :  ******************************************************************************
      10                 :  * Copyright (c) 2005, Andrey Kiselev <dron@ak4719.spb.edu>
      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                 : #include "ogr_spatialref.h"
      32                 : #include "ogr_p.h"
      33                 : #include "cpl_conv.h"
      34                 : #include "cpl_csv.h"
      35                 : 
      36                 : CPL_CVSID("$Id: ogr_srs_panorama.cpp 17681 2009-09-25 08:41:18Z dron $");
      37                 : 
      38                 : #define TO_DEGREES 57.2957795130823208766
      39                 : #define TO_RADIANS 0.017453292519943295769
      40                 : 
      41                 : // XXX: this macro computes zone number from the central meridian parameter.
      42                 : // Note, that "Panorama" parameters are set in radians.
      43                 : // In degrees it means formulae:
      44                 : //
      45                 : //              zone = (central_meridian + 3) / 6
      46                 : //
      47                 : #define TO_ZONE(x) (((x) + 0.05235987755982989) / 0.1047197551196597)
      48                 : 
      49                 : /************************************************************************/
      50                 : /*  "Panorama" projection codes.                                        */
      51                 : /************************************************************************/
      52                 : 
      53                 : #define PAN_PROJ_NONE   -1L
      54                 : #define PAN_PROJ_TM     1L      // Gauss-Kruger (Transverse Mercator)
      55                 : #define PAN_PROJ_LCC    2L      // Lambert Conformal Conic 2SP
      56                 : #define PAN_PROJ_STEREO 5L      // Stereographic
      57                 : #define PAN_PROJ_AE     6L      // Azimuthal Equidistant (Postel)
      58                 : #define PAN_PROJ_MERCAT 8L      // Mercator
      59                 : #define PAN_PROJ_POLYC  10L     // Polyconic
      60                 : #define PAN_PROJ_PS     13L     // Polar Stereographic
      61                 : #define PAN_PROJ_GNOMON 15L     // Gnomonic
      62                 : #define PAN_PROJ_UTM    17L     // Universal Transverse Mercator (UTM)
      63                 : #define PAN_PROJ_WAG1   18L     // Wagner I (Kavraisky VI)
      64                 : #define PAN_PROJ_MOLL   19L     // Mollweide
      65                 : #define PAN_PROJ_EC     20L     // Equidistant Conic
      66                 : #define PAN_PROJ_LAEA   24L     // Lambert Azimuthal Equal Area
      67                 : #define PAN_PROJ_EQC    27L     // Equirectangular
      68                 : #define PAN_PROJ_CEA    28L     // Cylindrical Equal Area (Lambert)
      69                 : #define PAN_PROJ_IMWP   29L     // International Map of the World Polyconic
      70                 : 
      71                 : /************************************************************************/
      72                 : /*  "Panorama" datum codes.                                             */
      73                 : /************************************************************************/
      74                 : 
      75                 : #define PAN_DATUM_NONE      -1L
      76                 : #define PAN_DATUM_PULKOVO42 1L  // Pulkovo 1942
      77                 : #define PAN_DATUM_WGS84     2L  // WGS84
      78                 : 
      79                 : /************************************************************************/
      80                 : /*  "Panorama" ellipsod codes.                                          */
      81                 : /************************************************************************/
      82                 : 
      83                 : #define PAN_ELLIPSOID_NONE          -1L
      84                 : #define PAN_ELLIPSOID_KRASSOVSKY    1L  // Krassovsky, 1940
      85                 : #define PAN_ELLIPSOID_WGS72         2L  // WGS, 1972
      86                 : #define PAN_ELLIPSOID_INT1924       3L  // International, 1924 (Hayford, 1909)
      87                 : #define PAN_ELLIPSOID_CLARCKE1880   4L  // Clarke, 1880
      88                 : #define PAN_ELLIPSOID_CLARCKE1866   5L  // Clarke, 1866 (NAD1927)
      89                 : #define PAN_ELLIPSOID_EVEREST1830   6L  // Everest, 1830
      90                 : #define PAN_ELLIPSOID_BESSEL1841    7L  // Bessel, 1841
      91                 : #define PAN_ELLIPSOID_AIRY1830      8L  // Airy, 1830
      92                 : #define PAN_ELLIPSOID_WGS84         9L  // WGS, 1984 (GPS)
      93                 : 
      94                 : /************************************************************************/
      95                 : /*  Correspondence between "Panorama" and EPSG datum codes.             */
      96                 : /************************************************************************/
      97                 : 
      98                 : static const long aoDatums[] =
      99                 : {
     100                 :     0,
     101                 :     4284,   // Pulkovo, 1942
     102                 :     4326,   // WGS, 1984,
     103                 :     4277,   // OSGB 1936 (British National Grid)
     104                 :     0,
     105                 :     0,
     106                 :     0,
     107                 :     0,
     108                 :     0,
     109                 :     4200    // Pulkovo, 1995
     110                 : };
     111                 : 
     112                 : #define NUMBER_OF_DATUMS        (long)(sizeof(aoDatums)/sizeof(aoDatums[0]))
     113                 : 
     114                 : /************************************************************************/
     115                 : /*  Correspondence between "Panorama" and EPSG ellipsoid codes.         */
     116                 : /************************************************************************/
     117                 : 
     118                 : static const long aoEllips[] =
     119                 : {
     120                 :     0,
     121                 :     7024,   // Krassovsky, 1940
     122                 :     7043,   // WGS, 1972
     123                 :     7022,   // International, 1924 (Hayford, 1909)
     124                 :     7034,   // Clarke, 1880
     125                 :     7008,   // Clarke, 1866 (NAD1927)
     126                 :     7015,   // Everest, 1830
     127                 :     7004,   // Bessel, 1841
     128                 :     7001,   // Airy, 1830
     129                 :     7030    // WGS, 1984 (GPS)
     130                 : };
     131                 : 
     132                 : #define NUMBER_OF_ELLIPSOIDS    (sizeof(aoEllips)/sizeof(aoEllips[0]))
     133                 : 
     134                 : /************************************************************************/
     135                 : /*                        OSRImportFromPanorama()                       */
     136                 : /************************************************************************/
     137                 : 
     138               0 : OGRErr OSRImportFromPanorama( OGRSpatialReferenceH hSRS,
     139                 :                               long iProjSys, long iDatum, long iEllips,
     140                 :                               double *padfPrjParams )
     141                 : 
     142                 : {
     143                 :     return ((OGRSpatialReference *) hSRS)->importFromPanorama( iProjSys,
     144                 :                                                                iDatum,iEllips,
     145               0 :                                                                padfPrjParams );
     146                 : }
     147                 : 
     148                 : /************************************************************************/
     149                 : /*                          importFromPanorama()                        */
     150                 : /************************************************************************/
     151                 : 
     152                 : /**
     153                 :  * Import coordinate system from "Panorama" GIS projection definition.
     154                 :  *
     155                 :  * This method will import projection definition in style, used by
     156                 :  * "Panorama" GIS.
     157                 :  *
     158                 :  * This function is the equivalent of the C function OSRImportFromPanorama().
     159                 :  *
     160                 :  * @param iProjSys Input projection system code, used in GIS "Panorama".
     161                 :  *
     162                 :  *      <h4>Supported Projections</h4>
     163                 :  * <pre>
     164                 :  *      1:  Gauss-Kruger (Transverse Mercator)
     165                 :  *      2:  Lambert Conformal Conic 2SP
     166                 :  *      5:  Stereographic
     167                 :  *      6:  Azimuthal Equidistant (Postel)
     168                 :  *      8:  Mercator
     169                 :  *      10: Polyconic
     170                 :  *      13: Polar Stereographic
     171                 :  *      15: Gnomonic
     172                 :  *      17: Universal Transverse Mercator (UTM)
     173                 :  *      18: Wagner I (Kavraisky VI)
     174                 :  *      19: Mollweide
     175                 :  *      20: Equidistant Conic
     176                 :  *      24: Lambert Azimuthal Equal Area
     177                 :  *      27: Equirectangular
     178                 :  *      28: Cylindrical Equal Area (Lambert)
     179                 :  *      29: International Map of the World Polyconic
     180                 :  * </pre>
     181                 :  *
     182                 :  * @param iDatum Input coordinate system.
     183                 :  *
     184                 :  *      <h4>Supported Datums</h4>
     185                 :  * <pre>
     186                 :  *       1: Pulkovo, 1942
     187                 :  *       2: WGS, 1984
     188                 :  *       3: OSGB 1936 (British National Grid)
     189                 :  *       9: Pulkovo, 1995
     190                 :  * </pre>
     191                 :  *
     192                 :  * @param iEllips Input spheroid.
     193                 :  * 
     194                 :  *      <h4>Supported Spheroids</h4>
     195                 :  * <pre>
     196                 :  *       1: Krassovsky, 1940
     197                 :  *       2: WGS, 1972
     198                 :  *       3: International, 1924 (Hayford, 1909)
     199                 :  *       4: Clarke, 1880
     200                 :  *       5: Clarke, 1866 (NAD1927)
     201                 :  *       6: Everest, 1830
     202                 :  *       7: Bessel, 1841
     203                 :  *       8: Airy, 1830
     204                 :  *       9: WGS, 1984 (GPS)
     205                 :  * </pre>
     206                 :  *
     207                 :  * @param padfPrjParams Array of 7 coordinate system parameters:
     208                 :  *
     209                 :  * <pre>
     210                 :  *      [0]  Latitude of the first standard parallel (radians)
     211                 :  *      [1]  Latitude of the second standard parallel (radians)
     212                 :  *      [2]  Latitude of center of projection (radians)
     213                 :  *      [3]  Longitude of center of projection (radians)
     214                 :  *      [4]  Scaling factor
     215                 :  *      [5]  False Easting
     216                 :  *      [6]  False Northing
     217                 :  * </pre>
     218                 :  *
     219                 :  * Particular projection uses different parameters, unused ones may be set to
     220                 :  * zero. If NULL supplied instead of array pointer default values will be used
     221                 :  * (i.e., zeroes).
     222                 :  *
     223                 :  * @return OGRERR_NONE on success or an error code in case of failure. 
     224                 :  */
     225                 : 
     226              16 : OGRErr OGRSpatialReference::importFromPanorama( long iProjSys, long iDatum,
     227                 :                                                 long iEllips,
     228                 :                                                 double *padfPrjParams )
     229                 : 
     230                 : {
     231              16 :     Clear();
     232                 : 
     233                 : /* -------------------------------------------------------------------- */
     234                 : /*      Use safe defaults if projection parameters are not supplied.    */
     235                 : /* -------------------------------------------------------------------- */
     236              16 :     int     bProjAllocated = FALSE;
     237                 : 
     238              16 :     if( padfPrjParams == NULL )
     239                 :     {
     240                 :         int     i;
     241                 : 
     242               0 :         padfPrjParams = (double *)CPLMalloc( 7 * sizeof(double) );
     243               0 :         if ( !padfPrjParams )
     244               0 :             return OGRERR_NOT_ENOUGH_MEMORY;
     245               0 :         for ( i = 0; i < 7; i++ )
     246               0 :             padfPrjParams[i] = 0.0;
     247               0 :         bProjAllocated = TRUE;
     248                 :     }
     249                 : 
     250                 : /* -------------------------------------------------------------------- */
     251                 : /*      Operate on the basis of the projection code.                    */
     252                 : /* -------------------------------------------------------------------- */
     253              16 :     switch ( iProjSys )
     254                 :     {
     255                 :         case PAN_PROJ_NONE:
     256               4 :             break;
     257                 : 
     258                 :         case PAN_PROJ_UTM:
     259                 :             {
     260               1 :                 long nZone = (long)TO_ZONE(padfPrjParams[3]);
     261                 : 
     262                 :                 // XXX: no way to determine south hemisphere. Always assume
     263                 :                 // nothern hemisphere.
     264               1 :                 SetUTM( nZone, TRUE );
     265                 :             }
     266               1 :             break;
     267                 : 
     268                 :         case PAN_PROJ_WAG1:
     269                 :             SetWagner( 1, 0.0,
     270               0 :                        padfPrjParams[5], padfPrjParams[6] );
     271               0 :             break;
     272                 : 
     273                 :         case PAN_PROJ_MERCAT:
     274               0 :             SetMercator( TO_DEGREES * padfPrjParams[0],
     275               0 :                          TO_DEGREES * padfPrjParams[3],
     276                 :                          padfPrjParams[4],
     277               0 :                          padfPrjParams[5], padfPrjParams[6] );
     278               0 :             break;
     279                 : 
     280                 :         case PAN_PROJ_PS:
     281               0 :             SetPS( TO_DEGREES * padfPrjParams[2],
     282               0 :                    TO_DEGREES * padfPrjParams[3],
     283                 :                    padfPrjParams[4],
     284               0 :                    padfPrjParams[5], padfPrjParams[6] );
     285               0 :             break;
     286                 : 
     287                 :         case PAN_PROJ_POLYC:
     288               0 :             SetPolyconic( TO_DEGREES * padfPrjParams[2],
     289               0 :                           TO_DEGREES * padfPrjParams[3],
     290               0 :                           padfPrjParams[5], padfPrjParams[6] );
     291               0 :             break;
     292                 : 
     293                 :         case PAN_PROJ_EC:
     294               0 :             SetEC( TO_DEGREES * padfPrjParams[0],
     295               0 :                    TO_DEGREES * padfPrjParams[1],
     296               0 :                    TO_DEGREES * padfPrjParams[2],
     297               0 :                    TO_DEGREES * padfPrjParams[3],
     298               0 :                    padfPrjParams[5], padfPrjParams[6] );
     299               0 :             break;
     300                 : 
     301                 :         case PAN_PROJ_LCC:
     302               0 :             SetLCC( TO_DEGREES * padfPrjParams[0],
     303               0 :                     TO_DEGREES * padfPrjParams[1],
     304               0 :                     TO_DEGREES * padfPrjParams[2],
     305               0 :                     TO_DEGREES * padfPrjParams[3],
     306               0 :                     padfPrjParams[5], padfPrjParams[6] );
     307               0 :             break;
     308                 : 
     309                 :         case PAN_PROJ_TM:
     310                 :             {
     311                 :                 // XXX: we need zone number to compute false easting
     312                 :                 // parameter, because usually it is not contained in the
     313                 :                 // "Panorama" projection definition.
     314                 :                 // FIXME: what to do with negative values?
     315              11 :                 long nZone = (long)TO_ZONE(padfPrjParams[3]);
     316                 : 
     317              11 :                 padfPrjParams[5] = nZone * 1000000.0 + 500000.0;
     318              11 :                 padfPrjParams[4] = 1.0;
     319              11 :                 SetTM( TO_DEGREES * padfPrjParams[2],
     320              11 :                        TO_DEGREES * padfPrjParams[3],
     321                 :                        padfPrjParams[4],
     322              33 :                        padfPrjParams[5], padfPrjParams[6] );
     323                 :             }
     324              11 :             break;
     325                 : 
     326                 :         case PAN_PROJ_STEREO:
     327               0 :             SetStereographic( TO_DEGREES * padfPrjParams[2],
     328               0 :                               TO_DEGREES * padfPrjParams[3],
     329                 :                               padfPrjParams[4],
     330               0 :                               padfPrjParams[5], padfPrjParams[6] );
     331               0 :             break;
     332                 : 
     333                 :         case PAN_PROJ_AE:
     334               0 :             SetAE( TO_DEGREES * padfPrjParams[0],
     335               0 :                    TO_DEGREES * padfPrjParams[3],
     336               0 :                    padfPrjParams[5], padfPrjParams[6] );
     337               0 :             break;
     338                 : 
     339                 :         case PAN_PROJ_GNOMON:
     340               0 :             SetGnomonic( TO_DEGREES * padfPrjParams[2],
     341               0 :                          TO_DEGREES * padfPrjParams[3],
     342               0 :                          padfPrjParams[5], padfPrjParams[6] );
     343               0 :             break;
     344                 : 
     345                 :         case PAN_PROJ_MOLL:
     346               0 :             SetMollweide( TO_DEGREES * padfPrjParams[3],
     347               0 :                           padfPrjParams[5], padfPrjParams[6] );
     348               0 :             break;
     349                 : 
     350                 :         case PAN_PROJ_LAEA:
     351               0 :             SetLAEA( TO_DEGREES * padfPrjParams[0],
     352               0 :                      TO_DEGREES * padfPrjParams[3],
     353               0 :                      padfPrjParams[5], padfPrjParams[6] );
     354               0 :             break;
     355                 : 
     356                 :         case PAN_PROJ_EQC:
     357               0 :             SetEquirectangular( TO_DEGREES * padfPrjParams[0],
     358               0 :                                 TO_DEGREES * padfPrjParams[3],
     359               0 :                                 padfPrjParams[5], padfPrjParams[6] );
     360               0 :             break;
     361                 : 
     362                 :         case PAN_PROJ_CEA:
     363               0 :             SetCEA( TO_DEGREES * padfPrjParams[0],
     364               0 :                     TO_DEGREES * padfPrjParams[3],
     365               0 :                     padfPrjParams[5], padfPrjParams[6] );
     366               0 :             break;
     367                 : 
     368                 :         case PAN_PROJ_IMWP:
     369               0 :             SetIWMPolyconic( TO_DEGREES * padfPrjParams[0],
     370               0 :                              TO_DEGREES * padfPrjParams[1],
     371               0 :                              TO_DEGREES * padfPrjParams[3],
     372               0 :                              padfPrjParams[5], padfPrjParams[6] );
     373               0 :             break;
     374                 : 
     375                 :         default:
     376               0 :             CPLDebug( "OSR_Panorama", "Unsupported projection: %ld", iProjSys );
     377                 :             SetLocalCS( CPLString().Printf("\"Panorama\" projection number %ld",
     378               0 :                                    iProjSys) );
     379                 :             break;
     380                 :             
     381                 :     }
     382                 : 
     383                 : /* -------------------------------------------------------------------- */
     384                 : /*      Try to translate the datum/spheroid.                            */
     385                 : /* -------------------------------------------------------------------- */
     386                 : 
     387              16 :     if ( !IsLocal() )
     388                 :     {
     389              24 :         if ( iDatum > 0 && iDatum < NUMBER_OF_DATUMS && aoDatums[iDatum] )
     390                 :         {
     391               8 :             OGRSpatialReference oGCS;
     392               8 :             oGCS.importFromEPSG( aoDatums[iDatum] );
     393               8 :             CopyGeogCSFrom( &oGCS );
     394                 :         }
     395                 : 
     396               8 :         else if ( iEllips > 0
     397                 :                   && iEllips < (long)NUMBER_OF_ELLIPSOIDS
     398               0 :                   && aoEllips[iEllips] )
     399                 :         {
     400               0 :             char    *pszName = NULL;
     401                 :             double  dfSemiMajor, dfInvFlattening;
     402                 : 
     403               0 :             if ( OSRGetEllipsoidInfo( aoEllips[iEllips], &pszName,
     404                 :                             &dfSemiMajor, &dfInvFlattening ) == OGRERR_NONE )
     405                 :             {
     406                 :                 SetGeogCS( CPLString().Printf(
     407                 :                             "Unknown datum based upon the %s ellipsoid",
     408                 :                             pszName ),
     409                 :                            CPLString().Printf(
     410                 :                             "Not specified (based on %s spheroid)", pszName ),
     411                 :                            pszName, dfSemiMajor, dfInvFlattening,
     412               0 :                            NULL, 0.0, NULL, 0.0 );
     413               0 :                 SetAuthority( "SPHEROID", "EPSG", aoEllips[iEllips] );
     414                 :             }
     415                 :             else
     416                 :             {
     417                 :                 CPLError( CE_Warning, CPLE_AppDefined,
     418                 :                           "Failed to lookup ellipsoid code %d, likely due to"
     419                 :                           " missing GDAL gcs.csv\n"
     420               0 :                           " file.  Falling back to use WGS84.", (int) iEllips );
     421               0 :                 SetWellKnownGeogCS( "WGS84" );
     422                 :             }
     423                 : 
     424               0 :             if ( pszName )
     425               0 :                 CPLFree( pszName );
     426                 :         }
     427                 :         
     428                 :         else
     429                 :         {
     430                 :             CPLError( CE_Warning, CPLE_AppDefined,
     431                 :                       "Wrong datum code %d. Supported datums are 1--%ld only.\n"
     432                 :                       "Setting WGS84 as a fallback.",
     433               8 :                       (int) iDatum, NUMBER_OF_DATUMS - 1 );
     434               8 :             SetWellKnownGeogCS( "WGS84" );
     435                 :         }
     436                 :     }
     437                 : 
     438                 : /* -------------------------------------------------------------------- */
     439                 : /*      Grid units translation                                          */
     440                 : /* -------------------------------------------------------------------- */
     441              16 :     if( IsLocal() || IsProjected() )
     442              12 :         SetLinearUnits( SRS_UL_METER, 1.0 );
     443                 : 
     444              16 :     FixupOrdering();
     445                 : 
     446              16 :     if ( bProjAllocated && padfPrjParams )
     447               0 :         CPLFree( padfPrjParams );
     448                 : 
     449              16 :     return OGRERR_NONE;
     450                 : }
     451                 : 
     452                 : /************************************************************************/
     453                 : /*                      OSRExportToPanorama()                           */
     454                 : /************************************************************************/
     455                 : 
     456               0 : OGRErr OSRExportToPanorama( OGRSpatialReferenceH hSRS,
     457                 :                             long *piProjSys, long *piDatum, long *piEllips,
     458                 :                             long *piZone, double *padfPrjParams )
     459                 : 
     460                 : {
     461                 :     return ((OGRSpatialReference *) hSRS)->exportToPanorama( piProjSys,
     462                 :                                                              piDatum, piEllips,
     463                 :                                                              piZone,
     464               0 :                                                              padfPrjParams );
     465                 : }
     466                 : 
     467                 : /************************************************************************/
     468                 : /*                           exportToPanorama()                         */
     469                 : /************************************************************************/
     470                 : 
     471                 : /**
     472                 :  * Export coordinate system in "Panorama" GIS projection definition.
     473                 :  *
     474                 :  * This method is the equivalent of the C function OSRExportToPanorama().
     475                 :  *
     476                 :  * @param piProjSys Pointer to variable, where the projection system code will
     477                 :  * be returned.
     478                 :  *
     479                 :  * @param piDatum Pointer to variable, where the coordinate system code will
     480                 :  * be returned.
     481                 :  *
     482                 :  * @param piEllips Pointer to variable, where the spheroid code will be
     483                 :  * returned.
     484                 :  * 
     485                 :  * @param piZone Pointer to variable, where the zone for UTM projection
     486                 :  * system will be returned.
     487                 :  *
     488                 :  * @param padfPrjParams an existing 7 double buffer into which the
     489                 :  * projection parameters will be placed. See importFromPanorama()
     490                 :  * for the list of parameters.
     491                 :  * 
     492                 :  * @return OGRERR_NONE on success or an error code on failure. 
     493                 :  */
     494                 : 
     495               7 : OGRErr OGRSpatialReference::exportToPanorama( long *piProjSys, long *piDatum,
     496                 :                                               long *piEllips, long *piZone,
     497                 :                                               double *padfPrjParams ) const
     498                 : 
     499                 : {
     500                 :     CPLAssert( padfPrjParams );
     501                 : 
     502               7 :     const char  *pszProjection = GetAttrValue("PROJECTION");
     503                 : 
     504                 : /* -------------------------------------------------------------------- */
     505                 : /*      Fill all projection parameters with zero.                       */
     506                 : /* -------------------------------------------------------------------- */
     507                 :     int     i;
     508                 : 
     509               7 :     *piDatum = 0L;
     510               7 :     *piEllips = 0L;
     511               7 :     *piZone = 0L;
     512              56 :     for ( i = 0; i < 7; i++ )
     513              49 :         padfPrjParams[i] = 0.0;
     514                 : 
     515                 : /* ==================================================================== */
     516                 : /*      Handle the projection definition.                               */
     517                 : /* ==================================================================== */
     518               7 :     if( IsLocal() )
     519               0 :         *piProjSys = PAN_PROJ_NONE;
     520                 : 
     521               7 :     else if( pszProjection == NULL )
     522                 :     {
     523                 : #ifdef DEBUG
     524                 :         CPLDebug( "OSR_Panorama",
     525                 :                   "Empty projection definition, considered as Geographic" );
     526                 : #endif
     527               5 :         *piProjSys = PAN_PROJ_NONE;
     528                 :     }
     529                 : 
     530               2 :     else if( EQUAL(pszProjection, SRS_PT_MERCATOR_1SP) )
     531                 :     {
     532               0 :         *piProjSys = PAN_PROJ_MERCAT;
     533               0 :         padfPrjParams[3] =
     534               0 :             TO_RADIANS * GetNormProjParm( SRS_PP_CENTRAL_MERIDIAN, 0.0 );
     535                 :         padfPrjParams[0] = 
     536               0 :             TO_RADIANS * GetNormProjParm( SRS_PP_LATITUDE_OF_ORIGIN, 0.0 );
     537               0 :         padfPrjParams[4] = GetNormProjParm( SRS_PP_SCALE_FACTOR, 1.0 );
     538               0 :         padfPrjParams[5] = GetNormProjParm( SRS_PP_FALSE_EASTING, 0.0 );
     539               0 :         padfPrjParams[6] = GetNormProjParm( SRS_PP_FALSE_NORTHING, 0.0 );
     540                 :     }
     541                 : 
     542               2 :     else if( EQUAL(pszProjection, SRS_PT_POLAR_STEREOGRAPHIC) )
     543                 :     {
     544               0 :         *piProjSys = PAN_PROJ_PS;
     545               0 :         padfPrjParams[3] =
     546               0 :             TO_RADIANS * GetNormProjParm( SRS_PP_CENTRAL_MERIDIAN, 0.0 );
     547               0 :         padfPrjParams[2] = 
     548               0 :             TO_RADIANS * GetNormProjParm( SRS_PP_LATITUDE_OF_ORIGIN, 0.0 );
     549               0 :         padfPrjParams[4] = GetNormProjParm( SRS_PP_SCALE_FACTOR, 1.0 );
     550               0 :         padfPrjParams[5] = GetNormProjParm( SRS_PP_FALSE_EASTING, 0.0 );
     551               0 :         padfPrjParams[6] = GetNormProjParm( SRS_PP_FALSE_NORTHING, 0.0 );
     552                 :     }
     553                 : 
     554               2 :     else if( EQUAL(pszProjection, SRS_PT_POLYCONIC) )
     555                 :     {
     556               0 :         *piProjSys = PAN_PROJ_POLYC;
     557               0 :         padfPrjParams[3] =
     558               0 :             TO_RADIANS * GetNormProjParm( SRS_PP_CENTRAL_MERIDIAN, 0.0 );
     559               0 :         padfPrjParams[2] = 
     560               0 :             TO_RADIANS * GetNormProjParm( SRS_PP_LATITUDE_OF_ORIGIN, 0.0 );
     561               0 :         padfPrjParams[5] = GetNormProjParm( SRS_PP_FALSE_EASTING, 0.0 );
     562               0 :         padfPrjParams[6] = GetNormProjParm( SRS_PP_FALSE_NORTHING, 0.0 );
     563                 :     }
     564                 : 
     565               2 :     else if( EQUAL(pszProjection, SRS_PT_EQUIDISTANT_CONIC) )
     566                 :     {
     567               0 :         *piProjSys = PAN_PROJ_EC;
     568                 :         padfPrjParams[0] =
     569               0 :             TO_RADIANS * GetNormProjParm( SRS_PP_STANDARD_PARALLEL_1, 0.0 );
     570               0 :         padfPrjParams[1] = 
     571               0 :             TO_RADIANS * GetNormProjParm( SRS_PP_STANDARD_PARALLEL_2, 0.0 );
     572               0 :         padfPrjParams[3] =
     573               0 :             TO_RADIANS * GetNormProjParm( SRS_PP_CENTRAL_MERIDIAN, 0.0 );
     574               0 :         padfPrjParams[2] = 
     575               0 :             TO_RADIANS * GetNormProjParm( SRS_PP_LATITUDE_OF_ORIGIN, 0.0 );
     576               0 :         padfPrjParams[5] = GetNormProjParm( SRS_PP_FALSE_EASTING, 0.0 );
     577               0 :         padfPrjParams[6] = GetNormProjParm( SRS_PP_FALSE_NORTHING, 0.0 );
     578                 :     }
     579                 : 
     580               2 :     else if( EQUAL(pszProjection, SRS_PT_LAMBERT_CONFORMAL_CONIC_2SP) )
     581                 :     {
     582               0 :         *piProjSys = PAN_PROJ_LCC;
     583                 :         padfPrjParams[0] =
     584               0 :             TO_RADIANS * GetNormProjParm( SRS_PP_STANDARD_PARALLEL_1, 0.0 );
     585               0 :         padfPrjParams[1] = 
     586               0 :             TO_RADIANS * GetNormProjParm( SRS_PP_STANDARD_PARALLEL_2, 0.0 );
     587               0 :         padfPrjParams[3] =
     588               0 :             TO_RADIANS * GetNormProjParm( SRS_PP_CENTRAL_MERIDIAN, 0.0 );
     589               0 :         padfPrjParams[2] = 
     590               0 :             TO_RADIANS * GetNormProjParm( SRS_PP_LATITUDE_OF_ORIGIN, 0.0 );
     591               0 :         padfPrjParams[5] = GetNormProjParm( SRS_PP_FALSE_EASTING, 0.0 );
     592               0 :         padfPrjParams[6] = GetNormProjParm( SRS_PP_FALSE_NORTHING, 0.0 );
     593                 :     }
     594                 : 
     595               2 :     else if( EQUAL(pszProjection, SRS_PT_TRANSVERSE_MERCATOR) )
     596                 :     {
     597                 :         int bNorth;
     598                 : 
     599               2 :         *piZone = GetUTMZone( &bNorth );
     600                 : 
     601               2 :         if( *piZone != 0 )
     602                 :         {
     603               0 :             *piProjSys = PAN_PROJ_UTM;
     604               0 :             if( !bNorth )
     605               0 :                 *piZone = - *piZone;
     606                 :         }            
     607                 :         else
     608                 :         {
     609               2 :             *piProjSys = PAN_PROJ_TM;
     610               2 :             padfPrjParams[3] =
     611               2 :                 TO_RADIANS * GetNormProjParm( SRS_PP_CENTRAL_MERIDIAN, 0.0 );
     612               2 :             padfPrjParams[2] = 
     613               2 :                 TO_RADIANS * GetNormProjParm( SRS_PP_LATITUDE_OF_ORIGIN, 0.0 );
     614               2 :             padfPrjParams[4] =
     615               2 :                 GetNormProjParm( SRS_PP_SCALE_FACTOR, 1.0 );
     616               2 :             padfPrjParams[5] =
     617               2 :                 GetNormProjParm( SRS_PP_FALSE_EASTING, 0.0 );
     618               2 :             padfPrjParams[6] =
     619               2 :                 GetNormProjParm( SRS_PP_FALSE_NORTHING, 0.0 );
     620                 :         }
     621                 :     }
     622                 : 
     623               0 :     else if( EQUAL(pszProjection, SRS_PT_WAGNER_I) )
     624                 :     {
     625               0 :         *piProjSys = PAN_PROJ_WAG1;
     626               0 :         padfPrjParams[5] = GetNormProjParm( SRS_PP_FALSE_EASTING, 0.0 );
     627               0 :         padfPrjParams[6] = GetNormProjParm( SRS_PP_FALSE_NORTHING, 0.0 );
     628                 :     }
     629                 : 
     630               0 :     else if( EQUAL(pszProjection, SRS_PT_STEREOGRAPHIC) )
     631                 :     {
     632               0 :         *piProjSys = PAN_PROJ_STEREO;
     633               0 :         padfPrjParams[3] =
     634               0 :             TO_RADIANS * GetNormProjParm( SRS_PP_CENTRAL_MERIDIAN, 0.0 );
     635               0 :         padfPrjParams[2] = 
     636               0 :             TO_RADIANS * GetNormProjParm( SRS_PP_LATITUDE_OF_ORIGIN, 0.0 );
     637               0 :         padfPrjParams[4] = GetNormProjParm( SRS_PP_SCALE_FACTOR, 1.0 );
     638               0 :         padfPrjParams[5] = GetNormProjParm( SRS_PP_FALSE_EASTING, 0.0 );
     639               0 :         padfPrjParams[6] = GetNormProjParm( SRS_PP_FALSE_NORTHING, 0.0 );
     640                 :     }
     641                 : 
     642               0 :     else if( EQUAL(pszProjection, SRS_PT_AZIMUTHAL_EQUIDISTANT) )
     643                 :     {
     644               0 :         *piProjSys = PAN_PROJ_AE;
     645               0 :         padfPrjParams[3] =
     646               0 :             TO_RADIANS * GetNormProjParm( SRS_PP_LONGITUDE_OF_CENTER, 0.0 );
     647                 :         padfPrjParams[0] = 
     648               0 :             TO_RADIANS * GetNormProjParm( SRS_PP_LATITUDE_OF_CENTER, 0.0 );
     649               0 :         padfPrjParams[5] = GetNormProjParm( SRS_PP_FALSE_EASTING, 0.0 );
     650               0 :         padfPrjParams[6] = GetNormProjParm( SRS_PP_FALSE_NORTHING, 0.0 );
     651                 :     }
     652                 : 
     653               0 :     else if( EQUAL(pszProjection, SRS_PT_GNOMONIC) )
     654                 :     {
     655               0 :         *piProjSys = PAN_PROJ_GNOMON;
     656               0 :         padfPrjParams[3] =
     657               0 :             TO_RADIANS * GetNormProjParm( SRS_PP_CENTRAL_MERIDIAN, 0.0 );
     658               0 :         padfPrjParams[2] = 
     659               0 :             TO_RADIANS * GetNormProjParm( SRS_PP_LATITUDE_OF_ORIGIN, 0.0 );
     660               0 :         padfPrjParams[5] = GetNormProjParm( SRS_PP_FALSE_EASTING, 0.0 );
     661               0 :         padfPrjParams[6] = GetNormProjParm( SRS_PP_FALSE_NORTHING, 0.0 );
     662                 :     }
     663                 : 
     664               0 :     else if( EQUAL(pszProjection, SRS_PT_MOLLWEIDE) )
     665                 :     {
     666               0 :         *piProjSys = PAN_PROJ_MOLL;
     667               0 :         padfPrjParams[3] =
     668               0 :             TO_RADIANS * GetNormProjParm( SRS_PP_CENTRAL_MERIDIAN, 0.0 );
     669               0 :         padfPrjParams[5] = GetNormProjParm( SRS_PP_FALSE_EASTING, 0.0 );
     670               0 :         padfPrjParams[6] = GetNormProjParm( SRS_PP_FALSE_NORTHING, 0.0 );
     671                 :     }
     672                 : 
     673               0 :     else if( EQUAL(pszProjection, SRS_PT_LAMBERT_AZIMUTHAL_EQUAL_AREA) )
     674                 :     {
     675               0 :         *piProjSys = PAN_PROJ_LAEA;
     676               0 :         padfPrjParams[3] =
     677               0 :             TO_RADIANS * GetNormProjParm( SRS_PP_CENTRAL_MERIDIAN, 0.0 );
     678                 :         padfPrjParams[0] = 
     679               0 :             TO_RADIANS * GetNormProjParm( SRS_PP_LATITUDE_OF_ORIGIN, 0.0 );
     680               0 :         padfPrjParams[5] = GetNormProjParm( SRS_PP_FALSE_EASTING, 0.0 );
     681               0 :         padfPrjParams[6] = GetNormProjParm( SRS_PP_FALSE_NORTHING, 0.0 );
     682                 :     }
     683                 : 
     684               0 :     else if( EQUAL(pszProjection, SRS_PT_EQUIRECTANGULAR) )
     685                 :     {
     686               0 :         *piProjSys = PAN_PROJ_EQC;
     687               0 :         padfPrjParams[3] =
     688               0 :             TO_RADIANS * GetNormProjParm( SRS_PP_CENTRAL_MERIDIAN, 0.0 );
     689                 :         padfPrjParams[0] = 
     690               0 :             TO_RADIANS * GetNormProjParm( SRS_PP_LATITUDE_OF_ORIGIN, 0.0 );
     691               0 :         padfPrjParams[5] = GetNormProjParm( SRS_PP_FALSE_EASTING, 0.0 );
     692               0 :         padfPrjParams[6] = GetNormProjParm( SRS_PP_FALSE_NORTHING, 0.0 );
     693                 :     }
     694                 : 
     695               0 :     else if( EQUAL(pszProjection, SRS_PT_CYLINDRICAL_EQUAL_AREA) )
     696                 :     {
     697               0 :         *piProjSys = PAN_PROJ_CEA;
     698               0 :         padfPrjParams[3] =
     699               0 :             TO_RADIANS * GetNormProjParm( SRS_PP_CENTRAL_MERIDIAN, 0.0 );
     700               0 :         padfPrjParams[2] = 
     701               0 :             TO_RADIANS * GetNormProjParm( SRS_PP_STANDARD_PARALLEL_1, 0.0 );
     702               0 :         padfPrjParams[5] = GetNormProjParm( SRS_PP_FALSE_EASTING, 0.0 );
     703               0 :         padfPrjParams[6] = GetNormProjParm( SRS_PP_FALSE_NORTHING, 0.0 );
     704                 :     }
     705                 : 
     706               0 :     else if( EQUAL(pszProjection, SRS_PT_IMW_POLYCONIC) )
     707                 :     {
     708               0 :         *piProjSys = PAN_PROJ_IMWP;
     709               0 :         padfPrjParams[3] =
     710               0 :             TO_RADIANS * GetNormProjParm( SRS_PP_CENTRAL_MERIDIAN, 0.0 );
     711                 :         padfPrjParams[0] = 
     712               0 :             TO_RADIANS * GetNormProjParm( SRS_PP_LATITUDE_OF_1ST_POINT, 0.0 );
     713               0 :         padfPrjParams[1] = 
     714               0 :             TO_RADIANS * GetNormProjParm( SRS_PP_LATITUDE_OF_2ND_POINT, 0.0 );
     715               0 :         padfPrjParams[5] = GetNormProjParm( SRS_PP_FALSE_EASTING, 0.0 );
     716               0 :         padfPrjParams[6] = GetNormProjParm( SRS_PP_FALSE_NORTHING, 0.0 );
     717                 :     }
     718                 : 
     719                 :     // Projection unsupported by "Panorama" GIS
     720                 :     else
     721                 :     {
     722                 :         CPLDebug( "OSR_Panorama",
     723                 :                   "Projection \"%s\" unsupported by \"Panorama\" GIS. "
     724               0 :                   "Geographic system will be used.", pszProjection );
     725               0 :         *piProjSys = PAN_PROJ_NONE;
     726                 :     }
     727                 :  
     728                 : /* -------------------------------------------------------------------- */
     729                 : /*      Translate the datum.                                            */
     730                 : /* -------------------------------------------------------------------- */
     731               7 :     const char  *pszDatum = GetAttrValue( "DATUM" );
     732                 : 
     733               7 :     if ( pszDatum == NULL )
     734                 :     {
     735               0 :         *piDatum = PAN_DATUM_NONE;
     736               0 :         *piEllips = PAN_ELLIPSOID_NONE;
     737                 :     }
     738               7 :     else if ( EQUAL( pszDatum, "Pulkovo_1942" ) )
     739                 :     {
     740               0 :         *piDatum = PAN_DATUM_PULKOVO42;
     741               0 :         *piEllips = PAN_ELLIPSOID_KRASSOVSKY;
     742                 :     }
     743               7 :     else if( EQUAL( pszDatum, SRS_DN_WGS84 ) )
     744                 :     {
     745               7 :         *piDatum = PAN_DATUM_WGS84;
     746               7 :         *piEllips = PAN_ELLIPSOID_WGS84;
     747                 :     }
     748                 : 
     749                 :     // If not found well known datum, translate ellipsoid
     750                 :     else
     751                 :     {
     752               0 :         double      dfSemiMajor = GetSemiMajor();
     753               0 :         double      dfInvFlattening = GetInvFlattening();
     754                 :         size_t      i;
     755                 : 
     756                 : #ifdef DEBUG
     757                 :         CPLDebug( "OSR_Panorama",
     758                 :                   "Datum \"%s\" unsupported by \"Panorama\" GIS. "
     759                 :                   "Try to translate ellipsoid definition.", pszDatum );
     760                 : #endif
     761                 :        
     762               0 :         for ( i = 0; i < NUMBER_OF_ELLIPSOIDS; i++ )
     763                 :         {
     764               0 :             if ( aoEllips[i] )
     765                 :             {
     766               0 :                 double  dfSM = 0.0;
     767               0 :                 double  dfIF = 1.0;
     768                 : 
     769               0 :                 if ( OSRGetEllipsoidInfo( aoEllips[i], NULL,
     770                 :                                           &dfSM, &dfIF ) == OGRERR_NONE
     771                 :                      && CPLIsEqual(dfSemiMajor, dfSM)
     772                 :                      && CPLIsEqual(dfInvFlattening, dfIF) )
     773                 :                 {
     774               0 :                     *piEllips = i;
     775               0 :                     break;
     776                 :                 }
     777                 :             }
     778                 :         }
     779                 : 
     780               0 :         if ( i == NUMBER_OF_ELLIPSOIDS )    // Didn't found matches.
     781                 :         {
     782                 : #ifdef DEBUG
     783                 :             CPLDebug( "OSR_Panorama",
     784                 :                       "Ellipsoid \"%s\" unsupported by \"Panorama\" GIS.",
     785                 :                       pszDatum );
     786                 : #endif
     787               0 :             *piDatum = PAN_DATUM_NONE;
     788               0 :             *piEllips = PAN_ELLIPSOID_NONE;
     789                 :         }
     790                 :     }
     791                 : 
     792               7 :     return OGRERR_NONE;
     793                 : }
     794                 : 

Generated by: LCOV version 1.7