LTP GCOV extension - code coverage report
Current view: directory - ogr/ogrsf_frmts/mitab - mitab_spatialref.cpp
Test: gdal_filtered.info
Date: 2010-07-12 Instrumented lines: 434
Code covered: 31.8 % Executed lines: 138

       1                 : /**********************************************************************
       2                 :  * $Id: mitab_spatialref.cpp,v 1.49 2009-10-15 16:16:37 fwarmerdam Exp $
       3                 :  *
       4                 :  * Name:     mitab_spatialref.cpp
       5                 :  * Project:  MapInfo TAB Read/Write library
       6                 :  * Language: C++
       7                 :  * Purpose:  Implementation of the SpatialRef stuff in the TABFile class.
       8                 :  * Author:   Frank Warmerdam, warmerdam@pobox.com
       9                 :  *
      10                 :  **********************************************************************
      11                 :  * Copyright (c) 1999-2001, Frank Warmerdam
      12                 :  *
      13                 :  * Permission is hereby granted, free of charge, to any person obtaining a
      14                 :  * copy of this software and associated documentation files (the "Software"),
      15                 :  * to deal in the Software without restriction, including without limitation
      16                 :  * the rights to use, copy, modify, merge, publish, distribute, sublicense,
      17                 :  * and/or sell copies of the Software, and to permit persons to whom the
      18                 :  * Software is furnished to do so, subject to the following conditions:
      19                 :  * 
      20                 :  * The above copyright notice and this permission notice shall be included
      21                 :  * in all copies or substantial portions of the Software.
      22                 :  * 
      23                 :  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
      24                 :  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
      25                 :  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
      26                 :  * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
      27                 :  * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
      28                 :  * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 
      29                 :  * DEALINGS IN THE SOFTWARE.
      30                 :  **********************************************************************
      31                 :  *
      32                 :  * $Log: mitab_spatialref.cpp,v $
      33                 :  * Revision 1.49  2009-10-15 16:16:37  fwarmerdam
      34                 :  * add the default EPSG/OGR name for new zealand datums (gdal #3187)
      35                 :  *
      36                 :  * Revision 1.48  2007/11/21 21:15:45  dmorissette
      37                 :  * Fix asDatumInfoList[] and asSpheroidInfoList[] defns/refs (bug 1826)
      38                 :  *
      39                 :  * Revision 1.47  2006/07/10 17:58:48  fwarmerdam
      40                 :  * North_American_Datum_1927 support
      41                 :  *
      42                 :  * Revision 1.46  2006/07/07 19:41:32  dmorissette
      43                 :  * Fixed problem with uninitialized sTABProj.nAffineFlag (bug 1254,1319)
      44                 :  *
      45                 :  * Revision 1.45  2006/05/09 20:21:29  fwarmerdam
      46                 :  * Coordsys false easting and northing are in the units of the coordsys, not
      47                 :  * necessarily meters.  Adjusted mitab_spatialref.cpp to reflect this.
      48                 :  * http://bugzilla.remotesensing.org/show_bug.cgi?id=1113
      49                 :  *
      50                 :  * Revision 1.44  2005/09/29 20:15:36  dmorissette
      51                 :  * More improvements to handling of modified TM projections 21-24.
      52                 :  * Added correct name stings to all datum definitions (Anthony D, bug 1155)
      53                 :  *
      54                 :  * Revision 1.43  2005/05/12 22:07:52  dmorissette
      55                 :  * Improved handling of Danish modified TM proj#21-24 (hss, bugs 976,1010)
      56                 :  *
      57                 :  * Revision 1.42  2005/03/22 23:24:54  dmorissette
      58                 :  * Added support for datum id in .MAP header (bug 910)
      59                 :  *
      60                 :  * Revision 1.41  2004/10/11 20:50:04  dmorissette
      61                 :  * 7 new datum defns, 1 fixed and list of ellipsoids updated (Bug 608,Uffe K.)
      62                 :  *
      63                 :  * Revision 1.40  2003/03/21 14:20:42  warmerda
      64                 :  * fixed up regional mercator handling, was screwing up transverse mercator
      65                 :  *
      66                 :  * Revision 1.39  2002/12/19 20:46:01  warmerda
      67                 :  * fixed spelling of Provisional_South_American_Datum_1956
      68                 :  *
      69                 :  * Revision 1.38  2002/12/12 20:12:18  warmerda
      70                 :  * fixed signs of rotational parameters for TOWGS84 in WKT
      71                 :  *
      72                 :  * Revision 1.37  2002/10/15 14:33:30  warmerda
      73                 :  * Added untested support in mitab_spatialref.cpp, and mitab_coordsys.cpp for
      74                 :  * projections Regional Mercator (26), Polyconic (27), Azimuthal Equidistant -
      75                 :  * All origin latitudes (28), and Lambert Azimuthal Equal Area - any aspect 
      76                 :  * (29).
      77                 :  *
      78                 :  * Revision 1.36  2002/09/05 15:38:16  warmerda
      79                 :  * one more ogc datum name
      80                 :  *
      81                 :  * Revision 1.35  2002/09/05 15:23:22  warmerda
      82                 :  * added some EPSG datum names provided by Siro Martello @ Cadcorp
      83                 :  *
      84                 :  * Revision 1.34  2002/04/01 19:49:24  warmerda
      85                 :  * added support for cassini/soldner - proj 30
      86                 :  *
      87                 :  * Revision 1.33  2002/03/01 19:00:15  warmerda
      88                 :  * False Easting/Northing should be in the linear units of measure in MapInfo,
      89                 :  * but in OGRSpatialReference/WKT they are always in meters.  Convert accordingly.
      90                 :  *
      91                 :  * Revision 1.32  2001/10/25 16:13:41  warmerda
      92                 :  * Added OGC string for datum 12
      93                 :  *
      94                 :  * Revision 1.31  2001/08/10 21:25:59  warmerda
      95                 :  * SetSpatialRef() now makes a clone of the srs instead of taking a ref to it
      96                 :  *
      97                 :  * Revision 1.30  2001/04/23 17:38:06  warmerda
      98                 :  * fixed use of freed points bug for datum 999/9999
      99                 :  *
     100                 :  * Revision 1.29  2001/04/04 21:43:19  warmerda
     101                 :  * added code to set WGS84 values
     102                 :  *
     103                 :  * Revision 1.28  2001/01/23 21:23:42  daniel
     104                 :  * Added projection bounds lookup table, called from TABFile::SetProjInfo()
     105                 :  *
     106                 :  * Revision 1.27  2001/01/22 16:00:53  warmerda
     107                 :  * reworked swiss projection support
     108                 :  *
     109                 :  * Revision 1.26  2001/01/19 21:56:18  warmerda
     110                 :  * added untested support for Swiss Oblique Mercator
     111                 :  *
     112                 :  * Revision 1.25  2000/12/05 14:56:55  daniel
     113                 :  * Added some missing unit names (aliases) in TABFile::SetSpatialRef()
     114                 :  *
     115                 :  * Revision 1.24  2000/10/16 21:44:50  warmerda
     116                 :  * added nonearth support
     117                 :  *
     118                 :  * Revision 1.23  2000/10/16 18:01:20  warmerda
     119                 :  * added check for NULL on passed in spatial ref
     120                 :  *
     121                 :  * Revision 1.22  2000/10/02 14:46:36  daniel
     122                 :  * Added 7 parameter datums with id 1000+
     123                 :  *
     124                 :  * Revision 1.21  2000/09/29 22:09:18  daniel
     125                 :  * Added new datums/ellipsoid from MapInfo V6.0
     126                 :  *
     127                 :  * Revision 1.20  2000/09/28 16:39:44  warmerda
     128                 :  * avoid warnings for unused, and unitialized variables
     129                 :  *
     130                 :  * Revision 1.19  2000/02/07 17:43:17  daniel
     131                 :  * Fixed offset in parsing of custom datum string in SetSpatialRef()
     132                 :  *
     133                 :  * Revision 1.18  2000/02/04 05:30:50  daniel
     134                 :  * Fixed problem in GetSpatialRef() with szDatumName[] buffer size and added
     135                 :  * use of an epsilon in comparing of datum parameters.
     136                 :  *
     137                 :  * Revision 1.17  2000/01/15 22:30:45  daniel
     138                 :  * Switch to MIT/X-Consortium OpenSource license
     139                 :  *
     140                 :  * Revision 1.16  1999/12/21 20:01:47  warmerda
     141                 :  * added support for DATUM 0
     142                 :  *
     143                 :  * Revision 1.15  1999/11/11 02:56:17  warmerda
     144                 :  * fixed problems with stereographic
     145                 :  *
     146                 :  * Revision 1.14  1999/11/10 20:13:12  warmerda
     147                 :  * implement spheroid table
     148                 :  *
     149                 :  * Revision 1.13  1999/11/09 22:31:38  warmerda
     150                 :  * initial implementation of MIF CoordSys support
     151                 :  *
     152                 :  * Revision 1.12  1999/10/19 16:31:32  warmerda
     153                 :  * Improved mile support.
     154                 :  *
     155                 :  * Revision 1.11  1999/10/19 16:27:50  warmerda
     156                 :  * Added support for Mile (units=0).  Also added support for nonearth
     157                 :  * projections.
     158                 :  *
     159                 :  * Revision 1.10  1999/10/05 18:56:08  warmerda
     160                 :  * fixed lots of bugs with projection parameters
     161                 :  *
     162                 :  * Revision 1.9  1999/10/04 21:17:47  warmerda
     163                 :  * Make sure that asDatumInfoList comparisons include the ellipsoid code.
     164                 :  * Don't include OGC name for local NAD27 values.  Put NAD83 ahead of GRS80
     165                 :  * so it will be used in preference even though they are identical parms.
     166                 :  *
     167                 :  * Revision 1.8  1999/10/04 19:46:42  warmerda
     168                 :  * assorted changes, including rework of units
     169                 :  *
     170                 :  * Revision 1.7  1999/09/28 04:52:17  daniel
     171                 :  * Added missing param in sprintf() format for szDatumName[]
     172                 :  *
     173                 :  * Revision 1.6  1999/09/28 02:51:46  warmerda
     174                 :  * Added ellipsoid codes, and bulk of write implementation.
     175                 :  *
     176                 :  * Revision 1.5  1999/09/27 21:23:41  warmerda
     177                 :  * added more projections
     178                 :  *
     179                 :  * Revision 1.4  1999/09/24 04:01:28  warmerda
     180                 :  * remember nMIDatumId changes
     181                 :  *
     182                 :  * Revision 1.3  1999/09/23 19:51:38  warmerda
     183                 :  * added datum mapping table support
     184                 :  *
     185                 :  * Revision 1.2  1999/09/22 23:04:59  daniel
     186                 :  * Handle reference count on OGRSpatialReference properly
     187                 :  *
     188                 :  * Revision 1.1  1999/09/21 19:39:22  daniel
     189                 :  * Moved Get/SetSpatialRef() to a separate file
     190                 :  *
     191                 :  **********************************************************************/
     192                 : 
     193                 : #include "mitab.h"
     194                 : 
     195                 : /* -------------------------------------------------------------------- */
     196                 : /*      This table was automatically generated by doing translations    */
     197                 : /*      between mif and tab for each datum, and extracting the          */
     198                 : /*      parameters from the tab file.  The OGC names were added         */
     199                 : /*      afterwards and may be incomplete or inaccurate.                 */
     200                 : /* -------------------------------------------------------------------- */
     201                 : MapInfoDatumInfo asDatumInfoList[] =
     202                 : {
     203                 : 
     204                 : {104, "WGS_1984",                   28,0, 0, 0, 0, 0, 0, 0, 0},
     205                 : {74,  "North_American_Datum_1983",  0, 0, 0, 0, 0, 0, 0, 0, 0},
     206                 : 
     207                 : {0,  "",                            29, 0,   0,    0,   0, 0, 0, 0, 0}, // Datum ignore
     208                 : 
     209                 : {1,  "Adindan",                     6, -162, -12,  206, 0, 0, 0, 0, 0},
     210                 : {2,  "Afgooye",                     3, -43,  -163, 45,  0, 0, 0, 0, 0},
     211                 : {3,  "Ain_el_Abd_1970",             4, -150, -251, -2,  0, 0, 0, 0, 0},
     212                 : {4,  "Anna_1_Astro_1965",           2, -491, -22,  435, 0, 0, 0, 0, 0},
     213                 : {5,  "Arc_1950",                    15,-143, -90,  -294,0, 0, 0, 0, 0},
     214                 : {6,  "Arc_1960",                    6, -160, -8,   -300,0, 0, 0, 0, 0},
     215                 : {7,  "Ascension_Islands",           4, -207, 107,  52,  0, 0, 0, 0, 0},
     216                 : {8,  "Astro_Beacon_E",              4, 145,  75,   -272,0, 0, 0, 0, 0},
     217                 : {9,  "Astro_B4_Sorol_Atoll",        4, 114,  -116, -333,0, 0, 0, 0, 0},
     218                 : {10, "Astro_Dos_71_4",              4, -320, 550,  -494,0, 0, 0, 0, 0},
     219                 : {11, "Astronomic_Station_1952",     4, 124,  -234, -25, 0, 0, 0, 0, 0},
     220                 : {12, "Australian_Geodetic_Datum_66",2, -133, -48,  148, 0, 0, 0, 0, 0},
     221                 : {13, "Australian_Geodetic_Datum_84",2, -134, -48,  149, 0, 0, 0, 0, 0},
     222                 : {14, "Bellevue_Ign",                4, -127, -769, 472, 0, 0, 0, 0, 0},
     223                 : {15, "Bermuda_1957",                7, -73,  213,  296, 0, 0, 0, 0, 0},
     224                 : {16, "Bogota",                      4, 307,  304,  -318,0, 0, 0, 0, 0},
     225                 : {17, "Campo_Inchauspe",             4, -148, 136,  90,  0, 0, 0, 0, 0},
     226                 : {18, "Canton_Astro_1966",           4, 298,  -304, -375,0, 0, 0, 0, 0},
     227                 : {19, "Cape",                        6, -136, -108, -292,0, 0, 0, 0, 0},
     228                 : {20, "Cape_Canaveral",              7, -2,   150,  181, 0, 0, 0, 0, 0},
     229                 : {21, "Carthage",                    6, -263, 6,    431, 0, 0, 0, 0, 0},
     230                 : {22, "Chatham_1971",                4, 175,  -38,  113, 0, 0, 0, 0, 0},
     231                 : {23, "Chua",                        4, -134, 229,  -29, 0, 0, 0, 0, 0},
     232                 : {24, "Corrego_Alegre",              4, -206, 172,  -6,  0, 0, 0, 0, 0},
     233                 : {25, "Batavia",                     10,-377,681,   -50, 0, 0, 0, 0, 0},
     234                 : {26, "Dos_1968",                    4, 230,  -199, -752,0, 0, 0, 0, 0},
     235                 : {27, "Easter_Island_1967",          4, 211,  147,  111, 0, 0, 0, 0, 0},
     236                 : {28, "European_Datum_1950",         4, -87,  -98,  -121,0, 0, 0, 0, 0},
     237                 : {29, "European_Datum_1979",         4, -86,  -98,  -119,0, 0, 0, 0, 0},
     238                 : {30, "Gandajika_1970",              4, -133, -321, 50,  0, 0, 0, 0, 0},
     239                 : {31, "New_Zealand_GD49",            4, 84,   -22,  209, 0, 0, 0, 0, 0},
     240                 : {31, "New_Zealand_Geodetic_Datum_1949",4,84, -22,  209, 0, 0, 0, 0, 0},
     241                 : {32, "GRS_67",                      21,0,    0,    0,   0, 0, 0, 0, 0},
     242                 : {33, "GRS_80",                      0, 0,    0,    0,   0, 0, 0, 0, 0},
     243                 : {34, "Guam_1963",                   7, -100, -248, 259, 0, 0, 0, 0, 0},
     244                 : {35, "Gux_1_Astro",                 4, 252,  -209, -751,0, 0, 0, 0, 0},
     245                 : {36, "Hito_XVIII_1963",             4, 16,   196,  93,  0, 0, 0, 0, 0},
     246                 : {37, "Hjorsey_1955",                4, -73,  46,   -86, 0, 0, 0, 0, 0},
     247                 : {38, "Hong_Kong_1963",              4, -156, -271, -189,0, 0, 0, 0, 0},
     248                 : {39, "Hu_Tzu_Shan",                 4, -634, -549, -201,0, 0, 0, 0, 0},
     249                 : {40, "Indian_Thailand_Vietnam",     11,214,  836,  303, 0, 0, 0, 0, 0},
     250                 : {41, "Indian_Bangladesh",           11,289,  734,  257, 0, 0, 0, 0, 0},
     251                 : {42, "Ireland_1965",                13,506,  -122, 611, 0, 0, 0, 0, 0},
     252                 : {43, "ISTS_073_Astro_1969",         4, 208,  -435, -229,0, 0, 0, 0, 0},
     253                 : {44, "Johnston_Island_1961",        4, 191,  -77,  -204,0, 0, 0, 0, 0},
     254                 : {45, "Kandawala",                   11,-97,  787,  86,  0, 0, 0, 0, 0},
     255                 : {46, "Kerguyelen_Island",           4, 145,  -187, 103, 0, 0, 0, 0, 0},
     256                 : {47, "Kertau",                      17,-11,  851,  5,   0, 0, 0, 0, 0},
     257                 : {48, "L_C_5_Astro",                 7, 42,   124,  147, 0, 0, 0, 0, 0},
     258                 : {49, "Liberia_1964",                6, -90,  40,   88,  0, 0, 0, 0, 0},
     259                 : {50, "Luzon_Phillippines",          7, -133, -77,  -51, 0, 0, 0, 0, 0},
     260                 : {51, "Luzon_Mindanao_Island",       7, -133, -79,  -72, 0, 0, 0, 0, 0},
     261                 : {52, "Mahe_1971",                   6, 41,   -220, -134,0, 0, 0, 0, 0},
     262                 : {53, "Marco_Astro",                 4, -289, -124, 60,  0, 0, 0, 0, 0},
     263                 : {54, "Massawa",                     10,639,  405,  60,  0, 0, 0, 0, 0},
     264                 : {55, "Merchich",                    16,31,   146,  47,  0, 0, 0, 0, 0},
     265                 : {56, "Midway_Astro_1961",           4, 912,  -58,  1227,0, 0, 0, 0, 0},
     266                 : {57, "Minna",                       6, -92,  -93,  122, 0, 0, 0, 0, 0},
     267                 : {58, "Nahrwan_Masirah_Island",      6, -247, -148, 369, 0, 0, 0, 0, 0},
     268                 : {59, "Nahrwan_Un_Arab_Emirates",    6, -249, -156, 381, 0, 0, 0, 0, 0},
     269                 : {60, "Nahrwan_Saudi_Arabia",        6, -231, -196, 482, 0, 0, 0, 0, 0},
     270                 : {61, "Naparima_1972",               4, -2,   374,  172, 0, 0, 0, 0, 0},
     271                 : {62, "NAD_1927",                    7, -8,   160,  176, 0, 0, 0, 0, 0},
     272                 : {62, "North_American_Datum_1927",   7, -8,   160,  176, 0, 0, 0, 0, 0},
     273                 : {63, "NAD_27_Alaska",               7, -5,   135,  172, 0, 0, 0, 0, 0},
     274                 : {64, "NAD_27_Bahamas",              7, -4,   154,  178, 0, 0, 0, 0, 0},
     275                 : {65, "NAD_27_San_Salvador",         7, 1,    140,  165, 0, 0, 0, 0, 0},
     276                 : {66, "NAD_27_Canada",               7, -10,  158,  187, 0, 0, 0, 0, 0},
     277                 : {67, "NAD_27_Canal_Zone",           7, 0,    125,  201, 0, 0, 0, 0, 0},
     278                 : {68, "NAD_27_Caribbean",            7, -7,   152,  178, 0, 0, 0, 0, 0},
     279                 : {69, "NAD_27_Central_America",      7, 0,    125,  194, 0, 0, 0, 0, 0},
     280                 : {70, "NAD_27_Cuba",                 7, -9,   152,  178, 0, 0, 0, 0, 0},
     281                 : {71, "NAD_27_Greenland",            7, 11,   114,  195, 0, 0, 0, 0, 0},
     282                 : {72, "NAD_27_Mexico",               7, -12,  130,  190, 0, 0, 0, 0, 0},
     283                 : {73, "NAD_27_Michigan",             8, -8,   160,  176, 0, 0, 0, 0, 0},
     284                 : {75, "Observatorio_1966",           4, -425, -169, 81,  0, 0, 0, 0, 0},
     285                 : {76, "Old_Egyptian",                22,-130, 110, -13,  0, 0, 0, 0, 0},
     286                 : {77, "Old_Hawaiian",                7, 61,   -285, -181,0, 0, 0, 0, 0},
     287                 : {78, "Oman",                        6, -346, -1,   224, 0, 0, 0, 0, 0},
     288                 : {79, "OSGB_1936",                   9, 375,  -111, 431, 0, 0, 0, 0, 0},
     289                 : {80, "Pico_De_Las_Nieves",          4, -307, -92,  127, 0, 0, 0, 0, 0},
     290                 : {81, "Pitcairn_Astro_1967",         4, 185,  165,  42,  0, 0, 0, 0, 0},
     291                 : {82, "Provisional_South_American",  4, -288, 175,  -376,0, 0, 0, 0, 0},
     292                 : {83, "Puerto_Rico",                 7, 11,   72,   -101,0, 0, 0, 0, 0},
     293                 : {84, "Qatar_National",              4, -128, -283, 22,  0, 0, 0, 0, 0},
     294                 : {85, "Qornoq",                      4, 164,  138, -189, 0, 0, 0, 0, 0},
     295                 : {86, "Reunion",                     4, 94,   -948,-1262,0, 0, 0, 0, 0},
     296                 : {87, "Monte_Mario",                 4, -225, -65, 9,    0, 0, 0, 0, 0},
     297                 : {88, "Santo_Dos",                   4, 170,  42,  84,   0, 0, 0, 0, 0},
     298                 : {89, "Sao_Braz",                    4, -203, 141, 53,   0, 0, 0, 0, 0},
     299                 : {90, "Sapper_Hill_1943",            4, -355, 16,  74,   0, 0, 0, 0, 0},
     300                 : {91, "Schwarzeck",                  14,616,  97,  -251, 0, 0, 0, 0, 0},
     301                 : {92, "South_American_Datum_1969",   24,-57,  1,   -41,  0, 0, 0, 0, 0},
     302                 : {93, "South_Asia",                  19,7,    -10, -26,  0, 0, 0, 0, 0},
     303                 : {94, "Southeast_Base",              4, -499, -249,314,  0, 0, 0, 0, 0},
     304                 : {95, "Southwest_Base",              4, -104, 167, -38,  0, 0, 0, 0, 0},
     305                 : {96, "Timbalai_1948",               11,-689, 691, -46,  0, 0, 0, 0, 0},
     306                 : {97, "Tokyo",                       10,-128, 481, 664,  0, 0, 0, 0, 0},
     307                 : {98, "Tristan_Astro_1968",          4, -632, 438, -609, 0, 0, 0, 0, 0},
     308                 : {99, "Viti_Levu_1916",              6, 51,   391, -36,  0, 0, 0, 0, 0},
     309                 : {100, "Wake_Entiwetok_1960",        23,101,  52,  -39,  0, 0, 0, 0, 0},
     310                 : {101, "WGS_60",                     26,0,    0,   0,    0, 0, 0, 0, 0},
     311                 : {102, "WGS_66",                     27,0,    0,   0,    0, 0, 0, 0, 0},
     312                 : {103, "WGS_1972",                   1, 0,    8,   10,   0, 0, 0, 0, 0},
     313                 : {104, "WGS_1984",                   28,0,    0,   0,    0, 0, 0, 0, 0},
     314                 : {105, "Yacare",                     4, -155, 171, 37,   0, 0, 0, 0, 0},
     315                 : {106, "Zanderij",                   4, -265, 120, -358, 0, 0, 0, 0, 0},
     316                 : {107, "NTF",                        30,-168, -60, 320,  0, 0, 0, 0, 0},
     317                 : {108, "European_Datum_1987",        4, -83,  -96, -113, 0, 0, 0, 0, 0},
     318                 : {109, "Netherlands_Bessel",         10,593,  26,  478,  0, 0, 0, 0, 0},
     319                 : {110, "Belgium_Hayford",            4, 81,   120, 129,  0, 0, 0, 0, 0},
     320                 : {111, "NWGL_10",                    1, -1,   15,  1,    0, 0, 0, 0, 0},
     321                 : {112, "Rikets_koordinatsystem_1990",10,498,  -36, 568,  0, 0, 0, 0, 0},
     322                 : {113, "Lisboa_DLX",                 4, -303, -62, 105,  0, 0, 0, 0, 0},
     323                 : {114, "Melrica_1973_D73",           4, -223, 110, 37,   0, 0, 0, 0, 0},
     324                 : {115, "Euref_98",                   0, 0,    0,   0,    0, 0, 0, 0, 0},
     325                 : {116, "GDA94",                      0, 0,    0,   0,    0, 0, 0, 0, 0},
     326                 : {117, "NZGD2000",                   0, 0,    0,   0,    0, 0, 0, 0, 0},
     327                 : {117, "New_Zealand_Geodetic_Datum_2000",0,0, 0,   0,    0, 0, 0, 0, 0},
     328                 : {118, "America_Samoa",              7, -115, 118, 426,  0, 0, 0, 0, 0},
     329                 : {119, "Antigua_Astro_1965",         6, -270, 13,  62,   0, 0, 0, 0, 0},
     330                 : {120, "Ayabelle_Lighthouse",        6, -79, -129, 145,  0, 0, 0, 0, 0},
     331                 : {121, "Bukit_Rimpah",               10,-384, 664, -48,  0, 0, 0, 0, 0},
     332                 : {122, "Estonia_1937",               10,374, 150,  588,  0, 0, 0, 0, 0},
     333                 : {123, "Dabola",                     6, -83, 37,   124,  0, 0, 0, 0, 0},
     334                 : {124, "Deception_Island",           6, 260, 12,   -147, 0, 0, 0, 0, 0},
     335                 : {125, "Fort_Thomas_1955",           6, -7, 215,   225,  0, 0, 0, 0, 0},
     336                 : {126, "Graciosa_base_1948",         4, -104, 167, -38,  0, 0, 0, 0, 0},
     337                 : {127, "Herat_North",                4, -333, -222,114,  0, 0, 0, 0, 0},
     338                 : {128, "Hermanns_Kogel",             10,682, -203, 480,  0, 0, 0, 0, 0},
     339                 : {129, "Indian",                     50,283, 682,  231,  0, 0, 0, 0, 0},
     340                 : {130, "Indian_1954",                11,217, 823,  299,  0, 0, 0, 0, 0},
     341                 : {131, "Indian_1960",                11,198, 881,  317,  0, 0, 0, 0, 0},
     342                 : {132, "Indian_1975",                11,210, 814,  289,  0, 0, 0, 0, 0},
     343                 : {133, "Indonesian_Datum_1974",      4, -24, -15,  5,    0, 0, 0, 0, 0},
     344                 : {134, "ISTS061_Astro_1968",         4, -794, 119, -298, 0, 0, 0, 0, 0},
     345                 : {135, "Kusaie_Astro_1951",          4, 647, 1777, -1124,0, 0, 0, 0, 0},
     346                 : {136, "Leigon",                     6, -130, 29,  364,  0, 0, 0, 0, 0},
     347                 : {137, "Montserrat_Astro_1958",      6, 174, 359,  365,  0, 0, 0, 0, 0},
     348                 : {138, "Mporaloko",                  6, -74, -130, 42,   0, 0, 0, 0, 0},
     349                 : {139, "North_Sahara_1959",          6, -186, -93, 310,  0, 0, 0, 0, 0},
     350                 : {140, "Observatorio_Met_1939",      4, -425, -169,81,   0, 0, 0, 0, 0},
     351                 : {141, "Point_58",                   6, -106, -129,165,  0, 0, 0, 0, 0},
     352                 : {142, "Pointe_Noire",               6, -148, 51,  -291, 0, 0, 0, 0, 0},
     353                 : {143, "Porto_Santo_1936",           4, -499, -249,314,  0, 0, 0, 0, 0},
     354                 : {144, "Selvagem_Grande_1938",       4, -289, -124,60,   0, 0, 0, 0, 0},
     355                 : {145, "Sierra_Leone_1960",          6, -88,  4,   101,  0, 0, 0, 0, 0},
     356                 : {146, "S_JTSK_Ferro",               10, 589, 76,  480,  0, 0, 0, 0, 0},
     357                 : {147, "Tananarive_1925",            4, -189, -242,-91,  0, 0, 0, 0, 0},
     358                 : {148, "Voirol_1874",                6, -73,  -247,227,  0, 0, 0, 0, 0},
     359                 : {149, "Virol_1960",                 6, -123, -206,219,  0, 0, 0, 0, 0},
     360                 : {150, "Hartebeesthoek94",           0, 0,    0,   0,    0, 0, 0, 0, 0},
     361                 : {151, "ATS77",                      51, 0, 0, 0, 0, 0, 0, 0, 0},
     362                 : {152, "JGD2000",                    0, 0, 0, 0, 0, 0, 0, 0, 0},
     363                 : {1000,"DHDN_Potsdam_Rauenberg",     10,582,  105, 414, -1.04, -0.35, 3.08, 8.3, 0},
     364                 : {1001,"Pulkovo_1942",               3, 24,   -123, -94, -0.02, 0.25, 0.13, 1.1, 0},
     365                 : {1002,"NTF_Paris_Meridian",         30,-168, -60, 320, 0, 0, 0, 0, 2.337229166667},
     366                 : {1003,"Switzerland_CH_1903",        10,660.077,13.551, 369.344, 0.804816, 0.577692, 0.952236, 5.66,0},
     367                 : {1004,"Hungarian_Datum_1972",       21,-56,  75.77, 15.31, -0.37, -0.2, -0.21, -1.01, 0},
     368                 : {1005,"Cape_7_Parameter",           28,-134.73,-110.92, -292.66, 0, 0, 0, 1, 0},
     369                 : {1006,"AGD84_7_Param_Aust",         2, -117.763,-51.51, 139.061, -0.292, -0.443, -0.277, -0.191, 0},
     370                 : {1007,"AGD66_7_Param_ACT",          2, -129.193,-41.212, 130.73, -0.246, -0.374, -0.329, -2.955, 0},
     371                 : {1008,"AGD66_7_Param_TAS",          2, -120.271,-64.543, 161.632, -0.2175, 0.0672, 0.1291, 2.4985, 0},
     372                 : {1009,"AGD66_7_Param_VIC_NSW",      2, -119.353,-48.301, 139.484, -0.415, -0.26, -0.437, -0.613, 0},
     373                 : {1010,"NZGD_7_Param_49",            4, 59.47, -5.04, 187.44, -0.47, 0.1, -1.024, -4.5993, 0},
     374                 : {1011,"Rikets_Tri_7_Param_1990",    10,419.3836, 99.3335, 591.3451, -0.850389, -1.817277, 7.862238, -0.99496, 0},
     375                 : {1012,"Russia_PZ90",                52, -1.08,-0.27,-0.9,0, 0, -0.16,-0.12, 0},
     376                 : {1013,"Russia_SK42",                52, 23.92,-141.27,-80.9, 0, -0.35,-0.82, -0.12, 0},
     377                 : {1014,"Russia_SK95",                52, 24.82,-131.21,-82.66,0,0,-0.16,-0.12, 0},
     378                 : {1015,"Tokyo",                      10, -146.414, 507.337, 680.507,0,0,0,0,0},
     379                 : {1016,"Finnish_KKJ",                4, -96.062, -82.428, -121.754, -4.801, -0.345, 1.376, 1.496, 0},
     380                 : 
     381                 : {-1, NULL,                          0, 0, 0, 0, 0, 0, 0, 0, 0}
     382                 : };
     383                 : 
     384                 : /* -------------------------------------------------------------------- */
     385                 : /*      This table was hand entered from Appendix I of the mapinfo 6    */
     386                 : /*      manuals.                                                        */
     387                 : /* -------------------------------------------------------------------- */
     388                 : 
     389                 : MapInfoSpheroidInfo asSpheroidInfoList[] =
     390                 : {
     391                 : { 9,"Airy 1930",                                6377563.396,    299.3249646},
     392                 : {13,"Airy 1930 (modified for Ireland 1965",     6377340.189,    299.3249646},
     393                 : {51,"ATS77 (Average Terrestrial System 1977)",  6378135,        298.257},
     394                 : { 2,"Australian",                               6378160.0,      298.25},
     395                 : {10,"Bessel 1841",                              6377397.155,    299.1528128},
     396                 : {35,"Bessel 1841 (modified for NGO 1948)",      6377492.0176,   299.15281},
     397                 : {14,"Bessel 1841 (modified for Schwarzeck)",    6377483.865,    299.1528128},
     398                 : {36,"Clarke 1858",                              6378293.639,    294.26068},
     399                 : { 7,"Clarke 1866",                              6378206.4,      294.9786982},
     400                 : { 8,"Clarke 1866 (modified for Michigan)",      6378450.047484481,294.9786982},
     401                 : { 6,"Clarke 1880",                              6378249.145,    293.465},
     402                 : {15,"Clarke 1880 (modified for Arc 1950)",      6378249.145326, 293.4663076},
     403                 : {30,"Clarke 1880 (modified for IGN)",           6378249.2,      293.4660213},
     404                 : {37,"Clarke 1880 (modified for Jamaica)",       6378249.136,    293.46631},
     405                 : {16,"Clarke 1880 (modified for Merchich)",      6378249.2,      293.46598},
     406                 : {38,"Clarke 1880 (modified for Palestine)",     6378300.79,     293.46623},
     407                 : {39,"Everest (Brunei and East Malaysia)",       6377298.556,    300.8017},
     408                 : {11,"Everest (India 1830)",                     6377276.345,    300.8017},
     409                 : {40,"Everest (India 1956)",                     6377301.243,    300.80174},
     410                 : {50,"Everest (Pakistan)",                       6377309.613,    300.8017},
     411                 : {17,"Everest (W. Malaysia and Singapore 1948)", 6377304.063,    300.8017},
     412                 : {48,"Everest (West Malaysia 1969)",             6377304.063,    300.8017},
     413                 : {18,"Fischer 1960",                             6378166.0,      298.3},
     414                 : {19,"Fischer 1960 (modified for South Asia)",   6378155.0,      298.3},
     415                 : {20,"Fischer 1968",                             6378150.0,      298.3},
     416                 : {21,"GRS 67",                                   6378160.0,      298.247167427},
     417                 : { 0,"GRS 80",                                   6378137.0,      298.257222101},
     418                 : { 5,"Hayford",                                  6378388.0,      297.0},
     419                 : {22,"Helmert 1906",                             6378200.0,      298.3},
     420                 : {23,"Hough",                                    6378270.0,      297.0},
     421                 : {31,"IAG 75",                                   6378140.0,      298.257222},
     422                 : {41,"Indonesian",                               6378160.0,      298.247},
     423                 : { 4,"International 1924",                       6378388.0,      297.0},
     424                 : {49,"Irish (WOFO)",                             6377542.178,    299.325},
     425                 : { 3,"Krassovsky",                               6378245.0,      298.3},
     426                 : {32,"MERIT 83",                                 6378137.0,      298.257},
     427                 : {33,"New International 1967",                   6378157.5,      298.25},
     428                 : {42,"NWL 9D",                                   6378145.0,      298.25},
     429                 : {43,"NWL 10D",                                  6378135.0,      298.26},
     430                 : {44,"OSU86F",                                   6378136.2,      298.25722},
     431                 : {45,"OSU91A",                                   6378136.3,      298.25722},
     432                 : {46,"Plessis 1817",                             6376523.0,      308.64},
     433                 : {52,"PZ90",                                     6378136.0,      298.257839303},
     434                 : {24,"South American",                           6378160.0,      298.25},
     435                 : {12,"Sphere",                                   6370997.0,      0.0},
     436                 : {47,"Struve 1860",                              6378297.0,      294.73},
     437                 : {34,"Walbeck",                                  6376896.0,      302.78},
     438                 : {25,"War Office",                               6378300.583,    296.0},
     439                 : {26,"WGS 60",                                   6378165.0,      298.3},
     440                 : {27,"WGS 66",                                   6378145.0,      298.25},
     441                 : { 1,"WGS 72",                                   6378135.0,      298.26},
     442                 : {28,"WGS 84",                                   6378137.0,      298.257223563},
     443                 : {29,"WGS 84 (MAPINFO Datum 0)",                 6378137.01,     298.257223563},
     444                 : {-1,NULL,                                       0.0,            0.0}
     445                 : };
     446                 :  
     447                 : /**********************************************************************
     448                 :  *                   TABFile::GetSpatialRef()
     449                 :  *
     450                 :  * Returns a reference to an OGRSpatialReference for this dataset.
     451                 :  * If the projection parameters have not been parsed yet, then we will
     452                 :  * parse them before returning.
     453                 :  *
     454                 :  * The returned object is owned and maintained by this TABFile and
     455                 :  * should not be modified or freed by the caller.
     456                 :  *
     457                 :  * Returns NULL if the SpatialRef cannot be accessed.
     458                 :  **********************************************************************/
     459               1 : OGRSpatialReference *TABFile::GetSpatialRef()
     460                 : {
     461               1 :     if (m_eAccessMode != TABRead)
     462                 :     {
     463                 :         CPLError(CE_Failure, CPLE_NotSupported,
     464               0 :                  "GetSpatialRef() can be used only with Read access.");
     465               0 :         return NULL;
     466                 :     }
     467                 :  
     468               1 :     if (m_poMAPFile == NULL )
     469                 :     {
     470                 :         CPLError(CE_Failure, CPLE_AssertionFailed,
     471               0 :                  "GetSpatialRef() failed: file has not been opened yet.");
     472               0 :         return NULL;
     473                 :     }
     474                 : 
     475                 :     /*-----------------------------------------------------------------
     476                 :      * If projection params have already been processed, just use them.
     477                 :      *----------------------------------------------------------------*/
     478               1 :     if (m_poSpatialRef != NULL)
     479               0 :         return m_poSpatialRef;
     480                 :     
     481                 : 
     482                 :     /*-----------------------------------------------------------------
     483                 :      * Fetch the parameters from the header.
     484                 :      *----------------------------------------------------------------*/
     485                 :     TABMAPHeaderBlock *poHeader;
     486                 :     TABProjInfo     sTABProj;
     487                 : 
     488               1 :     if ((poHeader = m_poMAPFile->GetHeaderBlock()) == NULL ||
     489                 :         poHeader->GetProjInfo( &sTABProj ) != 0)
     490                 :     {
     491                 :         CPLError(CE_Failure, CPLE_FileIO,
     492               0 :                  "GetSpatialRef() failed reading projection parameters.");
     493               0 :         return NULL;
     494                 :     }
     495                 : 
     496                 :     /*-----------------------------------------------------------------
     497                 :      * Get the units name, and translation factor.
     498                 :      *----------------------------------------------------------------*/
     499                 :     const char *pszUnitsName; 
     500                 :     const char *pszUnitsConv;
     501               1 :     double      dfConv = 1.0;
     502                 : 
     503               1 :     switch( sTABProj.nUnitsId )
     504                 :     {
     505                 :       case 0:
     506               0 :         pszUnitsName = "Mile";
     507               0 :         pszUnitsConv = "1609.344";
     508               0 :         break;
     509                 : 
     510                 :       case 1:
     511               0 :         pszUnitsName = "Kilometer";
     512               0 :         pszUnitsConv = "1000.0";
     513               0 :         break;
     514                 :             
     515                 :       case 2:
     516               0 :         pszUnitsName = "IINCH";
     517               0 :         pszUnitsConv = "0.0254";
     518               0 :         break;
     519                 :             
     520                 :       case 3:
     521               0 :         pszUnitsName = SRS_UL_FOOT;
     522               0 :         pszUnitsConv = SRS_UL_FOOT_CONV;
     523               0 :         break;
     524                 :             
     525                 :       case 4:
     526               0 :         pszUnitsName = "IYARD";
     527               0 :         pszUnitsConv = "0.9144";
     528               0 :         break;
     529                 :             
     530                 :       case 5:
     531               0 :         pszUnitsName = "Millimeter";
     532               0 :         pszUnitsConv = "0.001";
     533               0 :         break;
     534                 :             
     535                 :       case 6:
     536               0 :         pszUnitsName = "Centimeter";
     537               0 :         pszUnitsConv = "0.01";
     538               0 :         break;
     539                 :             
     540                 :       case 7:
     541               1 :         pszUnitsName = SRS_UL_METER;
     542               1 :         pszUnitsConv = "1.0";
     543               1 :         break;
     544                 :             
     545                 :       case 8:
     546               0 :         pszUnitsName = SRS_UL_US_FOOT;
     547               0 :         pszUnitsConv = SRS_UL_US_FOOT_CONV;
     548               0 :         break;
     549                 :             
     550                 :       case 9:
     551               0 :         pszUnitsName = SRS_UL_NAUTICAL_MILE;
     552               0 :         pszUnitsConv = SRS_UL_NAUTICAL_MILE_CONV;
     553               0 :         break;
     554                 :             
     555                 :       case 30:
     556               0 :         pszUnitsName = SRS_UL_LINK;
     557               0 :         pszUnitsConv = SRS_UL_LINK_CONV;
     558               0 :         break;
     559                 :             
     560                 :       case 31:
     561               0 :         pszUnitsName = SRS_UL_CHAIN;
     562               0 :         pszUnitsConv = SRS_UL_CHAIN_CONV;
     563               0 :         break;
     564                 :             
     565                 :       case 32:
     566               0 :         pszUnitsName = SRS_UL_ROD;
     567               0 :         pszUnitsConv = SRS_UL_ROD_CONV;
     568               0 :         break;
     569                 :             
     570                 :       default:
     571               0 :         pszUnitsName = SRS_UL_METER;
     572               0 :         pszUnitsConv = "1.0";
     573                 :         break;
     574                 :     }
     575                 : 
     576               1 :     dfConv = atof(pszUnitsConv);
     577                 : 
     578                 :     /*-----------------------------------------------------------------
     579                 :      * Transform them into an OGRSpatialReference.
     580                 :      *----------------------------------------------------------------*/
     581               1 :     m_poSpatialRef = new OGRSpatialReference;
     582                 : 
     583                 :     /*-----------------------------------------------------------------
     584                 :      * Handle the PROJCS style projections, but add the datum later.
     585                 :      *----------------------------------------------------------------*/
     586               1 :     switch( sTABProj.nProjId )
     587                 :     {
     588                 :         /*--------------------------------------------------------------
     589                 :          * NonEarth ... we return with an empty SpatialRef.  Eventually
     590                 :          * we might want to include the units, but not for now.
     591                 :          *-------------------------------------------------------------*/
     592                 :       case 0:
     593               0 :         m_poSpatialRef->SetLocalCS( "Nonearth" );
     594               0 :         break;
     595                 : 
     596                 :         /*--------------------------------------------------------------
     597                 :          * lat/long .. just add the GEOGCS later.
     598                 :          *-------------------------------------------------------------*/
     599                 :       case 1:
     600               0 :         break;
     601                 : 
     602                 :         /*--------------------------------------------------------------
     603                 :          * Cylindrical Equal Area
     604                 :          *-------------------------------------------------------------*/
     605                 :       case 2:
     606                 :         m_poSpatialRef->SetCEA( sTABProj.adProjParams[1],
     607                 :                                 sTABProj.adProjParams[0],
     608                 :                                 sTABProj.adProjParams[2],
     609               0 :                                 sTABProj.adProjParams[3] );
     610               0 :         break;
     611                 : 
     612                 :         /*--------------------------------------------------------------
     613                 :          * Lambert Conic Conformal
     614                 :          *-------------------------------------------------------------*/
     615                 :       case 3:
     616                 :         m_poSpatialRef->SetLCC( sTABProj.adProjParams[2],
     617                 :                                 sTABProj.adProjParams[3],
     618                 :                                 sTABProj.adProjParams[1],
     619                 :                                 sTABProj.adProjParams[0],
     620                 :                                 sTABProj.adProjParams[4],
     621               0 :                                 sTABProj.adProjParams[5] );
     622               0 :         break;
     623                 : 
     624                 :         /*--------------------------------------------------------------
     625                 :          * Lambert Azimuthal Equal Area
     626                 :          *-------------------------------------------------------------*/
     627                 :       case 4:
     628                 :       case 29:
     629                 :         m_poSpatialRef->SetLAEA( sTABProj.adProjParams[1],
     630                 :                                  sTABProj.adProjParams[0],
     631               0 :                                  0.0, 0.0 );
     632               0 :         break;
     633                 : 
     634                 :         /*--------------------------------------------------------------
     635                 :          * Azimuthal Equidistant (Polar aspect only)
     636                 :          *-------------------------------------------------------------*/
     637                 :       case 5:
     638                 :       case 28:
     639                 :         m_poSpatialRef->SetAE( sTABProj.adProjParams[1],
     640                 :                                sTABProj.adProjParams[0],
     641               0 :                                0.0, 0.0 );
     642               0 :         break;
     643                 : 
     644                 :         /*--------------------------------------------------------------
     645                 :          * Equidistant Conic
     646                 :          *-------------------------------------------------------------*/
     647                 :       case 6:
     648                 :         m_poSpatialRef->SetEC( sTABProj.adProjParams[2],
     649                 :                                sTABProj.adProjParams[3],
     650                 :                                sTABProj.adProjParams[1],
     651                 :                                sTABProj.adProjParams[0],
     652                 :                                sTABProj.adProjParams[4],
     653               0 :                                sTABProj.adProjParams[5] );
     654               0 :         break;
     655                 : 
     656                 :         /*--------------------------------------------------------------
     657                 :          * Hotine Oblique Mercator
     658                 :          *-------------------------------------------------------------*/
     659                 :       case 7:
     660                 :         m_poSpatialRef->SetHOM( sTABProj.adProjParams[1],
     661                 :                                 sTABProj.adProjParams[0], 
     662                 :                                 sTABProj.adProjParams[2],
     663                 :                                 90.0, 
     664                 :                                 sTABProj.adProjParams[3],
     665                 :                                 sTABProj.adProjParams[4],
     666               0 :                                 sTABProj.adProjParams[5] );
     667               0 :         break;
     668                 : 
     669                 :         /*--------------------------------------------------------------
     670                 :          * Transverse Mercator
     671                 :          *-------------------------------------------------------------*/
     672                 :       case 8:
     673                 :         m_poSpatialRef->SetTM( sTABProj.adProjParams[1],
     674                 :                                sTABProj.adProjParams[0],
     675                 :                                sTABProj.adProjParams[2],
     676                 :                                sTABProj.adProjParams[3],
     677               1 :                                sTABProj.adProjParams[4] );
     678               1 :         break;
     679                 : 
     680                 :         /*----------------------------------------------------------------
     681                 :          * Transverse Mercator,(modified for Danish System 34 Jylland-Fyn)
     682                 :          *---------------------------------------------------------------*/
     683                 :       case 21:
     684                 :          m_poSpatialRef->SetTMVariant( SRS_PT_TRANSVERSE_MERCATOR_MI_21,
     685                 :                                        sTABProj.adProjParams[1],
     686                 :                                        sTABProj.adProjParams[0],
     687                 :                                        sTABProj.adProjParams[2],
     688                 :                                        sTABProj.adProjParams[3],
     689               0 :                                        sTABProj.adProjParams[4] );
     690               0 :          break;
     691                 : 
     692                 :         /*--------------------------------------------------------------
     693                 :          * Transverse Mercator,(modified for Danish System 34 Sjaelland)
     694                 :          *-------------------------------------------------------------*/
     695                 :       case 22:
     696                 :          m_poSpatialRef->SetTMVariant( SRS_PT_TRANSVERSE_MERCATOR_MI_22,
     697                 :                                        sTABProj.adProjParams[1],
     698                 :                                        sTABProj.adProjParams[0],
     699                 :                                        sTABProj.adProjParams[2],
     700                 :                                        sTABProj.adProjParams[3],
     701               0 :                                        sTABProj.adProjParams[4] );
     702               0 :          break;
     703                 : 
     704                 :         /*----------------------------------------------------------------
     705                 :          * Transverse Mercator,(modified for Danish System 34/45 Bornholm)
     706                 :          *---------------------------------------------------------------*/
     707                 :       case 23:
     708                 :          m_poSpatialRef->SetTMVariant( SRS_PT_TRANSVERSE_MERCATOR_MI_23,
     709                 :                                        sTABProj.adProjParams[1],
     710                 :                                        sTABProj.adProjParams[0],
     711                 :                                        sTABProj.adProjParams[2],
     712                 :                                        sTABProj.adProjParams[3],
     713               0 :                                        sTABProj.adProjParams[4] );
     714               0 :          break;
     715                 : 
     716                 :         /*--------------------------------------------------------------
     717                 :          * Transverse Mercator,(modified for Finnish KKJ)
     718                 :          *-------------------------------------------------------------*/
     719                 :       case 24:
     720                 :          m_poSpatialRef->SetTMVariant( SRS_PT_TRANSVERSE_MERCATOR_MI_24,
     721                 :                                        sTABProj.adProjParams[1],
     722                 :                                        sTABProj.adProjParams[0],
     723                 :                                        sTABProj.adProjParams[2],
     724                 :                                        sTABProj.adProjParams[3],
     725               0 :                                        sTABProj.adProjParams[4] );
     726               0 :          break;
     727                 : 
     728                 :         /*--------------------------------------------------------------
     729                 :          * Albers Conic Equal Area
     730                 :          *-------------------------------------------------------------*/
     731                 :       case 9:
     732                 :         m_poSpatialRef->SetACEA( sTABProj.adProjParams[2],
     733                 :                                  sTABProj.adProjParams[3],
     734                 :                                  sTABProj.adProjParams[1],
     735                 :                                  sTABProj.adProjParams[0],
     736                 :                                  sTABProj.adProjParams[4],
     737               0 :                                  sTABProj.adProjParams[5] );
     738               0 :         break;
     739                 : 
     740                 :         /*--------------------------------------------------------------
     741                 :          * Mercator
     742                 :          *-------------------------------------------------------------*/
     743                 :       case 10:
     744                 :         m_poSpatialRef->SetMercator( 0.0, sTABProj.adProjParams[0],
     745               0 :                                      1.0, 0.0, 0.0 );
     746               0 :         break;
     747                 : 
     748                 :         /*--------------------------------------------------------------
     749                 :          * Miller Cylindrical
     750                 :          *-------------------------------------------------------------*/
     751                 :       case 11:
     752                 :         m_poSpatialRef->SetMC( 0.0, sTABProj.adProjParams[0],
     753               0 :                                0.0, 0.0 );
     754               0 :         break;
     755                 : 
     756                 :         /*--------------------------------------------------------------
     757                 :          * Robinson
     758                 :          *-------------------------------------------------------------*/
     759                 :       case 12:
     760                 :         m_poSpatialRef->SetRobinson( sTABProj.adProjParams[0],
     761               0 :                                      0.0, 0.0 );
     762               0 :         break;
     763                 : 
     764                 :         /*--------------------------------------------------------------
     765                 :          * Mollweide
     766                 :          *-------------------------------------------------------------*/
     767                 :       case 13:
     768                 :         m_poSpatialRef->SetMollweide( sTABProj.adProjParams[0],
     769               0 :                                       0.0, 0.0 );
     770                 : 
     771                 :         /*--------------------------------------------------------------
     772                 :          * Eckert IV
     773                 :          *-------------------------------------------------------------*/
     774                 :       case 14:
     775               0 :         m_poSpatialRef->SetEckertIV( sTABProj.adProjParams[0], 0.0, 0.0 );
     776               0 :         break;
     777                 : 
     778                 :         /*--------------------------------------------------------------
     779                 :          * Eckert VI
     780                 :          *-------------------------------------------------------------*/
     781                 :       case 15:
     782               0 :         m_poSpatialRef->SetEckertVI( sTABProj.adProjParams[0], 0.0, 0.0 );
     783               0 :         break;
     784                 : 
     785                 :         /*--------------------------------------------------------------
     786                 :          * Sinusoidal
     787                 :          *-------------------------------------------------------------*/
     788                 :       case 16:
     789                 :         m_poSpatialRef->SetSinusoidal( sTABProj.adProjParams[0],
     790               0 :                                        0.0, 0.0 );
     791               0 :         break;
     792                 : 
     793                 :         /*--------------------------------------------------------------
     794                 :          * Gall Stereographic
     795                 :          *-------------------------------------------------------------*/
     796                 :       case 17:
     797               0 :         m_poSpatialRef->SetGS( sTABProj.adProjParams[0], 0.0, 0.0 );
     798               0 :         break;
     799                 :         
     800                 :         /*--------------------------------------------------------------
     801                 :          * New Zealand Map Grid
     802                 :          *-------------------------------------------------------------*/
     803                 :       case 18:
     804                 :         m_poSpatialRef->SetNZMG( sTABProj.adProjParams[1],
     805                 :                                  sTABProj.adProjParams[0],
     806                 :                                  sTABProj.adProjParams[2],
     807               0 :                                  sTABProj.adProjParams[3] );
     808               0 :         break;
     809                 : 
     810                 :         /*--------------------------------------------------------------
     811                 :          * Lambert Conic Conformal (Belgium)
     812                 :          *-------------------------------------------------------------*/
     813                 :       case 19:
     814                 :         m_poSpatialRef->SetLCCB( sTABProj.adProjParams[2],
     815                 :                                  sTABProj.adProjParams[3],
     816                 :                                  sTABProj.adProjParams[1],
     817                 :                                  sTABProj.adProjParams[0],
     818                 :                                  sTABProj.adProjParams[4],
     819               0 :                                  sTABProj.adProjParams[5] );
     820               0 :         break;
     821                 : 
     822                 :         /*--------------------------------------------------------------
     823                 :          * Stereographic
     824                 :          *-------------------------------------------------------------*/
     825                 :       case 20:
     826                 :       case 31: /* this is called Double Stereographic, whats the diff? */
     827                 :         m_poSpatialRef->SetStereographic( sTABProj.adProjParams[1],
     828                 :                                           sTABProj.adProjParams[0],
     829                 :                                           sTABProj.adProjParams[2],
     830                 :                                           sTABProj.adProjParams[3],
     831               0 :                                           sTABProj.adProjParams[4] );
     832               0 :         break;
     833                 : 
     834                 :         /*--------------------------------------------------------------
     835                 :          * Swiss Oblique Mercator / Cylindrical
     836                 :          *-------------------------------------------------------------*/
     837                 :       case 25:
     838                 :         m_poSpatialRef->SetSOC( sTABProj.adProjParams[1],
     839                 :                                 sTABProj.adProjParams[0],
     840                 :                                 sTABProj.adProjParams[2],
     841               0 :                                 sTABProj.adProjParams[3] );
     842               0 :         break;
     843                 : 
     844                 :         /*--------------------------------------------------------------
     845                 :          * Regional Mercator (regular mercator with a latitude).
     846                 :          *-------------------------------------------------------------*/
     847                 :       case 26:
     848                 :         m_poSpatialRef->SetMercator( sTABProj.adProjParams[1],
     849                 :                                      sTABProj.adProjParams[0],
     850               0 :                                      1.0, 0.0, 0.0 );
     851               0 :         break;
     852                 : 
     853                 :         /*--------------------------------------------------------------
     854                 :          * Polyconic
     855                 :          *-------------------------------------------------------------*/
     856                 :       case 27:
     857                 :         m_poSpatialRef->SetPolyconic( sTABProj.adProjParams[1],
     858                 :                                       sTABProj.adProjParams[0],
     859                 :                                       sTABProj.adProjParams[2],
     860               0 :                                       sTABProj.adProjParams[3] );
     861               0 :         break;
     862                 : 
     863                 :         /*--------------------------------------------------------------
     864                 :          * Cassini/Soldner
     865                 :          *-------------------------------------------------------------*/
     866                 :       case 30:
     867                 :         m_poSpatialRef->SetCS( sTABProj.adProjParams[1],
     868                 :                                sTABProj.adProjParams[0],
     869                 :                                sTABProj.adProjParams[2],
     870               0 :                                sTABProj.adProjParams[3] );
     871                 :         break;
     872                 : 
     873                 :       default:
     874                 :         break;
     875                 :     }
     876                 : 
     877                 :     /*-----------------------------------------------------------------
     878                 :      * Collect units definition.
     879                 :      *----------------------------------------------------------------*/
     880               1 :     if( sTABProj.nProjId != 1 && m_poSpatialRef->GetRoot() != NULL )
     881                 :     {
     882               1 :         OGR_SRSNode     *poUnits = new OGR_SRSNode("UNIT");
     883                 :         
     884               1 :         m_poSpatialRef->GetRoot()->AddChild(poUnits);
     885                 : 
     886               2 :         poUnits->AddChild( new OGR_SRSNode( pszUnitsName ) );
     887               2 :         poUnits->AddChild( new OGR_SRSNode( pszUnitsConv ) );
     888                 :     }
     889                 : 
     890                 : #ifdef MITAB_AFFINE_PARAMS  // See MITAB bug 1155
     891                 :     /*-----------------------------------------------------------------
     892                 :      * Collect affine definitions. (Added by Encom 2003)
     893                 :      *----------------------------------------------------------------*/
     894                 :     if( sTABProj.nAffineFlag==1 && m_poSpatialRef->GetRoot() != NULL )
     895                 :     {
     896                 :         m_poSpatialRef->nAffineFlag = 1;
     897                 :         m_poSpatialRef->nAffineUnit = sTABProj.nAffineUnits;
     898                 :         m_poSpatialRef->dAffineParamA = sTABProj.dAffineParamA;
     899                 :         m_poSpatialRef->dAffineParamB = sTABProj.dAffineParamB;
     900                 :         m_poSpatialRef->dAffineParamC = sTABProj.dAffineParamC;
     901                 :         m_poSpatialRef->dAffineParamD = sTABProj.dAffineParamD;
     902                 :         m_poSpatialRef->dAffineParamE = sTABProj.dAffineParamE;
     903                 :         m_poSpatialRef->dAffineParamF = sTABProj.dAffineParamF;
     904                 :     }
     905                 :     else
     906                 :     {
     907                 :         m_poSpatialRef->nAffineFlag = 0;
     908                 :     }
     909                 : #endif // MITAB_AFFINE_PARAMS
     910                 : 
     911                 :     /*-----------------------------------------------------------------
     912                 :      * Local (nonearth) coordinate systems have no Geographic relationship
     913                 :      * so we just return from here. 
     914                 :      *----------------------------------------------------------------*/
     915               1 :     if( sTABProj.nProjId == 0 )
     916               0 :         return m_poSpatialRef;
     917                 : 
     918                 :     /*-----------------------------------------------------------------
     919                 :      * Set the datum.  We are only given the X, Y and Z shift for
     920                 :      * the datum, so for now we just synthesize a name from this.
     921                 :      * It would be better if we could lookup a name based on the shift.
     922                 :      *
     923                 :      * Since we have already encountered files in which adDatumParams[] values
     924                 :      * were in the order of 1e-150 when they should have actually been zeros,
     925                 :      * we will use an epsilon in our scan instead of looking for equality.
     926                 :      *----------------------------------------------------------------*/
     927                 : #define TAB_EQUAL(a, b) (((a)<(b) ? ((b)-(a)) : ((a)-(b))) < 1e-10)
     928                 :     char        szDatumName[160];
     929                 :     int         iDatumInfo;
     930               1 :     MapInfoDatumInfo *psDatumInfo = NULL;
     931                 : 
     932               1 :     for( iDatumInfo = 0;
     933                 :          asDatumInfoList[iDatumInfo].nMapInfoDatumID != -1;
     934                 :          iDatumInfo++ )
     935                 :     {
     936               1 :         psDatumInfo = asDatumInfoList + iDatumInfo;
     937                 :         
     938               1 :         if( TAB_EQUAL(psDatumInfo->nEllipsoid, sTABProj.nEllipsoidId) &&
     939                 :             ((sTABProj.nDatumId > 0 && 
     940                 :               sTABProj.nDatumId == psDatumInfo->nMapInfoDatumID) ||
     941                 :              (sTABProj.nDatumId <= 0
     942                 :               && TAB_EQUAL(psDatumInfo->dfShiftX, sTABProj.dDatumShiftX)
     943                 :               && TAB_EQUAL(psDatumInfo->dfShiftY, sTABProj.dDatumShiftY)
     944                 :               && TAB_EQUAL(psDatumInfo->dfShiftZ, sTABProj.dDatumShiftZ)
     945                 :               && TAB_EQUAL(psDatumInfo->dfDatumParm0,sTABProj.adDatumParams[0])
     946                 :               && TAB_EQUAL(psDatumInfo->dfDatumParm1,sTABProj.adDatumParams[1])
     947                 :               && TAB_EQUAL(psDatumInfo->dfDatumParm2,sTABProj.adDatumParams[2])
     948                 :               && TAB_EQUAL(psDatumInfo->dfDatumParm3,sTABProj.adDatumParams[3])
     949                 :               && TAB_EQUAL(psDatumInfo->dfDatumParm4,sTABProj.adDatumParams[4]))))
     950               1 :             break;
     951                 : 
     952               0 :         psDatumInfo = NULL;
     953                 :     }
     954                 : 
     955               1 :     if( psDatumInfo == NULL )
     956                 :     {
     957               0 :         if( sTABProj.adDatumParams[0] == 0.0
     958                 :             && sTABProj.adDatumParams[1] == 0.0
     959                 :             && sTABProj.adDatumParams[2] == 0.0
     960                 :             && sTABProj.adDatumParams[3] == 0.0
     961                 :             && sTABProj.adDatumParams[4] == 0.0 )
     962                 :         {
     963                 :             sprintf( szDatumName,
     964                 :                      "MIF 999,%d,%.4g,%.4g,%.4g",
     965                 :                      sTABProj.nEllipsoidId,
     966                 :                      sTABProj.dDatumShiftX, 
     967                 :                      sTABProj.dDatumShiftY, 
     968               0 :                      sTABProj.dDatumShiftZ );
     969                 :         }
     970                 :         else
     971                 :         {
     972                 :             sprintf( szDatumName,
     973                 :                      "MIF 9999,%d,%.4g,%.4g,%.4g,%.15g,%.15g,%.15g,%.15g,%.15g",
     974                 :                      sTABProj.nEllipsoidId,
     975                 :                      sTABProj.dDatumShiftX, 
     976                 :                      sTABProj.dDatumShiftY, 
     977                 :                      sTABProj.dDatumShiftZ,
     978                 :                      sTABProj.adDatumParams[0],
     979                 :                      sTABProj.adDatumParams[1],
     980                 :                      sTABProj.adDatumParams[2],
     981                 :                      sTABProj.adDatumParams[3],
     982               0 :                      sTABProj.adDatumParams[4] );
     983                 :         }
     984                 :     }
     985               1 :     else if( strlen(psDatumInfo->pszOGCDatumName) > 0 )
     986                 :     {
     987                 :         strncpy( szDatumName, psDatumInfo->pszOGCDatumName,
     988               1 :                  sizeof(szDatumName) );
     989                 :     }
     990                 :     else
     991                 :     {
     992               0 :         sprintf( szDatumName, "MIF %d", psDatumInfo->nMapInfoDatumID );
     993                 :     }
     994                 : 
     995                 :     /*-----------------------------------------------------------------
     996                 :      * Set the spheroid.
     997                 :      *----------------------------------------------------------------*/
     998               1 :     double      dfSemiMajor=0.0, dfInvFlattening=0.0;
     999               1 :     const char *pszSpheroidName = NULL;
    1000                 : 
    1001              52 :     for( int i = 0; asSpheroidInfoList[i].nMapInfoId != -1; i++ )
    1002                 :     {
    1003              52 :         if( asSpheroidInfoList[i].nMapInfoId == sTABProj.nEllipsoidId )
    1004                 :         {
    1005               1 :             dfSemiMajor = asSpheroidInfoList[i].dfA;
    1006               1 :             dfInvFlattening = asSpheroidInfoList[i].dfInvFlattening;
    1007               1 :             pszSpheroidName = asSpheroidInfoList[i].pszMapinfoName;
    1008               1 :             break;
    1009                 :         }
    1010                 :     }
    1011                 : 
    1012                 :     // use WGS 84 if nothing is known.
    1013               1 :     if( pszSpheroidName == NULL )
    1014                 :     {
    1015               0 :         pszSpheroidName = "unknown";
    1016               0 :         dfSemiMajor = 6378137.0;
    1017               0 :         dfInvFlattening = 298.257223563;
    1018                 :     }
    1019                 : 
    1020                 :     /*-----------------------------------------------------------------
    1021                 :      * Set the prime meridian.
    1022                 :      *----------------------------------------------------------------*/
    1023               1 :     double      dfPMOffset = 0.0;
    1024               1 :     const char *pszPMName = "Greenwich";
    1025                 :     
    1026               1 :     if( sTABProj.adDatumParams[4] != 0.0 )
    1027                 :     {
    1028               0 :         dfPMOffset = sTABProj.adDatumParams[4];
    1029                 : 
    1030               0 :         pszPMName = "non-Greenwich";
    1031                 :     }
    1032                 :                     
    1033                 :     /*-----------------------------------------------------------------
    1034                 :      * Create a GEOGCS definition.
    1035                 :      *----------------------------------------------------------------*/
    1036                 : 
    1037                 :     m_poSpatialRef->SetGeogCS( "unnamed",
    1038                 :                                szDatumName,
    1039                 :                                pszSpheroidName,
    1040                 :                                dfSemiMajor, dfInvFlattening,
    1041                 :                                pszPMName, dfPMOffset,
    1042               1 :                                SRS_UA_DEGREE, atof(SRS_UA_DEGREE_CONV));
    1043                 : 
    1044               1 :     if( psDatumInfo != NULL )
    1045                 :     {
    1046                 :         m_poSpatialRef->SetTOWGS84( psDatumInfo->dfShiftX, 
    1047                 :                                     psDatumInfo->dfShiftY,
    1048                 :                                     psDatumInfo->dfShiftZ,
    1049                 :                                     -psDatumInfo->dfDatumParm0, 
    1050                 :                                     -psDatumInfo->dfDatumParm1, 
    1051                 :                                     -psDatumInfo->dfDatumParm2, 
    1052               1 :                                     psDatumInfo->dfDatumParm3 );
    1053                 :     }
    1054                 : 
    1055               1 :     return m_poSpatialRef;
    1056                 : }
    1057                 : 
    1058                 : /**********************************************************************
    1059                 :  *                   TABFile::SetSpatialRef()
    1060                 :  *
    1061                 :  * Set the OGRSpatialReference for this dataset.
    1062                 :  * A reference to the OGRSpatialReference will be kept, and it will also
    1063                 :  * be converted into a TABProjInfo to be stored in the .MAP header.
    1064                 :  *
    1065                 :  * Returns 0 on success, and -1 on error.
    1066                 :  **********************************************************************/
    1067               1 : int TABFile::SetSpatialRef(OGRSpatialReference *poSpatialRef)
    1068                 : {
    1069               1 :     if (m_eAccessMode != TABWrite)
    1070                 :     {
    1071                 :         CPLError(CE_Failure, CPLE_NotSupported,
    1072               0 :                  "SetSpatialRef() can be used only with Write access.");
    1073               0 :         return -1;
    1074                 :     }
    1075                 : 
    1076               1 :     if (m_poMAPFile == NULL )
    1077                 :     {
    1078                 :         CPLError(CE_Failure, CPLE_AssertionFailed,
    1079               0 :                  "SetSpatialRef() failed: file has not been opened yet.");
    1080               0 :         return -1;
    1081                 :     }
    1082                 : 
    1083               1 :     if( poSpatialRef == NULL )
    1084                 :     {
    1085                 :         CPLError(CE_Failure, CPLE_AssertionFailed,
    1086               0 :                  "SetSpatialRef() failed: Called with NULL poSpatialRef.");
    1087               0 :         return -1;
    1088                 :     }
    1089                 : 
    1090                 :     /*-----------------------------------------------------------------
    1091                 :      * Keep a copy of the OGRSpatialReference...
    1092                 :      * Note: we have to take the reference count into account...
    1093                 :      *----------------------------------------------------------------*/
    1094               1 :     if (m_poSpatialRef && m_poSpatialRef->Dereference() == 0)
    1095               0 :         delete m_poSpatialRef;
    1096                 :     
    1097               1 :     m_poSpatialRef = poSpatialRef->Clone();
    1098                 : 
    1099                 :     /*-----------------------------------------------------------------
    1100                 :      * Initialize TABProjInfo
    1101                 :      *----------------------------------------------------------------*/
    1102                 :     TABProjInfo     sTABProj;
    1103                 : 
    1104               1 :     sTABProj.nProjId = 0;
    1105               1 :     sTABProj.nEllipsoidId = 0; /* how will we set this? */
    1106               1 :     sTABProj.nUnitsId = 7;
    1107               1 :     sTABProj.adProjParams[0] = sTABProj.adProjParams[1] = 0.0;
    1108               1 :     sTABProj.adProjParams[2] = sTABProj.adProjParams[3] = 0.0;
    1109               1 :     sTABProj.adProjParams[4] = sTABProj.adProjParams[5] = 0.0;
    1110                 :     
    1111               1 :     sTABProj.nDatumId = 0;
    1112               1 :     sTABProj.dDatumShiftX = 0.0;
    1113               1 :     sTABProj.dDatumShiftY = 0.0;
    1114               1 :     sTABProj.dDatumShiftZ = 0.0;
    1115               1 :     sTABProj.adDatumParams[0] = 0.0;
    1116               1 :     sTABProj.adDatumParams[1] = 0.0;
    1117               1 :     sTABProj.adDatumParams[2] = 0.0;
    1118               1 :     sTABProj.adDatumParams[3] = 0.0;
    1119               1 :     sTABProj.adDatumParams[4] = 0.0;
    1120                 : 
    1121                 :     // Encom 2003
    1122               1 :     sTABProj.nAffineFlag   = 0;
    1123               1 :     sTABProj.nAffineUnits  = 7;
    1124               1 :     sTABProj.dAffineParamA = 0.0;
    1125               1 :     sTABProj.dAffineParamB = 0.0;
    1126               1 :     sTABProj.dAffineParamC = 0.0;
    1127               1 :     sTABProj.dAffineParamD = 0.0;
    1128               1 :     sTABProj.dAffineParamE = 0.0;
    1129               1 :     sTABProj.dAffineParamF = 0.0;
    1130                 :     
    1131                 :     /*-----------------------------------------------------------------
    1132                 :      * Get the linear units and conversion.
    1133                 :      *----------------------------------------------------------------*/
    1134                 :     char        *pszLinearUnits;
    1135                 :     double      dfLinearConv;
    1136                 : 
    1137               1 :     dfLinearConv = poSpatialRef->GetLinearUnits( &pszLinearUnits );
    1138               1 :     if( dfLinearConv == 0.0 )
    1139               0 :         dfLinearConv = 1.0;
    1140                 : 
    1141                 :     /*-----------------------------------------------------------------
    1142                 :      * Transform the projection and projection parameters.
    1143                 :      *----------------------------------------------------------------*/
    1144               1 :     const char *pszProjection = poSpatialRef->GetAttrValue("PROJECTION");
    1145               1 :     double      *parms = sTABProj.adProjParams;
    1146                 : 
    1147               1 :     if( pszProjection == NULL && poSpatialRef->GetAttrNode("LOCAL_CS") != NULL)
    1148                 :     {
    1149                 :         /* nonearth */
    1150               0 :         sTABProj.nProjId = 0;
    1151                 :     }
    1152                 : 
    1153               1 :     else if( pszProjection == NULL )
    1154                 :     {
    1155               0 :         sTABProj.nProjId = 1;
    1156                 :     }
    1157                 : 
    1158               1 :     else if( EQUAL(pszProjection,SRS_PT_ALBERS_CONIC_EQUAL_AREA) )
    1159                 :     {
    1160               0 :         sTABProj.nProjId = 9;
    1161               0 :         parms[0] = poSpatialRef->GetProjParm(SRS_PP_LONGITUDE_OF_CENTER,0.0);
    1162               0 :         parms[1] = poSpatialRef->GetProjParm(SRS_PP_LATITUDE_OF_CENTER,0.0);
    1163               0 :         parms[2] = poSpatialRef->GetProjParm(SRS_PP_STANDARD_PARALLEL_1,0.0);
    1164               0 :         parms[3] = poSpatialRef->GetProjParm(SRS_PP_STANDARD_PARALLEL_2,0.0);
    1165               0 :         parms[4] = poSpatialRef->GetProjParm(SRS_PP_FALSE_EASTING,0.0);
    1166               0 :         parms[5] = poSpatialRef->GetProjParm(SRS_PP_FALSE_NORTHING,0.0);
    1167                 :     }
    1168                 : 
    1169               1 :     else if( EQUAL(pszProjection,SRS_PT_AZIMUTHAL_EQUIDISTANT) )
    1170                 :     {
    1171               0 :         sTABProj.nProjId = 5;
    1172               0 :         parms[0] = poSpatialRef->GetProjParm(SRS_PP_LONGITUDE_OF_CENTER,0.0);
    1173               0 :         parms[1] = poSpatialRef->GetProjParm(SRS_PP_LATITUDE_OF_CENTER,0.0);
    1174               0 :         parms[2] = 90.0;
    1175                 : 
    1176               0 :         if( ABS((ABS(parms[1]) - 90)) > 0.001 )
    1177               0 :             sTABProj.nProjId = 28;
    1178                 :     }
    1179                 : 
    1180               1 :     else if( EQUAL(pszProjection,SRS_PT_CYLINDRICAL_EQUAL_AREA) )
    1181                 :     {
    1182               0 :         sTABProj.nProjId = 2;
    1183               0 :         parms[0] = poSpatialRef->GetProjParm(SRS_PP_CENTRAL_MERIDIAN,0.0);
    1184               0 :         parms[1] = poSpatialRef->GetProjParm(SRS_PP_STANDARD_PARALLEL_1,0.0);
    1185                 :     }
    1186                 : 
    1187               1 :     else if( EQUAL(pszProjection,SRS_PT_ECKERT_IV) )
    1188                 :     {
    1189               0 :         sTABProj.nProjId = 14;
    1190               0 :         parms[0] = poSpatialRef->GetProjParm(SRS_PP_CENTRAL_MERIDIAN,0.0);
    1191                 :     }
    1192                 : 
    1193               1 :     else if( EQUAL(pszProjection,SRS_PT_ECKERT_VI) )
    1194                 :     {
    1195               0 :         sTABProj.nProjId = 15;
    1196               0 :         parms[0] = poSpatialRef->GetProjParm(SRS_PP_CENTRAL_MERIDIAN,0.0);
    1197                 :     }
    1198                 : 
    1199               1 :     else if( EQUAL(pszProjection,SRS_PT_EQUIDISTANT_CONIC) )
    1200                 :     {
    1201               0 :         sTABProj.nProjId = 6;
    1202               0 :         parms[0] = poSpatialRef->GetProjParm(SRS_PP_LONGITUDE_OF_CENTER,0.0);
    1203               0 :         parms[1] = poSpatialRef->GetProjParm(SRS_PP_LATITUDE_OF_CENTER,0.0);
    1204               0 :         parms[2] = poSpatialRef->GetProjParm(SRS_PP_STANDARD_PARALLEL_1,0.0);
    1205               0 :         parms[3] = poSpatialRef->GetProjParm(SRS_PP_STANDARD_PARALLEL_2,0.0);
    1206               0 :         parms[4] = poSpatialRef->GetProjParm(SRS_PP_FALSE_EASTING,0.0);
    1207               0 :         parms[5] = poSpatialRef->GetProjParm(SRS_PP_FALSE_NORTHING,0.0);
    1208                 :     }
    1209                 : 
    1210               1 :     else if( EQUAL(pszProjection,SRS_PT_GALL_STEREOGRAPHIC) )
    1211                 :     {
    1212               0 :         sTABProj.nProjId = 17;
    1213               0 :         parms[0] = poSpatialRef->GetProjParm(SRS_PP_CENTRAL_MERIDIAN,0.0);
    1214                 :     }
    1215                 : 
    1216               1 :     else if( EQUAL(pszProjection,SRS_PT_HOTINE_OBLIQUE_MERCATOR) )
    1217                 :     {
    1218               0 :         sTABProj.nProjId = 7;
    1219               0 :         parms[0] = poSpatialRef->GetProjParm(SRS_PP_LONGITUDE_OF_CENTER,0.0);
    1220               0 :         parms[1] = poSpatialRef->GetProjParm(SRS_PP_LATITUDE_OF_CENTER,0.0);
    1221               0 :         parms[2] = poSpatialRef->GetProjParm(SRS_PP_AZIMUTH,0.0);
    1222               0 :         parms[3] = poSpatialRef->GetProjParm(SRS_PP_SCALE_FACTOR,1.0);
    1223               0 :         parms[4] = poSpatialRef->GetProjParm(SRS_PP_FALSE_EASTING,0.0);
    1224               0 :         parms[5] = poSpatialRef->GetProjParm(SRS_PP_FALSE_NORTHING,0.0);
    1225                 :     }
    1226                 : 
    1227               1 :     else if( EQUAL(pszProjection,SRS_PT_LAMBERT_AZIMUTHAL_EQUAL_AREA) )
    1228                 :     {
    1229               0 :         sTABProj.nProjId = 4;
    1230               0 :         parms[0] = poSpatialRef->GetProjParm(SRS_PP_LONGITUDE_OF_CENTER,0.0);
    1231               0 :         parms[1] = poSpatialRef->GetProjParm(SRS_PP_LATITUDE_OF_CENTER,0.0);
    1232               0 :         parms[2] = 90.0;
    1233                 : 
    1234               0 :         if( ABS((ABS(parms[1]) - 90)) > 0.001 )
    1235               0 :             sTABProj.nProjId = 28;
    1236                 :     }
    1237                 : 
    1238               1 :     else if( EQUAL(pszProjection,SRS_PT_LAMBERT_CONFORMAL_CONIC_2SP) )
    1239                 :     {
    1240               0 :         sTABProj.nProjId = 3;
    1241               0 :         parms[0] = poSpatialRef->GetProjParm(SRS_PP_CENTRAL_MERIDIAN,0.0);
    1242               0 :         parms[1] = poSpatialRef->GetProjParm(SRS_PP_LATITUDE_OF_ORIGIN,0.0);
    1243               0 :         parms[2] = poSpatialRef->GetProjParm(SRS_PP_STANDARD_PARALLEL_1,0.0);
    1244               0 :         parms[3] = poSpatialRef->GetProjParm(SRS_PP_STANDARD_PARALLEL_2,0.0);
    1245               0 :         parms[4] = poSpatialRef->GetProjParm(SRS_PP_FALSE_EASTING,0.0);
    1246               0 :         parms[5] = poSpatialRef->GetProjParm(SRS_PP_FALSE_NORTHING,0.0);
    1247                 :     }
    1248                 : 
    1249               1 :     else if( EQUAL(pszProjection,SRS_PT_LAMBERT_CONFORMAL_CONIC_2SP_BELGIUM) )
    1250                 :     {
    1251               0 :         sTABProj.nProjId = 19;
    1252               0 :         parms[0] = poSpatialRef->GetProjParm(SRS_PP_CENTRAL_MERIDIAN,0.0);
    1253               0 :         parms[1] = poSpatialRef->GetProjParm(SRS_PP_LATITUDE_OF_ORIGIN,0.0);
    1254               0 :         parms[2] = poSpatialRef->GetProjParm(SRS_PP_STANDARD_PARALLEL_1,0.0);
    1255               0 :         parms[3] = poSpatialRef->GetProjParm(SRS_PP_STANDARD_PARALLEL_2,0.0);
    1256               0 :         parms[4] = poSpatialRef->GetProjParm(SRS_PP_FALSE_EASTING,0.0);
    1257               0 :         parms[5] = poSpatialRef->GetProjParm(SRS_PP_FALSE_NORTHING,0.0);
    1258                 :     }
    1259                 : 
    1260               1 :     else if( EQUAL(pszProjection,SRS_PT_MERCATOR_1SP) )
    1261                 :     {
    1262               0 :         sTABProj.nProjId = 10;
    1263               0 :         parms[0] = poSpatialRef->GetProjParm(SRS_PP_CENTRAL_MERIDIAN,0.0);
    1264               0 :         parms[1] = poSpatialRef->GetProjParm(SRS_PP_LATITUDE_OF_ORIGIN,0.0);
    1265               0 :         parms[2] = poSpatialRef->GetProjParm(SRS_PP_SCALE_FACTOR,1.0);
    1266                 : 
    1267               0 :         if( parms[1] != 0.0 )
    1268               0 :             sTABProj.nProjId = 26;
    1269                 :     }
    1270                 : 
    1271               1 :     else if( EQUAL(pszProjection,SRS_PT_MILLER_CYLINDRICAL) )
    1272                 :     {
    1273               0 :         sTABProj.nProjId = 11;
    1274               0 :         parms[0] = poSpatialRef->GetProjParm(SRS_PP_LONGITUDE_OF_CENTER,0.0);
    1275                 :     }
    1276                 : 
    1277               1 :     else if( EQUAL(pszProjection,SRS_PT_MOLLWEIDE) )
    1278                 :     {
    1279               0 :         sTABProj.nProjId = 13;
    1280               0 :         parms[0] = poSpatialRef->GetProjParm(SRS_PP_CENTRAL_MERIDIAN,0.0);
    1281                 :     }
    1282                 : 
    1283               1 :     else if( EQUAL(pszProjection,SRS_PT_NEW_ZEALAND_MAP_GRID) )
    1284                 :     {
    1285               0 :         sTABProj.nProjId = 18;
    1286               0 :         parms[0] = poSpatialRef->GetProjParm(SRS_PP_CENTRAL_MERIDIAN,0.0);
    1287               0 :         parms[1] = poSpatialRef->GetProjParm(SRS_PP_LATITUDE_OF_ORIGIN,0.0);
    1288               0 :         parms[2] = poSpatialRef->GetProjParm(SRS_PP_FALSE_EASTING,0.0);
    1289               0 :         parms[3] = poSpatialRef->GetProjParm(SRS_PP_FALSE_NORTHING,0.0);
    1290                 :     }
    1291                 : 
    1292               1 :     else if( EQUAL(pszProjection,SRS_PT_SWISS_OBLIQUE_CYLINDRICAL) )
    1293                 :     {
    1294               0 :         sTABProj.nProjId = 25;
    1295               0 :         parms[0] = poSpatialRef->GetProjParm(SRS_PP_CENTRAL_MERIDIAN,0.0);
    1296               0 :         parms[1] = poSpatialRef->GetProjParm(SRS_PP_LATITUDE_OF_ORIGIN,0.0);
    1297               0 :         parms[2] = poSpatialRef->GetProjParm(SRS_PP_FALSE_EASTING,0.0);
    1298               0 :         parms[3] = poSpatialRef->GetProjParm(SRS_PP_FALSE_NORTHING,0.0);
    1299                 :     }
    1300                 : 
    1301               1 :     else if( EQUAL(pszProjection,SRS_PT_ROBINSON) )
    1302                 :     {
    1303               0 :         sTABProj.nProjId = 12;
    1304               0 :         parms[0] = poSpatialRef->GetProjParm(SRS_PP_CENTRAL_MERIDIAN,0.0);
    1305                 :     }
    1306                 : 
    1307               1 :     else if( EQUAL(pszProjection,SRS_PT_SINUSOIDAL) )
    1308                 :     {
    1309               0 :         sTABProj.nProjId = 16;
    1310               0 :         parms[0] = poSpatialRef->GetProjParm(SRS_PP_CENTRAL_MERIDIAN,0.0);
    1311                 :     }
    1312                 : 
    1313               1 :     else if( EQUAL(pszProjection,SRS_PT_STEREOGRAPHIC) )
    1314                 :     {
    1315               0 :         sTABProj.nProjId = 20;
    1316               0 :         parms[0] = poSpatialRef->GetProjParm(SRS_PP_CENTRAL_MERIDIAN,0.0);
    1317               0 :         parms[1] = poSpatialRef->GetProjParm(SRS_PP_LATITUDE_OF_ORIGIN,0.0);
    1318               0 :         parms[2] = poSpatialRef->GetProjParm(SRS_PP_SCALE_FACTOR,1.0);
    1319               0 :         parms[3] = poSpatialRef->GetProjParm(SRS_PP_FALSE_EASTING,0.0);
    1320               0 :         parms[4] = poSpatialRef->GetProjParm(SRS_PP_FALSE_NORTHING,0.0);
    1321                 :     }
    1322                 : 
    1323               1 :     else if( EQUAL(pszProjection,SRS_PT_TRANSVERSE_MERCATOR) )
    1324                 :     {
    1325               1 :         sTABProj.nProjId = 8;
    1326               1 :         parms[0] = poSpatialRef->GetProjParm(SRS_PP_CENTRAL_MERIDIAN,0.0);
    1327               1 :         parms[1] = poSpatialRef->GetProjParm(SRS_PP_LATITUDE_OF_ORIGIN,0.0);
    1328               1 :         parms[2] = poSpatialRef->GetProjParm(SRS_PP_SCALE_FACTOR,1.0);
    1329               1 :         parms[3] = poSpatialRef->GetProjParm(SRS_PP_FALSE_EASTING,0.0);
    1330               1 :         parms[4] = poSpatialRef->GetProjParm(SRS_PP_FALSE_NORTHING,0.0);
    1331                 :     }
    1332                 : 
    1333               0 :     else if( EQUAL(pszProjection,SRS_PT_TRANSVERSE_MERCATOR_MI_21) ) // Encom 2003
    1334                 :     {
    1335               0 :         sTABProj.nProjId = 21;
    1336               0 :         parms[0] = poSpatialRef->GetProjParm(SRS_PP_CENTRAL_MERIDIAN,0.0);
    1337               0 :         parms[1] = poSpatialRef->GetProjParm(SRS_PP_LATITUDE_OF_ORIGIN,0.0);
    1338               0 :         parms[2] = poSpatialRef->GetProjParm(SRS_PP_SCALE_FACTOR,1.0);
    1339               0 :         parms[3] = poSpatialRef->GetProjParm(SRS_PP_FALSE_EASTING,0.0);
    1340               0 :         parms[4] = poSpatialRef->GetProjParm(SRS_PP_FALSE_NORTHING,0.0);
    1341                 :     }
    1342                 : 
    1343               0 :     else if( EQUAL(pszProjection,SRS_PT_TRANSVERSE_MERCATOR_MI_22) ) // Encom 2003
    1344                 :     {
    1345               0 :         sTABProj.nProjId = 22;
    1346               0 :         parms[0] = poSpatialRef->GetProjParm(SRS_PP_CENTRAL_MERIDIAN,0.0);
    1347               0 :         parms[1] = poSpatialRef->GetProjParm(SRS_PP_LATITUDE_OF_ORIGIN,0.0);
    1348               0 :         parms[2] = poSpatialRef->GetProjParm(SRS_PP_SCALE_FACTOR,1.0);
    1349               0 :         parms[3] = poSpatialRef->GetProjParm(SRS_PP_FALSE_EASTING,0.0);
    1350               0 :         parms[4] = poSpatialRef->GetProjParm(SRS_PP_FALSE_NORTHING,0.0);
    1351                 :     }
    1352                 : 
    1353               0 :     else if( EQUAL(pszProjection,SRS_PT_TRANSVERSE_MERCATOR_MI_23) ) // Encom 2003
    1354                 :     {
    1355               0 :         sTABProj.nProjId = 23;
    1356               0 :         parms[0] = poSpatialRef->GetProjParm(SRS_PP_CENTRAL_MERIDIAN,0.0);
    1357               0 :         parms[1] = poSpatialRef->GetProjParm(SRS_PP_LATITUDE_OF_ORIGIN,0.0);
    1358               0 :         parms[2] = poSpatialRef->GetProjParm(SRS_PP_SCALE_FACTOR,1.0);
    1359               0 :         parms[3] = poSpatialRef->GetProjParm(SRS_PP_FALSE_EASTING,0.0);
    1360               0 :         parms[4] = poSpatialRef->GetProjParm(SRS_PP_FALSE_NORTHING,0.0);
    1361                 :     }
    1362                 : 
    1363               0 :     else if( EQUAL(pszProjection,SRS_PT_TRANSVERSE_MERCATOR_MI_24) ) // Encom 2003
    1364                 :     {
    1365               0 :         sTABProj.nProjId = 24;
    1366               0 :         parms[0] = poSpatialRef->GetProjParm(SRS_PP_CENTRAL_MERIDIAN,0.0);
    1367               0 :         parms[1] = poSpatialRef->GetProjParm(SRS_PP_LATITUDE_OF_ORIGIN,0.0);
    1368               0 :         parms[2] = poSpatialRef->GetProjParm(SRS_PP_SCALE_FACTOR,1.0);
    1369               0 :         parms[3] = poSpatialRef->GetProjParm(SRS_PP_FALSE_EASTING,0.0);
    1370               0 :         parms[4] = poSpatialRef->GetProjParm(SRS_PP_FALSE_NORTHING,0.0);
    1371                 :     }
    1372                 : 
    1373               0 :     else if( EQUAL(pszProjection,SRS_PT_CASSINI_SOLDNER) )
    1374                 :     {
    1375               0 :         sTABProj.nProjId = 30;
    1376               0 :         parms[0] = poSpatialRef->GetProjParm(SRS_PP_CENTRAL_MERIDIAN,0.0);
    1377               0 :         parms[1] = poSpatialRef->GetProjParm(SRS_PP_LATITUDE_OF_ORIGIN,0.0);
    1378               0 :         parms[2] = poSpatialRef->GetProjParm(SRS_PP_FALSE_EASTING,0.0);
    1379               0 :         parms[3] = poSpatialRef->GetProjParm(SRS_PP_FALSE_NORTHING,0.0);
    1380                 :     }
    1381                 : 
    1382               0 :     else if( EQUAL(pszProjection,SRS_PT_NEW_ZEALAND_MAP_GRID) )
    1383                 :     {
    1384               0 :         sTABProj.nProjId = 18;
    1385               0 :         parms[0] = poSpatialRef->GetProjParm(SRS_PP_CENTRAL_MERIDIAN,0.0);
    1386               0 :         parms[1] = poSpatialRef->GetProjParm(SRS_PP_LATITUDE_OF_ORIGIN,0.0);
    1387               0 :         parms[2] = poSpatialRef->GetProjParm(SRS_PP_FALSE_EASTING,0.0);
    1388               0 :         parms[3] = poSpatialRef->GetProjParm(SRS_PP_FALSE_NORTHING,0.0);
    1389                 :     }
    1390                 : 
    1391               0 :     else if( EQUAL(pszProjection,SRS_PT_POLYCONIC) )
    1392                 :     {
    1393               0 :         sTABProj.nProjId = 27;
    1394               0 :         parms[0] = poSpatialRef->GetProjParm(SRS_PP_CENTRAL_MERIDIAN,0.0);
    1395               0 :         parms[1] = poSpatialRef->GetProjParm(SRS_PP_LATITUDE_OF_ORIGIN,0.0);
    1396               0 :         parms[2] = poSpatialRef->GetProjParm(SRS_PP_FALSE_EASTING,0.0);
    1397               0 :         parms[3] = poSpatialRef->GetProjParm(SRS_PP_FALSE_NORTHING,0.0);
    1398                 :     }
    1399                 : 
    1400                 :     /* ==============================================================
    1401                 :      * Translate Datum and Ellipsoid
    1402                 :      * ============================================================== */
    1403               1 :     const char *pszWKTDatum = poSpatialRef->GetAttrValue("DATUM");
    1404               1 :     MapInfoDatumInfo *psDatumInfo = NULL;
    1405                 :     
    1406                 :     /*-----------------------------------------------------------------
    1407                 :      * Default to WGS83 if we have no datum at all.
    1408                 :      *----------------------------------------------------------------*/
    1409               1 :     if( pszWKTDatum == NULL )
    1410                 :     {
    1411               0 :         psDatumInfo = asDatumInfoList+0; /* WGS 84 */
    1412                 :     }
    1413                 :     
    1414                 :     /*-----------------------------------------------------------------
    1415                 :      * We know the MIF datum number, and need to look it up to
    1416                 :      * translate into datum parameters.
    1417                 :      *----------------------------------------------------------------*/
    1418               1 :     else if( EQUALN(pszWKTDatum,"MIF ",4)
    1419                 :              && atoi(pszWKTDatum+4) != 999
    1420                 :              && atoi(pszWKTDatum+4) != 9999 )
    1421                 :     {
    1422                 :         int     i;
    1423                 : 
    1424               0 :         for( i = 0; asDatumInfoList[i].nMapInfoDatumID != -1; i++ )
    1425                 :         {
    1426               0 :             if( atoi(pszWKTDatum+4) == asDatumInfoList[i].nMapInfoDatumID )
    1427                 :             {
    1428               0 :                 psDatumInfo = asDatumInfoList + i;
    1429               0 :                 break;
    1430                 :             }
    1431                 :         }
    1432                 : 
    1433               0 :         if( psDatumInfo == NULL )
    1434               0 :             psDatumInfo = asDatumInfoList+0; /* WGS 84 */
    1435                 :     }
    1436                 : 
    1437                 :     /*-----------------------------------------------------------------
    1438                 :      * We have the MIF datum parameters, and apply those directly.
    1439                 :      *----------------------------------------------------------------*/
    1440               1 :     else if( EQUALN(pszWKTDatum,"MIF ",4)
    1441                 :              && (atoi(pszWKTDatum+4) == 999 || atoi(pszWKTDatum+4) == 9999) )
    1442                 :     {
    1443                 :         char **papszFields;
    1444                 : 
    1445                 :         papszFields =
    1446               0 :             CSLTokenizeStringComplex( pszWKTDatum+4, ",", FALSE, TRUE);
    1447                 : 
    1448               0 :         if( CSLCount(papszFields) >= 5 )
    1449                 :         {
    1450               0 :             sTABProj.nEllipsoidId = atoi(papszFields[1]);
    1451               0 :             sTABProj.dDatumShiftX = atof(papszFields[2]);
    1452               0 :             sTABProj.dDatumShiftY = atof(papszFields[3]);
    1453               0 :             sTABProj.dDatumShiftZ = atof(papszFields[4]);
    1454                 :         }
    1455                 : 
    1456               0 :         if( CSLCount(papszFields) >= 10 )
    1457                 :         {
    1458               0 :             sTABProj.adDatumParams[0] = atof(papszFields[5]);
    1459               0 :             sTABProj.adDatumParams[1] = atof(papszFields[6]);
    1460               0 :             sTABProj.adDatumParams[2] = atof(papszFields[7]);
    1461               0 :             sTABProj.adDatumParams[3] = atof(papszFields[8]);
    1462               0 :             sTABProj.adDatumParams[4] = atof(papszFields[9]);
    1463                 :         }
    1464                 : 
    1465               0 :         if( CSLCount(papszFields) < 5 )
    1466               0 :             psDatumInfo = asDatumInfoList+0; /* WKS84 */
    1467                 : 
    1468               0 :         CSLDestroy( papszFields );
    1469                 :     }
    1470                 :     
    1471                 :     /*-----------------------------------------------------------------
    1472                 :      * We have a "real" datum name.  Try to look it up and get the
    1473                 :      * parameters.  If we don't find it just use WGS84.
    1474                 :      *----------------------------------------------------------------*/
    1475                 :     else 
    1476                 :     {
    1477                 :         int     i;
    1478                 : 
    1479               1 :         for( i = 0; asDatumInfoList[i].nMapInfoDatumID != -1; i++ )
    1480                 :         {
    1481               1 :             if( EQUAL(pszWKTDatum,asDatumInfoList[i].pszOGCDatumName) )
    1482                 :             {
    1483               1 :                 psDatumInfo = asDatumInfoList + i;
    1484               1 :                 break;
    1485                 :             }
    1486                 :         }
    1487                 : 
    1488               1 :          if( psDatumInfo == NULL )
    1489               0 :             psDatumInfo = asDatumInfoList+0; /* WGS 84 */
    1490                 :     }
    1491                 : 
    1492               1 :     if( psDatumInfo != NULL )
    1493                 :     {
    1494               1 :         sTABProj.nEllipsoidId = psDatumInfo->nEllipsoid;
    1495               1 :         sTABProj.nDatumId = psDatumInfo->nMapInfoDatumID;
    1496               1 :         sTABProj.dDatumShiftX = psDatumInfo->dfShiftX;
    1497               1 :         sTABProj.dDatumShiftY = psDatumInfo->dfShiftY;
    1498               1 :         sTABProj.dDatumShiftZ = psDatumInfo->dfShiftZ;
    1499               1 :         sTABProj.adDatumParams[0] = psDatumInfo->dfDatumParm0;
    1500               1 :         sTABProj.adDatumParams[1] = psDatumInfo->dfDatumParm1;
    1501               1 :         sTABProj.adDatumParams[2] = psDatumInfo->dfDatumParm2;
    1502               1 :         sTABProj.adDatumParams[3] = psDatumInfo->dfDatumParm3;
    1503               1 :         sTABProj.adDatumParams[4] = psDatumInfo->dfDatumParm4;
    1504                 :     }
    1505                 :     
    1506                 :     /*-----------------------------------------------------------------
    1507                 :      * Translate the units
    1508                 :      *----------------------------------------------------------------*/
    1509               1 :     if( sTABProj.nProjId == 1 || pszLinearUnits == NULL )
    1510               0 :         sTABProj.nUnitsId = 13;
    1511               1 :     else if( dfLinearConv == 1000.0 )
    1512               0 :         sTABProj.nUnitsId = 1;
    1513               1 :     else if( dfLinearConv == 0.0254 || EQUAL(pszLinearUnits,"Inch")
    1514                 :              || EQUAL(pszLinearUnits,"IINCH") )
    1515               0 :         sTABProj.nUnitsId = 2;
    1516               1 :     else if( dfLinearConv == atof(SRS_UL_FOOT_CONV)
    1517                 :              || EQUAL(pszLinearUnits,SRS_UL_FOOT) )
    1518               0 :         sTABProj.nUnitsId = 3;
    1519               1 :     else if( EQUAL(pszLinearUnits,"YARD") || EQUAL(pszLinearUnits,"IYARD") 
    1520                 :              || dfLinearConv == 0.9144 )
    1521               0 :         sTABProj.nUnitsId = 4;
    1522               1 :     else if( dfLinearConv == 0.001 )
    1523               0 :         sTABProj.nUnitsId = 5;
    1524               1 :     else if( dfLinearConv == 0.01 )
    1525               0 :         sTABProj.nUnitsId = 6;
    1526               1 :     else if( dfLinearConv == 1.0 )
    1527               1 :         sTABProj.nUnitsId = 7;
    1528               0 :     else if( dfLinearConv == atof(SRS_UL_US_FOOT_CONV)
    1529                 :              || EQUAL(pszLinearUnits,SRS_UL_US_FOOT) )
    1530               0 :         sTABProj.nUnitsId = 8;
    1531               0 :     else if( EQUAL(pszLinearUnits,SRS_UL_NAUTICAL_MILE) )
    1532               0 :         sTABProj.nUnitsId = 9;
    1533               0 :     else if( EQUAL(pszLinearUnits,SRS_UL_LINK) 
    1534                 :              || EQUAL(pszLinearUnits,"GUNTERLINK") )
    1535               0 :         sTABProj.nUnitsId = 30;
    1536               0 :     else if( EQUAL(pszLinearUnits,SRS_UL_CHAIN) 
    1537                 :              || EQUAL(pszLinearUnits,"GUNTERCHAIN") )
    1538               0 :         sTABProj.nUnitsId = 31;
    1539               0 :     else if( EQUAL(pszLinearUnits,SRS_UL_ROD) )
    1540               0 :         sTABProj.nUnitsId = 32;
    1541               0 :     else if( EQUAL(pszLinearUnits,"Mile") 
    1542                 :              || EQUAL(pszLinearUnits,"IMILE") )
    1543               0 :         sTABProj.nUnitsId = 0;
    1544                 :     else
    1545               0 :         sTABProj.nUnitsId = 7;
    1546                 :     
    1547                 :     /*-----------------------------------------------------------------
    1548                 :      * Set the new parameters in the .MAP header.
    1549                 :      * This will also trigger lookup of default bounds for the projection.
    1550                 :      *----------------------------------------------------------------*/
    1551               1 :     if ( SetProjInfo( &sTABProj ) != 0 )
    1552                 :     {
    1553                 :         CPLError(CE_Failure, CPLE_FileIO,
    1554               0 :                  "SetSpatialRef() failed setting projection parameters.");
    1555               0 :         return -1;
    1556                 :     }
    1557                 : 
    1558               1 :     return 0;
    1559                 : }
    1560                 : 

Generated by: LTP GCOV extension version 1.5