LCOV - code coverage report
Current view: directory - frmts/ilwis - ilwiscoordinatesystem.cpp (source / functions) Found Hit Coverage
Test: gdal_filtered.info Lines: 439 143 32.6 %
Date: 2010-01-09 Functions: 30 5 16.7 %

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

Generated by: LCOV version 1.7