LCOV - code coverage report
Current view: directory - frmts/ilwis - ilwiscoordinatesystem.cpp (source / functions) Found Hit Coverage
Test: gdal_filtered.info Lines: 438 143 32.6 %
Date: 2011-12-18 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                 : #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              58 :     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               5 :     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 void scaleFromLATTS( string sEllips, double phits, double &scale )
     356                 : {
     357               0 :     if( EQUALN( sEllips.c_str(), "Sphere", 6 ) ) 
     358                 :     {
     359               0 :         scale = cos(phits);
     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                 :     }
     378               0 : }
     379                 : 
     380                 : /************************************************************************/
     381                 : /*                          ReadProjection()                           */
     382                 : /************************************************************************/
     383                 : 
     384                 : /**
     385                 :  * Import coordinate system from ILWIS projection definition.
     386                 :  *
     387                 :  * The method will import projection definition in ILWIS, 
     388                 :  * It uses 13 parameters to define the coordinate system
     389                 :  * and datum/ellipsoid specieied in the padfPrjParams array. 
     390                 :  *
     391                 :  * @param padfPrjParams Array of 10 coordinate system parameters:
     392                 :  *
     393                 :  * [0]  Spheroid semi major axis
     394                 :  * [1]  Spheroid semi minor axis
     395                 :  * [2]  Spheroid inverse flattening
     396                 :  * [3]  False Easting
     397                 :  * [4]  False Northing
     398                 :  * [5]  Central Parallel // latitude_of_origin
     399                 :  * [6]  Central Meridian 
     400                 :  * [7]  First Standard Parallel
     401                 :  * [8]  Second Standard Parallel
     402                 :  * [9]  Scale Factor
     403                 :  * [10] Latitude_Of_True_Scale
     404                 :  * [11] Zone
     405                 :  * [12] Satellite Height
     406                 : **/ 
     407                 : 
     408               5 : CPLErr ILWISDataset::ReadProjection( string csyFileName )
     409                 : {
     410               5 :     string pszEllips;
     411               5 :     string pszDatum;
     412               5 :     string pszProj;
     413                 :     
     414                 :     //translate ILWIS pre-defined coordinate systems
     415               5 :     if( EQUALN( csyFileName.c_str(), "latlon.csy", 10 )) 
     416                 :     {
     417               0 :         pszProj = "LatLon";
     418               0 :         pszDatum = "";
     419               0 :         pszEllips = "Sphere";
     420                 :     } 
     421               5 :     else if ( EQUALN( csyFileName.c_str(), "LatlonWGS84.csy", 15 ))     
     422                 :     {
     423               0 :         pszProj = "LatLon";
     424               0 :         pszDatum = "WGS 1984";
     425               0 :         pszEllips = "WGS 84";
     426                 :     }
     427                 :     else
     428                 :     {
     429               5 :         pszProj = ReadElement("CoordSystem", "Type", csyFileName);
     430               5 :         if( !EQUALN( pszProj.c_str(), "LatLon", 7 ) )
     431               5 :             pszProj = ReadElement("CoordSystem", "Projection", csyFileName);
     432               5 :         pszDatum = ReadElement("CoordSystem", "Datum", csyFileName);
     433               5 :         pszEllips = ReadElement("CoordSystem", "Ellipsoid", csyFileName);
     434                 :     }
     435                 : 
     436                 : /* -------------------------------------------------------------------- */
     437                 : /*      Fetch array containing 13 coordinate system parameters          */
     438                 : /* -------------------------------------------------------------------- */
     439                 :     double     padfPrjParams[13];
     440               5 :     fetchParms(csyFileName, padfPrjParams);
     441                 :     
     442               5 :     OGRSpatialReference oSRS;
     443                 : /* -------------------------------------------------------------------- */
     444                 : /*      Operate on the basis of the projection name.                    */
     445                 : /* -------------------------------------------------------------------- */
     446               5 :     if( EQUALN( pszProj.c_str(), "LatLon", 7 ) )
     447                 :     {
     448                 :         //set datum later
     449                 :     }
     450               5 :     else if( EQUALN( pszProj.c_str(), "Albers EqualArea Conic", 22  ) )
     451                 :     {
     452               0 :         oSRS.SetProjCS("Albers EqualArea Conic");
     453                 :         oSRS.SetACEA( padfPrjParams[7], padfPrjParams[8],
     454                 :                       padfPrjParams[5], padfPrjParams[6],
     455               0 :                       padfPrjParams[3], padfPrjParams[4] );
     456                 :                  
     457                 :     }
     458               5 :     else if( EQUALN( pszProj.c_str(), "Azimuthal Equidistant", 21 ) )
     459                 :     {
     460               0 :         oSRS.SetProjCS("Azimuthal Equidistant");
     461                 :         oSRS.SetAE( padfPrjParams[5], padfPrjParams[6],
     462               0 :                     padfPrjParams[3], padfPrjParams[4] );
     463                 :     }
     464               5 :     else if( EQUALN( pszProj.c_str(), "Central Cylindrical", 19 ) )
     465                 :     {
     466                 :         //Use Central Parallel for dfStdP1
     467                 :         //padfPrjParams[5] is always to zero
     468               0 :         oSRS.SetProjCS("Central Cylindrical");
     469                 :         oSRS.SetCEA( padfPrjParams[5], padfPrjParams[6],
     470               0 :                      padfPrjParams[3], padfPrjParams[4] ); 
     471                 :     }
     472               5 :     else if( EQUALN( pszProj.c_str(), "Cassini", 7 ) )
     473                 :     {
     474                 :         //Use Latitude_Of_True_Scale for dfCenterLat 
     475                 :         //Scale Factor 1.0 should always be defined
     476               0 :         oSRS.SetProjCS("Cassini");
     477                 :         oSRS.SetCS(  padfPrjParams[10], padfPrjParams[6],  
     478               0 :                      padfPrjParams[3], padfPrjParams[4] );
     479                 :     }
     480               5 :     else if( EQUALN( pszProj.c_str(), "DutchRD", 7 ) )
     481                 :     {
     482               0 :         oSRS.SetProjCS("DutchRD");
     483                 :         oSRS.SetStereographic  (  52.156160556,  5.387638889,
     484                 :                                   0.9999079,  
     485               0 :                                   155000,  463000);
     486                 :                                    
     487                 :     }
     488               5 :     else if( EQUALN( pszProj.c_str(), "Equidistant Conic", 17 ) )
     489                 :     {
     490               0 :         oSRS.SetProjCS("Equidistant Conic");
     491                 :         oSRS.SetEC(  padfPrjParams[7], padfPrjParams[8],
     492                 :                      padfPrjParams[5], padfPrjParams[6],  
     493               0 :                      padfPrjParams[3], padfPrjParams[4] );
     494                 :     }
     495               5 :     else if( EQUALN( pszProj.c_str(), "Gauss-Krueger Germany", 21 ) )
     496                 :     {
     497                 :         //FalseNorthing and CenterLat are always set to 0
     498                 :         //Scale 1.0 is defined
     499                 :         //FalseEasting and CentralMeridian are defined by the selected zone
     500                 :         mapTMParms("Gauss-Krueger Germany", padfPrjParams[11], 
     501               0 :                    padfPrjParams[3], padfPrjParams[6]);
     502               0 :         oSRS.SetProjCS("Gauss-Krueger Germany");
     503                 :         oSRS.SetTM(  0, padfPrjParams[6],
     504                 :                      1.0,   
     505               0 :                      padfPrjParams[3], 0 );
     506                 :     }
     507               5 :     else if ( EQUALN( pszProj.c_str(),"Gauss-Boaga Italy", 17 ) )
     508                 :     {
     509                 :         //FalseNorthing and CenterLat are always set to 0
     510                 :         //Scale 0.9996 is defined
     511                 :         //FalseEasting and CentralMeridian are defined by the selected zone
     512                 :         mapTMParms("Gauss-Boaga Italy", padfPrjParams[11], 
     513               0 :                    padfPrjParams[3], padfPrjParams[6]);
     514               0 :         oSRS.SetProjCS("Gauss-Boaga Italy");
     515                 :         oSRS.SetTM(  0, padfPrjParams[6],
     516                 :                      0.9996,  
     517               0 :                      padfPrjParams[3], 0 );
     518                 :     }
     519               5 :     else if ( EQUALN( pszProj.c_str(),"Gauss Colombia", 14 ))
     520                 :     {
     521                 :         // 1000000 used for FalseNorthing and FalseEasting
     522                 :         // 1.0 used for scale 
     523                 :         // CenterLat is defined 45.1609259259259 
     524                 :         // CentralMeridian is defined by the selected zone
     525                 :         mapTMParms("Gauss Colombia", padfPrjParams[11], 
     526               0 :                    padfPrjParams[3], padfPrjParams[6]);
     527               0 :         oSRS.SetProjCS("Gauss Colombia");
     528                 :         oSRS.SetTM(  45.1609259259259, padfPrjParams[6],
     529                 :                      1.0,   
     530               0 :                      1000000, 1000000 );
     531                 :     }
     532               5 :     else if( EQUALN( pszProj.c_str(), "Gnomonic", 8 ) )
     533                 :     {
     534               0 :         oSRS.SetProjCS("Gnomonic");
     535                 :         oSRS.SetGnomonic( padfPrjParams[5], padfPrjParams[6],
     536               0 :                           padfPrjParams[3], padfPrjParams[4] );
     537                 :     }
     538               5 :     else if( EQUALN( pszProj.c_str(), "Lambert Conformal Conic", 23 ) )
     539                 :     {
     540                 :         // should use 1.0 for scale factor in Ilwis definition 
     541               0 :         oSRS.SetProjCS("Lambert Conformal Conic");
     542                 :         oSRS.SetLCC(  padfPrjParams[7], padfPrjParams[8],
     543                 :                         padfPrjParams[5], padfPrjParams[6],
     544               0 :                         padfPrjParams[3], padfPrjParams[4] );
     545                 :     }
     546               5 :     else if( EQUALN( pszProj.c_str(), "Lambert Cylind EqualArea", 24 ) )
     547                 :     {
     548                 :         // Latitude_Of_True_Scale used for dfStdP1 ?
     549               0 :         oSRS.SetProjCS("Lambert Conformal Conic");
     550                 :         oSRS.SetCEA(  padfPrjParams[10], 
     551                 :                         padfPrjParams[6], 
     552               0 :                         padfPrjParams[3], padfPrjParams[4] );
     553                 :     }
     554               5 :     else if( EQUALN( pszProj.c_str(), "Mercator", 8 ) )
     555                 :     {
     556                 :         // use 0 for CenterLat, scale is computed from the 
     557                 :         // Latitude_Of_True_Scale
     558               0 :         scaleFromLATTS( pszEllips, padfPrjParams[10], padfPrjParams[9] );
     559               0 :         oSRS.SetProjCS("Mercator");
     560                 :         oSRS.SetMercator( 0, padfPrjParams[6], 
     561                 :                                 padfPrjParams[9], 
     562               0 :                                 padfPrjParams[3], padfPrjParams[4] );
     563                 :     }
     564               5 :     else if( EQUALN( pszProj.c_str(), "Miller", 6 ) )
     565                 :     {
     566                 :         // use 0 for CenterLat
     567               0 :         oSRS.SetProjCS("Miller");
     568                 :         oSRS.SetMC( 0, padfPrjParams[6], 
     569               0 :                         padfPrjParams[3], padfPrjParams[4] );
     570                 :     }
     571               5 :     else if( EQUALN( pszProj.c_str(), "Mollweide", 9 ) )
     572                 :     {
     573               0 :         oSRS.SetProjCS("Mollweide");
     574                 :         oSRS.SetMollweide(  padfPrjParams[6], 
     575               0 :                                 padfPrjParams[3], padfPrjParams[4] );
     576                 :     }
     577               5 :     else if( EQUALN( pszProj.c_str(), "Orthographic", 12 ) )
     578                 :     {
     579               0 :         oSRS.SetProjCS("Orthographic");
     580                 :         oSRS.SetOrthographic (  padfPrjParams[5], padfPrjParams[6], 
     581               0 :                                 padfPrjParams[3], padfPrjParams[4] );
     582                 :     }
     583               5 :     else if( EQUALN( pszProj.c_str(), "Plate Carree", 12 ) ||
     584                 :              EQUALN( pszProj.c_str(), "Plate Rectangle", 15 ))
     585                 :     {
     586                 :         // set 0.0 for CenterLat for Plate Carree projection
     587                 :         // skipp Latitude_Of_True_Scale for Plate Rectangle projection definition
     588               0 :         oSRS.SetProjCS(pszProj.c_str());        
     589                 :         oSRS.SetEquirectangular(  padfPrjParams[5], padfPrjParams[6], 
     590               0 :                                         padfPrjParams[3], padfPrjParams[4] );
     591                 :     }
     592               5 :     else if( EQUALN( pszProj.c_str(), "PolyConic", 9 ) )
     593                 :     {
     594                 :         // skipp scale factor
     595               0 :         oSRS.SetProjCS("PolyConic");
     596                 :         oSRS.SetPolyconic(  padfPrjParams[5], padfPrjParams[6], 
     597               0 :                                 padfPrjParams[3], padfPrjParams[4] );
     598                 :     }
     599               5 :     else if( EQUALN( pszProj.c_str(), "Robinson", 8 ) )
     600                 :     {
     601               0 :         oSRS.SetProjCS("Robinson");
     602                 :         oSRS.SetRobinson( padfPrjParams[6],
     603               0 :                                 padfPrjParams[3], padfPrjParams[4] );
     604                 :     }
     605               5 :     else if( EQUALN( pszProj.c_str(), "Sinusoidal", 10 ) )
     606                 :     {
     607               0 :         oSRS.SetProjCS("Sinusoidal"); 
     608                 :         oSRS.SetSinusoidal( padfPrjParams[6], 
     609               0 :                                 padfPrjParams[3], padfPrjParams[4] );
     610                 :     }
     611               5 :     else if( EQUALN( pszProj.c_str(), "Stereographic", 13 ) )
     612                 :     {
     613               0 :         oSRS.SetProjCS("Stereographic");  
     614                 :         oSRS.SetStereographic(  padfPrjParams[5], padfPrjParams[6],
     615                 :                                 padfPrjParams[9],
     616               0 :                                 padfPrjParams[3], padfPrjParams[4] );
     617                 :   
     618                 :     }
     619               5 :     else if( EQUALN( pszProj.c_str(), "Transverse Mercator", 19 ) )
     620                 :     {
     621               0 :         oSRS.SetProjCS("Transverse Mercator");  
     622                 :         oSRS.SetStereographic(  padfPrjParams[5], padfPrjParams[6],
     623                 :                                 padfPrjParams[9],
     624               0 :                                 padfPrjParams[3], padfPrjParams[4] );
     625                 :     }
     626               5 :     else if( EQUALN( pszProj.c_str(), "UTM", 3 ) )
     627                 :     {
     628               5 :         string pszNH = ReadElement("Projection", "Northern Hemisphere", csyFileName);
     629               5 :         oSRS.SetProjCS("UTM");
     630               5 :         if( EQUALN( pszNH.c_str(), "Yes", 3 ) )
     631               4 :             oSRS.SetUTM( (int) padfPrjParams[11], 1);  
     632                 :         else
     633               1 :             oSRS.SetUTM( (int) padfPrjParams[11], 0);  
     634                 :     }
     635               0 :     else if( EQUALN( pszProj.c_str(), "VanderGrinten", 13 ) )
     636                 :     {
     637                 :         oSRS.SetVDG(  padfPrjParams[6],
     638               0 :                         padfPrjParams[3], padfPrjParams[4] );
     639                 :     }
     640               0 :     else if( EQUALN( pszProj.c_str(), "GeoStationary Satellite", 23 ) )
     641                 :     {
     642                 :         oSRS.SetGEOS( padfPrjParams[6], 
     643                 :                       padfPrjParams[12], 
     644                 :                       padfPrjParams[3], 
     645               0 :                       padfPrjParams[4] );
     646                 :     }
     647               0 :     else if( EQUALN( pszProj.c_str(), "MSG Perspective", 15 ) )
     648                 :     {
     649                 :         oSRS.SetGEOS( padfPrjParams[6], 
     650                 :                       padfPrjParams[12], 
     651                 :                       padfPrjParams[3], 
     652               0 :                       padfPrjParams[4] );
     653                 :     }
     654                 :     else
     655                 :     {
     656               0 :         oSRS.SetLocalCS( pszProj.c_str() );
     657                 :     }
     658                 : /* -------------------------------------------------------------------- */
     659                 : /*      Try to translate the datum/spheroid.                            */
     660                 : /* -------------------------------------------------------------------- */
     661                 : 
     662               5 :     if ( !oSRS.IsLocal() )
     663                 :     {
     664               5 :         const IlwisDatums   *piwDatum = iwDatums;
     665                 : 
     666                 :         // Search for matching datum
     667             227 :         while ( piwDatum->pszIlwisDatum )
     668                 :         {
     669             222 :             if( EQUALN( pszDatum.c_str(), piwDatum->pszIlwisDatum, strlen(piwDatum->pszIlwisDatum) ) )
     670                 :             {
     671               5 :                 OGRSpatialReference oOGR;
     672               5 :                 oOGR.importFromEPSG( piwDatum->nEPSGCode );
     673               5 :                 oSRS.CopyGeogCSFrom( &oOGR );
     674               5 :                 break;
     675                 :             }
     676             217 :             piwDatum++;
     677                 :         } //end of searchong for matching datum
     678                 : 
     679                 : 
     680                 : /* -------------------------------------------------------------------- */
     681                 : /*      If no matching for datum definition, fetch info about an        */
     682                 : /*      ellipsoid.  semi major axis is always returned in meters        */ 
     683                 : /* -------------------------------------------------------------------- */
     684               5 :         const IlwisEllips *piwEllips =  iwEllips;
     685               5 :         if (pszEllips.length() == 0)
     686               1 :             pszEllips="Sphere";
     687               5 :         if ( !piwDatum->pszIlwisDatum )  
     688                 :                                          
     689                 :         {
     690               0 :             while ( piwEllips->pszIlwisEllips )
     691                 :             {
     692               0 :                 if( EQUALN( pszEllips.c_str(), piwEllips->pszIlwisEllips, strlen(piwEllips->pszIlwisEllips) ) )
     693                 :                 {
     694               0 :                     double dfSemiMajor = piwEllips->semiMajor;
     695               0 :                     if( EQUALN( pszEllips.c_str(), "Sphere", 6 ) && padfPrjParams[0] != 0 )
     696                 :                     { 
     697               0 :                         dfSemiMajor = padfPrjParams[0];
     698                 :                     }
     699                 :                     oSRS.SetGeogCS( CPLSPrintf(
     700                 :                                         "Unknown datum based upon the %s ellipsoid",
     701                 :                                         piwEllips->pszIlwisEllips ),
     702                 :                                     CPLSPrintf(
     703                 :                                         "Not specified (based on %s spheroid)",
     704                 :                                         piwEllips->pszIlwisEllips ),
     705                 :                                     piwEllips->pszIlwisEllips, 
     706                 :                                     dfSemiMajor,
     707                 :                                     piwEllips->invFlattening,
     708               0 :                                     NULL, 0.0, NULL, 0.0 );
     709               0 :                     oSRS.SetAuthority( "SPHEROID", "EPSG", piwEllips->nEPSGCode );
     710                 :                     
     711               0 :                     break;
     712                 :                 }
     713               0 :                 piwEllips++;
     714                 :             } //end of searching for matching ellipsoid
     715                 :         } 
     716                 :         
     717                 : /* -------------------------------------------------------------------- */
     718                 : /*      If no matching for ellipsoid definition, fetch info about an    */
     719                 : /*      user defined ellipsoid. If cannot find, default to WGS 84       */
     720                 : /* -------------------------------------------------------------------- */
     721               5 :         if ( !piwEllips->pszIlwisEllips )      
     722                 :         {
     723                 : 
     724               0 :             if( EQUALN( pszEllips.c_str(), "User Defined", 12 ) )
     725                 :             {
     726                 :                 
     727                 :                 oSRS.SetGeogCS( "Unknown datum based upon the custom ellipsoid",
     728                 :                                 "Not specified (based on custom ellipsoid)",
     729                 :                                 "Custom ellipsoid",
     730                 :                                 padfPrjParams[0], padfPrjParams[2],
     731               0 :                                 NULL, 0, NULL, 0 );
     732                 :             }
     733                 :             else
     734                 :             {
     735                 :                 //if cannot find the user defined ellips, default to WGS84
     736               0 :                 oSRS.SetWellKnownGeogCS( "WGS84" );
     737                 :             }
     738                 :         }
     739                 : 
     740                 :     } // end of if ( !IsLocal() )
     741                 :     
     742                 : /* -------------------------------------------------------------------- */
     743                 : /*      Units translation                                          */
     744                 : /* -------------------------------------------------------------------- */
     745               5 :     if( oSRS.IsLocal() || oSRS.IsProjected() )
     746                 :     {
     747               5 :         oSRS.SetLinearUnits( SRS_UL_METER, 1.0 );
     748                 :     }
     749               5 :     oSRS.FixupOrdering();
     750               5 :     CPLFree(pszProjection);
     751               5 :     oSRS.exportToWkt( &pszProjection );
     752                 :     
     753                 : 
     754               5 :     return CE_None;
     755                 : }
     756                 : 
     757               0 : void WriteFalseEastNorth(string csFileName, OGRSpatialReference oSRS)
     758                 : {
     759                 :       WriteElement("Projection", ILW_False_Easting, csFileName, 
     760               0 :                     oSRS.GetNormProjParm(SRS_PP_FALSE_EASTING, 0.0));
     761                 :       WriteElement("Projection", ILW_False_Northing, csFileName, 
     762               0 :                     oSRS.GetNormProjParm(SRS_PP_FALSE_NORTHING, 0.0));
     763               0 : }
     764                 : 
     765               0 : void WriteProjectionName(string csFileName, string stProjection)
     766                 : {
     767               0 :     WriteElement("CoordSystem", "Type", csFileName, "Projection");
     768               0 :     WriteElement("CoordSystem", "Projection", csFileName, stProjection);
     769               0 : }
     770                 : 
     771               2 : void WriteUTM(string csFileName, OGRSpatialReference oSRS)
     772                 : {
     773                 :     int bNorth, nZone;
     774                 : 
     775               2 :     nZone = oSRS.GetUTMZone( &bNorth );
     776               2 :     WriteElement("CoordSystem", "Type", csFileName, "Projection");
     777               4 :     WriteElement("CoordSystem", "Projection", csFileName, "UTM");
     778               2 :     if (bNorth)
     779               2 :         WriteElement("Projection", "Northern Hemisphere", csFileName, "Yes");
     780                 :     else
     781               0 :         WriteElement("Projection", "Northern Hemisphere", csFileName, "No");
     782               2 :     WriteElement("Projection", "Zone", csFileName, nZone);
     783               2 : }
     784                 : 
     785               0 : void WriteAlbersConicEqualArea(string csFileName, OGRSpatialReference oSRS)
     786                 : {
     787               0 :     WriteProjectionName(csFileName, "Albers EqualArea Conic");
     788               0 :     WriteFalseEastNorth(csFileName, oSRS);
     789                 :     WriteElement("Projection", ILW_Central_Meridian, csFileName, 
     790               0 :                  oSRS.GetNormProjParm(SRS_PP_CENTRAL_MERIDIAN, 0.0));
     791                 :     WriteElement("Projection", ILW_Central_Parallel, csFileName, 
     792               0 :                  oSRS.GetNormProjParm(SRS_PP_LATITUDE_OF_ORIGIN, 0.0));
     793                 :     WriteElement("Projection", ILW_Standard_Parallel_1, csFileName, 
     794               0 :                  oSRS.GetNormProjParm(SRS_PP_STANDARD_PARALLEL_1, 0.0));
     795                 :     WriteElement("Projection", ILW_Standard_Parallel_2, csFileName, 
     796               0 :                  oSRS.GetNormProjParm(SRS_PP_STANDARD_PARALLEL_2, 0.0));
     797               0 : }
     798               0 : void WriteAzimuthalEquidistant(string csFileName, OGRSpatialReference oSRS)
     799                 : {
     800               0 :     WriteProjectionName(csFileName, "Azimuthal Equidistant");
     801               0 :     WriteFalseEastNorth(csFileName, oSRS);
     802                 :     WriteElement("Projection", ILW_Central_Meridian, csFileName, 
     803               0 :                  oSRS.GetNormProjParm(SRS_PP_CENTRAL_MERIDIAN, 0.0));
     804                 :     WriteElement("Projection", ILW_Central_Parallel, csFileName, 
     805               0 :                  oSRS.GetNormProjParm(SRS_PP_LATITUDE_OF_ORIGIN, 0.0));
     806               0 :     WriteElement("Projection", ILW_Scale_Factor, csFileName, "1.0000000000"); 
     807               0 : }
     808               0 : void WriteCylindricalEqualArea(string csFileName, OGRSpatialReference oSRS)
     809                 : {
     810               0 :     WriteProjectionName(csFileName, "Central Cylindrical");
     811               0 :     WriteFalseEastNorth(csFileName, oSRS);
     812                 :     WriteElement("Projection", ILW_Central_Meridian, csFileName, 
     813               0 :                  oSRS.GetNormProjParm(SRS_PP_CENTRAL_MERIDIAN, 0.0));
     814               0 : }
     815                 : 
     816               0 : void WriteCassiniSoldner(string csFileName, OGRSpatialReference oSRS)
     817                 : {
     818               0 :     WriteProjectionName(csFileName, "Cassini");
     819               0 :     WriteFalseEastNorth(csFileName, oSRS);
     820                 :     WriteElement("Projection", ILW_Central_Meridian, csFileName, 
     821               0 :                  oSRS.GetNormProjParm(SRS_PP_CENTRAL_MERIDIAN, 0.0));
     822                 :     WriteElement("Projection", ILW_Latitude_True_Scale, csFileName, 
     823               0 :                  oSRS.GetNormProjParm(SRS_PP_LATITUDE_OF_ORIGIN, 0.0));
     824               0 :     WriteElement("Projection", ILW_Scale_Factor, csFileName, "1.0000000000"); 
     825               0 : }
     826                 : 
     827               0 : void WriteStereographic(string csFileName, OGRSpatialReference oSRS)
     828                 : {
     829               0 :     WriteProjectionName(csFileName, "Stereographic");
     830               0 :     WriteFalseEastNorth(csFileName, oSRS);
     831                 :     WriteElement("Projection", ILW_Central_Meridian, csFileName, 
     832               0 :                  oSRS.GetNormProjParm(SRS_PP_CENTRAL_MERIDIAN, 0.0));
     833                 :     WriteElement("Projection", ILW_Central_Parallel, csFileName, 
     834               0 :                  oSRS.GetNormProjParm(SRS_PP_LATITUDE_OF_ORIGIN, 0.0));
     835                 :     WriteElement("Projection", ILW_Scale_Factor, csFileName, 
     836               0 :                  oSRS.GetNormProjParm(SRS_PP_SCALE_FACTOR, 0.0)); 
     837               0 : }
     838                 : 
     839               0 : void WriteEquidistantConic(string csFileName, OGRSpatialReference oSRS)
     840                 : {
     841               0 :     WriteProjectionName(csFileName, "Equidistant Conic");
     842               0 :     WriteFalseEastNorth(csFileName, oSRS);
     843                 :     WriteElement("Projection", ILW_Central_Meridian, csFileName, 
     844               0 :                  oSRS.GetNormProjParm(SRS_PP_CENTRAL_MERIDIAN, 0.0));
     845                 :     WriteElement("Projection", ILW_Central_Parallel, csFileName, 
     846               0 :                  oSRS.GetNormProjParm(SRS_PP_LATITUDE_OF_ORIGIN, 0.0));
     847                 :     WriteElement("Projection", ILW_Standard_Parallel_1, csFileName, 
     848               0 :                  oSRS.GetNormProjParm(SRS_PP_STANDARD_PARALLEL_1, 0.0)); 
     849                 :     WriteElement("Projection", ILW_Standard_Parallel_2, csFileName, 
     850               0 :                  oSRS.GetNormProjParm(SRS_PP_STANDARD_PARALLEL_2, 0.0));
     851               0 : }
     852                 : 
     853               0 : void WriteTransverseMercator(string csFileName, OGRSpatialReference oSRS)
     854                 : {
     855               0 :     WriteProjectionName(csFileName, "Transverse Mercator");
     856               0 :     WriteFalseEastNorth(csFileName, oSRS);
     857                 :     WriteElement("Projection", ILW_Central_Meridian, csFileName, 
     858               0 :                  oSRS.GetNormProjParm(SRS_PP_CENTRAL_MERIDIAN, 0.0));
     859                 :     WriteElement("Projection", ILW_Central_Parallel, csFileName, 
     860               0 :                  oSRS.GetNormProjParm(SRS_PP_LATITUDE_OF_ORIGIN, 0.0));
     861                 :     WriteElement("Projection", ILW_Scale_Factor, csFileName, 
     862               0 :                  oSRS.GetNormProjParm(SRS_PP_SCALE_FACTOR, 0.0)); 
     863               0 : }
     864                 : 
     865               0 : void WriteGnomonic(string csFileName, OGRSpatialReference oSRS)
     866                 : {
     867               0 :     WriteProjectionName(csFileName, "Gnomonic");
     868               0 :     WriteFalseEastNorth(csFileName, oSRS);
     869                 :     WriteElement("Projection", ILW_Central_Meridian, csFileName, 
     870               0 :                  oSRS.GetNormProjParm(SRS_PP_CENTRAL_MERIDIAN, 0.0));
     871                 :     WriteElement("Projection", ILW_Central_Parallel, csFileName, 
     872               0 :                  oSRS.GetNormProjParm(SRS_PP_LATITUDE_OF_ORIGIN, 0.0));
     873               0 : }
     874                 : 
     875               0 : void WriteLambertConformalConic(string csFileName, OGRSpatialReference oSRS)
     876                 : {
     877               0 :     WriteProjectionName(csFileName, "Lambert Conformal Conic");
     878               0 :     WriteFalseEastNorth(csFileName, oSRS);
     879                 :     WriteElement("Projection", ILW_Central_Meridian, csFileName, 
     880               0 :                  oSRS.GetNormProjParm(SRS_PP_CENTRAL_MERIDIAN, 0.0));
     881                 :     WriteElement("Projection", ILW_Central_Parallel, csFileName, 
     882               0 :                  oSRS.GetNormProjParm(SRS_PP_LATITUDE_OF_ORIGIN, 0.0));
     883               0 :     WriteElement("Projection", ILW_Scale_Factor, csFileName, "1.0000000000"); 
     884               0 : }
     885                 : 
     886               0 : void WriteLambertConformalConic2SP(string csFileName, OGRSpatialReference oSRS)
     887                 : {
     888               0 :     WriteProjectionName(csFileName, "Lambert Conformal Conic");
     889               0 :     WriteFalseEastNorth(csFileName, oSRS);
     890                 :     WriteElement("Projection", ILW_Central_Meridian, csFileName, 
     891               0 :                  oSRS.GetNormProjParm(SRS_PP_CENTRAL_MERIDIAN, 0.0));
     892                 :     WriteElement("Projection", ILW_Central_Parallel, csFileName, 
     893               0 :                  oSRS.GetNormProjParm(SRS_PP_LATITUDE_OF_ORIGIN, 0.0));
     894               0 :     WriteElement("Projection", ILW_Scale_Factor, csFileName, "1.0000000000"); 
     895                 :     WriteElement("Projection", ILW_Standard_Parallel_1, csFileName, 
     896               0 :                  oSRS.GetNormProjParm(SRS_PP_STANDARD_PARALLEL_1, 0.0)); 
     897                 :     WriteElement("Projection", ILW_Standard_Parallel_2, csFileName, 
     898               0 :                  oSRS.GetNormProjParm(SRS_PP_STANDARD_PARALLEL_2, 0.0));
     899               0 : }
     900                 : 
     901               0 : void WriteLambertAzimuthalEqualArea(string csFileName, OGRSpatialReference oSRS)
     902                 : {
     903               0 :     WriteProjectionName(csFileName, "Lambert Azimuthal EqualArea");
     904               0 :     WriteFalseEastNorth(csFileName, oSRS);
     905                 :     WriteElement("Projection", ILW_Central_Meridian, csFileName, 
     906               0 :                  oSRS.GetNormProjParm(SRS_PP_CENTRAL_MERIDIAN, 0.0));
     907                 :     WriteElement("Projection", ILW_Central_Parallel, csFileName, 
     908               0 :                  oSRS.GetNormProjParm(SRS_PP_LATITUDE_OF_ORIGIN, 0.0));
     909               0 : }
     910                 : 
     911               0 : void WriteMercator_1SP(string csFileName, OGRSpatialReference oSRS)
     912                 : {
     913               0 :     WriteProjectionName(csFileName, "Mercator");
     914               0 :     WriteFalseEastNorth(csFileName, oSRS);
     915                 :     WriteElement("Projection", ILW_Central_Meridian, csFileName, 
     916               0 :                  oSRS.GetNormProjParm(SRS_PP_CENTRAL_MERIDIAN, 0.0));
     917                 :     WriteElement("Projection", ILW_Latitude_True_Scale, csFileName, 
     918               0 :                  oSRS.GetNormProjParm(SRS_PP_LATITUDE_OF_ORIGIN, 0.0));
     919               0 : }
     920                 : 
     921               0 : void WriteMillerCylindrical(string csFileName, OGRSpatialReference oSRS)
     922                 : {
     923               0 :     WriteProjectionName(csFileName, "Miller");
     924               0 :     WriteFalseEastNorth(csFileName, oSRS);
     925                 :     WriteElement("Projection", ILW_Central_Meridian, csFileName, 
     926               0 :                  oSRS.GetNormProjParm(SRS_PP_CENTRAL_MERIDIAN, 0.0));
     927               0 : }
     928                 : 
     929               0 : void WriteMolleweide(string csFileName, OGRSpatialReference oSRS)
     930                 : {
     931               0 :     WriteProjectionName(csFileName, "Mollweide");
     932               0 :     WriteFalseEastNorth(csFileName, oSRS);
     933                 :     WriteElement("Projection", ILW_Central_Meridian, csFileName, 
     934               0 :                  oSRS.GetNormProjParm(SRS_PP_CENTRAL_MERIDIAN, 0.0));
     935               0 : }
     936                 : 
     937               0 : void WriteOrthographic(string csFileName, OGRSpatialReference oSRS)
     938                 : {
     939               0 :     WriteProjectionName(csFileName, "Orthographic");
     940               0 :     WriteFalseEastNorth(csFileName, oSRS);
     941                 :     WriteElement("Projection", ILW_Central_Meridian, csFileName, 
     942               0 :                  oSRS.GetNormProjParm(SRS_PP_CENTRAL_MERIDIAN, 0.0));
     943                 :     WriteElement("Projection", ILW_Central_Parallel, csFileName, 
     944               0 :                  oSRS.GetNormProjParm(SRS_PP_LATITUDE_OF_ORIGIN, 0.0));
     945               0 : }
     946                 : 
     947               0 : void WritePlateRectangle(string csFileName, OGRSpatialReference oSRS)
     948                 : {
     949               0 :     WriteProjectionName(csFileName, "Plate Rectangle");
     950               0 :     WriteFalseEastNorth(csFileName, oSRS);
     951                 :     WriteElement("Projection", ILW_Central_Meridian, csFileName, 
     952               0 :                  oSRS.GetNormProjParm(SRS_PP_CENTRAL_MERIDIAN, 0.0));
     953                 :     WriteElement("Projection", ILW_Central_Parallel, csFileName, 
     954               0 :                  oSRS.GetNormProjParm(SRS_PP_LATITUDE_OF_ORIGIN, 0.0));
     955               0 :     WriteElement("Projection", ILW_Latitude_True_Scale, csFileName, "0.0000000000"); 
     956               0 : }
     957                 : 
     958               0 : void WritePolyConic(string csFileName, OGRSpatialReference oSRS)
     959                 : {
     960               0 :     WriteProjectionName(csFileName, "PolyConic");
     961               0 :     WriteFalseEastNorth(csFileName, oSRS);
     962                 :     WriteElement("Projection", ILW_Central_Meridian, csFileName, 
     963               0 :                  oSRS.GetNormProjParm(SRS_PP_CENTRAL_MERIDIAN, 0.0));
     964                 :     WriteElement("Projection", ILW_Central_Parallel, csFileName, 
     965               0 :                  oSRS.GetNormProjParm(SRS_PP_LATITUDE_OF_ORIGIN, 0.0));
     966               0 :     WriteElement("Projection", ILW_Scale_Factor, csFileName, "1.0000000000"); 
     967               0 : }
     968                 : 
     969               0 : void WriteRobinson(string csFileName, OGRSpatialReference oSRS)
     970                 : {
     971               0 :     WriteProjectionName(csFileName, "Robinson");
     972               0 :     WriteFalseEastNorth(csFileName, oSRS);
     973                 :     WriteElement("Projection", ILW_Central_Meridian, csFileName, 
     974               0 :                  oSRS.GetNormProjParm(SRS_PP_CENTRAL_MERIDIAN, 0.0));
     975               0 : }
     976                 : 
     977               0 : void WriteSinusoidal(string csFileName, OGRSpatialReference oSRS)
     978                 : {
     979               0 :     WriteProjectionName(csFileName, "Sinusoidal");
     980               0 :     WriteFalseEastNorth(csFileName, oSRS);
     981                 :     WriteElement("Projection", ILW_Central_Meridian, csFileName, 
     982               0 :                  oSRS.GetNormProjParm(SRS_PP_CENTRAL_MERIDIAN, 0.0));
     983               0 : }
     984                 : 
     985               0 : void WriteVanderGrinten(string csFileName, OGRSpatialReference oSRS)
     986                 : {
     987               0 :     WriteProjectionName(csFileName, "VanderGrinten");
     988               0 :     WriteFalseEastNorth(csFileName, oSRS);
     989                 :     WriteElement("Projection", ILW_Central_Meridian, csFileName, 
     990               0 :                  oSRS.GetNormProjParm(SRS_PP_CENTRAL_MERIDIAN, 0.0));
     991               0 : }
     992                 : 
     993               0 : void WriteGeoStatSat(string csFileName, OGRSpatialReference oSRS)
     994                 : {
     995               0 :     WriteProjectionName(csFileName, "GeoStationary Satellite");
     996               0 :     WriteFalseEastNorth(csFileName, oSRS);
     997                 :     WriteElement("Projection", ILW_Central_Meridian, csFileName, 
     998               0 :                  oSRS.GetNormProjParm(SRS_PP_CENTRAL_MERIDIAN, 0.0));
     999               0 :     WriteElement("Projection", ILW_Scale_Factor, csFileName, "1.0000000000"); 
    1000                 :     WriteElement("Projection", ILW_Height_Persp_Center, csFileName, 
    1001               0 :                  oSRS.GetNormProjParm(SRS_PP_SATELLITE_HEIGHT, 35785831.0));
    1002               0 : }
    1003                 : 
    1004                 : /************************************************************************/
    1005                 : /*                          WriteProjection()                           */
    1006                 : /************************************************************************/
    1007                 : /**
    1008                 :  * Export coordinate system in ILWIS projection definition.
    1009                 :  *
    1010                 :  * Converts the loaded coordinate reference system into ILWIS projection
    1011                 :  * definition to the extent possible. 
    1012                 :  */ 
    1013              31 : CPLErr ILWISDataset::WriteProjection() 
    1014                 : 
    1015                 : {
    1016              31 :     OGRSpatialReference oSRS;
    1017              31 :     OGRSpatialReference *poGeogSRS = NULL;
    1018                 :     int                 bHaveSRS;
    1019              31 :     char    *pszP = pszProjection;
    1020                 :     
    1021              31 :     string csFileName = CPLResetExtension(osFileName, "csy" );
    1022              62 :     string pszBaseName = string(CPLGetBasename( osFileName ));
    1023              62 :     string pszPath = string(CPLGetPath( osFileName ));
    1024              62 :     bool fProjection = ((strlen(pszProjection)>0) && (pszProjection != NULL));
    1025              31 :     if( fProjection && (oSRS.importFromWkt( &pszP ) == OGRERR_NONE) )
    1026                 :     {
    1027              31 :         bHaveSRS = TRUE;
    1028                 :     }
    1029                 :     else
    1030               0 :         bHaveSRS = FALSE;
    1031                 :     
    1032              31 :     const IlwisDatums   *piwDatum = iwDatums;
    1033              31 :     string pszEllips;
    1034              31 :     string pszDatum;
    1035              31 :     string pszProj;
    1036                 :     
    1037                 : /* -------------------------------------------------------------------- */
    1038                 : /*      Collect datum/ellips information.                                      */
    1039                 : /* -------------------------------------------------------------------- */
    1040              31 :     if( bHaveSRS )
    1041                 :     {
    1042              31 :         poGeogSRS = oSRS.CloneGeogCS();
    1043                 :     }
    1044                 : 
    1045              31 :     string grFileName = CPLResetExtension(osFileName, "grf" );
    1046              31 :     string csy;
    1047              31 :     if( poGeogSRS )
    1048                 :     {
    1049              31 :         csy = pszBaseName + ".csy";
    1050                 :         
    1051              31 :         WriteElement("Ilwis", "Type", csFileName, "CoordSystem");
    1052              62 :         pszDatum = poGeogSRS->GetAttrValue( "GEOGCS|DATUM" );
    1053                 : 
    1054                 :         /* WKT to ILWIS translation */
    1055            2089 :         while ( piwDatum->pszWKTDatum)
    1056                 :         {
    1057            2058 :             if( EQUALN( pszDatum.c_str(), piwDatum->pszWKTDatum, strlen(piwDatum->pszWKTDatum) ) )
    1058                 :             {
    1059              31 :                 WriteElement("CoordSystem", "Datum", csFileName, piwDatum->pszIlwisDatum);
    1060              31 :                 break;
    1061                 :             }
    1062            2027 :             piwDatum++;
    1063                 :         } //end of searchong for matching datum
    1064              31 :         WriteElement("CoordSystem", "Width", csFileName, 28);
    1065                 :         double a, b, f;
    1066              31 :         pszEllips = poGeogSRS->GetAttrValue( "GEOGCS|DATUM|SPHEROID" );
    1067              31 :         a = poGeogSRS->GetSemiMajor();
    1068              31 :         b = poGeogSRS->GetSemiMinor();
    1069              31 :         f = poGeogSRS->GetInvFlattening();
    1070              31 :         WriteElement("CoordSystem", "Ellipsoid", csFileName, "User Defined");
    1071              62 :         WriteElement("Ellipsoid", "a", csFileName, a);
    1072              31 :         WriteElement("Ellipsoid", "1/f", csFileName, f);
    1073                 :     }
    1074                 :     else
    1075               0 :         csy = "unknown.csy";
    1076                 : 
    1077                 : /* -------------------------------------------------------------------- */
    1078                 : /*  Determine to write a geo-referencing file for the dataset to create */
    1079                 : /* -------------------------------------------------------------------- */
    1080              31 :     if( adfGeoTransform[0] != 0.0 || adfGeoTransform[1] != 1.0
    1081               0 :         || adfGeoTransform[2] != 0.0 || adfGeoTransform[3] != 0.0
    1082               0 :         || adfGeoTransform[4] != 0.0 || fabs(adfGeoTransform[5]) != 1.0)
    1083              31 :         WriteElement("GeoRef", "CoordSystem", grFileName, csy);
    1084                 : 
    1085                 : /* -------------------------------------------------------------------- */
    1086                 : /*  Recognise various projections.                                      */
    1087                 : /* -------------------------------------------------------------------- */
    1088              31 :     const char * pszProjName = NULL;
    1089                 : 
    1090              31 :     if( bHaveSRS )
    1091              31 :         pszProjName = oSRS.GetAttrValue( "PROJCS|PROJECTION" );
    1092                 : 
    1093              31 :     if( pszProjName == NULL )
    1094                 :     {
    1095              29 :         if( bHaveSRS && oSRS.IsGeographic() )
    1096                 :         {
    1097              29 :             WriteElement("CoordSystem", "Type", csFileName, "LatLon");
    1098                 :         }
    1099                 :     }
    1100               2 :     else if( oSRS.GetUTMZone( NULL ) != 0 )
    1101                 :     {
    1102               2 :         WriteUTM(csFileName, oSRS);
    1103                 :     }
    1104               0 :     else if( EQUAL(pszProjName,SRS_PT_ALBERS_CONIC_EQUAL_AREA) )
    1105                 :     {
    1106               0 :         WriteAlbersConicEqualArea(csFileName, oSRS);
    1107                 :     }
    1108               0 :     else if( EQUAL(pszProjName,SRS_PT_AZIMUTHAL_EQUIDISTANT) )
    1109                 :     {
    1110               0 :         WriteAzimuthalEquidistant(csFileName, oSRS);
    1111                 :     }
    1112               0 :     else if( EQUAL(pszProjName,SRS_PT_CYLINDRICAL_EQUAL_AREA) )
    1113                 :     {
    1114               0 :         WriteCylindricalEqualArea(csFileName, oSRS);
    1115                 :     }
    1116               0 :     else if( EQUAL(pszProjName,SRS_PT_CASSINI_SOLDNER) )
    1117                 :     {
    1118               0 :         WriteCassiniSoldner(csFileName, oSRS);
    1119                 :     }
    1120               0 :     else if( EQUAL(pszProjName,SRS_PT_STEREOGRAPHIC) )
    1121                 :     {
    1122               0 :         WriteStereographic(csFileName, oSRS);   
    1123                 :     }
    1124               0 :     else if( EQUAL(pszProjName,SRS_PT_EQUIDISTANT_CONIC) )
    1125                 :     {
    1126               0 :         WriteEquidistantConic(csFileName, oSRS);
    1127                 :     }
    1128               0 :     else if( EQUAL(pszProjName,SRS_PT_TRANSVERSE_MERCATOR) )
    1129                 :     {
    1130               0 :         WriteTransverseMercator(csFileName, oSRS);
    1131                 :     }
    1132               0 :     else if( EQUAL(pszProjName,SRS_PT_GNOMONIC) )
    1133                 :     {
    1134               0 :         WriteGnomonic(csFileName, oSRS);
    1135                 :     }
    1136               0 :     else if( EQUAL(pszProjName,"Lambert_Conformal_Conic") )
    1137                 :     {
    1138               0 :         WriteLambertConformalConic(csFileName, oSRS);
    1139                 :     }
    1140               0 :     else if( EQUAL(pszProjName,SRS_PT_LAMBERT_CONFORMAL_CONIC_1SP) )
    1141                 :     {
    1142               0 :         WriteLambertConformalConic(csFileName, oSRS);
    1143                 :     }
    1144               0 :     else if( EQUAL(pszProjName,SRS_PT_LAMBERT_CONFORMAL_CONIC_2SP) )
    1145                 :     {
    1146               0 :         WriteLambertConformalConic2SP(csFileName, oSRS);
    1147                 :     }
    1148               0 :     else if( EQUAL(pszProjName,SRS_PT_LAMBERT_AZIMUTHAL_EQUAL_AREA) )
    1149                 :     {
    1150               0 :         WriteLambertAzimuthalEqualArea(csFileName, oSRS);
    1151                 :     }
    1152               0 :     else if( EQUAL(pszProjName,SRS_PT_MERCATOR_1SP) )
    1153                 :     {
    1154               0 :         WriteMercator_1SP(csFileName, oSRS);
    1155                 :     }
    1156               0 :     else if( EQUAL(pszProjName,SRS_PT_MILLER_CYLINDRICAL) )
    1157                 :     {
    1158               0 :         WriteMillerCylindrical(csFileName, oSRS);
    1159                 :     }
    1160               0 :     else if( EQUAL(pszProjName,SRS_PT_MOLLWEIDE) )
    1161                 :     {
    1162               0 :         WriteMolleweide(csFileName, oSRS);
    1163                 :     }
    1164               0 :     else if( EQUAL(pszProjName,SRS_PT_ORTHOGRAPHIC) )
    1165                 :     {
    1166               0 :         WriteOrthographic(csFileName, oSRS);
    1167                 :     }
    1168               0 :     else if( EQUAL(pszProjName,SRS_PT_EQUIRECTANGULAR) )
    1169                 :     {
    1170               0 :         WritePlateRectangle(csFileName, oSRS);
    1171                 :     }
    1172               0 :     else if( EQUAL(pszProjName,SRS_PT_POLYCONIC) )
    1173                 :     {
    1174               0 :         WritePolyConic(csFileName, oSRS);
    1175                 :     }
    1176               0 :     else if( EQUAL(pszProjName,SRS_PT_ROBINSON) )
    1177                 :     {
    1178               0 :         WriteRobinson(csFileName, oSRS);
    1179                 :     }
    1180               0 :     else if( EQUAL(pszProjName,SRS_PT_SINUSOIDAL) )
    1181                 :     {
    1182               0 :         WriteSinusoidal(csFileName, oSRS);
    1183                 :     }
    1184               0 :     else if( EQUAL(pszProjName,SRS_PT_VANDERGRINTEN) )
    1185                 :     {
    1186               0 :         WriteVanderGrinten(csFileName, oSRS);  
    1187                 :     }
    1188               0 :     else if( EQUAL(pszProjName,SRS_PT_GEOSTATIONARY_SATELLITE) )
    1189                 :     {
    1190               0 :         WriteGeoStatSat(csFileName, oSRS);  
    1191                 :     }
    1192                 :     else
    1193                 :     {
    1194                 :         // Projection unknown by ILWIS
    1195                 :         
    1196                 :     }
    1197                 : 
    1198                 : /* -------------------------------------------------------------------- */
    1199                 : /*      Cleanup                                                         */
    1200                 : /* -------------------------------------------------------------------- */
    1201              31 :     if( poGeogSRS != NULL )
    1202              31 :         delete poGeogSRS;
    1203                 : 
    1204              31 :     return CE_None;
    1205                 : }
    1206                 : 

Generated by: LCOV version 1.7