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