LTP GCOV extension - code coverage report
Current view: directory - frmts/ilwis - ilwiscoordinatesystem.cpp
Test: gdal_filtered.info
Date: 2010-07-12 Instrumented lines: 437
Code covered: 32.7 % Executed lines: 143

       1                 : /******************************************************************************
       2                 :  *
       3                 :  * Purpose: Translation from ILWIS coordinate system information.
       4                 :  * Author:   Lichun Wang, lichun@itc.nl
       5                 :  *
       6                 :  ******************************************************************************
       7                 :  * Copyright (c) 2004, ITC
       8                 :  *
       9                 :  * Permission is hereby granted, free of charge, to any person obtaining a
      10                 :  * copy of this software and associated documentation files (the "Software"),
      11                 :  * to deal in the Software without restriction, including without limitation
      12                 :  * the rights to use, copy, modify, merge, publish, distribute, sublicense,
      13                 :  * and/or sell copies of the Software, and to permit persons to whom the
      14                 :  * Software is furnished to do so, subject to the following conditions:
      15                 :  *
      16                 :  * The above copyright notice and this permission notice shall be included
      17                 :  * in all copies or substantial portions of the Software.
      18                 :  *
      19                 :  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
      20                 :  * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
      21                 :  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
      22                 :  * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
      23                 :  * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
      24                 :  * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
      25                 :  * DEALINGS IN THE SOFTWARE.
      26                 :  ****************************************************************************/
      27                 : #include "cpl_conv.h"
      28                 : #include "ilwisdataset.h"
      29                 : 
      30                 : #include <string>
      31                 : using namespace std;
      32                 : 
      33                 : typedef struct 
      34                 : {
      35                 :     const char  *pszIlwisDatum;
      36                 :     const char  *pszWKTDatum; 
      37                 :     int   nEPSGCode;
      38                 : } IlwisDatums;
      39                 : 
      40                 : typedef struct 
      41                 : {
      42                 :     const char  *pszIlwisEllips;
      43                 :     int   nEPSGCode;
      44                 :     double semiMajor;
      45                 :     double invFlattening; 
      46                 : } IlwisEllips;
      47                 : 
      48                 : string ReadElement(string section, string entry, string filename);
      49                 : bool WriteElement(string sSection, string sEntry, string fn, string sValue);
      50                 : bool WriteElement(string sSection, string sEntry, string fn, int nValue);
      51                 : bool WriteElement(string sSection, string sEntry, string fn, double dValue);
      52                 : 
      53                 : static const IlwisDatums iwDatums[] =
      54                 : {
      55                 :     { "Adindan", "Adindan", 4201 },               
      56                 :     { "Afgooye", "Afgooye", 4205 },               
      57                 :     //AGREF --- skipped
      58                 :     { "Ain el Abd 1970", "Ain_el_Abd_1970", 4204 },       
      59                 :     { "American Samoa 1962", "American_Samoa_1962", 4169 },    
      60                 :     //Anna 1 Astro 1965 --- skipped
      61                 :     { "Antigua Island Astro 1943", "Antigua_1943", 4601 },    
      62                 :     { "Arc 1950", "Arc_1950", 4209 },    //Arc 1950
      63                 :     { "Arc 1960", "Arc_1960", 4210 },    //Arc 1960
      64                 :     //Ascension Island 1958
      65                 :     //Astro Beacon E 1945
      66                 :     //Astro DOS 71/4
      67                 :     //Astro Tern Island (FRIG) 1961
      68                 :     //Astronomical Station 1952
      69                 :     { "Australian Geodetic 1966", "Australian_Geodetic_Datum_1966", 4202 },    
      70                 :     { "Australian Geodetic 1984", "Australian_Geodetic_Datum_1984", 4203 },
      71                 :     //Ayabelle Lighthouse
      72                 :     //Bellevue (IGN)
      73                 :     { "Bermuda 1957", "Bermuda_1957", 4216 },
      74                 :     { "Bissau", "Bissau", 4165 },
      75                 :     { "Bogota Observatory  (1975)", "Bogota", 4218 },
      76                 :     { "Bukit Rimpah", "Bukit_Rimpah", 4219 },
      77                 :     //Camp Area Astro
      78                 :     { "Campo Inchauspe", "Campo_Inchauspe", 4221 },
      79                 :     //Canton Astro 1966
      80                 :     { "Cape", "Cape", 4222 },
      81                 :     //Cape Canaveral
      82                 :     { "Carthage", "Carthage", 4223 },
      83                 :     { "CH1903", "CH1903", 4149 },
      84                 :     //Chatham Island Astro 1971
      85                 :     { "Chua Astro", "Chua", 4224 },
      86                 :     { "Corrego Alegre", "Corrego_Alegre", 4225 },
      87                 :     //Croatia
      88                 :     //D-PAF (Orbits)
      89                 :     { "Dabola", "Dabola_1981", 4155 },
      90                 :     //Deception Island
      91                 :     //Djakarta (Batavia)
      92                 :     //DOS 1968
      93                 :     //Easter Island 1967
      94                 :     //Estonia 1937
      95                 :     { "European 1950 (ED 50)", "European_Datum_1950", 4154 },
      96                 :     //European 1979 (ED 79
      97                 :     //Fort Thomas 1955
      98                 :     { "Gan 1970", "Gandajika_1970", 4233 },
      99                 :     //Geodetic Datum 1949
     100                 :     //Graciosa Base SW 1948
     101                 :     //Guam 1963
     102                 :     { "Gunung Segara", "Gunung_Segara", 4613 },
     103                 :     //GUX 1 Astro
     104                 :     { "Herat North", "Herat_North", 4255 },
     105                 :     //Hermannskogel
     106                 :     //Hjorsey 1955
     107                 :     //Hong Kong 1963
     108                 :     { "Hu-Tzu-Shan", "Hu_Tzu_Shan", 4236 },
     109                 :     //Indian (Bangladesh)
     110                 :     //Indian (India, Nepal)
     111                 :     //Indian (Pakistan)
     112                 :     { "Indian 1954", "Indian_1954", 4239 },
     113                 :     { "Indian 1960", "Indian_1960", 4131 },
     114                 :     { "Indian 1975", "Indian_1975", 4240 },
     115                 :     { "Indonesian 1974", "Indonesian_Datum_1974", 4238 },
     116                 :     //Ireland 1965
     117                 :     //ISTS 061 Astro 1968
     118                 :     //ISTS 073 Astro 1969
     119                 :     //Johnston Island 1961
     120                 :     { "Kandawala", "Kandawala", 4244 },
     121                 :     //Kerguelen Island 1949
     122                 :     { "Kertau 1948", "Kertau", 4245 },
     123                 :     //Kusaie Astro 1951
     124                 :     //L. C. 5 Astro 1961
     125                 :     { "Leigon", "Leigon", 4250 },
     126                 :     { "Liberia 1964", "Liberia_1964", 4251 },
     127                 :     { "Luzon", "Luzon_1911", 4253 },
     128                 :     //M'Poraloko
     129                 :     { "Mahe 1971", "Mahe_1971", 4256 },
     130                 :     { "Massawa", "Massawa", 4262 },
     131                 :     { "Merchich", "Merchich", 4261 },
     132                 :     { "MGI (Hermannskogel)", "Militar_Geographische_Institute",4312 },
     133                 :     //Midway Astro 1961
     134                 :     { "Minna", "Minna", 4263 },
     135                 :     { "Montserrat Island Astro 1958", "Montserrat_1958", 4604 },
     136                 :     { "Nahrwan", "Nahrwan_1967", 4270 },
     137                 :     { "Naparima BWI", "Naparima_1955", 4158 },
     138                 :     { "North American 1927 (NAD 27)", "North_American_Datum_1927", 4267 },
     139                 :     { "North American 1983 (NAD 83)", "North_American_Datum_1983", 4269 },
     140                 :     //North Sahara 1959
     141                 :     { "NTF (Nouvelle Triangulation de France)", "Nouvelle_Triangulation_Francaise", 4807 },
     142                 :     //Observatorio Meteorologico 1939
     143                 :     //Old Egyptian 1907
     144                 :     { "Old Hawaiian", "Old_Hawaiian", 4135 },
     145                 :     //Oman
     146                 :     //Ordnance Survey Great Britain 1936
     147                 :     //Pico de las Nieves
     148                 :     //Pitcairn Astro 1967
     149                 :     //Point 58
     150                 :     { "Pointe Noire 1948", "Pointe_Noire", 4282 },
     151                 :     { "Porto Santo 1936", "Porto_Santo",4615 },
     152                 :     //Potsdam (Rauenburg)
     153                 :     { "Potsdam (Rauenburg)", "Deutsches_Hauptdreiecksnetz", 4314 },
     154                 :     { "Provisional South American 1956", "Provisional_South_American_Datum_1956", 4248 },
     155                 :     //Provisional South Chilean 1963
     156                 :     { "Puerto Rico", "Puerto_Rico", 4139 },
     157                 :     { "Pulkovo 1942", "Pulkovo_1942", 4178 },
     158                 :     //{ "Qatar National", "Qatar_National_Datum_1995", 4614 },
     159                 :     { "Qornoq", "Qornoq", 4287 },
     160                 :     { "Puerto Rico", "Puerto_Rico", 4139 },
     161                 :     //Reunion
     162                 :     { "Rome 1940", "Monte_Mario", 4806 },
     163                 :     { "RT90", "Rikets_koordinatsystem_1990", 4124 },
     164                 :     { "Rijks Driehoeksmeting", "Amersfoort", 4289 },
     165                 :     { "S-42 (Pulkovo 1942)", "Pulkovo_1942", 4178 },
     166                 :     //{ "S-JTSK", "Jednotne_Trigonometricke_Site_Katastralni", 4156 },
     167                 :     //Santo (DOS) 1965
     168                 :     //Sao Braz
     169                 :     { "Sapper Hill 1943", "Sapper_Hill_1943", 4292 },
     170                 :     { "Schwarzeck", "Schwarzeck", 4293 },
     171                 :     { "Selvagem Grande 1938", "Selvagem_Grande", 4616 },
     172                 :     //vSGS 1985
     173                 :     //Sierra Leone 1960
     174                 :     { "South American 1969", "South_American_Datum_1969", 4291 },
     175                 :     //South Asia
     176                 :     { "Tananarive Observatory 1925", "Tananarive_1925", 4297 },
     177                 :     { "Timbalai 1948", "Timbalai_1948", 4298 },
     178                 :     { "Tokyo", "Tokyo", 4301 },
     179                 :     //Tristan Astro 1968
     180                 :     //Viti Levu 1916
     181                 :     { "Voirol 1874", "Voirol_1875", 4304 },
     182                 :     //Voirol 1960
     183                 :     //Wake Island Astro 1952
     184                 :     //Wake-Eniwetok 1960
     185                 :     { "WGS 1972", "WGS_1972", 4322 },
     186                 :     { "WGS 1984", "WGS_1984", 4326 },
     187                 :     { "Yacare", "Yacare", 4309 },
     188                 :     { "Zanderij", "Zanderij", 4311 },
     189                 :     { NULL, NULL, 0 }
     190                 : };
     191                 : 
     192                 : static const IlwisEllips iwEllips[] =
     193                 : {
     194                 :     { "Sphere", 7035, 6371007, 0.0  },  //rad 6370997 m (normal sphere)   
     195                 :     { "Airy 1830", 7031, 6377563.396, 299.3249646 },   
     196                 :     { "Modified Airy", 7002, 6377340.189, 299.3249646 },   
     197                 :     { "ATS77", 7204, 6378135.0, 298.257000006 },   
     198                 :     { "Australian National", 7003, 6378160, 298.249997276 },   
     199                 :     { "Bessel 1841", 7042, 6377397.155, 299.1528128},   
     200                 :     { "Bessel 1841 (Japan By Law)", 7046 , 6377397.155, 299.152815351 }, 
     201                 :     { "Bessel 1841 (Namibia)", 7006, 6377483.865, 299.1528128 },   
     202                 :     { "Clarke 1866", 7008, 6378206.4, 294.9786982 },   
     203                 :     { "Clarke 1880", 7034, 6378249.145, 293.465 },   
     204                 :     { "Clarke 1880 (IGN)", 7011, 6378249.2, 293.466  },   
     205                 :     // FIXME: D-PAF (Orbits) --- skipped
     206                 :     // FIXME: Du Plessis Modified --- skipped
     207                 :     // FIXME: Du Plessis Reconstituted --- skipped
     208                 :     { "Everest (India 1830)", 7015, 6377276.345, 300.8017 },
     209                 :     // Everest (India 1956) --- skipped
     210                 :     // Everest (Malaysia 1969) --- skipped
     211                 :     { "Everest (E. Malaysia and Brunei)", 7016, 6377298.556, 300.8017 },   
     212                 :     { "Everest (Malay. and Singapore 1948)", 7018, 6377304.063, 300.8017 },   
     213                 :     { "Everest (Pakistan)", 7044, 6377309.613, 300.8017 }, 
     214                 :     // Everest (Sabah Sarawak) --- skipped
     215                 :     // Fischer 1960 --- skipped
     216                 :     // Fischer 1960 (Modified) --- skipped
     217                 :     // Fischer 1968 --- skipped
     218                 :     { "GRS 80", 7019, 6378137, 298.257222101  },   
     219                 :     { "Helmert 1906", 7020, 6378200, 298.3 }, 
     220                 :     // Hough 1960 --- skipped
     221                 :     { "Indonesian 1974", 7021, 6378160, 298.247 }, 
     222                 :     { "International 1924", 7022, 6378388, 297 }, 
     223                 :     { "Krassovsky 1940", 7024, 6378245, 298.3 }, 
     224                 :     // New_International 1967
     225                 :     // SGS 85 
     226                 :     // South American 1969
     227                 :     // WGS 60
     228                 :     // WGS 66
     229                 :     { "WGS 72", 7020, 6378135.0, 298.259998590  }, 
     230                 :     { "WGS 84", 7030, 6378137, 298.257223563 }, 
     231                 :     { NULL, 0 }
     232                 : };
     233                 : 
     234                 : #ifndef PI
     235                 : #  define PI 3.14159265358979323846
     236                 : #endif
     237                 : 
     238                 : #ifndef R2D
     239                 : #  define R2D (180/PI)
     240                 : #endif
     241                 : #ifndef D2R
     242                 : #  define D2R (PI/180)
     243                 : #endif
     244                 : 
     245                 : /* ==================================================================== */
     246                 : /*      Some "standard" strings.                                        */
     247                 : /* ==================================================================== */
     248                 : 
     249                 : #define ILW_False_Easting "False Easting"
     250                 : #define ILW_False_Northing "False Northing"
     251                 : #define ILW_Central_Meridian "Central Meridian"
     252                 : #define ILW_Central_Parallel "Central Parallel"
     253                 : #define ILW_Standard_Parallel_1 "Standard Parallel 1"
     254                 : #define ILW_Standard_Parallel_2 "Standard Parallel 2"
     255                 : #define ILW_Scale_Factor "Scale Factor"
     256                 : #define ILW_Latitude_True_Scale "Latitude of True Scale"
     257                 : #define ILW_Height_Persp_Center "Height Persp. Center"
     258                 : 
     259              58 : double ReadPrjParms(string section, string entry, string filename)
     260                 : {
     261              58 :     string str = ReadElement(section, entry, filename);
     262                 :     //string str="";
     263             116 :     if (str.length() != 0)
     264              13 :         return atof(str.c_str());
     265                 :     else
     266              45 :         return 0;
     267                 : }
     268                 : 
     269               5 : static int fetchParms(string csyFileName, double * padfPrjParams)
     270                 : {
     271                 :     int     i;
     272                 : 
     273                 :     //Fill all projection parameters with zero
     274              70 :     for ( i = 0; i < 13; i++ )
     275              65 :         padfPrjParams[i] = 0.0;
     276                 :     
     277               5 :     string pszProj = ReadElement("CoordSystem", "Projection", csyFileName);
     278              10 :     string pszEllips = ReadElement("CoordSystem", "Ellipsoid", csyFileName);
     279                 : 
     280                 :     //fetch info about a custom ellipsoid
     281               5 :     if( EQUALN( pszEllips.c_str(), "User Defined", 12 ) )
     282                 :     {
     283               4 :         padfPrjParams[0] = ReadPrjParms("Ellipsoid", "a", csyFileName);
     284               4 :         padfPrjParams[2] = ReadPrjParms("Ellipsoid", "1/f", csyFileName);
     285                 :     }
     286               1 :     else if( EQUALN( pszEllips.c_str(), "Sphere", 6 ) )
     287                 :     {
     288               0 :         padfPrjParams[0] = ReadPrjParms("CoordSystem", "Sphere Radius", csyFileName);
     289                 :     }
     290                 : 
     291               5 :     padfPrjParams[3] = ReadPrjParms("Projection", "False Easting", csyFileName);
     292               5 :     padfPrjParams[4] = ReadPrjParms("Projection", "False Northing", csyFileName);
     293                 : 
     294               5 :     padfPrjParams[5] = ReadPrjParms("Projection", "Central Parallel", csyFileName);
     295               5 :     padfPrjParams[6] = ReadPrjParms("Projection", "Central Meridian", csyFileName);
     296                 : 
     297               5 :     padfPrjParams[7] = ReadPrjParms("Projection", "Standard Parallel 1", csyFileName);
     298               5 :     padfPrjParams[8] = ReadPrjParms("Projection", "Standard Parallel 2", csyFileName);
     299                 : 
     300               5 :     padfPrjParams[9] = ReadPrjParms("Projection", "Scale Factor", csyFileName);
     301               5 :     padfPrjParams[10] = ReadPrjParms("Projection", "Latitude of True Scale", csyFileName);
     302               5 :     padfPrjParams[11] = ReadPrjParms("Projection", "Zone", csyFileName);
     303               5 :     padfPrjParams[12] = ReadPrjParms("Projection", ILW_Height_Persp_Center, csyFileName);
     304                 : 
     305               5 :     return true;
     306                 : }
     307                 : 
     308                 : /************************************************************************/
     309                 : /*                          mapTMParms                                  */
     310                 : /************************************************************************/
     311                 : /**
     312                 :  * fetch the parameters from ILWIS projection definition for
     313                 :  * --- Gauss-Krueger Germany.
     314                 :  * --- Gauss Colombia
     315                 :  * --- Gauss-Boaga Italy
     316                 : **/
     317               0 : static int mapTMParms(string sProj, double dfZone, double &dfFalseEasting, double &dfCentralMeridian)
     318                 : {
     319               0 :     if( EQUALN( sProj.c_str(), "Gauss-Krueger Germany", 21 ) )
     320                 :     {
     321                 :         //Zone number must be in the range 1 to 3
     322               0 :         dfCentralMeridian = 6.0 + (dfZone - 1) * 3;
     323               0 :         dfFalseEasting = 2500000 + (dfZone - 1) * 1000000; 
     324                 :     }
     325               0 :     else if( EQUALN( sProj.c_str(), "Gauss-Boaga Italy", 17 ) )
     326                 :     {
     327               0 :         if ( dfZone == 1)
     328                 :         {
     329               0 :             dfCentralMeridian = 9;
     330               0 :             dfFalseEasting = 1500000;
     331                 :         }
     332               0 :         else if ( dfZone == 2)
     333                 :         {
     334               0 :             dfCentralMeridian = 15;
     335               0 :             dfFalseEasting = 2520000;
     336                 :         }
     337                 :         else
     338               0 :             return false;
     339                 :     }
     340               0 :     else if( EQUALN( sProj.c_str(), "Gauss Colombia", 14 ) )
     341                 :     {
     342                 :         //Zone number must be in the range 1 to 4
     343               0 :         dfCentralMeridian = -77.08097220 + (dfZone - 1) * 3;
     344                 :     }
     345               0 :     return true;
     346                 : }
     347                 : 
     348                 : /************************************************************************/
     349                 : /*                          scaleFromLATTS()                             */
     350                 : /************************************************************************/
     351                 : /**
     352                 :  * Compute the scale factor from Latitude_Of_True_Scale parameter.
     353                 :  *
     354                 : **/
     355               0 : static int scaleFromLATTS( string sEllips, double phits, double &scale )  
     356                 : {
     357               0 :     if( EQUALN( sEllips.c_str(), "Sphere", 6 ) ) 
     358                 :     {
     359               0 :         scale = cos(phits);
     360               0 :         return true;
     361                 :     }
     362                 :     else
     363                 :     {
     364               0 :         const IlwisEllips *piwEllips =  iwEllips;
     365               0 :         double e2 = 0.0;
     366               0 :         while ( piwEllips->pszIlwisEllips )
     367                 :         {
     368               0 :             if( EQUALN( sEllips.c_str(), piwEllips->pszIlwisEllips, strlen(piwEllips->pszIlwisEllips) ) )
     369                 :             {
     370               0 :                 double a = piwEllips->semiMajor;
     371               0 :                 double b = a * ( 1 - piwEllips->invFlattening);
     372               0 :                 e2 = ( a*a - b*b ) /( a*a );
     373               0 :                 break;
     374                 :             }
     375               0 :             piwEllips++;
     376                 :         }
     377               0 :         scale = cos(phits) / sqrt (1. - e2 * sin(phits) * sin(phits));
     378               0 :         return true;
     379                 :     }
     380                 :     return false;
     381                 : }
     382                 : 
     383                 : /************************************************************************/
     384                 : /*                          ReadProjection()                           */
     385                 : /************************************************************************/
     386                 : 
     387                 : /**
     388                 :  * Import coordinate system from ILWIS projection definition.
     389                 :  *
     390                 :  * The method will import projection definition in ILWIS, 
     391                 :  * It uses 13 parameters to define the coordinate system
     392                 :  * and datum/ellipsoid specieied in the padfPrjParams array. 
     393                 :  *
     394                 :  * @param padfPrjParams Array of 10 coordinate system parameters:
     395                 :  *
     396                 :  * [0]  Spheroid semi major axis
     397                 :  * [1]  Spheroid semi minor axis
     398                 :  * [2]  Spheroid inverse flattening
     399                 :  * [3]  False Easting
     400                 :  * [4]  False Northing
     401                 :  * [5]  Central Parallel // latitude_of_origin
     402                 :  * [6]  Central Meridian 
     403                 :  * [7]  First Standard Parallel
     404                 :  * [8]  Second Standard Parallel
     405                 :  * [9]  Scale Factor
     406                 :  * [10] Latitude_Of_True_Scale
     407                 :  * [11] Zone
     408                 :  * [12] Satellite Height
     409                 : **/ 
     410                 : 
     411               5 : CPLErr ILWISDataset::ReadProjection( string csyFileName )
     412                 : {
     413               5 :     string pszEllips;
     414               5 :     string pszDatum;
     415               5 :     string pszProj;
     416                 :     
     417                 :     //translate ILWIS pre-defined coordinate systems
     418               5 :     if( EQUALN( csyFileName.c_str(), "latlon.csy", 10 )) 
     419                 :     {
     420               0 :         pszProj = "LatLon";
     421               0 :         pszDatum = "";
     422               0 :         pszEllips = "Sphere";
     423                 :     } 
     424               5 :     else if ( EQUALN( csyFileName.c_str(), "LatlonWGS84.csy", 15 ))     
     425                 :     {
     426               0 :         pszProj = "LatLon";
     427               0 :         pszDatum = "WGS 1984";
     428               0 :         pszEllips = "WGS 84";
     429                 :     }
     430                 :     else
     431                 :     {
     432               5 :         pszProj = ReadElement("CoordSystem", "Type", csyFileName);
     433               5 :         if( !EQUALN( pszProj.c_str(), "LatLon", 7 ) )
     434               5 :             pszProj = ReadElement("CoordSystem", "Projection", csyFileName);
     435               5 :         pszDatum = ReadElement("CoordSystem", "Datum", csyFileName);
     436               5 :         pszEllips = ReadElement("CoordSystem", "Ellipsoid", csyFileName);
     437                 :     }
     438                 : 
     439                 : /* -------------------------------------------------------------------- */
     440                 : /*      Fetch array containing 13 coordinate system parameters          */
     441                 : /* -------------------------------------------------------------------- */
     442                 :     double     padfPrjParams[13];
     443               5 :     fetchParms(csyFileName, padfPrjParams);
     444                 :     
     445               5 :     OGRSpatialReference oSRS;
     446                 : /* -------------------------------------------------------------------- */
     447                 : /*      Operate on the basis of the projection name.                    */
     448                 : /* -------------------------------------------------------------------- */
     449               5 :     if( EQUALN( pszProj.c_str(), "LatLon", 7 ) )
     450                 :     {
     451                 :         //set datum later
     452                 :     }
     453               5 :     else if( EQUALN( pszProj.c_str(), "Albers EqualArea Conic", 22  ) )
     454                 :     {
     455               0 :         oSRS.SetProjCS("Albers EqualArea Conic");
     456                 :         oSRS.SetACEA( padfPrjParams[7], padfPrjParams[8],
     457                 :                       padfPrjParams[5], padfPrjParams[6],
     458               0 :                       padfPrjParams[3], padfPrjParams[4] );
     459                 :                  
     460                 :     }
     461               5 :     else if( EQUALN( pszProj.c_str(), "Azimuthal Equidistant", 21 ) )
     462                 :     {
     463               0 :         oSRS.SetProjCS("Azimuthal Equidistant");
     464                 :         oSRS.SetAE( padfPrjParams[5], padfPrjParams[6],
     465               0 :                     padfPrjParams[3], padfPrjParams[4] );
     466                 :     }
     467               5 :     else if( EQUALN( pszProj.c_str(), "Central Cylindrical", 19 ) )
     468                 :     {
     469                 :         //Use Central Parallel for dfStdP1
     470                 :         //padfPrjParams[5] is always to zero
     471               0 :         oSRS.SetProjCS("Central Cylindrical");
     472                 :         oSRS.SetCEA( padfPrjParams[5], padfPrjParams[6],
     473               0 :                      padfPrjParams[3], padfPrjParams[4] ); 
     474                 :     }
     475               5 :     else if( EQUALN( pszProj.c_str(), "Cassini", 7 ) )
     476                 :     {
     477                 :         //Use Latitude_Of_True_Scale for dfCenterLat 
     478                 :         //Scale Factor 1.0 should always be defined
     479               0 :         oSRS.SetProjCS("Cassini");
     480                 :         oSRS.SetCS(  padfPrjParams[10], padfPrjParams[6],  
     481               0 :                      padfPrjParams[3], padfPrjParams[4] );
     482                 :     }
     483               5 :     else if( EQUALN( pszProj.c_str(), "DutchRD", 7 ) )
     484                 :     {
     485               0 :         oSRS.SetProjCS("DutchRD");
     486                 :         oSRS.SetStereographic  (  52.156160556,  5.387638889,
     487                 :                                   0.9999079,  
     488               0 :                                   155000,  463000);
     489                 :                                    
     490                 :     }
     491               5 :     else if( EQUALN( pszProj.c_str(), "Equidistant Conic", 17 ) )
     492                 :     {
     493               0 :         oSRS.SetProjCS("Equidistant Conic");
     494                 :         oSRS.SetEC(  padfPrjParams[7], padfPrjParams[8],
     495                 :                      padfPrjParams[5], padfPrjParams[6],  
     496               0 :                      padfPrjParams[3], padfPrjParams[4] );
     497                 :     }
     498               5 :     else if( EQUALN( pszProj.c_str(), "Gauss-Krueger Germany", 21 ) )
     499                 :     {
     500                 :         //FalseNorthing and CenterLat are always set to 0
     501                 :         //Scale 1.0 is defined
     502                 :         //FalseEasting and CentralMeridian are defined by the selected zone
     503                 :         mapTMParms("Gauss-Krueger Germany", padfPrjParams[11], 
     504               0 :                    padfPrjParams[3], padfPrjParams[6]);
     505               0 :         oSRS.SetProjCS("Gauss-Krueger Germany");
     506                 :         oSRS.SetTM(  0, padfPrjParams[6],
     507                 :                      1.0,   
     508               0 :                      padfPrjParams[3], 0 );
     509                 :     }
     510               5 :     else if ( EQUALN( pszProj.c_str(),"Gauss-Boaga Italy", 17 ) )
     511                 :     {
     512                 :         //FalseNorthing and CenterLat are always set to 0
     513                 :         //Scale 0.9996 is defined
     514                 :         //FalseEasting and CentralMeridian are defined by the selected zone
     515                 :         mapTMParms("Gauss-Boaga Italy", padfPrjParams[11], 
     516               0 :                    padfPrjParams[3], padfPrjParams[6]);
     517               0 :         oSRS.SetProjCS("Gauss-Boaga Italy");
     518                 :         oSRS.SetTM(  0, padfPrjParams[6],
     519                 :                      0.9996,  
     520               0 :                      padfPrjParams[3], 0 );
     521                 :     }
     522               5 :     else if ( EQUALN( pszProj.c_str(),"Gauss Colombia", 14 ))
     523                 :     {
     524                 :         // 1000000 used for FalseNorthing and FalseEasting
     525                 :         // 1.0 used for scale 
     526                 :         // CenterLat is defined 45.1609259259259 
     527                 :         // CentralMeridian is defined by the selected zone
     528                 :         mapTMParms("Gauss Colombia", padfPrjParams[11], 
     529               0 :                    padfPrjParams[3], padfPrjParams[6]);
     530               0 :         oSRS.SetProjCS("Gauss Colombia");
     531                 :         oSRS.SetTM(  45.1609259259259, padfPrjParams[6],
     532                 :                      1.0,   
     533               0 :                      1000000, 1000000 );
     534                 :     }
     535               5 :     else if( EQUALN( pszProj.c_str(), "Gnomonic", 8 ) )
     536                 :     {
     537               0 :         oSRS.SetProjCS("Gnomonic");
     538                 :         oSRS.SetGnomonic( padfPrjParams[5], padfPrjParams[6],
     539               0 :                           padfPrjParams[3], padfPrjParams[4] );
     540                 :     }
     541               5 :     else if( EQUALN( pszProj.c_str(), "Lambert Conformal Conic", 23 ) )
     542                 :     {
     543                 :         // should use 1.0 for scale factor in Ilwis definition 
     544               0 :         oSRS.SetProjCS("Lambert Conformal Conic");
     545                 :         oSRS.SetLCC(  padfPrjParams[7], padfPrjParams[8],
     546                 :                         padfPrjParams[5], padfPrjParams[6],
     547               0 :                         padfPrjParams[3], padfPrjParams[4] );
     548                 :     }
     549               5 :     else if( EQUALN( pszProj.c_str(), "Lambert Cylind EqualArea", 24 ) )
     550                 :     {
     551                 :         // Latitude_Of_True_Scale used for dfStdP1 ?
     552               0 :         oSRS.SetProjCS("Lambert Conformal Conic");
     553                 :         oSRS.SetCEA(  padfPrjParams[10], 
     554                 :                         padfPrjParams[6], 
     555               0 :                         padfPrjParams[3], padfPrjParams[4] );
     556                 :     }
     557               5 :     else if( EQUALN( pszProj.c_str(), "Mercator", 8 ) )
     558                 :     {
     559                 :         // use 0 for CenterLat, scale is computed from the 
     560                 :         // Latitude_Of_True_Scale
     561               0 :         scaleFromLATTS( pszEllips, padfPrjParams[10], padfPrjParams[9] );
     562               0 :         oSRS.SetProjCS("Mercator");
     563                 :         oSRS.SetMercator( 0, padfPrjParams[6], 
     564                 :                                 padfPrjParams[9], 
     565               0 :                                 padfPrjParams[3], padfPrjParams[4] );
     566                 :     }
     567               5 :     else if( EQUALN( pszProj.c_str(), "Miller", 6 ) )
     568                 :     {
     569                 :         // use 0 for CenterLat
     570               0 :         oSRS.SetProjCS("Miller");
     571                 :         oSRS.SetMC( 0, padfPrjParams[6], 
     572               0 :                         padfPrjParams[3], padfPrjParams[4] );
     573                 :     }
     574               5 :     else if( EQUALN( pszProj.c_str(), "Mollweide", 9 ) )
     575                 :     {
     576               0 :         oSRS.SetProjCS("Mollweide");
     577                 :         oSRS.SetMollweide(  padfPrjParams[6], 
     578               0 :                                 padfPrjParams[3], padfPrjParams[4] );
     579                 :     }
     580               5 :     else if( EQUALN( pszProj.c_str(), "Orthographic", 12 ) )
     581                 :     {
     582               0 :         oSRS.SetProjCS("Orthographic");
     583                 :         oSRS.SetOrthographic (  padfPrjParams[5], padfPrjParams[6], 
     584               0 :                                 padfPrjParams[3], padfPrjParams[4] );
     585                 :     }
     586               5 :     else if( EQUALN( pszProj.c_str(), "Plate Carree", 12 ) ||
     587                 :              EQUALN( pszProj.c_str(), "Plate Rectangle", 15 ))
     588                 :     {
     589                 :         // set 0.0 for CenterLat for Plate Carree projection
     590                 :         // skipp Latitude_Of_True_Scale for Plate Rectangle projection definition
     591               0 :         oSRS.SetProjCS(pszProj.c_str());        
     592                 :         oSRS.SetEquirectangular(  padfPrjParams[5], padfPrjParams[6], 
     593               0 :                                         padfPrjParams[3], padfPrjParams[4] );
     594                 :     }
     595               5 :     else if( EQUALN( pszProj.c_str(), "PolyConic", 9 ) )
     596                 :     {
     597                 :         // skipp scale factor
     598               0 :         oSRS.SetProjCS("PolyConic");
     599                 :         oSRS.SetPolyconic(  padfPrjParams[5], padfPrjParams[6], 
     600               0 :                                 padfPrjParams[3], padfPrjParams[4] );
     601                 :     }
     602               5 :     else if( EQUALN( pszProj.c_str(), "Robinson", 8 ) )
     603                 :     {
     604               0 :         oSRS.SetProjCS("Robinson");
     605                 :         oSRS.SetRobinson( padfPrjParams[6],
     606               0 :                                 padfPrjParams[3], padfPrjParams[4] );
     607                 :     }
     608               5 :     else if( EQUALN( pszProj.c_str(), "Sinusoidal", 10 ) )
     609                 :     {
     610               0 :         oSRS.SetProjCS("Sinusoidal"); 
     611                 :         oSRS.SetSinusoidal( padfPrjParams[6], 
     612               0 :                                 padfPrjParams[3], padfPrjParams[4] );
     613                 :     }
     614               5 :     else if( EQUALN( pszProj.c_str(), "Stereographic", 13 ) )
     615                 :     {
     616               0 :         oSRS.SetProjCS("Stereographic");  
     617                 :         oSRS.SetStereographic(  padfPrjParams[5], padfPrjParams[6],
     618                 :                                 padfPrjParams[9],
     619               0 :                                 padfPrjParams[3], padfPrjParams[4] );
     620                 :   
     621                 :     }
     622               5 :     else if( EQUALN( pszProj.c_str(), "Transverse Mercator", 19 ) )
     623                 :     {
     624               0 :         oSRS.SetProjCS("Transverse Mercator");  
     625                 :         oSRS.SetStereographic(  padfPrjParams[5], padfPrjParams[6],
     626                 :                                 padfPrjParams[9],
     627               0 :                                 padfPrjParams[3], padfPrjParams[4] );
     628                 :     }
     629               5 :     else if( EQUALN( pszProj.c_str(), "UTM", 3 ) )
     630                 :     {
     631               5 :         string pszNH = ReadElement("Projection", "Northern Hemisphere", csyFileName);
     632               5 :         oSRS.SetProjCS("UTM");
     633               5 :         if( EQUALN( pszNH.c_str(), "Yes", 3 ) )
     634               4 :             oSRS.SetUTM( (int) padfPrjParams[11], 1);  
     635                 :         else
     636               1 :             oSRS.SetUTM( (int) padfPrjParams[11], 0);  
     637                 :     }
     638               0 :     else if( EQUALN( pszProj.c_str(), "VanderGrinten", 13 ) )
     639                 :     {
     640                 :         oSRS.SetVDG(  padfPrjParams[6],
     641               0 :                         padfPrjParams[3], padfPrjParams[4] );
     642                 :     }
     643               0 :     else if( EQUALN( pszProj.c_str(), "GeoStationary Satellite", 23 ) )
     644                 :     {
     645                 :         oSRS.SetGEOS( padfPrjParams[6], 
     646                 :                       padfPrjParams[12], 
     647                 :                       padfPrjParams[3], 
     648               0 :                       padfPrjParams[4] );
     649                 :     }
     650               0 :     else if( EQUALN( pszProj.c_str(), "MSG Perspective", 15 ) )
     651                 :     {
     652                 :         oSRS.SetGEOS( padfPrjParams[6], 
     653                 :                       padfPrjParams[12], 
     654                 :                       padfPrjParams[3], 
     655               0 :                       padfPrjParams[4] );
     656                 :     }
     657                 :     else
     658                 :     {
     659               0 :         oSRS.SetLocalCS( pszProj.c_str() );
     660                 :     }
     661                 : /* -------------------------------------------------------------------- */
     662                 : /*      Try to translate the datum/spheroid.                            */
     663                 : /* -------------------------------------------------------------------- */
     664                 : 
     665               5 :     if ( !oSRS.IsLocal() )
     666                 :     {
     667               5 :         const IlwisDatums   *piwDatum = iwDatums;
     668                 : 
     669                 :         // Search for matching datum
     670             227 :         while ( piwDatum->pszIlwisDatum )
     671                 :         {
     672             222 :             if( EQUALN( pszDatum.c_str(), piwDatum->pszIlwisDatum, strlen(piwDatum->pszIlwisDatum) ) )
     673                 :             {
     674               5 :                 OGRSpatialReference oOGR;
     675               5 :                 oOGR.importFromEPSG( piwDatum->nEPSGCode );
     676               5 :                 oSRS.CopyGeogCSFrom( &oOGR );
     677               5 :                 break;
     678                 :             }
     679             217 :             piwDatum++;
     680                 :         } //end of searchong for matching datum
     681                 : 
     682                 : 
     683                 : /* -------------------------------------------------------------------- */
     684                 : /*      If no matching for datum definition, fetch info about an        */
     685                 : /*      ellipsoid.  semi major axis is always returned in meters        */ 
     686                 : /* -------------------------------------------------------------------- */
     687               5 :         const IlwisEllips *piwEllips =  iwEllips;
     688               5 :         if (pszEllips.length() == 0)
     689               1 :             pszEllips="Sphere";
     690               5 :         if ( !piwDatum->pszIlwisDatum )  
     691                 :                                          
     692                 :         {
     693               0 :             while ( piwEllips->pszIlwisEllips )
     694                 :             {
     695               0 :                 if( EQUALN( pszEllips.c_str(), piwEllips->pszIlwisEllips, strlen(piwEllips->pszIlwisEllips) ) )
     696                 :                 {
     697               0 :                     double dfSemiMajor = piwEllips->semiMajor;
     698               0 :                     if( EQUALN( pszEllips.c_str(), "Sphere", 6 ) && padfPrjParams[0] != 0 )
     699                 :                     { 
     700               0 :                         dfSemiMajor = padfPrjParams[0];
     701                 :                     }
     702                 :                     oSRS.SetGeogCS( CPLSPrintf(
     703                 :                                         "Unknown datum based upon the %s ellipsoid",
     704                 :                                         piwEllips->pszIlwisEllips ),
     705                 :                                     CPLSPrintf(
     706                 :                                         "Not specified (based on %s spheroid)",
     707                 :                                         piwEllips->pszIlwisEllips ),
     708                 :                                     piwEllips->pszIlwisEllips, 
     709                 :                                     dfSemiMajor,
     710                 :                                     piwEllips->invFlattening,
     711               0 :                                     NULL, 0.0, NULL, 0.0 );
     712               0 :                     oSRS.SetAuthority( "SPHEROID", "EPSG", piwEllips->nEPSGCode );
     713                 :                     
     714               0 :                     break;
     715                 :                 }
     716               0 :                 piwEllips++;
     717                 :             } //end of searching for matching ellipsoid
     718                 :         } 
     719                 :         
     720                 : /* -------------------------------------------------------------------- */
     721                 : /*      If no matching for ellipsoid definition, fetch info about an    */
     722                 : /*      user defined ellipsoid. If cannot find, default to WGS 84       */
     723                 : /* -------------------------------------------------------------------- */
     724               5 :         if ( !piwEllips->pszIlwisEllips )      
     725                 :         {
     726                 : 
     727               0 :             if( EQUALN( pszEllips.c_str(), "User Defined", 12 ) )
     728                 :             {
     729                 :                 
     730                 :                 oSRS.SetGeogCS( "Unknown datum based upon the custom ellipsoid",
     731                 :                                 "Not specified (based on custom ellipsoid)",
     732                 :                                 "Custom ellipsoid",
     733                 :                                 padfPrjParams[0], padfPrjParams[2],
     734               0 :                                 NULL, 0, NULL, 0 );
     735                 :             }
     736                 :             else
     737                 :             {
     738                 :                 //if cannot find the user defined ellips, default to WGS84
     739               0 :                 oSRS.SetWellKnownGeogCS( "WGS84" );
     740                 :             }
     741                 :         }
     742                 : 
     743                 :     } // end of if ( !IsLocal() )
     744                 :     
     745                 : /* -------------------------------------------------------------------- */
     746                 : /*      Units translation                                          */
     747                 : /* -------------------------------------------------------------------- */
     748               5 :     if( oSRS.IsLocal() || oSRS.IsProjected() )
     749                 :     {
     750               5 :         oSRS.SetLinearUnits( SRS_UL_METER, 1.0 );
     751                 :     }
     752               5 :     oSRS.FixupOrdering();
     753               5 :     CPLFree(pszProjection);
     754               5 :     oSRS.exportToWkt( &pszProjection );
     755                 :     
     756                 : 
     757               5 :     return CE_None;
     758                 : }
     759                 : 
     760               0 : void WriteFalseEastNorth(string csFileName, OGRSpatialReference oSRS)
     761                 : {
     762                 :       WriteElement("Projection", ILW_False_Easting, csFileName, 
     763               0 :                     oSRS.GetNormProjParm(SRS_PP_FALSE_EASTING, 0.0));
     764                 :       WriteElement("Projection", ILW_False_Northing, csFileName, 
     765               0 :                     oSRS.GetNormProjParm(SRS_PP_FALSE_NORTHING, 0.0));
     766               0 : }
     767                 : 
     768               0 : void WriteProjectionName(string csFileName, string stProjection)
     769                 : {
     770               0 :     WriteElement("CoordSystem", "Type", csFileName, "Projection");
     771               0 :     WriteElement("CoordSystem", "Projection", csFileName, stProjection);
     772               0 : }
     773                 : 
     774               2 : void WriteUTM(string csFileName, OGRSpatialReference oSRS)
     775                 : {
     776                 :     int bNorth, nZone;
     777                 : 
     778               2 :     nZone = oSRS.GetUTMZone( &bNorth );
     779               2 :     WriteElement("CoordSystem", "Type", csFileName, "Projection");
     780               4 :     WriteElement("CoordSystem", "Projection", csFileName, "UTM");
     781               2 :     if (bNorth)
     782               2 :         WriteElement("Projection", "Northern Hemisphere", csFileName, "Yes");
     783                 :     else
     784               0 :         WriteElement("Projection", "Northern Hemisphere", csFileName, "No");
     785               2 :     WriteElement("Projection", "Zone", csFileName, nZone);
     786               2 : }
     787                 : 
     788               0 : void WriteAlbersConicEqualArea(string csFileName, OGRSpatialReference oSRS)
     789                 : {
     790               0 :     WriteProjectionName(csFileName, "Albers EqualArea Conic");
     791               0 :     WriteFalseEastNorth(csFileName, oSRS);
     792                 :     WriteElement("Projection", ILW_Central_Meridian, csFileName, 
     793               0 :                  oSRS.GetNormProjParm(SRS_PP_CENTRAL_MERIDIAN, 0.0));
     794                 :     WriteElement("Projection", ILW_Central_Parallel, csFileName, 
     795               0 :                  oSRS.GetNormProjParm(SRS_PP_LATITUDE_OF_ORIGIN, 0.0));
     796                 :     WriteElement("Projection", ILW_Standard_Parallel_1, csFileName, 
     797               0 :                  oSRS.GetNormProjParm(SRS_PP_STANDARD_PARALLEL_1, 0.0));
     798                 :     WriteElement("Projection", ILW_Standard_Parallel_2, csFileName, 
     799               0 :                  oSRS.GetNormProjParm(SRS_PP_STANDARD_PARALLEL_2, 0.0));
     800               0 : }
     801               0 : void WriteAzimuthalEquidistant(string csFileName, OGRSpatialReference oSRS)
     802                 : {
     803               0 :     WriteProjectionName(csFileName, "Azimuthal Equidistant");
     804               0 :     WriteFalseEastNorth(csFileName, oSRS);
     805                 :     WriteElement("Projection", ILW_Central_Meridian, csFileName, 
     806               0 :                  oSRS.GetNormProjParm(SRS_PP_CENTRAL_MERIDIAN, 0.0));
     807                 :     WriteElement("Projection", ILW_Central_Parallel, csFileName, 
     808               0 :                  oSRS.GetNormProjParm(SRS_PP_LATITUDE_OF_ORIGIN, 0.0));
     809               0 :     WriteElement("Projection", ILW_Scale_Factor, csFileName, "1.0000000000"); 
     810               0 : }
     811               0 : void WriteCylindricalEqualArea(string csFileName, OGRSpatialReference oSRS)
     812                 : {
     813               0 :     WriteProjectionName(csFileName, "Central Cylindrical");
     814               0 :     WriteFalseEastNorth(csFileName, oSRS);
     815                 :     WriteElement("Projection", ILW_Central_Meridian, csFileName, 
     816               0 :                  oSRS.GetNormProjParm(SRS_PP_CENTRAL_MERIDIAN, 0.0));
     817               0 : }
     818                 : 
     819               0 : void WriteCassiniSoldner(string csFileName, OGRSpatialReference oSRS)
     820                 : {
     821               0 :     WriteProjectionName(csFileName, "Cassini");
     822               0 :     WriteFalseEastNorth(csFileName, oSRS);
     823                 :     WriteElement("Projection", ILW_Central_Meridian, csFileName, 
     824               0 :                  oSRS.GetNormProjParm(SRS_PP_CENTRAL_MERIDIAN, 0.0));
     825                 :     WriteElement("Projection", ILW_Latitude_True_Scale, csFileName, 
     826               0 :                  oSRS.GetNormProjParm(SRS_PP_LATITUDE_OF_ORIGIN, 0.0));
     827               0 :     WriteElement("Projection", ILW_Scale_Factor, csFileName, "1.0000000000"); 
     828               0 : }
     829                 : 
     830               0 : void WriteStereographic(string csFileName, OGRSpatialReference oSRS)
     831                 : {
     832               0 :     WriteProjectionName(csFileName, "Stereographic");
     833               0 :     WriteFalseEastNorth(csFileName, oSRS);
     834                 :     WriteElement("Projection", ILW_Central_Meridian, csFileName, 
     835               0 :                  oSRS.GetNormProjParm(SRS_PP_CENTRAL_MERIDIAN, 0.0));
     836                 :     WriteElement("Projection", ILW_Central_Parallel, csFileName, 
     837               0 :                  oSRS.GetNormProjParm(SRS_PP_LATITUDE_OF_ORIGIN, 0.0));
     838                 :     WriteElement("Projection", ILW_Scale_Factor, csFileName, 
     839               0 :                  oSRS.GetNormProjParm(SRS_PP_SCALE_FACTOR, 0.0)); 
     840               0 : }
     841                 : 
     842               0 : void WriteEquidistantConic(string csFileName, OGRSpatialReference oSRS)
     843                 : {
     844               0 :     WriteProjectionName(csFileName, "Equidistant Conic");
     845               0 :     WriteFalseEastNorth(csFileName, oSRS);
     846                 :     WriteElement("Projection", ILW_Central_Meridian, csFileName, 
     847               0 :                  oSRS.GetNormProjParm(SRS_PP_CENTRAL_MERIDIAN, 0.0));
     848                 :     WriteElement("Projection", ILW_Central_Parallel, csFileName, 
     849               0 :                  oSRS.GetNormProjParm(SRS_PP_LATITUDE_OF_ORIGIN, 0.0));
     850                 :     WriteElement("Projection", ILW_Standard_Parallel_1, csFileName, 
     851               0 :                  oSRS.GetNormProjParm(SRS_PP_STANDARD_PARALLEL_1, 0.0)); 
     852                 :     WriteElement("Projection", ILW_Standard_Parallel_2, csFileName, 
     853               0 :                  oSRS.GetNormProjParm(SRS_PP_STANDARD_PARALLEL_2, 0.0));
     854               0 : }
     855                 : 
     856               0 : void WriteTransverseMercator(string csFileName, OGRSpatialReference oSRS)
     857                 : {
     858               0 :     WriteProjectionName(csFileName, "Transverse Mercator");
     859               0 :     WriteFalseEastNorth(csFileName, oSRS);
     860                 :     WriteElement("Projection", ILW_Central_Meridian, csFileName, 
     861               0 :                  oSRS.GetNormProjParm(SRS_PP_CENTRAL_MERIDIAN, 0.0));
     862                 :     WriteElement("Projection", ILW_Central_Parallel, csFileName, 
     863               0 :                  oSRS.GetNormProjParm(SRS_PP_LATITUDE_OF_ORIGIN, 0.0));
     864                 :     WriteElement("Projection", ILW_Scale_Factor, csFileName, 
     865               0 :                  oSRS.GetNormProjParm(SRS_PP_SCALE_FACTOR, 0.0)); 
     866               0 : }
     867                 : 
     868               0 : void WriteGnomonic(string csFileName, OGRSpatialReference oSRS)
     869                 : {
     870               0 :     WriteProjectionName(csFileName, "Gnomonic");
     871               0 :     WriteFalseEastNorth(csFileName, oSRS);
     872                 :     WriteElement("Projection", ILW_Central_Meridian, csFileName, 
     873               0 :                  oSRS.GetNormProjParm(SRS_PP_CENTRAL_MERIDIAN, 0.0));
     874                 :     WriteElement("Projection", ILW_Central_Parallel, csFileName, 
     875               0 :                  oSRS.GetNormProjParm(SRS_PP_LATITUDE_OF_ORIGIN, 0.0));
     876               0 : }
     877                 : 
     878               0 : void WriteLambertConformalConic(string csFileName, OGRSpatialReference oSRS)
     879                 : {
     880               0 :     WriteProjectionName(csFileName, "Lambert Conformal Conic");
     881               0 :     WriteFalseEastNorth(csFileName, oSRS);
     882                 :     WriteElement("Projection", ILW_Central_Meridian, csFileName, 
     883               0 :                  oSRS.GetNormProjParm(SRS_PP_CENTRAL_MERIDIAN, 0.0));
     884                 :     WriteElement("Projection", ILW_Central_Parallel, csFileName, 
     885               0 :                  oSRS.GetNormProjParm(SRS_PP_LATITUDE_OF_ORIGIN, 0.0));
     886               0 :     WriteElement("Projection", ILW_Scale_Factor, csFileName, "1.0000000000"); 
     887               0 : }
     888                 : 
     889               0 : void WriteLambertConformalConic2SP(string csFileName, OGRSpatialReference oSRS)
     890                 : {
     891               0 :     WriteProjectionName(csFileName, "Lambert Conformal Conic");
     892               0 :     WriteFalseEastNorth(csFileName, oSRS);
     893                 :     WriteElement("Projection", ILW_Central_Meridian, csFileName, 
     894               0 :                  oSRS.GetNormProjParm(SRS_PP_CENTRAL_MERIDIAN, 0.0));
     895                 :     WriteElement("Projection", ILW_Central_Parallel, csFileName, 
     896               0 :                  oSRS.GetNormProjParm(SRS_PP_LATITUDE_OF_ORIGIN, 0.0));
     897               0 :     WriteElement("Projection", ILW_Scale_Factor, csFileName, "1.0000000000"); 
     898                 :     WriteElement("Projection", ILW_Standard_Parallel_1, csFileName, 
     899               0 :                  oSRS.GetNormProjParm(SRS_PP_STANDARD_PARALLEL_1, 0.0)); 
     900                 :     WriteElement("Projection", ILW_Standard_Parallel_2, csFileName, 
     901               0 :                  oSRS.GetNormProjParm(SRS_PP_STANDARD_PARALLEL_2, 0.0));
     902               0 : }
     903                 : 
     904               0 : void WriteLambertAzimuthalEqualArea(string csFileName, OGRSpatialReference oSRS)
     905                 : {
     906               0 :     WriteProjectionName(csFileName, "Lambert Azimuthal EqualArea");
     907               0 :     WriteFalseEastNorth(csFileName, oSRS);
     908                 :     WriteElement("Projection", ILW_Central_Meridian, csFileName, 
     909               0 :                  oSRS.GetNormProjParm(SRS_PP_CENTRAL_MERIDIAN, 0.0));
     910                 :     WriteElement("Projection", ILW_Central_Parallel, csFileName, 
     911               0 :                  oSRS.GetNormProjParm(SRS_PP_LATITUDE_OF_ORIGIN, 0.0));
     912               0 : }
     913                 : 
     914               0 : void WriteMercator_1SP(string csFileName, OGRSpatialReference oSRS)
     915                 : {
     916               0 :     WriteProjectionName(csFileName, "Mercator");
     917               0 :     WriteFalseEastNorth(csFileName, oSRS);
     918                 :     WriteElement("Projection", ILW_Central_Meridian, csFileName, 
     919               0 :                  oSRS.GetNormProjParm(SRS_PP_CENTRAL_MERIDIAN, 0.0));
     920                 :     WriteElement("Projection", ILW_Latitude_True_Scale, csFileName, 
     921               0 :                  oSRS.GetNormProjParm(SRS_PP_LATITUDE_OF_ORIGIN, 0.0));
     922               0 : }
     923                 : 
     924               0 : void WriteMillerCylindrical(string csFileName, OGRSpatialReference oSRS)
     925                 : {
     926               0 :     WriteProjectionName(csFileName, "Miller");
     927               0 :     WriteFalseEastNorth(csFileName, oSRS);
     928                 :     WriteElement("Projection", ILW_Central_Meridian, csFileName, 
     929               0 :                  oSRS.GetNormProjParm(SRS_PP_CENTRAL_MERIDIAN, 0.0));
     930               0 : }
     931                 : 
     932               0 : void WriteMolleweide(string csFileName, OGRSpatialReference oSRS)
     933                 : {
     934               0 :     WriteProjectionName(csFileName, "Mollweide");
     935               0 :     WriteFalseEastNorth(csFileName, oSRS);
     936                 :     WriteElement("Projection", ILW_Central_Meridian, csFileName, 
     937               0 :                  oSRS.GetNormProjParm(SRS_PP_CENTRAL_MERIDIAN, 0.0));
     938               0 : }
     939                 : 
     940               0 : void WriteOrthographic(string csFileName, OGRSpatialReference oSRS)
     941                 : {
     942               0 :     WriteProjectionName(csFileName, "Orthographic");
     943               0 :     WriteFalseEastNorth(csFileName, oSRS);
     944                 :     WriteElement("Projection", ILW_Central_Meridian, csFileName, 
     945               0 :                  oSRS.GetNormProjParm(SRS_PP_CENTRAL_MERIDIAN, 0.0));
     946                 :     WriteElement("Projection", ILW_Central_Parallel, csFileName, 
     947               0 :                  oSRS.GetNormProjParm(SRS_PP_LATITUDE_OF_ORIGIN, 0.0));
     948               0 : }
     949                 : 
     950               0 : void WritePlateRectangle(string csFileName, OGRSpatialReference oSRS)
     951                 : {
     952               0 :     WriteProjectionName(csFileName, "Plate Rectangle");
     953               0 :     WriteFalseEastNorth(csFileName, oSRS);
     954                 :     WriteElement("Projection", ILW_Central_Meridian, csFileName, 
     955               0 :                  oSRS.GetNormProjParm(SRS_PP_CENTRAL_MERIDIAN, 0.0));
     956                 :     WriteElement("Projection", ILW_Central_Parallel, csFileName, 
     957               0 :                  oSRS.GetNormProjParm(SRS_PP_LATITUDE_OF_ORIGIN, 0.0));
     958               0 :     WriteElement("Projection", ILW_Latitude_True_Scale, csFileName, "0.0000000000"); 
     959               0 : }
     960                 : 
     961               0 : void WritePolyConic(string csFileName, OGRSpatialReference oSRS)
     962                 : {
     963               0 :     WriteProjectionName(csFileName, "PolyConic");
     964               0 :     WriteFalseEastNorth(csFileName, oSRS);
     965                 :     WriteElement("Projection", ILW_Central_Meridian, csFileName, 
     966               0 :                  oSRS.GetNormProjParm(SRS_PP_CENTRAL_MERIDIAN, 0.0));
     967                 :     WriteElement("Projection", ILW_Central_Parallel, csFileName, 
     968               0 :                  oSRS.GetNormProjParm(SRS_PP_LATITUDE_OF_ORIGIN, 0.0));
     969               0 :     WriteElement("Projection", ILW_Scale_Factor, csFileName, "1.0000000000"); 
     970               0 : }
     971                 : 
     972               0 : void WriteRobinson(string csFileName, OGRSpatialReference oSRS)
     973                 : {
     974               0 :     WriteProjectionName(csFileName, "Robinson");
     975               0 :     WriteFalseEastNorth(csFileName, oSRS);
     976                 :     WriteElement("Projection", ILW_Central_Meridian, csFileName, 
     977               0 :                  oSRS.GetNormProjParm(SRS_PP_CENTRAL_MERIDIAN, 0.0));
     978               0 : }
     979                 : 
     980               0 : void WriteSinusoidal(string csFileName, OGRSpatialReference oSRS)
     981                 : {
     982               0 :     WriteProjectionName(csFileName, "Sinusoidal");
     983               0 :     WriteFalseEastNorth(csFileName, oSRS);
     984                 :     WriteElement("Projection", ILW_Central_Meridian, csFileName, 
     985               0 :                  oSRS.GetNormProjParm(SRS_PP_CENTRAL_MERIDIAN, 0.0));
     986               0 : }
     987                 : 
     988               0 : void WriteVanderGrinten(string csFileName, OGRSpatialReference oSRS)
     989                 : {
     990               0 :     WriteProjectionName(csFileName, "VanderGrinten");
     991               0 :     WriteFalseEastNorth(csFileName, oSRS);
     992                 :     WriteElement("Projection", ILW_Central_Meridian, csFileName, 
     993               0 :                  oSRS.GetNormProjParm(SRS_PP_CENTRAL_MERIDIAN, 0.0));
     994               0 : }
     995                 : 
     996               0 : void WriteGeoStatSat(string csFileName, OGRSpatialReference oSRS)
     997                 : {
     998               0 :     WriteProjectionName(csFileName, "GeoStationary Satellite");
     999               0 :     WriteFalseEastNorth(csFileName, oSRS);
    1000                 :     WriteElement("Projection", ILW_Central_Meridian, csFileName, 
    1001               0 :                  oSRS.GetNormProjParm(SRS_PP_CENTRAL_MERIDIAN, 0.0));
    1002               0 :     WriteElement("Projection", ILW_Scale_Factor, csFileName, "1.0000000000"); 
    1003                 :     WriteElement("Projection", ILW_Height_Persp_Center, csFileName, 
    1004               0 :                  oSRS.GetNormProjParm(SRS_PP_SATELLITE_HEIGHT, 35785831.0));
    1005               0 : }
    1006                 : 
    1007                 : /************************************************************************/
    1008                 : /*                          WriteProjection()                           */
    1009                 : /************************************************************************/
    1010                 : /**
    1011                 :  * Export coordinate system in ILWIS projection definition.
    1012                 :  *
    1013                 :  * Converts the loaded coordinate reference system into ILWIS projection
    1014                 :  * definition to the extent possible. 
    1015                 :  */ 
    1016              31 : CPLErr ILWISDataset::WriteProjection() 
    1017                 : 
    1018                 : {
    1019              31 :     OGRSpatialReference oSRS;
    1020              31 :     OGRSpatialReference *poGeogSRS = NULL;
    1021                 :     int                 bHaveSRS;
    1022              31 :     char    *pszP = pszProjection;
    1023                 :     
    1024              31 :     string csFileName = CPLResetExtension(osFileName, "csy" );
    1025              62 :     string pszBaseName = string(CPLGetBasename( osFileName ));
    1026              62 :     string pszPath = string(CPLGetPath( osFileName ));
    1027              62 :     bool fProjection = ((strlen(pszProjection)>0) && (pszProjection != NULL));
    1028              31 :     if( fProjection && (oSRS.importFromWkt( &pszP ) == OGRERR_NONE) )
    1029                 :     {
    1030              31 :         bHaveSRS = TRUE;
    1031                 :     }
    1032                 :     else
    1033               0 :         bHaveSRS = FALSE;
    1034                 :     
    1035              31 :     const IlwisDatums   *piwDatum = iwDatums;
    1036              31 :     string pszEllips;
    1037              31 :     string pszDatum;
    1038              31 :     string pszProj;
    1039                 :     
    1040                 : /* -------------------------------------------------------------------- */
    1041                 : /*      Collect datum/ellips information.                                      */
    1042                 : /* -------------------------------------------------------------------- */
    1043              31 :     if( bHaveSRS )
    1044                 :     {
    1045              31 :         poGeogSRS = oSRS.CloneGeogCS();
    1046                 :     }
    1047                 : 
    1048              31 :     string grFileName = CPLResetExtension(osFileName, "grf" );
    1049              31 :     string csy;
    1050              31 :     if( poGeogSRS )
    1051                 :     {
    1052              31 :         csy = pszBaseName + ".csy";
    1053                 :         
    1054              31 :         WriteElement("Ilwis", "Type", csFileName, "CoordSystem");
    1055              62 :         pszDatum = poGeogSRS->GetAttrValue( "GEOGCS|DATUM" );
    1056                 : 
    1057                 :         /* WKT to ILWIS translation */
    1058            2089 :         while ( piwDatum->pszWKTDatum)
    1059                 :         {
    1060            2058 :             if( EQUALN( pszDatum.c_str(), piwDatum->pszWKTDatum, strlen(piwDatum->pszWKTDatum) ) )
    1061                 :             {
    1062              31 :                 WriteElement("CoordSystem", "Datum", csFileName, piwDatum->pszIlwisDatum);
    1063              31 :                 break;
    1064                 :             }
    1065            2027 :             piwDatum++;
    1066                 :         } //end of searchong for matching datum
    1067              31 :         WriteElement("CoordSystem", "Width", csFileName, 28);
    1068                 :         double a, b, f;
    1069              31 :         pszEllips = poGeogSRS->GetAttrValue( "GEOGCS|DATUM|SPHEROID" );
    1070              31 :         a = poGeogSRS->GetSemiMajor();
    1071              31 :         b = poGeogSRS->GetSemiMinor();
    1072              31 :         f = poGeogSRS->GetInvFlattening();
    1073              31 :         WriteElement("CoordSystem", "Ellipsoid", csFileName, "User Defined");
    1074              62 :         WriteElement("Ellipsoid", "a", csFileName, a);
    1075              31 :         WriteElement("Ellipsoid", "1/f", csFileName, f);
    1076                 :     }
    1077                 :     else
    1078               0 :         csy = "unknown.csy";
    1079                 : 
    1080                 : /* -------------------------------------------------------------------- */
    1081                 : /*  Determine to write a geo-referencing file for the dataset to create */
    1082                 : /* -------------------------------------------------------------------- */
    1083              31 :     if( adfGeoTransform[0] != 0.0 || adfGeoTransform[1] != 1.0
    1084                 :         || adfGeoTransform[2] != 0.0 || adfGeoTransform[3] != 0.0
    1085                 :         || adfGeoTransform[4] != 0.0 || fabs(adfGeoTransform[5]) != 1.0)
    1086              31 :         WriteElement("GeoRef", "CoordSystem", grFileName, csy);
    1087                 : 
    1088                 : /* -------------------------------------------------------------------- */
    1089                 : /*  Recognise various projections.                                      */
    1090                 : /* -------------------------------------------------------------------- */
    1091              31 :     const char * pszProjName = NULL;
    1092                 : 
    1093              31 :     if( bHaveSRS )
    1094              31 :         pszProjName = oSRS.GetAttrValue( "PROJCS|PROJECTION" );
    1095                 : 
    1096              31 :     if( pszProjName == NULL )
    1097                 :     {
    1098              29 :         if( bHaveSRS && oSRS.IsGeographic() )
    1099                 :         {
    1100              29 :             WriteElement("CoordSystem", "Type", csFileName, "LatLon");
    1101                 :         }
    1102                 :     }
    1103               2 :     else if( oSRS.GetUTMZone( NULL ) != 0 )
    1104                 :     {
    1105               2 :         WriteUTM(csFileName, oSRS);
    1106                 :     }
    1107               0 :     else if( EQUAL(pszProjName,SRS_PT_ALBERS_CONIC_EQUAL_AREA) )
    1108                 :     {
    1109               0 :         WriteAlbersConicEqualArea(csFileName, oSRS);
    1110                 :     }
    1111               0 :     else if( EQUAL(pszProjName,SRS_PT_AZIMUTHAL_EQUIDISTANT) )
    1112                 :     {
    1113               0 :         WriteAzimuthalEquidistant(csFileName, oSRS);
    1114                 :     }
    1115               0 :     else if( EQUAL(pszProjName,SRS_PT_CYLINDRICAL_EQUAL_AREA) )
    1116                 :     {
    1117               0 :         WriteCylindricalEqualArea(csFileName, oSRS);
    1118                 :     }
    1119               0 :     else if( EQUAL(pszProjName,SRS_PT_CASSINI_SOLDNER) )
    1120                 :     {
    1121               0 :         WriteCassiniSoldner(csFileName, oSRS);
    1122                 :     }
    1123               0 :     else if( EQUAL(pszProjName,SRS_PT_STEREOGRAPHIC) )
    1124                 :     {
    1125               0 :         WriteStereographic(csFileName, oSRS);   
    1126                 :     }
    1127               0 :     else if( EQUAL(pszProjName,SRS_PT_EQUIDISTANT_CONIC) )
    1128                 :     {
    1129               0 :         WriteEquidistantConic(csFileName, oSRS);
    1130                 :     }
    1131               0 :     else if( EQUAL(pszProjName,SRS_PT_TRANSVERSE_MERCATOR) )
    1132                 :     {
    1133               0 :         WriteTransverseMercator(csFileName, oSRS);
    1134                 :     }
    1135               0 :     else if( EQUAL(pszProjName,SRS_PT_GNOMONIC) )
    1136                 :     {
    1137               0 :         WriteGnomonic(csFileName, oSRS);
    1138                 :     }
    1139               0 :     else if( EQUAL(pszProjName,"Lambert_Conformal_Conic") )
    1140                 :     {
    1141               0 :         WriteLambertConformalConic(csFileName, oSRS);
    1142                 :     }
    1143               0 :     else if( EQUAL(pszProjName,SRS_PT_LAMBERT_CONFORMAL_CONIC_1SP) )
    1144                 :     {
    1145               0 :         WriteLambertConformalConic(csFileName, oSRS);
    1146                 :     }
    1147               0 :     else if( EQUAL(pszProjName,SRS_PT_LAMBERT_CONFORMAL_CONIC_2SP) )
    1148                 :     {
    1149               0 :         WriteLambertConformalConic2SP(csFileName, oSRS);
    1150                 :     }
    1151               0 :     else if( EQUAL(pszProjName,SRS_PT_LAMBERT_AZIMUTHAL_EQUAL_AREA) )
    1152                 :     {
    1153               0 :         WriteLambertAzimuthalEqualArea(csFileName, oSRS);
    1154                 :     }
    1155               0 :     else if( EQUAL(pszProjName,SRS_PT_MERCATOR_1SP) )
    1156                 :     {
    1157               0 :         WriteMercator_1SP(csFileName, oSRS);
    1158                 :     }
    1159               0 :     else if( EQUAL(pszProjName,SRS_PT_MILLER_CYLINDRICAL) )
    1160                 :     {
    1161               0 :         WriteMillerCylindrical(csFileName, oSRS);
    1162                 :     }
    1163               0 :     else if( EQUAL(pszProjName,SRS_PT_MOLLWEIDE) )
    1164                 :     {
    1165               0 :         WriteMolleweide(csFileName, oSRS);
    1166                 :     }
    1167               0 :     else if( EQUAL(pszProjName,SRS_PT_ORTHOGRAPHIC) )
    1168                 :     {
    1169               0 :         WriteOrthographic(csFileName, oSRS);
    1170                 :     }
    1171               0 :     else if( EQUAL(pszProjName,SRS_PT_EQUIRECTANGULAR) )
    1172                 :     {
    1173               0 :         WritePlateRectangle(csFileName, oSRS);
    1174                 :     }
    1175               0 :     else if( EQUAL(pszProjName,SRS_PT_POLYCONIC) )
    1176                 :     {
    1177               0 :         WritePolyConic(csFileName, oSRS);
    1178                 :     }
    1179               0 :     else if( EQUAL(pszProjName,SRS_PT_ROBINSON) )
    1180                 :     {
    1181               0 :         WriteRobinson(csFileName, oSRS);
    1182                 :     }
    1183               0 :     else if( EQUAL(pszProjName,SRS_PT_SINUSOIDAL) )
    1184                 :     {
    1185               0 :         WriteSinusoidal(csFileName, oSRS);
    1186                 :     }
    1187               0 :     else if( EQUAL(pszProjName,SRS_PT_VANDERGRINTEN) )
    1188                 :     {
    1189               0 :         WriteVanderGrinten(csFileName, oSRS);  
    1190                 :     }
    1191               0 :     else if( EQUAL(pszProjName,SRS_PT_GEOSTATIONARY_SATELLITE) )
    1192                 :     {
    1193               0 :         WriteGeoStatSat(csFileName, oSRS);  
    1194                 :     }
    1195                 :     else
    1196                 :     {
    1197                 :         // Projection unknown by ILWIS
    1198                 :         
    1199                 :     }
    1200                 : 
    1201                 : /* -------------------------------------------------------------------- */
    1202                 : /*      Cleanup                                                         */
    1203                 : /* -------------------------------------------------------------------- */
    1204              31 :     if( poGeogSRS != NULL )
    1205              31 :         delete poGeogSRS;
    1206                 : 
    1207              31 :     return CE_None;
    1208                 : }
    1209                 : 

Generated by: LTP GCOV extension version 1.5