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

Generated by: LCOV version 1.7