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 1193 1194 1195 1196 1197 1198 1199 1200 1201 1202 1203 1204 1205 1206 1207 1208 1209 1210 1211 1212 1213 1214 1215 1216 1217 1218 1219 1220 1221 1222 1223 1224 1225 1226 1227 1228 1229 1230 1231 1232 1233 1234 1235 1236 1237 1238 1239 1240 1241 1242 1243 1244 1245 1246 1247 1248 1249 1250 1251 1252 1253 1254 1255 1256 1257 1258 1259 1260 1261 1262 1263 1264 1265 1266 1267 1268 1269 1270 1271 1272 1273 1274 1275 1276 1277 1278 1279 1280 1281 1282 1283 1284 1285 1286 1287 1288 1289 1290 1291 1292 1293 1294 1295 1296 1297 1298 1299 1300 1301 1302 1303 1304 1305 1306 1307 1308 1309 1310 1311 1312 1313 1314 1315 1316 1317 1318 1319 1320 1321 1322 1323 1324 1325 1326 1327 1328 1329 1330 1331 1332 1333 1334 1335 1336 1337 1338 1339 1340 1341 1342 1343 1344 1345 1346 1347 1348 1349 1350 1351 1352 1353 1354 1355 1356 1357 1358 1359 1360 1361 1362 1363 1364 1365 1366 1367 1368 1369 1370 1371 1372 1373 1374 1375 1376 1377 1378 1379 1380 1381 1382 1383 1384 1385 1386 1387 1388 1389 1390 1391 1392 1393 1394 1395 1396 1397 1398 1399 1400 1401 1402 1403 1404 1405 1406 1407 1408 1409 1410 1411 1412 1413 1414 1415 1416 1417 1418 1419 1420 1421 1422 1423 1424 1425 1426 1427 1428 1429 1430 1431 1432 1433 1434 1435 1436 1437 1438 1439 1440 1441 1442 1443 1444 1445 1446 1447 1448 1449 1450 1451 1452 1453 1454 1455 1456 1457 1458 1459 1460 1461 1462 1463 1464 1465 1466 1467 1468 1469 1470 1471 1472 1473 1474 1475 1476 1477 1478 1479 1480 1481 1482 1483 1484 1485 1486 1487 1488 1489 1490 1491 1492 1493 1494 1495 1496 1497 1498 1499 1500 1501 1502 1503 1504 1505 1506 1507 1508 1509 1510 1511 1512 1513 1514 1515 1516 1517 1518 1519 1520 1521 1522 1523 1524 1525 1526 1527 1528 1529 1530 1531 1532 1533 1534 1535 1536 1537 1538 1539 1540 1541 1542 1543 1544 1545 1546 1547 1548 1549 1550 1551 1552 1553 1554 1555 1556 1557 1558 1559 1560 1561 1562 1563 1564 1565 1566 1567 1568 1569 1570 1571 1572 1573 1574 1575 1576 1577 1578 1579 1580 1581 1582 1583 1584 1585 1586 1587 1588 1589 1590 1591 1592 1593 1594 1595 1596 1597 1598 1599 1600 1601 1602 1603 1604 1605 1606 1607 1608 1609 1610 1611 1612 1613 1614 1615 1616 1617 1618 1619 1620 1621 1622 1623 1624 1625 1626 1627 1628 1629 1630 1631 1632 1633 1634 1635 1636 1637 1638 1639 1640 1641 1642 1643 1644 1645 1646 1647 1648 1649 1650 1651 1652 1653 1654 1655 1656 1657 1658 1659 1660 1661 1662 1663 1664 1665 1666 1667 1668 1669 1670 1671 1672 1673 1674 1675 1676 1677 1678 1679 1680 1681 1682 1683 1684 1685 1686 1687 1688 1689 1690 1691 1692 1693 1694 1695 1696 1697 1698 1699 1700 1701 1702 1703 1704 1705 1706 1707 1708 1709 1710 1711 1712 1713 1714 1715 1716 1717 1718 1719 1720 1721 1722 1723 1724 1725 1726 1727 1728 1729 1730 1731 1732 1733 1734 1735 1736 1737 1738 1739 1740 1741 1742 1743 1744 1745 1746 1747 1748 1749 1750 1751 1752 1753 1754 1755 1756 1757 1758 1759 1760 1761 1762 1763 1764 1765 1766 1767 1768 1769 1770 1771 1772 1773 1774 1775 1776 1777 1778 1779 1780 1781 1782 1783 1784 1785 1786 1787 1788 1789 1790 1791 1792 1793 1794 1795 1796 1797 1798 1799 1800 1801 1802 1803 1804 1805 1806 1807 1808 1809 1810 1811 1812 1813 1814 1815 1816 1817 1818 1819 1820 1821 1822 1823 1824 1825 1826 1827 1828 1829 1830 1831 1832 1833 1834 1835 1836 1837 1838 1839 1840 1841 1842 1843 1844 1845 1846 1847 1848 1849 1850 1851 1852 1853 1854 1855 1856 1857 1858 1859 1860 1861 1862 1863 1864 1865 1866 1867 1868 1869 1870 1871 1872 1873 1874 1875 1876 1877 1878 1879 1880 1881 1882 1883 1884 1885 1886 1887 1888 1889 1890 1891 1892 1893 1894 1895 1896 1897 1898 1899 1900 1901 1902 1903 1904 1905 1906 1907 1908 1909 1910 1911 1912 1913 1914 1915 1916 1917 1918 1919 1920 1921 1922 1923 1924 1925 1926 1927 1928 1929 1930 1931 1932 1933 1934 1935 1936 1937 1938 1939 1940 1941 1942 1943 1944 1945 1946 1947 1948 1949 1950 1951 1952 1953 1954 1955 1956 1957 1958 1959 1960 1961 1962 1963 1964 1965 1966 1967 1968 1969 1970 1971 1972 1973 1974 1975 1976 1977 1978 1979 1980 1981 1982 1983 1984 1985 1986 1987 1988 1989 1990 1991 1992 1993 1994 1995 1996 1997 1998 1999 2000 2001 2002 2003 2004 2005 2006 2007 2008 2009 2010 2011 2012 2013 2014 2015 2016 2017 2018 2019 2020 2021 2022 2023 2024 2025 2026 2027 2028 2029 2030 2031 2032 2033 2034 2035 2036 2037 2038 2039 2040 2041 2042 2043 2044 2045 2046 2047 2048 2049 2050 2051 2052 2053 2054 2055 2056 2057 2058 2059 2060 2061 2062 2063 2064 2065 2066 2067 2068 2069 2070 2071 2072 2073 2074 2075 2076 2077 2078 2079 2080 2081 2082 2083 2084 2085 2086 2087 2088 2089 2090 2091 2092 2093 2094 2095 2096 2097 2098 2099 2100 2101 2102 2103 2104 2105 2106 2107 2108 2109 2110 2111 2112 2113 2114 2115 2116 2117 2118 2119 2120 2121 2122 2123 2124 2125 2126 2127 2128 2129 2130 2131 2132 2133 2134 2135 2136 2137 2138 2139 2140 2141 2142 2143 2144 2145 2146 2147 2148 2149 2150 2151 2152 2153 2154 2155 2156 2157 2158 2159 2160 2161 2162 2163 2164 2165 2166 2167 2168 2169 2170 2171 2172 2173 2174 2175 2176 2177 2178 2179 2180 2181 2182 2183 2184 2185 2186 2187 2188 2189 2190 2191 2192 2193 2194 2195 2196 2197 2198 2199 2200 2201 2202 2203 2204 2205 2206 2207 2208 2209 2210 2211 2212 2213 2214 2215 2216 2217 2218 2219 2220 2221 2222 2223 2224 2225 2226 2227 2228 2229 2230 2231 2232 2233 2234 2235 2236 2237 2238 2239 2240 2241 2242 2243 2244 2245 2246 2247 2248 2249 2250 2251 2252 2253 2254 2255 2256 2257 2258 2259 2260 2261 2262 2263 2264 2265 2266 2267 2268 2269 2270 2271 2272 2273 2274 2275 2276 2277 2278 2279 2280 2281 2282 2283 2284 2285 2286 2287 2288 2289 2290 2291 2292 2293 2294 2295 2296 2297 2298 2299 2300 2301 2302 2303 2304 2305 2306 2307 2308 2309 2310 2311 2312 2313 2314 2315 2316 2317 2318 2319 2320 2321 2322 2323 2324 2325 2326 2327 2328 2329 2330 2331 2332 2333 2334 2335 2336 2337 2338 2339 2340 2341 2342 2343 2344 2345 2346 2347 2348 2349 2350 2351 2352 2353 2354 2355 2356 2357 2358 2359 2360 2361 2362 2363 2364 2365 2366 2367 2368 2369 2370 2371 2372 2373 2374 2375 2376 2377 2378 2379 2380 2381 2382 2383 2384 2385 2386 2387 2388 2389 2390 2391 2392 2393 2394 2395 2396 2397 2398 2399
|
/******************************************************************************
* $Id: mapwcs.c 11821 2011-06-14 20:49:10Z warmerdam $
*
* Project: MapServer
* Purpose: OpenGIS Web Coverage Server (WCS) Implementation.
* Author: Steve Lime and the MapServer team.
*
******************************************************************************
* Copyright (c) 1996-2005 Regents of the University of Minnesota.
*
* 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 of this Software or works derived from this 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 "mapserver.h"
#include "maperror.h"
#include "mapthread.h"
#include <assert.h>
MS_CVSID("$Id: mapwcs.c 11821 2011-06-14 20:49:10Z warmerdam $")
#ifdef USE_WCS_SVR
#include "mapwcs.h"
#include "maptime.h"
#include <time.h>
#include "gdal.h"
#include "cpl_string.h" /* GDAL string handling */
/************************************************************************/
/* msWCSValidateRangeSetParam() */
/************************************************************************/
static int msWCSValidateRangeSetParam(layerObj *lp, char *name, const char *value) {
char **allowed_ri_values;
char **client_ri_values;
int allowed_count, client_count;
int i_client, i, all_match = 1;
char *tmpname = NULL;
const char *ri_values_list;
if( name == NULL )
return MS_FAILURE;
/* Fetch the available values list for the rangeset item and tokenize */
tmpname = (char *)msSmallMalloc(sizeof(char)*strlen(name) + 10);
sprintf(tmpname,"%s_values", name);
ri_values_list = msOWSLookupMetadata(&(lp->metadata), "CO", tmpname);
msFree( tmpname );
if (ri_values_list == NULL)
return MS_FAILURE;
allowed_ri_values = msStringSplit( ri_values_list, ',', &allowed_count);
/* Parse the client value list into tokens. */
client_ri_values = msStringSplit( value, ',', &client_count );
/* test each client value against the allowed list. */
for( i_client = 0; all_match && i_client < client_count; i_client++ )
{
for( i = 0;
i < allowed_count
&& strcasecmp(client_ri_values[i_client],
allowed_ri_values[i]) != 0;
i++ ) {}
if( i == allowed_count )
all_match = 0;
}
msFreeCharArray(allowed_ri_values, allowed_count );
msFreeCharArray(client_ri_values, client_count );
if (all_match == 0)
return MS_FAILURE;
else
return MS_SUCCESS;
}
/************************************************************************/
/* msWCSConvertRangeSetToString() */
/************************************************************************/
static char *msWCSConvertRangeSetToString(const char *value) {
char **tokens;
int numtokens;
double min, max, res;
double val;
char buf1[128], *buf2=NULL;
if(strchr(value, '/')) { /* value is min/max/res */
tokens = msStringSplit(value, '/', &numtokens);
if(tokens==NULL || numtokens != 3) {
msFreeCharArray(tokens, numtokens);
return NULL; /* not a set of equally spaced intervals */
}
min = atof(tokens[0]);
max = atof(tokens[1]);
res = atof(tokens[2]);
msFreeCharArray(tokens, numtokens);
for(val=min; val<=max; val+=res) {
if(val == min)
snprintf(buf1, sizeof(buf1), "%g", val);
else
snprintf(buf1, sizeof(buf1), ",%g", val);
buf2 = msStringConcatenate(buf2, buf1);
}
return buf2;
} else
return msStrdup(value);
}
/************************************************************************/
/* msWCSException() */
/************************************************************************/
int msWCSException(mapObj *map, const char *code, const char *locator,
const char *version )
{
char *pszEncodedVal = NULL;
const char *encoding;
if( version == NULL )
version = "1.0.0";
#if defined(USE_LIBXML2)
if( msOWSParseVersionString(version) >= OWS_2_0_0 )
return msWCSException20( map, code, locator, version );
#endif
if( msOWSParseVersionString(version) >= OWS_1_1_0 )
return msWCSException11( map, code, locator, version );
encoding = msOWSLookupMetadata(&(map->web.metadata), "CO", "encoding");
if (encoding)
msIO_printf("Content-type: application/vnd.ogc.se_xml; charset=%s%c%c", encoding,10,10);
else
msIO_printf("Content-type: application/vnd.ogc.se_xml%c%c",10,10);
/* msIO_printf("Content-type: text/xml%c%c",10,10); */
msOWSPrintEncodeMetadata(stdout, &(map->web.metadata), NULL, "wcs_encoding", OWS_NOERR, "<?xml version='1.0' encoding=\"%s\" ?>\n", "ISO-8859-1");
msIO_printf("<ServiceExceptionReport version=\"1.2.0\"\n");
msIO_printf("xmlns=\"http://www.opengis.net/ogc\" ");
msIO_printf("xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" ");
pszEncodedVal = msEncodeHTMLEntities(msOWSGetSchemasLocation(map));
msIO_printf("xsi:schemaLocation=\"http://www.opengis.net/ogc %s/wcs/1.0.0/OGC-exception.xsd\">\n",
pszEncodedVal);
msFree(pszEncodedVal);
msIO_printf(" <ServiceException");
if (code) {
msIO_printf(" code=\"%s\"", code);
}
if (locator) {
msIO_printf(" locator=\"%s\"", locator);
}
msIO_printf(">");
msWriteErrorXML(stdout);
msIO_printf(" </ServiceException>\n");
msIO_printf("</ServiceExceptionReport>\n");
return MS_FAILURE;
}
/************************************************************************/
/* msWCSPrintRequestCapability() */
/************************************************************************/
static void msWCSPrintRequestCapability(const char *version, const char *request_tag, const char *script_url)
{
msIO_printf(" <%s>\n", request_tag);
msIO_printf(" <DCPType>\n");
msIO_printf(" <HTTP>\n");
msIO_printf(" <Get><OnlineResource xlink:type=\"simple\" xlink:href=\"%s\" /></Get>\n", script_url);
msIO_printf(" </HTTP>\n");
msIO_printf(" </DCPType>\n");
msIO_printf(" <DCPType>\n");
msIO_printf(" <HTTP>\n");
msIO_printf(" <Post><OnlineResource xlink:type=\"simple\" xlink:href=\"%s\" /></Post>\n", script_url);
msIO_printf(" </HTTP>\n");
msIO_printf(" </DCPType>\n");
msIO_printf(" </%s>\n", request_tag);
}
/************************************************************************/
/* msWCSCreateParams() */
/************************************************************************/
static wcsParamsObj *msWCSCreateParams()
{
wcsParamsObj *params;
params = (wcsParamsObj *) calloc(1, sizeof(wcsParamsObj));
MS_CHECK_ALLOC(params, sizeof(wcsParamsObj), NULL);
return params;
}
/************************************************************************/
/* msWCSFreeParams() */
/************************************************************************/
void msWCSFreeParams(wcsParamsObj *params)
{
if(params) {
/* TODO */
if(params->version) free(params->version);
if(params->updatesequence) free(params->updatesequence);
if(params->request) free(params->request);
if(params->service) free(params->service);
if(params->section) free(params->section);
if(params->crs) free(params->crs);
if(params->response_crs) free(params->response_crs);
if(params->format) free(params->format);
if(params->exceptions) free(params->exceptions);
if(params->time) free(params->time);
if(params->interpolation) free(params->interpolation);
}
}
/************************************************************************/
/* msWCSIsLayerSupported() */
/************************************************************************/
int msWCSIsLayerSupported(layerObj *layer)
{
/* only raster layers, are elligible to be served via WCS, WMS rasters are not ok */
if((layer->type == MS_LAYER_RASTER) && layer->connectiontype != MS_WMS) return MS_TRUE;
return MS_FALSE;
}
/************************************************************************/
/* msWCSGetRequestParameter() */
/* */
/************************************************************************/
const char *msWCSGetRequestParameter(cgiRequestObj *request, char *name) {
int i;
if(!request || !name) /* nothing to do */
return NULL;
if(request->NumParams > 0) {
for(i=0; i<request->NumParams; i++) {
if(strcasecmp(request->ParamNames[i], name) == 0)
return request->ParamValues[i];
}
}
return NULL;
}
/************************************************************************/
/* msWCSSetDefaultBandsRangeSetInfo() */
/************************************************************************/
void msWCSSetDefaultBandsRangeSetInfo( wcsParamsObj *params,
coverageMetadataObj *cm,
layerObj *lp )
{
/* This function will provide default rangeset information for the "special" */
/* "bands" rangeset if it appears in the axes list but has no specifics provided */
/* in the metadata. */
const char *value;
char *bandlist;
size_t bufferSize = 0;
int i;
/* Does this item exist in the axes list? */
value = msOWSLookupMetadata(&(lp->metadata), "CO", "rangeset_axes");
if( value == NULL )
return;
value = strstr(value,"bands");
if( value[5] != '\0' && value[5] != ' ' )
return;
/* Are there any w*s_bands_ metadata already? If so, skip out. */
if( msOWSLookupMetadata(&(lp->metadata), "CO", "bands_description") != NULL
|| msOWSLookupMetadata(&(lp->metadata), "CO", "bands_name") != NULL
|| msOWSLookupMetadata(&(lp->metadata), "CO", "bands_label") != NULL
|| msOWSLookupMetadata(&(lp->metadata), "CO", "bands_values") != NULL
|| msOWSLookupMetadata(&(lp->metadata), "CO", "bands_values_semantic") != NULL
|| msOWSLookupMetadata(&(lp->metadata), "CO", "bands_values_type") != NULL
|| msOWSLookupMetadata(&(lp->metadata), "CO", "bands_rangeitem") != NULL
|| msOWSLookupMetadata(&(lp->metadata), "CO", "bands_semantic") != NULL
|| msOWSLookupMetadata(&(lp->metadata), "CO", "bands_refsys") != NULL
|| msOWSLookupMetadata(&(lp->metadata), "CO", "bands_refsyslabel") != NULL
|| msOWSLookupMetadata(&(lp->metadata), "CO", "bands_interval") != NULL )
return;
/* OK, we have decided to fill in the information. */
msInsertHashTable( &(lp->metadata), "wcs_bands_name", "bands" );
msInsertHashTable( &(lp->metadata), "wcs_bands_label", "Bands/Channels/Samples" );
msInsertHashTable( &(lp->metadata), "wcs_bands_rangeitem", "_bands" ); /* ? */
bufferSize = cm->bandcount*30+30;
bandlist = (char *) msSmallMalloc(bufferSize);
strcpy( bandlist, "1" );
for( i = 1; i < cm->bandcount; i++ )
snprintf( bandlist+strlen(bandlist), bufferSize-strlen(bandlist), ",%d", i+1 );
msInsertHashTable( &(lp->metadata), "wcs_bands_values", bandlist );
free( bandlist );
}
/************************************************************************/
/* msWCSParseRequest() */
/************************************************************************/
static int msWCSParseRequest(cgiRequestObj *request, wcsParamsObj *params, mapObj *map)
{
int i, n;
char **tokens;
if(!request || !params) /* nothing to do */
return MS_SUCCESS;
/* -------------------------------------------------------------------- */
/* Check if this appears to be an XML POST WCS request. */
/* -------------------------------------------------------------------- */
msDebug("msWCSParseRequest(): request is %s.\n", (request->type == MS_POST_REQUEST)?"POST":"KVP");
if( request->type == MS_POST_REQUEST
&& request->postrequest )
{
#if defined(USE_LIBXML2)
xmlDocPtr doc = NULL;
xmlNodePtr root = NULL, child = NULL;
char *tmp = NULL;
/* parse to DOM-Structure and get root element */
if((doc = xmlParseMemory(request->postrequest, strlen(request->postrequest)))
== NULL) {
xmlErrorPtr error = xmlGetLastError();
msSetError(MS_WCSERR, "XML parsing error: %s",
"msWCSParseRequest()", error->message);
return MS_FAILURE;
}
root = xmlDocGetRootElement(doc);
/* Get service, version and request from root */
params->request = strdup((char *) root->name);
if ((tmp = (char *) xmlGetProp(root, BAD_CAST "service")) != NULL)
params->service = tmp;
if ((tmp = (char *) xmlGetProp(root, BAD_CAST "version")) != NULL)
params->version = tmp;
/* search first level children, either CoverageID, */
for (child = root->children; child != NULL; child = child->next)
{
if (EQUAL((char *)child->name, "AcceptVersions"))
{
/* will be overridden to 1.1.1 anyway */
}
else if (EQUAL((char *) child->name, "UpdateSequence"))
{
params->updatesequence = (char *)xmlNodeGetContent(child);
}
else if (EQUAL((char *) child->name, "Sections"))
{
xmlNodePtr sectionNode = NULL;
/* concatenate all sections by ',' */
for(sectionNode = child->children; sectionNode != NULL; sectionNode = sectionNode->next)
{
char *content;
if(!EQUAL((char *)sectionNode->name, "Section"))
continue;
content = (char *)xmlNodeGetContent(sectionNode);
if(!params->section)
{
params->section = content;
}
else
{
params->section = msStringConcatenate(params->section, ",");
params->section = msStringConcatenate(params->section, content);
xmlFree(content);
}
}
}
else if(EQUAL((char *) child->name, "AcceptFormats"))
{
/* TODO: implement */
}
else if(EQUAL((char *) child->name, "Identifier"))
{
char *content = (char *)xmlNodeGetContent(child);
params->coverages = CSLAddString(params->coverages, content);
xmlFree(content);
}
else if(EQUAL((char *) child->name, "DomainSubset"))
{
xmlNodePtr tmpNode = NULL;
for(tmpNode = child->children; tmpNode != NULL; tmpNode = tmpNode->next)
{
if(EQUAL((char *) tmpNode->name, "BoundingBox"))
{
xmlNodePtr cornerNode = NULL;
params->crs = (char *)xmlGetProp(tmpNode, BAD_CAST "crs");
if( strncasecmp(params->crs,"urn:ogc:def:crs:",16) == 0
&& strncasecmp(params->crs+strlen(params->crs)-8,"imageCRS",8)==0)
strcpy( params->crs, "imageCRS" );
for(cornerNode = tmpNode->children; cornerNode != NULL; cornerNode = cornerNode->next)
{
if(EQUAL((char *) cornerNode->name, "LowerCorner"))
{
char *value = (char *)xmlNodeGetContent(cornerNode);
tokens = msStringSplit(value, ' ', &n);
if(tokens==NULL || n < 2) {
msSetError(MS_WCSERR, "Wrong number of arguments for LowerCorner",
"msWCSParseRequest()");
return msWCSException(map, "InvalidParameterValue", "LowerCorner",
params->version );
}
params->bbox.minx = atof(tokens[0]);
params->bbox.miny = atof(tokens[1]);
msFreeCharArray(tokens, n);
xmlFree(value);
}
if(EQUAL((char *) cornerNode->name, "UpperCorner"))
{
char *value = (char *)xmlNodeGetContent(cornerNode);
tokens = msStringSplit(value, ' ', &n);
if(tokens==NULL || n < 2) {
msSetError(MS_WCSERR, "Wrong number of arguments for UpperCorner",
"msWCSParseRequest()");
return msWCSException(map, "InvalidParameterValue", "UpperCorner",
params->version );
}
params->bbox.maxx = atof(tokens[0]);
params->bbox.maxy = atof(tokens[1]);
msFreeCharArray(tokens, n);
xmlFree(value);
}
}
}
}
}
else if(EQUAL((char *) child->name, "RangeSubset"))
{
/* TODO: not implemented in mapserver WCS 1.1? */
}
else if(EQUAL((char *) child->name, "Output"))
{
xmlNodePtr tmpNode = NULL;
params->format = (char *)xmlGetProp(child, BAD_CAST "format");
for(tmpNode = child->children; tmpNode != NULL; tmpNode = tmpNode->next)
{
if(EQUAL((char *) tmpNode->name, "GridCRS"))
{
xmlNodePtr crsNode = NULL;
for(crsNode = tmpNode->children; crsNode != NULL; crsNode = crsNode->next)
{
if(EQUAL((char *) crsNode->name, "GridBaseCRS"))
{
params->response_crs = (char *) xmlNodeGetContent(crsNode);
}
else if (EQUAL((char *) crsNode->name, "GridOrigin"))
{
char *value = (char *)xmlNodeGetContent(crsNode);
tokens = msStringSplit(value, ' ', &n);
if(tokens==NULL || n < 2) {
msSetError(MS_WCSERR, "Wrong number of arguments for GridOrigin",
"msWCSParseRequest()");
return msWCSException(map, "InvalidParameterValue", "GridOffsets",
params->version );
}
params->originx = atof(tokens[0]);
params->originy = atof(tokens[1]);
msFreeCharArray(tokens, n);
xmlFree(value);
}
else if (EQUAL((char *) crsNode->name, "GridOffsets"))
{
char *value = (char *)xmlNodeGetContent(crsNode);
tokens = msStringSplit(value, ' ', &n);
if(tokens==NULL || n < 2) {
msSetError(MS_WCSERR, "Wrong number of arguments for GridOffsets",
"msWCSParseRequest()");
return msWCSException(map, "InvalidParameterValue", "GridOffsets",
params->version );
}
/* take absolute values to convert to positive RESX/RESY style
WCS 1.0 behavior. *but* this does break some possibilities! */
params->resx = fabs(atof(tokens[0]));
params->resy = fabs(atof(tokens[1]));
msFreeCharArray(tokens, n);
xmlFree(value);
}
}
}
}
}
}
xmlFreeDoc(doc);
xmlCleanupParser();
return MS_SUCCESS;
#else /* defined(USE_LIBXML2) */
return MS_FAILURE;
#endif /* defined(USE_LIBXML2) */
}
/* -------------------------------------------------------------------- */
/* Extract WCS KVP Parameters. */
/* -------------------------------------------------------------------- */
if(request->NumParams > 0) {
for(i=0; i<request->NumParams; i++) {
if(strcasecmp(request->ParamNames[i], "VERSION") == 0)
params->version = msStrdup(request->ParamValues[i]);
if(strcasecmp(request->ParamNames[i], "UPDATESEQUENCE") == 0)
params->updatesequence = msStrdup(request->ParamValues[i]);
else if(strcasecmp(request->ParamNames[i], "REQUEST") == 0)
params->request = msStrdup(request->ParamValues[i]);
else if(strcasecmp(request->ParamNames[i], "INTERPOLATION") == 0)
params->interpolation = msStrdup(request->ParamValues[i]);
else if(strcasecmp(request->ParamNames[i], "SERVICE") == 0)
params->service = msStrdup(request->ParamValues[i]);
else if(strcasecmp(request->ParamNames[i], "SECTION") == 0) /* 1.0 */
params->section = msStrdup(request->ParamValues[i]); /* TODO: validate value here */
else if(strcasecmp(request->ParamNames[i], "SECTIONS") == 0) /* 1.1 */
params->section = msStrdup(request->ParamValues[i]); /* TODO: validate value here */
/* GetCoverage parameters. */
else if(strcasecmp(request->ParamNames[i], "BBOX") == 0) {
tokens = msStringSplit(request->ParamValues[i], ',', &n);
if(tokens==NULL || n != 4) {
msSetError(MS_WCSERR, "Wrong number of arguments for BBOX.", "msWCSParseRequest()");
return msWCSException(map, "InvalidParameterValue", "bbox",
params->version );
}
params->bbox.minx = atof(tokens[0]);
params->bbox.miny = atof(tokens[1]);
params->bbox.maxx = atof(tokens[2]);
params->bbox.maxy = atof(tokens[3]);
msFreeCharArray(tokens, n);
} else if(strcasecmp(request->ParamNames[i], "RESX") == 0)
params->resx = atof(request->ParamValues[i]);
else if(strcasecmp(request->ParamNames[i], "RESY") == 0)
params->resy = atof(request->ParamValues[i]);
else if(strcasecmp(request->ParamNames[i], "WIDTH") == 0)
params->width = atoi(request->ParamValues[i]);
else if(strcasecmp(request->ParamNames[i], "HEIGHT") == 0)
params->height = atoi(request->ParamValues[i]);
else if(strcasecmp(request->ParamNames[i], "COVERAGE") == 0)
params->coverages = CSLAddString(params->coverages, request->ParamValues[i]);
else if(strcasecmp(request->ParamNames[i], "TIME") == 0)
params->time = msStrdup(request->ParamValues[i]);
else if(strcasecmp(request->ParamNames[i], "FORMAT") == 0)
params->format = msStrdup(request->ParamValues[i]);
else if(strcasecmp(request->ParamNames[i], "CRS") == 0)
params->crs = msStrdup(request->ParamValues[i]);
else if(strcasecmp(request->ParamNames[i], "RESPONSE_CRS") == 0)
params->response_crs = msStrdup(request->ParamValues[i]);
/* WCS 1.1 DescribeCoverage and GetCoverage ... */
else if(strcasecmp(request->ParamNames[i], "IDENTIFIER") == 0
|| strcasecmp(request->ParamNames[i], "IDENTIFIERS") == 0 )
{
msDebug("msWCSParseRequest(): Whole String: %s\n", request->ParamValues[i]);
params->coverages = CSLAddString(params->coverages, request->ParamValues[i]);
}
/* WCS 1.1 style BOUNDINGBOX */
else if(strcasecmp(request->ParamNames[i], "BOUNDINGBOX") == 0) {
tokens = msStringSplit(request->ParamValues[i], ',', &n);
if(tokens==NULL || n < 5) {
msSetError(MS_WCSERR, "Wrong number of arguments for BOUNDINGBOX.", "msWCSParseRequest()");
return msWCSException(map, "InvalidParameterValue", "boundingbox",
params->version );
}
/* NOTE: WCS 1.1 boundingbox is center of pixel oriented, not edge
like in WCS 1.0. So bbox semantics are wonky till this is fixed
later in the GetCoverage processing. */
params->bbox.minx = atof(tokens[0]);
params->bbox.miny = atof(tokens[1]);
params->bbox.maxx = atof(tokens[2]);
params->bbox.maxy = atof(tokens[3]);
params->crs = msStrdup(tokens[4]);
msFreeCharArray(tokens, n);
/* normalize imageCRS urns to simply "imageCRS" */
if( strncasecmp(params->crs,"urn:ogc:def:crs:",16) == 0
&& strncasecmp(params->crs+strlen(params->crs)-8,"imageCRS",8)==0)
strcpy( params->crs, "imageCRS" );
} else if(strcasecmp(request->ParamNames[i], "GridOffsets") == 0) {
tokens = msStringSplit(request->ParamValues[i], ',', &n);
if(tokens==NULL || n < 2) {
msSetError(MS_WCSERR, "Wrong number of arguments for GridOffsets",
"msWCSParseRequest()");
return msWCSException(map, "InvalidParameterValue", "GridOffsets",
params->version );
}
/* take absolute values to convert to positive RESX/RESY style
WCS 1.0 behavior. *but* this does break some possibilities! */
params->resx = fabs(atof(tokens[0]));
params->resy = fabs(atof(tokens[1]));
msFreeCharArray(tokens, n);
} else if(strcasecmp(request->ParamNames[i], "GridOrigin") == 0) {
tokens = msStringSplit(request->ParamValues[i], ',', &n);
if(tokens==NULL || n < 2) {
msSetError(MS_WCSERR, "Wrong number of arguments for GridOrigin",
"msWCSParseRequest()");
return msWCSException(map, "InvalidParameterValue", "GridOffsets",
params->version );
}
params->originx = atof(tokens[0]);
params->originy = atof(tokens[1]);
msFreeCharArray(tokens, n);
}
/* and so on... */
}
}
/* we are not dealing with an XML encoded request at this point */
return MS_SUCCESS;
}
/************************************************************************/
/* msWCSGetCapabilities_Service_ResponsibleParty() */
/************************************************************************/
static void msWCSGetCapabilities_Service_ResponsibleParty(mapObj *map)
{
int bEnableTelephone=MS_FALSE, bEnableAddress=MS_FALSE, bEnableOnlineResource=MS_FALSE;
/* the WCS-specific way */
if(msOWSLookupMetadata(&(map->web.metadata), "CO", "responsibleparty_individualname") ||
msOWSLookupMetadata(&(map->web.metadata), "CO", "responsibleparty_organizationname")) {
msIO_printf("<responsibleParty>\n");
msOWSPrintEncodeMetadata(stdout, &(map->web.metadata), "CO", "responsibleparty_individualname", OWS_NOERR, " <individualName>%s</individualName>\n", NULL);
msOWSPrintEncodeMetadata(stdout, &(map->web.metadata), "CO", "responsibleparty_organizationname", OWS_NOERR, " <organisationName>%s</organisationName>\n", NULL);
msOWSPrintEncodeMetadata(stdout, &(map->web.metadata), "CO", "responsibleparty_positionname", OWS_NOERR, " <positionName>%s</positionName>\n", NULL);
if(msOWSLookupMetadata(&(map->web.metadata), "CO", "responsibleparty_phone_voice") ||
msOWSLookupMetadata(&(map->web.metadata), "CO", "responsibleparty_phone_facsimile")) bEnableTelephone = MS_TRUE;
if(msOWSLookupMetadata(&(map->web.metadata), "CO", "responsibleparty_address_deliverypoint") ||
msOWSLookupMetadata(&(map->web.metadata), "CO", "responsibleparty_address_city") ||
msOWSLookupMetadata(&(map->web.metadata), "CO", "responsibleparty_address_administrativearea") ||
msOWSLookupMetadata(&(map->web.metadata), "CO", "responsibleparty_address_postalcode") ||
msOWSLookupMetadata(&(map->web.metadata), "CO", "responsibleparty_address_country") ||
msOWSLookupMetadata(&(map->web.metadata), "CO", "responsibleparty_address_electronicmailaddress")) bEnableAddress = MS_TRUE;
if(msOWSLookupMetadata(&(map->web.metadata), "CO", "responsibleparty_onlineresource")) bEnableOnlineResource = MS_TRUE;
if(bEnableTelephone || bEnableAddress || bEnableOnlineResource) {
msIO_printf(" <contactInfo>\n");
if(bEnableTelephone) {
msIO_printf(" <phone>\n");
msOWSPrintEncodeMetadata(stdout, &(map->web.metadata), "CO", "responsibleparty_phone_voice", OWS_NOERR, " <voice>%s</voice>\n", NULL);
msOWSPrintEncodeMetadata(stdout, &(map->web.metadata), "CO", "responsibleparty_phone_facsimile", OWS_NOERR, " <facsimile>%s</facsimile>\n", NULL);
msIO_printf(" </phone>\n");
}
if(bEnableAddress) {
msIO_printf(" <address>\n");
msOWSPrintEncodeMetadata(stdout, &(map->web.metadata), "CO", "responsibleparty_address_deliverypoint", OWS_NOERR, " <deliveryPoint>%s</deliveryPoint>\n", NULL);
msOWSPrintEncodeMetadata(stdout, &(map->web.metadata), "CO", "responsibleparty_address_city", OWS_NOERR, " <city>%s</city>\n", NULL);
msOWSPrintEncodeMetadata(stdout, &(map->web.metadata), "CO", "responsibleparty_address_administrativearea", OWS_NOERR, " <administrativeArea>%s</administrativeArea>\n", NULL);
msOWSPrintEncodeMetadata(stdout, &(map->web.metadata), "CO", "responsibleparty_address_postalcode", OWS_NOERR, " <postalCode>%s</postalCode>\n", NULL);
msOWSPrintEncodeMetadata(stdout, &(map->web.metadata), "CO", "responsibleparty_address_country", OWS_NOERR, " <country>%s</country>\n", NULL);
msOWSPrintEncodeMetadata(stdout, &(map->web.metadata), "CO", "responsibleparty_address_electronicmailaddress", OWS_NOERR, " <electronicMailAddress>%s</electronicMailAddress>\n", NULL);
msIO_printf(" </address>\n");
}
msOWSPrintEncodeMetadata(stdout, &(map->web.metadata), "CO", "responsibleparty_onlineresource", OWS_NOERR, " <onlineResource xlink:type=\"simple\" xlink:href=\"%s\"/>\n", NULL);
msIO_printf(" </contactInfo>\n");
}
msIO_printf("</responsibleParty>\n");
} else if(msOWSLookupMetadata(&(map->web.metadata), "CO", "contactperson") ||
msOWSLookupMetadata(&(map->web.metadata), "CO", "contactorganization")) { /* leverage WMS contact information */
msIO_printf("<responsibleParty>\n");
msOWSPrintEncodeMetadata(stdout, &(map->web.metadata), "CO", "contactperson", OWS_NOERR, " <individualName>%s</individualName>\n", NULL);
msOWSPrintEncodeMetadata(stdout, &(map->web.metadata), "CO", "contactorganization", OWS_NOERR, " <organisationName>%s</organisationName>\n", NULL);
msOWSPrintEncodeMetadata(stdout, &(map->web.metadata), "CO", "contactposition", OWS_NOERR, " <positionName>%s</positionName>\n", NULL);
if(msOWSLookupMetadata(&(map->web.metadata), "CO", "contactvoicetelephone") ||
msOWSLookupMetadata(&(map->web.metadata), "CO", "contactfacsimiletelephone")) bEnableTelephone = MS_TRUE;
if(msOWSLookupMetadata(&(map->web.metadata), "CO", "address") ||
msOWSLookupMetadata(&(map->web.metadata), "CO", "city") ||
msOWSLookupMetadata(&(map->web.metadata), "CO", "stateorprovince") ||
msOWSLookupMetadata(&(map->web.metadata), "CO", "postcode") ||
msOWSLookupMetadata(&(map->web.metadata), "CO", "country") ||
msOWSLookupMetadata(&(map->web.metadata), "CO", "contactelectronicmailaddress")) bEnableAddress = MS_TRUE;
if(msOWSLookupMetadata(&(map->web.metadata), "CO", "service_onlineresource")) bEnableOnlineResource = MS_TRUE;
if(bEnableTelephone || bEnableAddress || bEnableOnlineResource) {
msIO_printf(" <contactInfo>\n");
if(bEnableTelephone) {
msIO_printf(" <phone>\n");
msOWSPrintEncodeMetadata(stdout, &(map->web.metadata), "CO", "contactvoicetelephone", OWS_NOERR, " <voice>%s</voice>\n", NULL);
msOWSPrintEncodeMetadata(stdout, &(map->web.metadata), "CO", "contactfacsimiletelephone", OWS_NOERR, " <facsimile>%s</facsimile>\n", NULL);
msIO_printf(" </phone>\n");
}
if(bEnableAddress) {
msIO_printf(" <address>\n");
msOWSPrintEncodeMetadata(stdout, &(map->web.metadata), "CO", "address", OWS_NOERR, " <deliveryPoint>%s</deliveryPoint>\n", NULL);
msOWSPrintEncodeMetadata(stdout, &(map->web.metadata), "CO", "city", OWS_NOERR, " <city>%s</city>\n", NULL);
msOWSPrintEncodeMetadata(stdout, &(map->web.metadata), "CO", "stateorprovince", OWS_NOERR, " <administrativeArea>%s</administrativeArea>\n", NULL);
msOWSPrintEncodeMetadata(stdout, &(map->web.metadata), "CO", "postcode", OWS_NOERR, " <postalCode>%s</postalCode>\n", NULL);
msOWSPrintEncodeMetadata(stdout, &(map->web.metadata), "CO", "country", OWS_NOERR, " <country>%s</country>\n", NULL);
msOWSPrintEncodeMetadata(stdout, &(map->web.metadata), "CO", "contactelectronicmailaddress", OWS_NOERR, " <electronicMailAddress>%s</electronicMailAddress>\n", NULL);
msIO_printf(" </address>\n");
}
msOWSPrintEncodeMetadata(stdout, &(map->web.metadata), "CO", "service_onlineresource", OWS_NOERR, " <onlineResource xlink:type=\"simple\" xlink:href=\"%s\"/>\n", NULL);
msIO_printf(" </contactInfo>\n");
}
msIO_printf("</responsibleParty>\n");
}
return;
}
/************************************************************************/
/* msWCSGetCapabilities_Service() */
/************************************************************************/
static int msWCSGetCapabilities_Service(mapObj *map, wcsParamsObj *params)
{
/* start the Service section, only need the full start tag if this is the only section requested */
if(!params->section || (params->section && strcasecmp(params->section, "/") == 0))
msIO_printf("<Service>\n");
else
msIO_printf("<Service\n"
" version=\"%s\" \n"
" updateSequence=\"%s\" \n"
" xmlns=\"http://www.opengis.net/wcs\" \n"
" xmlns:xlink=\"http://www.w3.org/1999/xlink\" \n"
" xmlns:gml=\"http://www.opengis.net/gml\" \n"
" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\"\n"
" xsi:schemaLocation=\"http://www.opengis.net/wcs %s/wcs/%s/wcsCapabilities.xsd\">\n", params->version, params->updatesequence, msOWSGetSchemasLocation(map), params->version);
/* optional metadataLink */
msOWSPrintURLType(stdout, &(map->web.metadata), "CO", "metadatalink",
OWS_NOERR,
" <metadataLink%s%s%s%s xlink:type=\"simple\"%s/>",
NULL, " metadataType=\"%s\"", NULL, NULL, NULL,
" xlink:href=\"%s\"", MS_FALSE, MS_FALSE, MS_FALSE,
MS_FALSE, MS_TRUE, "other", NULL, NULL, NULL, NULL, NULL);
msOWSPrintEncodeMetadata(stdout, &(map->web.metadata), "CO", "description", OWS_NOERR, " <description>%s</description>\n", NULL);
msOWSPrintEncodeMetadata(stdout, &(map->web.metadata), "CO", "name", OWS_NOERR, " <name>%s</name>\n", "MapServer WCS");
msOWSPrintEncodeMetadata(stdout, &(map->web.metadata), "CO", "label", OWS_WARN, " <label>%s</label>\n", NULL);
/* we are not supporting the optional keyword type, at least not yet */
msOWSPrintEncodeMetadataList(stdout, &(map->web.metadata), "CO", "keywordlist", " <keywords>\n", " </keywords>\n", " <keyword>%s</keyword>\n", NULL);
msWCSGetCapabilities_Service_ResponsibleParty(map);
msOWSPrintEncodeMetadata(stdout, &(map->web.metadata), "CO", "fees", OWS_NOERR, " <fees>%s</fees>\n", "NONE");
msOWSPrintEncodeMetadataList(stdout, &(map->web.metadata), "CO", "accessconstraints", " <accessConstraints>\n", " </accessConstraints>\n", " %s\n", "NONE");
/* done */
msIO_printf("</Service>\n");
return MS_SUCCESS;
}
/************************************************************************/
/* msWCSGetCapabilities_Capability() */
/************************************************************************/
static int msWCSGetCapabilities_Capability(mapObj *map, wcsParamsObj *params, cgiRequestObj *req)
{
char *script_url=NULL, *script_url_encoded=NULL;
/* we need this server's onlineresource for the request section */
if((script_url=msOWSGetOnlineResource(map, "CO", "onlineresource", req)) == NULL || (script_url_encoded = msEncodeHTMLEntities(script_url)) == NULL) {
free(script_url);
free(script_url_encoded);
return msWCSException(map, NULL, NULL, params->version );
}
/* start the Capabilty section, only need the full start tag if this is the only section requested */
if(!params->section || (params->section && strcasecmp(params->section, "/") == 0))
msIO_printf("<Capability>\n");
else
msIO_printf("<Capability\n"
" version=\"%s\" \n"
" updateSequence=\"%s\" \n"
" xmlns=\"http://www.opengis.net/wcs\" \n"
" xmlns:xlink=\"http://www.w3.org/1999/xlink\" \n"
" xmlns:gml=\"http://www.opengis.net/gml\" \n"
" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\"\n"
" xsi:schemaLocation=\"http://www.opengis.net/wcs %s/wcs/%s/wcsCapabilities.xsd\">\n", params->version, params->updatesequence, msOWSGetSchemasLocation(map), params->version);
/* describe the types of requests the server can handle */
msIO_printf(" <Request>\n");
msWCSPrintRequestCapability(params->version, "GetCapabilities", script_url_encoded);
if (msOWSRequestIsEnabled(map, NULL, "C", "DescribeCoverage", MS_TRUE))
msWCSPrintRequestCapability(params->version, "DescribeCoverage", script_url_encoded);
if (msOWSRequestIsEnabled(map, NULL, "C", "GetCoverage", MS_TRUE))
msWCSPrintRequestCapability(params->version, "GetCoverage", script_url_encoded);
msIO_printf(" </Request>\n");
/* describe the exception formats the server can produce */
msIO_printf(" <Exception>\n");
msIO_printf(" <Format>application/vnd.ogc.se_xml</Format>\n");
msIO_printf(" </Exception>\n");
/* describe any vendor specific capabilities */
/* msIO_printf(" <VendorSpecificCapabilities />\n"); */ /* none yet */
/* done */
msIO_printf("</Capability>\n");
free(script_url);
free(script_url_encoded);
return MS_SUCCESS;
}
/************************************************************************/
/* msWCSGetCapabilities_CoverageOfferingBrief() */
/************************************************************************/
static int msWCSGetCapabilities_CoverageOfferingBrief(layerObj *layer, wcsParamsObj *params)
{
coverageMetadataObj cm;
int status;
if((layer->status == MS_DELETE) || !msWCSIsLayerSupported(layer)) return MS_SUCCESS; /* not an error, this layer cannot be served via WCS */
status = msWCSGetCoverageMetadata(layer, &cm);
if(status != MS_SUCCESS) return MS_FAILURE;
/* start the CoverageOfferingBrief section */
msIO_printf(" <CoverageOfferingBrief>\n"); /* is this tag right? (I hate schemas without ANY examples) */
/* optional metadataLink */
msOWSPrintURLType(stdout, &(layer->metadata), "CO", "metadatalink",
OWS_NOERR,
" <metadataLink%s%s%s%s xlink:type=\"simple\"%s/>",
NULL, " metadataType=\"%s\"", NULL, NULL, NULL,
" xlink:href=\"%s\"", MS_FALSE, MS_FALSE, MS_FALSE,
MS_FALSE, MS_TRUE, "other", NULL, NULL, NULL, NULL, NULL);
msOWSPrintEncodeMetadata(stdout, &(layer->metadata), "CO", "description", OWS_NOERR, " <description>%s</description>\n", NULL);
msOWSPrintEncodeMetadata(stdout, &(layer->metadata), "CO", "name", OWS_NOERR, " <name>%s</name>\n", layer->name);
msOWSPrintEncodeMetadata(stdout, &(layer->metadata), "CO", "label", OWS_WARN, " <label>%s</label>\n", NULL);
/* TODO: add elevation ranges to lonLatEnvelope (optional) */
msIO_printf(" <lonLatEnvelope srsName=\"urn:ogc:def:crs:OGC:1.3:CRS84\">\n");
msIO_printf(" <gml:pos>%.15g %.15g</gml:pos>\n", cm.llextent.minx, cm.llextent.miny); /* TODO: don't know if this is right */
msIO_printf(" <gml:pos>%.15g %.15g</gml:pos>\n", cm.llextent.maxx, cm.llextent.maxy);
msOWSPrintEncodeMetadataList(stdout, &(layer->metadata), "CO", "timeposition", NULL, NULL, " <gml:timePosition>%s</gml:timePosition>\n", NULL);
msIO_printf(" </lonLatEnvelope>\n");
/* we are not supporting the optional keyword type, at least not yet */
msOWSPrintEncodeMetadataList(stdout, &(layer->metadata), "CO", "keywordlist", " <keywords>\n", " </keywords>\n", " <keyword>%s</keyword>\n", NULL);
/* done */
msIO_printf(" </CoverageOfferingBrief>\n");
return MS_SUCCESS;
}
/************************************************************************/
/* msWCSGetCapabilities_ContentMetadata() */
/************************************************************************/
static int msWCSGetCapabilities_ContentMetadata(mapObj *map, wcsParamsObj *params, owsRequestObj *ows_request)
{
int i;
/* start the ContentMetadata section, only need the full start tag if this is the only section requested */
/* TODO: add Xlink attributes for other sources of this information */
if(!params->section || (params->section && strcasecmp(params->section, "/") == 0))
msIO_printf("<ContentMetadata>\n");
else
msIO_printf("<ContentMetadata\n"
" version=\"%s\" \n"
" updateSequence=\"%s\" \n"
" xmlns=\"http://www.opengis.net/wcs\" \n"
" xmlns:xlink=\"http://www.w3.org/1999/xlink\" \n"
" xmlns:gml=\"http://www.opengis.net/gml\" \n"
" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\"\n"
" xsi:schemaLocation=\"http://www.opengis.net/wcs %s/wcs/%s/wcsCapabilities.xsd\">\n", params->version, params->updatesequence, msOWSGetSchemasLocation(map), params->version);
for(i=0; i<map->numlayers; i++) {
if (!msIntegerInArray(GET_LAYER(map, i)->index, ows_request->enabled_layers, ows_request->numlayers))
continue;
if( msWCSGetCapabilities_CoverageOfferingBrief((GET_LAYER(map, i)), params) != MS_SUCCESS ) {
msIO_printf("</ContentMetadata>\n");
return MS_FAILURE;
}
}
/* done */
msIO_printf("</ContentMetadata>\n");
return MS_SUCCESS;
}
/************************************************************************/
/* msWCSGetCapabilities() */
/************************************************************************/
static int msWCSGetCapabilities(mapObj *map, wcsParamsObj *params, cgiRequestObj *req, owsRequestObj *ows_request)
{
char tmpString[OWS_VERSION_MAXLEN];
int i, tmpInt = 0;
int wcsSupportedVersions[] = {OWS_1_1_2, OWS_1_1_1, OWS_1_1_0, OWS_1_0_0};
int wcsNumSupportedVersions = 4;
const char *updatesequence=NULL;
const char *encoding;
encoding = msOWSLookupMetadata(&(map->web.metadata), "CO", "encoding");
/* check version is valid */
tmpInt = msOWSParseVersionString(params->version);
if (tmpInt == OWS_VERSION_BADFORMAT)
{
return msWCSException(map, "InvalidParameterValue",
"request", "1.0.0 ");
}
/* negotiate version */
tmpInt = msOWSNegotiateVersion(tmpInt, wcsSupportedVersions, wcsNumSupportedVersions);
/* set result as string and carry on */
free(params->version);
params->version = msStrdup(msOWSGetVersionString(tmpInt, tmpString));
/* -------------------------------------------------------------------- */
/* 1.1.x is sufficiently different we have a whole case for */
/* it. The remainder of this function is for 1.0.0. */
/* -------------------------------------------------------------------- */
if( strncmp(params->version,"1.1",3) == 0 )
return msWCSGetCapabilities11( map, params, req, ows_request);
updatesequence = msOWSLookupMetadata(&(map->web.metadata), "CO", "updatesequence");
if (params->updatesequence != NULL) {
i = msOWSNegotiateUpdateSequence(params->updatesequence, updatesequence);
if (i == 0) { /* current */
msSetError(MS_WCSERR, "UPDATESEQUENCE parameter (%s) is equal to server (%s)", "msWCSGetCapabilities()", params->updatesequence, updatesequence);
return msWCSException(map, "CurrentUpdateSequence",
"updatesequence", params->version );
}
if (i > 0) { /* invalid */
msSetError(MS_WCSERR, "UPDATESEQUENCE parameter (%s) is higher than server (%s)", "msWCSGetCapabilities()", params->updatesequence, updatesequence);
return msWCSException(map, "InvalidUpdateSequence",
"updatesequence", params->version );
}
}
else { /* set default updatesequence */
if(!updatesequence)
updatesequence = msStrdup("0");
params->updatesequence = msStrdup(updatesequence);
}
/* if a bum section param is passed, throw exception */
if (params->section &&
strcasecmp(params->section, "/WCS_Capabilities/Service") != 0 &&
strcasecmp(params->section, "/WCS_Capabilities/Capability") != 0 &&
strcasecmp(params->section, "/WCS_Capabilities/ContentMetadata") != 0 &&
strcasecmp(params->section, "/") != 0) {
if (encoding)
msIO_printf("Content-type: application/vnd.ogc.se_xml; charset=%s%c%c", encoding,10,10);
else
msIO_printf("Content-type: application/vnd.ogc.se_xml%c%c",10,10);
msSetError( MS_WCSERR,
"Invalid SECTION parameter \"%s\"",
"msWCSGetCapabilities()", params->section);
return msWCSException(map, "InvalidParameterValue", "section",
params->version );
}
else {
if (encoding)
msIO_printf("Content-type: text/xml; charset=%s%c%c", encoding,10,10);
else
msIO_printf("Content-type: text/xml%c%c",10,10);
/* print common capability elements */
/* TODO: DocType? */
if (!updatesequence)
updatesequence = msStrdup("0");
msOWSPrintEncodeMetadata(stdout, &(map->web.metadata), NULL, "wcs_encoding", OWS_NOERR, "<?xml version='1.0' encoding=\"%s\" standalone=\"no\" ?>\n", "ISO-8859-1");
if(!params->section || (params->section && strcasecmp(params->section, "/") == 0)) msIO_printf("<WCS_Capabilities\n"
" version=\"%s\" \n"
" updateSequence=\"%s\" \n"
" xmlns=\"http://www.opengis.net/wcs\" \n"
" xmlns:xlink=\"http://www.w3.org/1999/xlink\" \n"
" xmlns:gml=\"http://www.opengis.net/gml\" \n"
" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\"\n"
" xsi:schemaLocation=\"http://www.opengis.net/wcs %s/wcs/%s/wcsCapabilities.xsd\">\n", params->version, updatesequence, msOWSGetSchemasLocation(map), params->version);
/* print the various capability sections */
if(!params->section || strcasecmp(params->section, "/WCS_Capabilities/Service") == 0)
msWCSGetCapabilities_Service(map, params);
if(!params->section || strcasecmp(params->section, "/WCS_Capabilities/Capability") == 0)
msWCSGetCapabilities_Capability(map, params, req);
if(!params->section || strcasecmp(params->section, "/WCS_Capabilities/ContentMetadata") == 0)
msWCSGetCapabilities_ContentMetadata(map, params, ows_request);
if(params->section && strcasecmp(params->section, "/") == 0) {
msWCSGetCapabilities_Service(map, params);
msWCSGetCapabilities_Capability(map, params, req);
msWCSGetCapabilities_ContentMetadata(map, params, ows_request);
}
/* done */
if(!params->section || (params->section && strcasecmp(params->section, "/") == 0)) msIO_printf("</WCS_Capabilities>\n");
}
return MS_SUCCESS;
}
/************************************************************************/
/* msWCSDescribeCoverage_AxisDescription() */
/************************************************************************/
static int msWCSDescribeCoverage_AxisDescription(layerObj *layer, char *name)
{
const char *value;
char tag[100]; /* should be plenty of space */
msIO_printf(" <axisDescription>\n");
msIO_printf(" <AxisDescription");
snprintf(tag, sizeof(tag), "%s_semantic", name); /* optional attributes follow (should escape?) */
msOWSPrintEncodeMetadata(stdout, &(layer->metadata), "CO", tag, OWS_NOERR, " semantic=\"%s\"", NULL);
snprintf(tag, sizeof(tag), "%s_refsys", name);
msOWSPrintEncodeMetadata(stdout, &(layer->metadata), "CO", tag, OWS_NOERR, " refSys=\"%s\"", NULL);
snprintf(tag, sizeof(tag), "%s_refsyslabel", name);
msOWSPrintEncodeMetadata(stdout, &(layer->metadata), "CO", tag, OWS_NOERR, " refSysLabel=\"%s\"", NULL);
msIO_printf(">\n");
/* TODO: add metadataLink (optional) */
snprintf(tag, sizeof(tag), "%s_description", name);
msOWSPrintEncodeMetadata(stdout, &(layer->metadata), "CO", tag, OWS_NOERR, " <description>%s</description>\n", NULL);
/* snprintf(tag, sizeof(tag), "%s_name", name); */
/* msOWSPrintEncodeMetadata(stdout, &(layer->metadata), "CO", tag, OWS_WARN, " <name>%s</name>\n", NULL); */
msIO_printf(" <name>%s</name>\n", name);
snprintf(tag, sizeof(tag), "%s_label", name);
msOWSPrintEncodeMetadata(stdout, &(layer->metadata), "CO", tag, OWS_WARN, " <label>%s</label>\n", NULL);
/* Values */
msIO_printf(" <values");
snprintf(tag, sizeof(tag), "%s_values_semantic", name); /* optional attributes follow (should escape?) */
msOWSPrintEncodeMetadata(stdout, &(layer->metadata), "CO", tag, OWS_NOERR, " semantic=\"%s\"", NULL);
snprintf(tag, sizeof(tag), "%s_values_type", name);
msOWSPrintEncodeMetadata(stdout, &(layer->metadata), "CO", tag, OWS_NOERR, " type=\"%s\"", NULL);
msIO_printf(">\n");
/* single values, we do not support optional type and semantic attributes */
snprintf(tag, sizeof(tag), "%s_values", name);
if(msOWSLookupMetadata(&(layer->metadata), "CO", tag))
msOWSPrintEncodeMetadataList(stdout, &(layer->metadata), "CO", tag, NULL, NULL, " <singleValue>%s</singleValue>\n", NULL);
/* intervals, only one per axis for now, we do not support optional type, atomic and semantic attributes */
snprintf(tag, sizeof(tag), "%s_interval", name);
if((value = msOWSLookupMetadata(&(layer->metadata), "CO", tag)) != NULL) {
char **tokens;
int numtokens;
tokens = msStringSplit(value, '/', &numtokens);
if(tokens && numtokens > 0) {
msIO_printf(" <interval>\n");
if(numtokens >= 1) msIO_printf(" <min>%s</min>\n", tokens[0]); /* TODO: handle closure */
if(numtokens >= 2) msIO_printf(" <max>%s</max>\n", tokens[1]);
if(numtokens >= 3) msIO_printf(" <res>%s</res>\n", tokens[2]);
msIO_printf(" </interval>\n");
}
}
/* TODO: add default (optional) */
msIO_printf(" </values>\n");
msIO_printf(" </AxisDescription>\n");
msIO_printf(" </axisDescription>\n");
return MS_SUCCESS;
}
/************************************************************************/
/* msWCSDescribeCoverage_CoverageOffering() */
/************************************************************************/
static int msWCSDescribeCoverage_CoverageOffering(layerObj *layer, wcsParamsObj *params)
{
char **tokens;
int numtokens;
const char *value;
coverageMetadataObj cm;
int i, status;
if ( msCheckParentPointer(layer->map,"map")==MS_FAILURE )
return MS_FAILURE;
if(!msWCSIsLayerSupported(layer)) return MS_SUCCESS; /* not an error, this layer cannot be served via WCS */
status = msWCSGetCoverageMetadata(layer, &cm);
if(status != MS_SUCCESS) return MS_FAILURE;
/* fill in bands rangeset info, if required. */
msWCSSetDefaultBandsRangeSetInfo( params, &cm, layer );
/* start the Coverage section */
msIO_printf(" <CoverageOffering>\n");
/* optional metadataLink */
msOWSPrintURLType(stdout, &(layer->metadata), "CO", "metadatalink",
OWS_NOERR,
" <metadataLink%s%s%s%s xlink:type=\"simple\"%s/>",
NULL, " metadataType=\"%s\"", NULL, NULL, NULL,
" xlink:href=\"%s\"", MS_FALSE, MS_FALSE, MS_FALSE,
MS_FALSE, MS_TRUE, "other", NULL, NULL, NULL, NULL, NULL);
msOWSPrintEncodeMetadata(stdout, &(layer->metadata), "CO", "description", OWS_NOERR, " <description>%s</description>\n", NULL);
msOWSPrintEncodeMetadata(stdout, &(layer->metadata), "CO", "name", OWS_NOERR, " <name>%s</name>\n", layer->name);
msOWSPrintEncodeMetadata(stdout, &(layer->metadata), "CO", "label", OWS_WARN, " <label>%s</label>\n", NULL);
/* TODO: add elevation ranges to lonLatEnvelope (optional) */
msIO_printf(" <lonLatEnvelope srsName=\"urn:ogc:def:crs:OGC:1.3:CRS84\">\n");
msIO_printf(" <gml:pos>%.15g %.15g</gml:pos>\n", cm.llextent.minx, cm.llextent.miny);
msIO_printf(" <gml:pos>%.15g %.15g</gml:pos>\n", cm.llextent.maxx, cm.llextent.maxy);
msOWSPrintEncodeMetadataList(stdout, &(layer->metadata), "CO", "timeposition", NULL, NULL, " <gml:timePosition>%s</gml:timePosition>\n", NULL);
msIO_printf(" </lonLatEnvelope>\n");
/* we are not supporting the optional keyword type, at least not yet */
msOWSPrintEncodeMetadataList(stdout, &(layer->metadata), "CO", "keywordlist", " <keywords>\n", " </keywords>\n", " <keyword>%s</keyword>\n", NULL);
/* DomainSet: starting simple, just a spatial domain (gml:envelope) and optionally a temporal domain */
msIO_printf(" <domainSet>\n");
/* SpatialDomain */
msIO_printf(" <spatialDomain>\n");
/* envelope in lat/lon */
msIO_printf(" <gml:Envelope srsName=\"EPSG:4326\">\n");
msIO_printf(" <gml:pos>%.15g %.15g</gml:pos>\n", cm.llextent.minx, cm.llextent.miny);
msIO_printf(" <gml:pos>%.15g %.15g</gml:pos>\n", cm.llextent.maxx, cm.llextent.maxy);
msIO_printf(" </gml:Envelope>\n");
/* envelope in the native srs */
if((value = msOWSGetEPSGProj(&(layer->projection), &(layer->metadata), "CO", MS_TRUE)) != NULL)
msIO_printf(" <gml:Envelope srsName=\"%s\">\n", value);
else if((value = msOWSGetEPSGProj(&(layer->map->projection), &(layer->map->web.metadata), "CO", MS_TRUE)) != NULL)
msIO_printf(" <gml:Envelope srsName=\"%s\">\n", value);
else
msIO_printf(" <!-- NativeCRSs ERROR: missing required information, no SRSs defined -->\n");
msIO_printf(" <gml:pos>%.15g %.15g</gml:pos>\n", cm.extent.minx, cm.extent.miny);
msIO_printf(" <gml:pos>%.15g %.15g</gml:pos>\n", cm.extent.maxx, cm.extent.maxy);
msIO_printf(" </gml:Envelope>\n");
/* gml:rectifiedGrid */
msIO_printf(" <gml:RectifiedGrid dimension=\"2\">\n");
msIO_printf(" <gml:limits>\n");
msIO_printf(" <gml:GridEnvelope>\n");
msIO_printf(" <gml:low>0 0</gml:low>\n");
msIO_printf(" <gml:high>%d %d</gml:high>\n", cm.xsize-1, cm.ysize-1);
msIO_printf(" </gml:GridEnvelope>\n");
msIO_printf(" </gml:limits>\n");
msIO_printf(" <gml:axisName>x</gml:axisName>\n");
msIO_printf(" <gml:axisName>y</gml:axisName>\n");
msIO_printf(" <gml:origin>\n");
msIO_printf(" <gml:pos>%.15g %.15g</gml:pos>\n", cm.geotransform[0], cm.geotransform[3]);
msIO_printf(" </gml:origin>\n");
msIO_printf(" <gml:offsetVector>%.15g %.15g</gml:offsetVector>\n", cm.geotransform[1], cm.geotransform[2]); /* offset vector in X direction */
msIO_printf(" <gml:offsetVector>%.15g %.15g</gml:offsetVector>\n", cm.geotransform[4], cm.geotransform[5]); /* offset vector in Y direction */
msIO_printf(" </gml:RectifiedGrid>\n");
msIO_printf(" </spatialDomain>\n");
/* TemporalDomain */
/* TODO: figure out when a temporal domain is valid, for example only tiled rasters support time as a domain, plus we need a timeitem */
if(msOWSLookupMetadata(&(layer->metadata), "CO", "timeposition") || msOWSLookupMetadata(&(layer->metadata), "CO", "timeperiod")) {
msIO_printf(" <temporalDomain>\n");
/* TimePosition (should support a value AUTO, then we could mine positions from the timeitem) */
msOWSPrintEncodeMetadataList(stdout, &(layer->metadata), "CO", "timeposition", NULL, NULL, " <gml:timePosition>%s</gml:timePosition>\n", NULL);
/* TODO: add TimePeriod (only one per layer) */
msIO_printf(" </temporalDomain>\n");
}
msIO_printf(" </domainSet>\n");
/* rangeSet */
msIO_printf(" <rangeSet>\n");
msIO_printf(" <RangeSet>\n"); /* TODO: there are some optional attributes */
/* TODO: add metadataLink (optional) */
msOWSPrintEncodeMetadata(stdout, &(layer->metadata), "CO", "rangeset_description", OWS_NOERR, " <description>%s</description>\n", NULL);
msOWSPrintEncodeMetadata(stdout, &(layer->metadata), "CO", "rangeset_name", OWS_WARN, " <name>%s</name>\n", NULL);
msOWSPrintEncodeMetadata(stdout, &(layer->metadata), "CO", "rangeset_label", OWS_WARN, " <label>%s</label>\n", NULL);
/* compound range sets */
if((value = msOWSLookupMetadata(&(layer->metadata), "CO", "rangeset_axes")) != NULL) {
tokens = msStringSplit(value, ',', &numtokens);
if(tokens && numtokens > 0) {
for(i=0; i<numtokens; i++)
msWCSDescribeCoverage_AxisDescription(layer, tokens[i]);
msFreeCharArray(tokens, numtokens);
}
}
if((value = msOWSLookupMetadata(&(layer->metadata), "CO", "rangeset_nullvalue")) != NULL) {
msIO_printf(" <nullValues>\n");
msIO_printf(" <singleValue>%s</singleValue>\n", value);
msIO_printf(" </nullValues>\n");
}
msIO_printf(" </RangeSet>\n");
msIO_printf(" </rangeSet>\n");
/* supportedCRSs */
msIO_printf(" <supportedCRSs>\n");
/* requestResposeCRSs: check the layer metadata/projection, and then the map metadata/projection if necessary (should never get to the error message) */
if((value = msOWSGetEPSGProj(&(layer->projection), &(layer->metadata), "CO", MS_FALSE)) != NULL) {
tokens = msStringSplit(value, ' ', &numtokens);
if(tokens && numtokens > 0) {
for(i=0; i<numtokens; i++)
msIO_printf(" <requestResponseCRSs>%s</requestResponseCRSs>\n", tokens[i]);
msFreeCharArray(tokens, numtokens);
}
} else if((value = msOWSGetEPSGProj(&(layer->map->projection), &(layer->map->web.metadata), "CO", MS_FALSE)) != NULL) {
tokens = msStringSplit(value, ' ', &numtokens);
if(tokens && numtokens > 0) {
for(i=0; i<numtokens; i++)
msIO_printf(" <requestResponseCRSs>%s</requestResponseCRSs>\n", tokens[i]);
msFreeCharArray(tokens, numtokens);
}
} else
msIO_printf(" <!-- requestResponseCRSs ERROR: missing required information, no SRSs defined -->\n");
/* nativeCRSs (only one in our case) */
if((value = msOWSGetEPSGProj(&(layer->projection), &(layer->metadata), "CO", MS_TRUE)) != NULL)
msIO_printf(" <nativeCRSs>%s</nativeCRSs>\n", value);
else if((value = msOWSGetEPSGProj(&(layer->map->projection), &(layer->map->web.metadata), "CO", MS_TRUE)) != NULL)
msIO_printf(" <nativeCRSs>%s</nativeCRSs>\n", value);
else
msIO_printf(" <!-- nativeCRSs ERROR: missing required information, no SRSs defined -->\n");
msIO_printf(" </supportedCRSs>\n");
/* supportedFormats */
msIO_printf(" <supportedFormats");
msOWSPrintEncodeMetadata(stdout, &(layer->metadata), "CO", "nativeformat", OWS_NOERR, " nativeFormat=\"%s\"", NULL);
msIO_printf(">\n");
if( (value = msOWSGetEncodeMetadata( &(layer->metadata), "CO", "formats",
"GTiff" )) != NULL ) {
tokens = msStringSplit(value, ' ', &numtokens);
if(tokens && numtokens > 0) {
for(i=0; i<numtokens; i++)
msIO_printf(" <formats>%s</formats>\n", tokens[i]);
msFreeCharArray(tokens, numtokens);
}
}
msIO_printf(" </supportedFormats>\n");
msIO_printf(" <supportedInterpolations default=\"nearest neighbor\">\n");
msIO_printf(" <interpolationMethod>nearest neighbor</interpolationMethod>\n" );
msIO_printf(" <interpolationMethod>bilinear</interpolationMethod>\n" );
/* msIO_printf(" <interpolationMethod>bicubic</interpolationMethod>\n" ); */
msIO_printf(" </supportedInterpolations>\n");
/* done */
msIO_printf(" </CoverageOffering>\n");
return MS_SUCCESS;
}
/************************************************************************/
/* msWCSDescribeCoverage() */
/************************************************************************/
static int msWCSDescribeCoverage(mapObj *map, wcsParamsObj *params, owsRequestObj *ows_request)
{
int i = 0,j = 0, k = 0;
const char *updatesequence=NULL;
char **coverages=NULL;
int numcoverages=0;
const char *encoding;
char *coverageName=NULL;
encoding = msOWSLookupMetadata(&(map->web.metadata), "CO", "encoding");
/* -------------------------------------------------------------------- */
/* 1.1.x is sufficiently different we have a whole case for */
/* it. The remainder of this function is for 1.0.0. */
/* -------------------------------------------------------------------- */
if( strncmp(params->version,"1.1",3) == 0 )
return msWCSDescribeCoverage11( map, params, ows_request);
/* -------------------------------------------------------------------- */
/* Process 1.0.0... */
/* -------------------------------------------------------------------- */
if(params->coverages) { /* use the list, but validate it first */
for(j=0; params->coverages[j]; j++) {
coverages = msStringSplit(params->coverages[j], ',', &numcoverages);
for(k=0; k<numcoverages; k++) {
for(i=0; i<map->numlayers; i++) {
coverageName = msOWSGetEncodeMetadata(&(GET_LAYER(map, i)->metadata), "CO", "name", GET_LAYER(map, i)->name);
if( EQUAL(coverageName, coverages[k]) &&
(msIntegerInArray(GET_LAYER(map, i)->index, ows_request->enabled_layers, ows_request->numlayers)) )
break;
}
/* i = msGetLayerIndex(map, coverages[k]); */
if(i == map->numlayers) { /* coverage not found */
msSetError( MS_WCSERR, "COVERAGE %s cannot be opened / does not exist", "msWCSDescribeCoverage()", coverages[k]);
return msWCSException(map, "CoverageNotDefined", "coverage", params->version );
}
} /* next coverage */
}
}
updatesequence = msOWSLookupMetadata(&(map->web.metadata), "CO", "updatesequence");
if (!updatesequence)
updatesequence = msStrdup("0");
/* printf("Content-type: application/vnd.ogc.se_xml%c%c",10,10); */
if (encoding)
msIO_printf("Content-type: text/xml; charset=%s%c%c", encoding,10,10);
else
msIO_printf("Content-type: text/xml%c%c",10,10);
/* print common capability elements */
msOWSPrintEncodeMetadata(stdout, &(map->web.metadata), NULL, "wcs_encoding", OWS_NOERR, "<?xml version='1.0' encoding=\"%s\" ?>\n", "ISO-8859-1");
/* start the DescribeCoverage section */
msIO_printf("<CoverageDescription\n"
" version=\"%s\" \n"
" updateSequence=\"%s\" \n"
" xmlns=\"http://www.opengis.net/wcs\" \n"
" xmlns:xlink=\"http://www.w3.org/1999/xlink\" \n"
" xmlns:gml=\"http://www.opengis.net/gml\" \n"
" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\"\n"
" xsi:schemaLocation=\"http://www.opengis.net/wcs %s/wcs/%s/describeCoverage.xsd\">\n", params->version, updatesequence, msOWSGetSchemasLocation(map), params->version);
if(params->coverages) { /* use the list */
for( j = 0; params->coverages[j]; j++ ) {
coverages = msStringSplit(params->coverages[j], ',', &numcoverages);
for(k=0;k<numcoverages;k++) {
for(i=0; i<map->numlayers; i++) {
coverageName = msOWSGetEncodeMetadata(&(GET_LAYER(map, i)->metadata), "CO", "name", GET_LAYER(map, i)->name);
if( EQUAL(coverageName, coverages[k]) ) break;
}
msWCSDescribeCoverage_CoverageOffering((GET_LAYER(map, i)), params);
}
}
} else { /* return all layers */
for(i=0; i<map->numlayers; i++) {
if (!msIntegerInArray(GET_LAYER(map, i)->index, ows_request->enabled_layers, ows_request->numlayers))
continue;
msWCSDescribeCoverage_CoverageOffering((GET_LAYER(map, i)), params);
}
}
/* done */
msIO_printf("</CoverageDescription>\n");
return MS_SUCCESS;
}
/************************************************************************/
/* msWCSGetCoverageBands10() */
/************************************************************************/
static int msWCSGetCoverageBands10( mapObj *map, cgiRequestObj *request,
wcsParamsObj *params, layerObj *lp,
char **p_bandlist )
{
const char *value = NULL;
int i;
/* Are there any non-spatio/temporal ranges to do subsetting on (e.g. bands) */
value = msOWSLookupMetadata(&(lp->metadata), "CO", "rangeset_axes"); /* this will get all the compound range sets */
if(value) {
char **tokens;
int numtokens;
char tag[100];
const char *rangeitem;
tokens = msStringSplit(value, ',', &numtokens);
for(i=0; i<numtokens; i++) {
if((value = msWCSGetRequestParameter(request, tokens[i])) == NULL) continue; /* next rangeset parameter */
/* ok, a parameter has been passed which matches a token in wcs_rangeset_axes */
if(msWCSValidateRangeSetParam(lp, tokens[i], value) != MS_SUCCESS) {
msSetError( MS_WCSERR, "Error specifying \"%s\" parameter value(s).", "msWCSGetCoverage()", tokens[i]);
return msWCSException(map, "InvalidParameterValue", tokens[i], params->version );
}
/* xxxxx_rangeitem tells us how to subset */
snprintf(tag, sizeof(tag), "%s_rangeitem", tokens[i]);
if((rangeitem = msOWSLookupMetadata(&(lp->metadata), "CO", tag)) == NULL) {
msSetError( MS_WCSERR, "Missing required metadata element \"%s\", unable to process %s=%s.", "msWCSGetCoverage()", tag, tokens[i], value);
return msWCSException(map, NULL, NULL, params->version);
}
if(strcasecmp(rangeitem, "_bands") == 0) { /* special case, subset bands */
*p_bandlist = msWCSConvertRangeSetToString(value);
if(!*p_bandlist) {
msSetError( MS_WCSERR, "Error specifying \"%s\" parameter value(s).", "msWCSGetCoverage()", tokens[i]);
return msWCSException(map, NULL, NULL, params->version );
}
} else if(strcasecmp(rangeitem, "_pixels") == 0) { /* special case, subset pixels */
msSetError( MS_WCSERR, "Arbitrary range sets based on pixel values are not yet supported.", "msWCSGetCoverage()" );
return msWCSException(map, NULL, NULL, params->version);
} else {
msSetError( MS_WCSERR, "Arbitrary range sets based on tile (i.e. image) attributes are not yet supported.", "msWCSGetCoverage()" );
return msWCSException(map, NULL, NULL, params->version );
}
}
/* clean-up */
msFreeCharArray(tokens, numtokens);
}
return MS_SUCCESS;
}
/************************************************************************/
/* msWCSGetCoverage_ImageCRSSetup() */
/* */
/* The request was in imageCRS - update the map projection to */
/* map the native projection of the layer, and reset the */
/* bounding box to match the projected bounds corresponding to */
/* the imageCRS request. */
/************************************************************************/
static int msWCSGetCoverage_ImageCRSSetup(
mapObj *map, cgiRequestObj *request, wcsParamsObj *params,
coverageMetadataObj *cm, layerObj *layer )
{
/* -------------------------------------------------------------------- */
/* Load map with the layer (coverage) coordinate system. We */
/* really need a set projectionObj from projectionObj function! */
/* -------------------------------------------------------------------- */
char *layer_proj = msGetProjectionString( &(layer->projection) );
if (msLoadProjectionString(&(map->projection), layer_proj) != 0)
return msWCSException( map, NULL, NULL, params->version );
free( layer_proj );
layer_proj = NULL;
/* -------------------------------------------------------------------- */
/* Reset bounding box. */
/* -------------------------------------------------------------------- */
if( params->bbox.maxx != params->bbox.minx )
{
rectObj orig_bbox = params->bbox;
params->bbox.minx =
cm->geotransform[0]
+ orig_bbox.minx * cm->geotransform[1]
+ orig_bbox.miny * cm->geotransform[2];
params->bbox.maxy =
cm->geotransform[3]
+ orig_bbox.minx * cm->geotransform[4]
+ orig_bbox.miny * cm->geotransform[5];
params->bbox.maxx =
cm->geotransform[0]
+ (orig_bbox.maxx+1) * cm->geotransform[1]
+ (orig_bbox.maxy+1) * cm->geotransform[2];
params->bbox.miny =
cm->geotransform[3]
+ (orig_bbox.maxx+1) * cm->geotransform[4]
+ (orig_bbox.maxy+1) * cm->geotransform[5];
/* WCS 1.1 boundbox is center of pixel oriented. */
if( strncasecmp(params->version,"1.1",3) == 0 )
{
params->bbox.minx += cm->geotransform[1]/2 + cm->geotransform[2]/2;
params->bbox.maxx -= cm->geotransform[1]/2 + cm->geotransform[2]/2;
params->bbox.maxy += cm->geotransform[4]/2 + cm->geotransform[5]/2;
params->bbox.miny -= cm->geotransform[4]/2 + cm->geotransform[5]/2;
}
}
/* -------------------------------------------------------------------- */
/* Reset resolution. */
/* -------------------------------------------------------------------- */
if( params->resx != 0.0 )
{
params->resx = cm->geotransform[1] * params->resx;
params->resy = fabs(cm->geotransform[5] * params->resy);
}
return MS_SUCCESS;
}
/************************************************************************/
/* msWCSGetCoverage() */
/************************************************************************/
static int msWCSGetCoverage(mapObj *map, cgiRequestObj *request,
wcsParamsObj *params, owsRequestObj *ows_request)
{
imageObj *image;
layerObj *lp;
int status, i;
const char *value;
outputFormatObj *format;
char *bandlist=NULL;
size_t bufferSize = 0;
char numbands[8]; /* should be large enough to hold the number of bands in the bandlist */
coverageMetadataObj cm;
rectObj reqextent;
rectObj covextent;
rasterBufferObj rb;
char *coverageName;
/* make sure all required parameters are available (at least the easy ones) */
if(!params->crs) {
msSetError( MS_WCSERR, "Required parameter CRS was not supplied.", "msWCSGetCoverage()");
return msWCSException(map, "MissingParameterValue", "crs", params->version);
}
if(!params->time && !params->bbox.minx && !params->bbox.miny
&& !params->bbox.maxx && !params->bbox.maxy) {
msSetError(MS_WCSERR, "One of BBOX or TIME is required", "msWCSGetCoverage()");
return msWCSException(map, "MissingParameterValue", "bbox/time", params->version);
}
if( params->coverages == NULL || params->coverages[0] == NULL ) {
msSetError( MS_WCSERR,
"Required parameter COVERAGE was not supplied.",
"msWCSGetCoverage()");
return msWCSException(map, "MissingParameterValue", "coverage", params->version);
}
/* For WCS 1.1, we need to normalize the axis order of the BBOX and
resolution values some coordinate systems (eg. EPSG geographic) */
if( strncasecmp(params->version,"1.0",3) != 0
&& params->crs != NULL
&& strncasecmp(params->crs,"urn:",4) == 0 )
{
projectionObj proj;
msInitProjection( &proj );
if( msLoadProjectionString( &proj, (char *) params->crs ) == 0 )
{
msAxisNormalizePoints( &proj, 1,
&(params->bbox.minx),
&(params->bbox.miny) );
msAxisNormalizePoints( &proj, 1,
&(params->bbox.maxx),
&(params->bbox.maxy) );
msAxisNormalizePoints( &proj, 1,
&(params->resx),
&(params->resy) );
msAxisNormalizePoints( &proj, 1,
&(params->originx),
&(params->originy) );
}
else
msResetErrorList();
msFreeProjection( &proj );
}
/* find the layer we are working with */
lp = NULL;
for(i=0; i<map->numlayers; i++) {
coverageName = msOWSGetEncodeMetadata(&(GET_LAYER(map, i)->metadata), "CO", "name", GET_LAYER(map, i)->name);
if( EQUAL(coverageName, params->coverages[0]) &&
(msIntegerInArray(GET_LAYER(map, i)->index, ows_request->enabled_layers, ows_request->numlayers)) ) {
lp = GET_LAYER(map, i);
break;
}
}
if(lp == NULL) {
msSetError( MS_WCSERR, "COVERAGE=%s not found, not in supported layer list.", "msWCSGetCoverage()", params->coverages[0] );
return msWCSException(map, "InvalidParameterValue", "coverage", params->version);
}
/* make sure the layer is on */
lp->status = MS_ON;
/* we need the coverage metadata, since things like numbands may not be available otherwise */
status = msWCSGetCoverageMetadata(lp, &cm);
if(status != MS_SUCCESS) return MS_FAILURE;
/* fill in bands rangeset info, if required. */
msWCSSetDefaultBandsRangeSetInfo(params, &cm, lp);
/* handle the response CRS, that is, set the map object projection */
if(params->response_crs || params->crs ) {
int iUnits;
const char *crs_to_use = params->response_crs;
if( crs_to_use == NULL )
crs_to_use = params->crs;
if (strncasecmp(crs_to_use, "EPSG:", 5) == 0 || strncasecmp(crs_to_use,"urn:ogc:def:crs:",16) == 0 ) {
if (msLoadProjectionString(&(map->projection), (char *) crs_to_use) != 0)
return msWCSException( map, NULL, NULL,params->version);
} else if( strcasecmp(crs_to_use,"imageCRS") == 0 ) {
/* use layer native CRS, and rework bounding box accordingly */
if( msWCSGetCoverage_ImageCRSSetup( map, request, params, &cm, lp ) != MS_SUCCESS )
return MS_FAILURE;
} else { /* should we support WMS style AUTO: projections? (not for now) */
msSetError(MS_WCSERR, "Unsupported SRS namespace (only EPSG currently supported).", "msWCSGetCoverage()");
return msWCSException(map, "InvalidParameterValue", "srs", params->version);
}
iUnits = GetMapserverUnitUsingProj(&(map->projection));
if (iUnits != -1)
map->units = iUnits;
}
/* did we get a TIME value (support only a single value for now) */
if(params->time) {
int tli;
layerObj *tlp=NULL;
/* need to handle NOW case */
/* check format of TIME parameter */
if(strchr(params->time, ',')) {
msSetError( MS_WCSERR, "Temporal lists are not supported, only individual values.", "msWCSGetCoverage()" );
return msWCSException(map, "InvalidParameterValue", "time", params->version);
}
if(strchr(params->time, '/')) {
msSetError( MS_WCSERR, "Temporal ranges are not supported, only individual values.", "msWCSGetCoverage()" );
return msWCSException(map, "InvalidParameterValue", "time", params->version);
}
/* TODO: will need to expand this check if a time period is supported */
value = msOWSLookupMetadata(&(lp->metadata), "CO", "timeposition");
if(!value) {
msSetError( MS_WCSERR, "The coverage does not support temporal subsetting.", "msWCSGetCoverage()" );
return msWCSException(map, "InvalidParameterValue", "time", params->version );
}
/* check if timestamp is covered by the wcs_timeposition definition */
if (msValidateTimeValue(params->time, value) == MS_FALSE) {
msSetError( MS_WCSERR, "The coverage does not have a time position of %s.", "msWCSGetCoverage()", params->time );
return msWCSException(map, "InvalidParameterValue", "time", params->version);
}
/* make sure layer is tiled appropriately */
if(!lp->tileindex) {
msSetError( MS_WCSERR, "Underlying layer is not tiled, unable to do temporal subsetting.", "msWCSGetCoverage()" );
return msWCSException(map, NULL, NULL, params->version);
}
tli = msGetLayerIndex(map, lp->tileindex);
if(tli == -1) {
msSetError( MS_WCSERR, "Underlying layer does not use appropriate tiling mechanism.", "msWCSGetCoverage()" );
return msWCSException(map, NULL, NULL, params->version);
}
tlp = (GET_LAYER(map, tli));
/* make sure there is enough information to filter */
value = msOWSLookupMetadata(&(lp->metadata), "CO", "timeitem");
if(!tlp->filteritem && !value) {
msSetError( MS_WCSERR, "Not enough information available to filter.", "msWCSGetCoverage()" );
return msWCSException(map, NULL, NULL, params->version);
}
/* override filteritem if specified in metadata */
if(value) {
if(tlp->filteritem) free(tlp->filteritem);
tlp->filteritem = msStrdup(value);
}
/* finally set the filter */
freeExpression(&tlp->filter);
msLayerSetTimeFilter(tlp, params->time, value);
}
if( strncasecmp(params->version,"1.0",3) == 0 )
status = msWCSGetCoverageBands10( map, request, params, lp, &bandlist );
else
status = msWCSGetCoverageBands11( map, request, params, lp, &bandlist );
if( status != MS_SUCCESS )
return status;
/* did we get BBOX values? if not use the exent stored in the coverageMetadataObj */
if( fabs((params->bbox.maxx - params->bbox.minx)) < 0.000000000001 || fabs(params->bbox.maxy - params->bbox.miny) < 0.000000000001 ) {
params->bbox = cm.extent;
/* WCS 1.1 boundbox is center of pixel oriented. */
if( strncasecmp(params->version,"1.1",3) == 0 ) {
params->bbox.minx += cm.geotransform[1]/2 + cm.geotransform[2]/2;
params->bbox.maxx -= cm.geotransform[1]/2 + cm.geotransform[2]/2;
params->bbox.maxy += cm.geotransform[4]/2 + cm.geotransform[5]/2;
params->bbox.miny -= cm.geotransform[4]/2 + cm.geotransform[5]/2;
}
}
/* WCS 1.1+ GridOrigin is effectively resetting the minx/maxy
BOUNDINGBOX values, so apply that here */
if( params->originx != 0.0 || params->originy != 0.0 ) {
assert( strncasecmp(params->version,"1.0",3) != 0 ); /* should always be 1.0 in this logic. */
params->bbox.minx = params->originx;
params->bbox.maxy = params->originy;
}
/* if necessary, project the BBOX to the map->projection */
if(params->response_crs && params->crs) {
projectionObj tmp_proj;
msInitProjection(&tmp_proj);
if (msLoadProjectionString(&tmp_proj, (char *) params->crs) != 0)
return msWCSException( map, NULL, NULL, params->version);
msProjectRect(&tmp_proj, &map->projection, &(params->bbox));
msFreeProjection(&tmp_proj);
}
/* in WCS 1.1 the default is full resolution */
if( strncasecmp(params->version,"1.1",3) == 0 && params->resx == 0.0 && params->resy == 0.0 ) {
params->resx = cm.geotransform[1];
params->resy = fabs(cm.geotransform[5]);
}
/* compute width/height from BBOX and cellsize. */
if( (params->resx == 0.0 || params->resy == 0.0) && params->width != 0 && params->height != 0 ) {
assert( strncasecmp(params->version,"1.0",3) == 0 ); /* should always be 1.0 in this logic. */
params->resx = (params->bbox.maxx -params->bbox.minx) / params->width;
params->resy = (params->bbox.maxy -params->bbox.miny) / params->height;
}
/* compute cellsize/res from bbox and raster size. */
if( (params->width == 0 || params->height == 0) && params->resx != 0 && params->resy != 0 ) {
/* WCS 1.0 boundbox is edge of pixel oriented. */
if( strncasecmp(params->version,"1.0",3) == 0 ) {
params->width = (int) ((params->bbox.maxx - params->bbox.minx) / params->resx + 0.5);
params->height = (int) ((params->bbox.maxy - params->bbox.miny) / params->resy + 0.5);
} else {
params->width = (int) ((params->bbox.maxx - params->bbox.minx) / params->resx + 1.000001);
params->height = (int) ((params->bbox.maxy - params->bbox.miny) / params->resy + 1.000001);
/* recompute bounding box so we get exactly the origin and
resolution requested. */
params->bbox.maxx = params->bbox.minx + (params->width-1) * params->resx;
params->bbox.miny = params->bbox.maxy - (params->height-1) * params->resy;
}
}
/* are we still underspecified? */
if( (params->width == 0 || params->height == 0) && (params->resx == 0.0 || params->resy == 0.0 )) {
msSetError( MS_WCSERR, "A non-zero RESX/RESY or WIDTH/HEIGHT is required but neither was provided.", "msWCSGetCoverage()" );
return msWCSException(map, "MissingParameterValue", "width/height/resx/resy", params->version);
}
map->cellsize = params->resx;
/* Do we need to force special handling? */
if( fabs(params->resx/params->resy - 1.0) > 0.001 ) {
map->gt.need_geotransform = MS_TRUE;
if( map->debug ) msDebug( "RESX and RESY don't match. Using geotransform/resample.\n");
}
/* Do we have a specified interpolation method */
if( params->interpolation != NULL ) {
if( strncasecmp(params->interpolation,"NEAREST",7) == 0 )
msLayerSetProcessingKey(lp, "RESAMPLE", "NEAREST");
else if( strcasecmp(params->interpolation,"BILINEAR") == 0 )
msLayerSetProcessingKey(lp, "RESAMPLE", "BILINEAR");
else if( strcasecmp(params->interpolation,"AVERAGE") == 0 )
msLayerSetProcessingKey(lp, "RESAMPLE", "AVERAGE");
else {
msSetError( MS_WCSERR, "INTERPOLATION=%s specifies an unsupported interpolation method.", "msWCSGetCoverage()", params->interpolation );
return msWCSException(map, "InvalidParameterValue", "interpolation", params->version);
}
}
/* apply region and size to map object. */
map->width = params->width;
map->height = params->height;
/* Are we exceeding the MAXSIZE limit on result size? */
if(map->width > map->maxsize || map->height > map->maxsize )
{
msSetError(MS_WCSERR, "Raster size out of range, width and height of resulting coverage must be no more than MAXSIZE=%d.", "msWCSGetCoverage()", map->maxsize);
return msWCSException(map, "InvalidParameterValue",
"width/height", params->version);
}
/* adjust OWS BBOX to MapServer's pixel model */
if( strncasecmp(params->version,"1.0",3) == 0 ) {
params->bbox.minx += params->resx*0.5;
params->bbox.miny += params->resy*0.5;
params->bbox.maxx -= params->resx*0.5;
params->bbox.maxy -= params->resy*0.5;
}
map->extent = params->bbox;
map->cellsize = params->resx; /* pick one, MapServer only supports square cells (what about msAdjustExtent here!) */
msMapComputeGeotransform(map);
/* Do we need to fake out stuff for rotated support? */
if( map->gt.need_geotransform )
msMapSetFakedExtent( map );
map->projection.gt = map->gt;
/* check for overlap */
/* get extent of bbox passed, and reproject */
reqextent.minx = map->extent.minx;
reqextent.miny = map->extent.miny;
reqextent.maxx = map->extent.maxx;
reqextent.maxy = map->extent.maxy;
/* reproject incoming bbox */
msProjectRect(&map->projection, &lp->projection, &(reqextent));
/* get extent of layer */
covextent.minx = cm.extent.minx;
covextent.miny = cm.extent.miny;
covextent.maxx = cm.extent.maxx;
covextent.maxy = cm.extent.maxy;
if(msRectOverlap(&reqextent, &covextent) == MS_FALSE) {
msSetError(MS_WCSERR, "Requested BBOX (%.15g,%.15g,%.15g,%.15g) is outside requested coverage BBOX (%.15g,%.15g,%.15g,%.15g)",
"msWCSGetCoverage()",
reqextent.minx, reqextent.miny, reqextent.maxx, reqextent.maxy,
covextent.minx, covextent.miny, covextent.maxx, covextent.maxy);
return msWCSException(map, "NoApplicableCode", "bbox", params->version);
}
/* check and make sure there is a format, and that it's valid (TODO: make sure in the layer metadata) */
if(!params->format) {
msSetError( MS_WCSERR, "Missing required FORMAT parameter.", "msWCSGetCoverage()" );
return msWCSException(map, "MissingParameterValue", "format", params->version);
}
msApplyDefaultOutputFormats(map);
if(msGetOutputFormatIndex(map,params->format) == -1) {
msSetError( MS_WCSERR, "Unrecognized value for the FORMAT parameter.", "msWCSGetCoverage()" );
return msWCSException(map, "InvalidParameterValue", "format",
params->version );
}
/* create a temporary outputformat (we likely will need to tweak parts) */
format = msCloneOutputFormat(msSelectOutputFormat(map,params->format));
msApplyOutputFormat(&(map->outputformat), format, MS_NOOVERRIDE, MS_NOOVERRIDE, MS_NOOVERRIDE);
if(!bandlist) { /* build a bandlist (default is ALL bands) */
bufferSize = cm.bandcount*30+30;
bandlist = (char *) msSmallMalloc(bufferSize);
strcpy(bandlist, "1");
for(i = 1; i < cm.bandcount; i++)
snprintf(bandlist+strlen(bandlist), bufferSize-strlen(bandlist), ",%d", i+1);
}
/* apply nullvalue to the output format object if we have it */
if((value = msOWSLookupMetadata(&(lp->metadata), "CO", "rangeset_nullvalue")) != NULL) {
msSetOutputFormatOption( map->outputformat, "NULLVALUE", value );
}
msLayerSetProcessingKey(lp, "BANDS", bandlist);
snprintf(numbands, sizeof(numbands), "%d", msCountChars(bandlist, ',')+1);
msSetOutputFormatOption(map->outputformat, "BAND_COUNT", numbands);
/* create the image object */
if(!map->outputformat) {
msSetError(MS_WCSERR, "The map outputformat is missing!", "msWCSGetCoverage()");
return msWCSException(map, NULL, NULL, params->version );
} else if( MS_RENDERER_RAWDATA(map->outputformat) || MS_RENDERER_PLUGIN(map->outputformat) ) {
image = msImageCreate(map->width, map->height, map->outputformat, map->web.imagepath, map->web.imageurl, map->resolution, map->defresolution, NULL);
} else {
msSetError(MS_WCSERR, "Map outputformat not supported for WCS!", "msWCSGetCoverage()");
return msWCSException(map, NULL, NULL, params->version );
}
if( image == NULL )
return msWCSException(map, NULL, NULL, params->version );
if( MS_RENDERER_RAWDATA(map->outputformat) ) {
status = msDrawRasterLayerLow( map, lp, image, NULL );
} else {
MS_IMAGE_RENDERER(image)->getRasterBufferHandle(image,&rb);
/* Actually produce the "grid". */
status = msDrawRasterLayerLow( map, lp, image, &rb );
}
if( status != MS_SUCCESS ) {
return msWCSException(map, NULL, NULL, params->version );
}
if( strncmp(params->version, "1.1",3) == 0 )
{
msWCSReturnCoverage11( params, map, image );
}
else /* WCS 1.0.0 - just return the binary data with a content type */
{
const char *fo_filename;
/* Do we have a predefined filename? */
fo_filename = msGetOutputFormatOption( format, "FILENAME", NULL );
if( fo_filename )
msIO_fprintf( stdout,
"Content-Disposition: attachment; filename=%s\n",
fo_filename );
/* Emit back to client. */
msIO_printf("Content-type: %s%c%c",
MS_IMAGE_MIME_TYPE(map->outputformat), 10,10);
status = msSaveImage(map, image, NULL);
if( status != MS_SUCCESS )
{
/* unfortunately, the image content type will have already been sent
but that is hard for us to avoid. The main error that could happen
here is a misconfigured tmp directory or running out of space. */
return msWCSException(map, NULL, NULL, params->version );
}
}
/* Cleanup */
msFreeImage(image);
msApplyOutputFormat(&(map->outputformat), NULL, MS_NOOVERRIDE, MS_NOOVERRIDE, MS_NOOVERRIDE);
/* msFreeOutputFormat(format); */
return status;
}
#endif /* def USE_WCS_SVR */
/************************************************************************/
/* msWCSDispatch() */
/* */
/* Entry point for WCS requests */
/************************************************************************/
int msWCSDispatch(mapObj *map, cgiRequestObj *request, owsRequestObj *ows_request)
{
#ifdef USE_WCS_SVR
wcsParamsObj *params;
int retVal = MS_DONE;
/* First try to dispatch WCS 2.0.0. */
/* TODO: Need to implement proper version negotiation (OWS Common) */
/* once WCS 2.0.0 is fully specified. */
/* Currently WCS 2.0.0 is only available if explicitly requested. */
if ((retVal = msWCSDispatch20(map, request, ows_request)) != MS_DONE )
{
return retVal;
}
/* populate the service parameters */
params = msWCSCreateParams();
if( msWCSParseRequest(request, params, map) == MS_FAILURE )
{
msWCSFreeParams(params); /* clean up */
free(params);
return MS_FAILURE;
}
/* If SERVICE is specified then it MUST be "WCS" */
if(params->service && strcasecmp(params->service, "WCS") != 0)
{
msWCSFreeParams(params); /* clean up */
free(params);
msDebug("msWCSDispatch(): SERVICE is not WCS\n");
return MS_DONE;
}
/* If SERVICE and REQUEST not included then not a WCS request */
if(!params->service && !params->request)
{
msWCSFreeParams(params); /* clean up */
free(params);
msDebug("msWCSDispatch(): SERVICE and REQUEST not included\n");
return MS_DONE;
}
msOWSRequestLayersEnabled(map, "C", params->request, ows_request);
if (ows_request->numlayers == 0)
{
msSetError(MS_WCSERR, "WCS request not enabled. Check wcs/ows_enable_request settings.", "msWCSDispatch()");
msWCSException(map, "InvalidParameterValue", "request",
params->version );
msWCSFreeParams(params); /* clean up */
free(params);
params = NULL;
return MS_FAILURE;
}
/*
** ok, it's a WCS request, check what we can at a global level and then dispatch to the various request handlers
*/
/* check for existence of REQUEST parameter */
if (!params->request) {
msSetError(MS_WCSERR, "Missing REQUEST parameter", "msWCSDispatch()");
msWCSException(map, "MissingParameterValue", "request",
params->version );
msWCSFreeParams(params); /* clean up */
free(params);
params = NULL;
return MS_FAILURE;
}
/* if either DescribeCoverage or GetCoverage, and version not passed
then return an exception */
if (((strcasecmp(params->request, "DescribeCoverage") == 0) ||
(strcasecmp(params->request, "GetCoverage") == 0)) &&
(!params->version)) {
msSetError(MS_WCSERR, "Missing VERSION parameter", "msWCSDispatch()");
msWCSException(map, "MissingParameterValue", "version", params->version);
msWCSFreeParams(params); /* clean up */
free(params);
params = NULL;
return MS_FAILURE;
}
/* For GetCapabilities, if version is not set, then set to the highest
version supported. This should be cleaned up once #996 gets implemented */
if (!params->version || strcasecmp(params->version, "") == 0 || params->version == NULL) { /* this is a GetCapabilities request, set version */
params->version = msStrdup("1.1.2");
}
/* version is optional, but we do set a default value of 1.1.2, make sure request isn't for something different */
if((strcmp(params->version, "1.0.0") != 0
&& strcmp(params->version, "1.1.0") != 0
&& strcmp(params->version, "1.1.1") != 0
&& strcmp(params->version, "1.1.2") != 0)
&& strcasecmp(params->request, "GetCapabilities") != 0) {
msSetError(MS_WCSERR, "WCS Server does not support VERSION %s.", "msWCSDispatch()", params->version);
msWCSException(map, "InvalidParameterValue", "version", params->version);
msWCSFreeParams(params); /* clean up */
free(params);
params = NULL;
return MS_FAILURE;
}
/*
** Start dispatching requests
*/
if(strcasecmp(params->request, "GetCapabilities") == 0)
retVal = msWCSGetCapabilities(map, params, request, ows_request);
else if(strcasecmp(params->request, "DescribeCoverage") == 0)
retVal = msWCSDescribeCoverage(map, params, ows_request);
else if(strcasecmp(params->request, "GetCoverage") == 0)
retVal = msWCSGetCoverage(map, request, params, ows_request);
else {
msSetError(MS_WCSERR, "Invalid REQUEST parameter \"%s\"", "msWCSDispatch()", params->request);
msWCSException(map, "InvalidParameterValue", "request", params->version);
msWCSFreeParams(params); /* clean up */
free(params);
params = NULL;
return MS_FAILURE;
}
msWCSFreeParams(params); /* clean up */
free(params);
return retVal; /* not a WCS request, let MapServer take it */
#else
msSetError(MS_WCSERR, "WCS server support is not available.", "msWCSDispatch()");
return MS_FAILURE;
#endif
}
/************************************************************************/
/* msWCSGetCoverageMetadata() */
/************************************************************************/
#ifdef USE_WCS_SVR
int msWCSGetCoverageMetadata( layerObj *layer, coverageMetadataObj *cm )
{
char *srs_urn = NULL;
int i = 0;
if ( msCheckParentPointer(layer->map,"map")==MS_FAILURE )
return MS_FAILURE;
/* -------------------------------------------------------------------- */
/* Get the SRS in WCS 1.0 format (eg. EPSG:n) */
/* -------------------------------------------------------------------- */
if((cm->srs = msOWSGetEPSGProj(&(layer->projection), &(layer->metadata), "CO", MS_TRUE)) == NULL) {
if((cm->srs = msOWSGetEPSGProj(&(layer->map->projection), &(layer->map->web.metadata), "CO", MS_TRUE)) == NULL) {
msSetError(MS_WCSERR, "Unable to determine the SRS for this layer, no projection defined and no metadata available.", "msWCSGetCoverageMetadata()");
return MS_FAILURE;
}
}
/* -------------------------------------------------------------------- */
/* Get the SRS in urn format. */
/* -------------------------------------------------------------------- */
if((srs_urn = msOWSGetProjURN(&(layer->projection), &(layer->metadata),
"CO", MS_TRUE)) == NULL) {
srs_urn = msOWSGetProjURN(&(layer->map->projection),
&(layer->map->web.metadata),
"CO", MS_TRUE);
}
if( srs_urn != NULL )
{
if( strlen(srs_urn) > sizeof(cm->srs_urn) - 1 )
{
msSetError(MS_WCSERR, "SRS URN too long!",
"msWCSGetCoverageMetadata()");
return MS_FAILURE;
}
strcpy( cm->srs_urn, srs_urn );
msFree( srs_urn );
}
else
cm->srs_urn[0] = '\0';
/* -------------------------------------------------------------------- */
/* If we have "virtual dataset" metadata on the layer, then use */
/* that in preference to inspecting the file(s). */
/* We require extent and either size or resolution. */
/* -------------------------------------------------------------------- */
if( msOWSLookupMetadata(&(layer->metadata), "CO", "extent") != NULL
&& (msOWSLookupMetadata(&(layer->metadata), "CO", "resolution") != NULL
|| msOWSLookupMetadata(&(layer->metadata), "CO", "size") != NULL) ){
const char *value;
/* get extent */
cm->extent.minx = 0.0;
cm->extent.maxx = 0.0;
cm->extent.miny = 0.0;
cm->extent.maxy = 0.0;
if( msOWSGetLayerExtent( layer->map, layer, "CO", &cm->extent ) == MS_FAILURE )
return MS_FAILURE;
/* get resolution */
cm->xresolution = 0.0;
cm->yresolution = 0.0;
if( (value = msOWSLookupMetadata(&(layer->metadata), "CO", "resolution")) != NULL ) {
char **tokens;
int n;
tokens = msStringSplit(value, ' ', &n);
if( tokens == NULL || n != 2 ) {
msSetError( MS_WCSERR, "Wrong number of arguments for wcs|ows_resolution metadata.", "msWCSGetCoverageMetadata()");
msFreeCharArray( tokens, n );
return MS_FAILURE;
}
cm->xresolution = atof(tokens[0]);
cm->yresolution = atof(tokens[1]);
msFreeCharArray( tokens, n );
}
/* get Size (in pixels and lines) */
cm->xsize = 0;
cm->ysize = 0;
if( (value=msOWSLookupMetadata(&(layer->metadata), "CO", "size")) != NULL ) {
char **tokens;
int n;
tokens = msStringSplit(value, ' ', &n);
if( tokens == NULL || n != 2 ) {
msSetError( MS_WCSERR, "Wrong number of arguments for wcs|ows_size metadata.", "msWCSGetCoverageDomain()");
msFreeCharArray( tokens, n );
return MS_FAILURE;
}
cm->xsize = atoi(tokens[0]);
cm->ysize = atoi(tokens[1]);
msFreeCharArray( tokens, n );
}
/* try to compute raster size */
if( cm->xsize == 0 && cm->ysize == 0 && cm->xresolution != 0.0 && cm->yresolution != 0.0 && cm->extent.minx != cm->extent.maxx && cm->extent.miny != cm->extent.maxy ) {
cm->xsize = (int) ((cm->extent.maxx - cm->extent.minx) / cm->xresolution + 0.5);
cm->ysize = (int) fabs((cm->extent.maxy - cm->extent.miny) / cm->yresolution + 0.5);
}
/* try to compute raster resolution */
if( (cm->xresolution == 0.0 || cm->yresolution == 0.0) && cm->xsize != 0 && cm->ysize != 0 ) {
cm->xresolution = (cm->extent.maxx - cm->extent.minx) / cm->xsize;
cm->yresolution = (cm->extent.maxy - cm->extent.miny) / cm->ysize;
}
/* do we have information to do anything */
if( cm->xresolution == 0.0 || cm->yresolution == 0.0 || cm->xsize == 0 || cm->ysize == 0 ) {
msSetError( MS_WCSERR, "Failed to collect extent and resolution for WCS coverage from metadata for layer '%s'. Need value wcs|ows_resolution or wcs|ows_size values.", "msWCSGetCoverageMetadata()", layer->name );
return MS_FAILURE;
}
/* compute geotransform */
cm->geotransform[0] = cm->extent.minx;
cm->geotransform[1] = cm->xresolution;
cm->geotransform[2] = 0.0;
cm->geotransform[3] = cm->extent.maxy;
cm->geotransform[4] = 0.0;
cm->geotransform[5] = -fabs(cm->yresolution);
/* get bands count, or assume 1 if not found */
cm->bandcount = 1;
if( (value=msOWSLookupMetadata(&(layer->metadata), "CO", "bandcount")) != NULL) {
cm->bandcount = atoi(value);
}
/* get bands type, or assume float if not found */
cm->imagemode = MS_IMAGEMODE_FLOAT32;
if( (value=msOWSLookupMetadata(&(layer->metadata), "CO", "imagemode")) != NULL ) {
if( EQUAL(value,"INT16") )
cm->imagemode = MS_IMAGEMODE_INT16;
else if( EQUAL(value,"FLOAT32") )
cm->imagemode = MS_IMAGEMODE_FLOAT32;
else if( EQUAL(value,"BYTE") )
cm->imagemode = MS_IMAGEMODE_BYTE;
else {
msSetError( MS_WCSERR, "Content of wcs|ows_imagemode (%s) not recognised. Should be one of BYTE, INT16 or FLOAT32.", "msWCSGetCoverageMetadata()", value );
return MS_FAILURE;
}
}
/* set color interpretation to undefined */
/* TODO: find better solution */
for(i = 0; i < 10; ++i) {
cm->bandinterpretation[i] = GDALGetColorInterpretationName(GCI_Undefined);
}
} else if( layer->data == NULL ) { /* no virtual metadata, not ok unless we're talking 1 image, hopefully we can fix that */
msSetError( MS_WCSERR, "RASTER Layer with no DATA statement and no WCS virtual dataset metadata. Tileindexed raster layers not supported for WCS without virtual dataset metadata (cm->extent, wcs_res, wcs_size).", "msWCSGetCoverageDomain()" );
return MS_FAILURE;
} else { /* work from the file (e.g. DATA) */
GDALDatasetH hDS;
GDALRasterBandH hBand;
char szPath[MS_MAXPATHLEN];
char *decrypted_path;
msGDALInitialize();
msTryBuildPath3(szPath, layer->map->mappath, layer->map->shapepath, layer->data);
decrypted_path = msDecryptStringTokens( layer->map, szPath );
if( !decrypted_path )
return MS_FAILURE;
msAcquireLock( TLOCK_GDAL );
hDS = GDALOpen( decrypted_path, GA_ReadOnly );
if( hDS == NULL ) {
const char *cpl_error_msg = CPLGetLastErrorMsg();
/* we wish to avoid reporting decrypted paths */
if( cpl_error_msg != NULL
&& strstr(cpl_error_msg,decrypted_path) != NULL
&& strcmp(decrypted_path,szPath) != 0 )
cpl_error_msg = NULL;
if( cpl_error_msg == NULL )
cpl_error_msg = "";
msReleaseLock( TLOCK_GDAL );
msSetError( MS_IOERR, "%s", "msWCSGetCoverageMetadata()",
cpl_error_msg );
msFree( decrypted_path );
return MS_FAILURE;
}
msFree( decrypted_path );
msGetGDALGeoTransform( hDS, layer->map, layer, cm->geotransform );
cm->xsize = GDALGetRasterXSize( hDS );
cm->ysize = GDALGetRasterYSize( hDS );
cm->extent.minx = cm->geotransform[0];
cm->extent.maxx = cm->geotransform[0] + cm->geotransform[1] * cm->xsize + cm->geotransform[2] * cm->ysize;
cm->extent.miny = cm->geotransform[3] + cm->geotransform[4] * cm->xsize + cm->geotransform[5] * cm->ysize;
cm->extent.maxy = cm->geotransform[3];
cm->xresolution = cm->geotransform[1];
cm->yresolution = cm->geotransform[5];
/* TODO: need to set resolution */
cm->bandcount = GDALGetRasterCount( hDS );
if( cm->bandcount == 0 ) {
msReleaseLock( TLOCK_GDAL );
msSetError( MS_WCSERR, "Raster file %s has no raster bands. This cannot be used in a layer.", "msWCSGetCoverageMetadata()", layer->data );
return MS_FAILURE;
}
hBand = GDALGetRasterBand( hDS, 1 );
switch( GDALGetRasterDataType( hBand ) ) {
case GDT_Byte:
cm->imagemode = MS_IMAGEMODE_BYTE;
break;
case GDT_Int16:
cm->imagemode = MS_IMAGEMODE_INT16;
break;
default:
cm->imagemode = MS_IMAGEMODE_FLOAT32;
break;
}
/* color interpretation */
for(i = 1; i <= 10 && i <= cm->bandcount; ++i) {
GDALColorInterp colorInterp;
hBand = GDALGetRasterBand( hDS, i );
colorInterp = GDALGetRasterColorInterpretation(hBand);
cm->bandinterpretation[i-1] = GDALGetColorInterpretationName(colorInterp);
}
GDALClose( hDS );
msReleaseLock( TLOCK_GDAL );
}
/* we must have the bounding box in lat/lon [WGS84(DD)/EPSG:4326] */
cm->llextent = cm->extent;
/* Already in latlong .. use directly. */
if( layer->projection.proj != NULL && pj_is_latlong(layer->projection.proj))
{
/* no change */
}
else if (layer->projection.numargs > 0 && !pj_is_latlong(layer->projection.proj)) /* check the layer projection */
msProjectRect(&(layer->projection), NULL, &(cm->llextent));
else if (layer->map->projection.numargs > 0 && !pj_is_latlong(layer->map->projection.proj)) /* check the map projection */
msProjectRect(&(layer->map->projection), NULL, &(cm->llextent));
else { /* projection was specified in the metadata only (EPSG:... only at the moment) */
projectionObj proj;
char projstring[32];
msInitProjection(&proj); /* or bad things happen */
snprintf(projstring, sizeof(projstring), "init=epsg:%.20s", cm->srs+5);
if (msLoadProjectionString(&proj, projstring) != 0) return MS_FAILURE;
msProjectRect(&proj, NULL, &(cm->llextent));
}
return MS_SUCCESS;
}
#endif /* def USE_WCS_SVR */
|