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 2400 2401 2402 2403 2404 2405 2406 2407 2408 2409 2410 2411 2412 2413 2414 2415 2416 2417 2418 2419 2420 2421 2422 2423 2424 2425 2426 2427 2428 2429 2430 2431 2432 2433 2434 2435 2436 2437 2438 2439 2440 2441 2442 2443 2444 2445 2446 2447 2448 2449 2450 2451 2452 2453 2454 2455 2456 2457 2458 2459 2460 2461 2462 2463 2464 2465 2466 2467 2468 2469 2470 2471 2472 2473 2474 2475 2476 2477 2478 2479 2480 2481 2482 2483 2484 2485 2486 2487 2488 2489 2490 2491 2492 2493 2494 2495 2496 2497 2498 2499 2500 2501 2502 2503 2504 2505 2506 2507 2508 2509 2510 2511 2512 2513 2514 2515 2516 2517 2518 2519 2520 2521 2522 2523 2524 2525 2526 2527 2528 2529 2530 2531 2532 2533 2534 2535 2536 2537 2538 2539 2540 2541 2542 2543 2544 2545 2546 2547 2548 2549 2550 2551 2552 2553 2554 2555 2556 2557 2558 2559 2560 2561 2562 2563 2564 2565 2566 2567 2568 2569 2570 2571 2572 2573 2574 2575 2576 2577 2578 2579 2580 2581 2582 2583 2584 2585 2586 2587 2588 2589 2590 2591 2592 2593 2594 2595 2596 2597 2598 2599 2600 2601 2602 2603 2604 2605 2606 2607 2608 2609 2610 2611 2612 2613 2614 2615 2616 2617 2618 2619 2620 2621 2622 2623 2624 2625 2626 2627 2628 2629 2630 2631 2632 2633 2634 2635 2636 2637 2638 2639 2640 2641 2642 2643 2644 2645 2646 2647 2648 2649 2650 2651 2652 2653 2654 2655 2656 2657 2658 2659 2660 2661 2662 2663 2664 2665 2666 2667 2668 2669 2670 2671 2672 2673 2674 2675 2676 2677 2678 2679 2680 2681 2682 2683 2684 2685 2686 2687 2688 2689 2690 2691 2692 2693 2694 2695 2696 2697 2698 2699 2700 2701 2702 2703 2704 2705 2706 2707 2708 2709 2710 2711 2712 2713 2714 2715 2716 2717 2718 2719 2720 2721 2722 2723 2724 2725 2726 2727 2728 2729 2730 2731 2732 2733 2734 2735 2736 2737 2738 2739 2740 2741 2742 2743 2744 2745 2746 2747 2748 2749 2750 2751 2752 2753 2754 2755 2756 2757 2758 2759 2760 2761 2762 2763 2764 2765 2766 2767 2768 2769 2770 2771 2772 2773 2774 2775 2776 2777 2778 2779 2780 2781 2782 2783 2784 2785 2786 2787 2788 2789 2790 2791 2792 2793 2794 2795 2796 2797 2798 2799 2800 2801 2802 2803 2804 2805 2806 2807 2808 2809 2810 2811 2812 2813 2814 2815 2816 2817 2818 2819 2820 2821 2822 2823 2824 2825 2826 2827 2828 2829 2830 2831 2832 2833 2834 2835 2836 2837 2838 2839 2840 2841 2842 2843 2844 2845 2846 2847 2848 2849 2850 2851 2852 2853 2854 2855 2856 2857 2858 2859 2860 2861 2862 2863 2864 2865 2866 2867 2868 2869 2870 2871 2872 2873 2874 2875 2876 2877 2878 2879 2880 2881 2882 2883 2884 2885 2886 2887 2888 2889 2890 2891 2892 2893 2894 2895 2896 2897 2898 2899 2900 2901 2902 2903 2904 2905 2906 2907 2908 2909 2910 2911 2912 2913 2914 2915 2916 2917 2918 2919 2920 2921 2922 2923 2924 2925 2926 2927 2928 2929 2930 2931 2932 2933 2934 2935 2936 2937 2938 2939 2940 2941 2942 2943 2944 2945 2946 2947 2948 2949 2950 2951 2952 2953 2954 2955 2956 2957 2958 2959 2960 2961 2962 2963 2964 2965 2966 2967 2968 2969 2970 2971 2972 2973 2974 2975 2976 2977 2978 2979 2980 2981 2982 2983 2984 2985 2986 2987 2988 2989 2990 2991 2992 2993 2994 2995 2996 2997 2998 2999 3000 3001 3002 3003 3004 3005 3006 3007 3008 3009 3010 3011 3012 3013 3014 3015 3016 3017 3018 3019 3020 3021 3022 3023 3024 3025 3026 3027 3028 3029 3030 3031 3032 3033 3034 3035 3036 3037 3038 3039 3040 3041 3042 3043 3044 3045 3046 3047 3048 3049 3050 3051 3052 3053 3054 3055 3056 3057 3058 3059 3060 3061 3062 3063 3064 3065 3066 3067 3068 3069 3070 3071 3072 3073 3074 3075 3076 3077 3078 3079 3080 3081 3082 3083 3084 3085 3086 3087 3088 3089 3090 3091 3092 3093 3094 3095 3096 3097 3098 3099 3100 3101 3102 3103 3104 3105 3106 3107 3108 3109 3110 3111 3112 3113 3114 3115 3116 3117 3118 3119 3120 3121 3122 3123 3124 3125 3126 3127 3128 3129 3130 3131 3132 3133 3134 3135 3136 3137 3138 3139 3140 3141 3142 3143 3144 3145 3146 3147 3148 3149 3150 3151 3152 3153 3154 3155 3156 3157 3158 3159 3160 3161 3162 3163 3164 3165 3166 3167 3168 3169 3170 3171 3172 3173 3174 3175 3176 3177 3178 3179 3180 3181 3182 3183 3184 3185 3186 3187 3188 3189 3190 3191 3192 3193 3194 3195 3196 3197 3198 3199 3200 3201 3202 3203 3204 3205 3206 3207 3208 3209 3210 3211 3212 3213 3214 3215 3216 3217 3218 3219 3220 3221 3222 3223 3224 3225 3226 3227 3228 3229 3230 3231 3232 3233 3234 3235 3236 3237 3238 3239 3240 3241 3242 3243 3244 3245 3246 3247 3248 3249 3250 3251 3252 3253 3254 3255 3256 3257 3258 3259 3260 3261 3262 3263 3264 3265 3266 3267 3268 3269 3270 3271 3272 3273 3274 3275 3276 3277 3278 3279 3280 3281 3282 3283 3284 3285 3286 3287 3288 3289 3290 3291 3292 3293 3294 3295 3296 3297 3298 3299 3300 3301 3302 3303 3304 3305 3306 3307 3308 3309 3310 3311 3312 3313 3314 3315 3316 3317 3318 3319 3320 3321 3322 3323 3324 3325 3326 3327 3328 3329 3330 3331 3332 3333 3334 3335 3336 3337 3338 3339 3340 3341 3342 3343 3344 3345 3346 3347 3348 3349 3350 3351 3352 3353 3354 3355 3356 3357 3358 3359 3360 3361 3362 3363 3364 3365 3366 3367 3368 3369 3370 3371 3372 3373 3374 3375 3376 3377 3378 3379 3380 3381 3382 3383 3384 3385 3386 3387 3388 3389 3390 3391 3392 3393 3394 3395 3396 3397 3398 3399 3400 3401 3402 3403 3404 3405 3406 3407 3408 3409 3410 3411 3412 3413 3414 3415 3416 3417 3418 3419 3420 3421 3422 3423 3424 3425 3426 3427 3428 3429 3430 3431 3432 3433 3434 3435 3436 3437 3438 3439 3440 3441 3442 3443 3444 3445 3446 3447 3448 3449 3450 3451 3452 3453 3454 3455 3456 3457 3458 3459 3460 3461 3462 3463 3464 3465 3466 3467 3468 3469 3470 3471 3472 3473 3474 3475 3476 3477 3478 3479 3480 3481 3482 3483 3484 3485 3486 3487 3488 3489 3490 3491 3492 3493 3494 3495 3496 3497 3498 3499 3500 3501 3502 3503 3504 3505 3506 3507 3508 3509 3510 3511 3512 3513 3514 3515 3516 3517 3518 3519 3520 3521 3522 3523 3524 3525 3526 3527 3528 3529 3530 3531 3532 3533 3534 3535 3536 3537 3538 3539 3540 3541 3542 3543 3544 3545 3546 3547 3548 3549 3550 3551 3552 3553 3554 3555 3556 3557 3558 3559 3560 3561 3562 3563 3564 3565 3566 3567 3568 3569 3570 3571 3572 3573 3574 3575 3576 3577 3578 3579 3580 3581 3582 3583 3584 3585 3586 3587 3588 3589 3590 3591 3592 3593 3594 3595 3596 3597 3598 3599 3600 3601 3602 3603 3604 3605 3606 3607 3608 3609 3610 3611 3612 3613 3614 3615 3616 3617 3618 3619 3620 3621 3622 3623 3624 3625 3626 3627 3628 3629 3630 3631 3632 3633 3634 3635 3636 3637 3638 3639 3640 3641 3642 3643 3644 3645 3646 3647 3648 3649 3650 3651 3652 3653 3654 3655 3656 3657 3658 3659 3660 3661 3662 3663 3664 3665 3666 3667 3668 3669 3670 3671 3672 3673 3674 3675 3676 3677 3678 3679 3680 3681 3682 3683 3684 3685 3686 3687 3688 3689 3690 3691 3692 3693 3694 3695 3696 3697 3698 3699 3700 3701 3702 3703 3704 3705 3706 3707 3708 3709 3710 3711 3712 3713 3714 3715 3716 3717 3718 3719 3720 3721 3722 3723 3724 3725 3726 3727 3728 3729 3730 3731 3732 3733 3734 3735 3736 3737 3738 3739 3740 3741 3742 3743 3744 3745 3746 3747 3748 3749 3750 3751 3752 3753 3754 3755 3756 3757 3758 3759 3760 3761 3762 3763 3764 3765 3766 3767 3768 3769 3770 3771 3772 3773 3774 3775 3776 3777 3778 3779 3780 3781 3782 3783 3784 3785 3786 3787 3788 3789 3790 3791 3792 3793 3794 3795 3796 3797 3798 3799 3800 3801 3802 3803 3804 3805 3806 3807 3808 3809 3810 3811 3812 3813 3814 3815 3816 3817 3818 3819 3820 3821 3822 3823 3824 3825 3826 3827 3828 3829 3830 3831 3832 3833 3834 3835 3836 3837 3838 3839 3840 3841 3842 3843 3844 3845 3846 3847 3848 3849 3850 3851 3852 3853 3854 3855 3856 3857 3858 3859 3860 3861 3862 3863 3864 3865 3866 3867 3868 3869 3870 3871 3872 3873 3874 3875 3876 3877 3878 3879 3880 3881 3882 3883 3884 3885 3886 3887 3888 3889 3890 3891 3892 3893 3894 3895 3896 3897 3898 3899 3900 3901 3902 3903 3904 3905 3906 3907 3908 3909 3910 3911 3912 3913 3914 3915 3916 3917 3918 3919 3920 3921 3922 3923 3924 3925 3926 3927 3928 3929 3930 3931 3932 3933 3934 3935 3936 3937 3938 3939 3940 3941 3942 3943 3944 3945 3946 3947 3948 3949 3950 3951 3952 3953 3954 3955 3956 3957 3958 3959 3960 3961 3962 3963 3964 3965 3966 3967 3968 3969 3970 3971 3972 3973 3974 3975 3976 3977 3978 3979 3980 3981 3982 3983 3984 3985 3986 3987 3988 3989 3990 3991 3992 3993 3994 3995 3996 3997 3998 3999 4000 4001 4002 4003 4004 4005 4006 4007 4008 4009 4010 4011 4012 4013 4014 4015 4016 4017 4018 4019 4020 4021 4022 4023 4024 4025 4026 4027 4028 4029 4030 4031 4032 4033 4034 4035 4036 4037 4038 4039 4040 4041 4042 4043 4044 4045 4046 4047 4048 4049 4050 4051 4052 4053 4054 4055 4056 4057 4058 4059 4060 4061 4062 4063 4064 4065 4066 4067 4068 4069 4070 4071 4072 4073 4074 4075 4076 4077 4078 4079 4080 4081 4082 4083 4084 4085 4086 4087 4088 4089 4090 4091 4092 4093 4094 4095 4096 4097 4098 4099 4100 4101 4102 4103 4104 4105 4106 4107 4108 4109 4110 4111 4112 4113 4114 4115 4116 4117 4118 4119 4120 4121 4122 4123 4124 4125 4126 4127 4128 4129 4130 4131 4132 4133 4134 4135 4136 4137 4138 4139 4140 4141 4142 4143 4144 4145 4146 4147 4148 4149 4150 4151 4152 4153 4154 4155 4156 4157 4158 4159 4160 4161 4162 4163 4164 4165 4166 4167 4168 4169 4170 4171 4172 4173 4174 4175 4176 4177 4178 4179 4180 4181 4182 4183 4184 4185 4186 4187 4188 4189 4190 4191 4192 4193 4194 4195 4196 4197 4198 4199 4200 4201 4202 4203 4204 4205 4206 4207 4208 4209 4210 4211 4212 4213 4214 4215 4216 4217 4218 4219 4220 4221 4222 4223 4224 4225 4226 4227 4228 4229 4230 4231 4232 4233 4234 4235 4236 4237 4238 4239 4240 4241 4242 4243 4244 4245 4246 4247 4248 4249 4250 4251 4252 4253 4254 4255 4256 4257 4258 4259 4260 4261 4262 4263 4264 4265 4266 4267 4268 4269 4270 4271 4272 4273 4274 4275 4276 4277 4278 4279 4280 4281 4282 4283 4284 4285 4286 4287 4288 4289 4290 4291 4292 4293 4294 4295 4296 4297 4298 4299 4300 4301 4302 4303 4304 4305 4306 4307 4308 4309 4310 4311 4312 4313 4314 4315 4316 4317 4318 4319 4320 4321 4322 4323 4324 4325 4326 4327 4328 4329 4330 4331 4332 4333 4334 4335 4336 4337 4338 4339 4340 4341 4342 4343 4344 4345 4346 4347 4348 4349 4350 4351 4352 4353 4354 4355 4356 4357 4358 4359 4360 4361 4362 4363 4364 4365 4366 4367 4368 4369 4370 4371 4372 4373 4374 4375 4376 4377 4378 4379 4380 4381 4382 4383 4384 4385 4386 4387 4388 4389 4390 4391 4392 4393 4394 4395 4396 4397 4398 4399 4400 4401 4402 4403 4404 4405 4406 4407 4408 4409 4410 4411 4412 4413 4414 4415 4416 4417 4418 4419 4420 4421 4422 4423 4424 4425 4426 4427 4428 4429 4430 4431 4432 4433 4434 4435 4436 4437 4438 4439 4440 4441 4442 4443 4444 4445 4446 4447 4448 4449 4450 4451 4452 4453 4454 4455 4456 4457 4458 4459 4460 4461 4462 4463 4464 4465 4466 4467 4468 4469 4470 4471 4472 4473 4474 4475 4476 4477 4478 4479 4480 4481 4482 4483 4484 4485 4486 4487 4488 4489 4490 4491 4492 4493 4494 4495 4496 4497 4498 4499 4500 4501 4502 4503 4504 4505 4506 4507 4508 4509 4510 4511 4512 4513 4514 4515 4516 4517 4518 4519 4520 4521 4522 4523 4524 4525 4526 4527 4528 4529 4530 4531 4532 4533 4534 4535 4536 4537 4538 4539 4540 4541 4542 4543 4544 4545 4546 4547 4548 4549 4550 4551 4552 4553 4554 4555 4556 4557 4558 4559 4560 4561 4562 4563 4564 4565 4566 4567 4568 4569 4570 4571 4572 4573 4574 4575 4576 4577 4578 4579 4580 4581 4582 4583 4584 4585 4586 4587 4588 4589 4590 4591 4592 4593 4594 4595 4596 4597 4598 4599 4600 4601 4602 4603 4604 4605 4606 4607 4608 4609
|
<!-- Converted by db4-upgrade version 1.1 -->
<chapter
xmlns="http://docbook.org/ns/docbook" version="5.0"
xmlns:xlink="http://www.w3.org/1999/xlink"
xml:id="Topology"
>
<title>Topology</title>
<para>The PostGIS Topology types and functions are used to manage topological objects such as faces, edges and nodes. </para>
<para>Sandro Santilli's presentation at PostGIS Day Paris 2011 conference gives a good synopsis of PostGIS Topology and where it is headed <link xlink:href="http://strk.kbt.io/projects/postgis/Paris2011_TopologyWithPostGIS_2_0.pdf">Topology with PostGIS 2.0 slide deck</link>.</para>
<para>
Vincent Picavet provides a good synopsis and overview of what is Topology,
how is it used, and various FOSS4G tools that support it in <link xlink:href="https://gitlab.com/Oslandia/documentation/presentations/-/blob/master/2012/pgconf_eu_2012/pgconfeu2012_vincent_picavet_postgis_topology.pdf">PostGIS Topology PGConf EU 2012</link>.
</para>
<para>An example of a topologically based GIS database is the <link xlink:href="https://www.census.gov/geo/maps-data/data/tiger.html">US Census Topologically Integrated Geographic Encoding and Referencing System (TIGER)</link> database. If you want to experiment with PostGIS topology and need some data, check out <xref linkend="Topology_Load_Tiger"/>.</para>
<para>The PostGIS topology module has existed in prior versions of PostGIS but was never part of the Official PostGIS documentation.
In PostGIS 2.0.0 major cleanup is going on to remove use of all deprecated functions in it, fix known usability issues, better document the features and functions, add new functions, and enhance to closer conform to SQL-MM standards.</para>
<para>Details of this project can be found at <link xlink:href="http://trac.osgeo.org/postgis/wiki/UsersWikiPostgisTopology">PostGIS Topology Wiki</link></para>
<para>All functions and tables associated with this module are installed in a schema called <varname>topology</varname>.</para>
<para>Functions that are defined in SQL/MM standard are prefixed with ST_ and functions specific to PostGIS are not prefixed.</para>
<para>Topology support is build by default starting with PostGIS 2.0, and can be disabled specifying --without-topology configure option at build time as described in <xref linkend="postgis_installation"/></para>
<section xml:id="Topology_Types">
<title>Topology Types</title><info>
<abstract>
<para>This section lists the PostgreSQL data types installed by PostGIS Topology. Note we describe the casting behavior of these which is very
important especially when designing your own functions.
</para>
</abstract>
</info>
<refentry xml:id="getfaceedges_returntype">
<refnamediv>
<refname>getfaceedges_returntype</refname>
<refpurpose>
A composite type that consists of a sequence
number and an edge number.
</refpurpose>
</refnamediv>
<refsection>
<title>Description</title>
<para>
A composite type that consists of a sequence number
and an edge number.
This is the return type for <varname>ST_GetFaceEdges</varname>
and <varname>GetNodeEdges</varname> functions.
</para>
<orderedlist>
<listitem>
<para><varname>sequence</varname> is an integer: Refers to a topology defined in the topology.topology table which defines the topology schema and srid.</para>
</listitem>
<listitem>
<para><varname>edge</varname> is an integer: The identifier of an edge.</para>
</listitem>
</orderedlist>
</refsection>
</refentry>
<refentry xml:id="topogeometry">
<refnamediv>
<refname>TopoGeometry</refname>
<refpurpose>A composite type representing a topologically defined geometry.</refpurpose>
</refnamediv>
<refsection>
<title>Description</title>
<para>A composite type that refers to a topology geometry in a specific topology layer, having a specific type and a specific id. The elements of a TopoGeometry are the properties: topology_id, layer_id, id integer, type integer.</para>
<orderedlist>
<listitem>
<para><varname>topology_id</varname> is an integer: Refers to a topology defined in the topology.topology table which defines the topology schema and srid.</para>
</listitem>
<listitem>
<para><varname>layer_id</varname> is an integer: The layer_id in the layers table that the TopoGeometry belongs to. The combination of topology_id, layer_id provides a unique reference in the topology.layers table.</para>
</listitem>
<listitem>
<para><varname>id</varname> is an integer: The id is the autogenerated sequence number that uniquely defines the topogeometry in the respective topology layer.</para>
</listitem>
<listitem>
<para><varname>type</varname> integer between 1 - 4 that defines the geometry type: 1:[multi]point, 2:[multi]line, 3:[multi]poly, 4:collection</para>
</listitem>
</orderedlist>
</refsection>
<refsection>
<title>Casting Behavior</title>
<para>This section lists the automatic as well as explicit casts allowed for this data type</para>
<informaltable rowsep="1" frame="all">
<tgroup cols="2">
<tbody>
<row>
<entry>Cast To</entry>
<entry>Behavior</entry>
</row>
<row>
<entry>geometry</entry>
<entry>automatic</entry>
</row>
</tbody>
</tgroup>
</informaltable>
</refsection>
<!-- Optionally add a "See Also" section -->
<refsection>
<title>See Also</title>
<para><xref linkend="CreateTopoGeom"/></para>
</refsection>
</refentry>
<refentry xml:id="validatetopology_returntype">
<refnamediv>
<refname>validatetopology_returntype</refname>
<refpurpose>A composite type that consists of an error message and id1 and id2 to denote location of error. This is the return type for <varname>ValidateTopology</varname>.</refpurpose>
</refnamediv>
<refsection>
<title>Description</title>
<para>A composite type that consists of an error message and two integers. The <xref linkend="ValidateTopology"/> function returns a set of these to denote validation errors and the id1 and id2 to denote the ids of the topology objects involved in the error.</para>
<orderedlist>
<listitem>
<para><varname>error</varname> is varchar: Denotes type of error. </para>
<para>Current error descriptors are: coincident nodes, edge crosses node, edge not simple, edge end node geometry mismatch, edge start node geometry mismatch, face overlaps face,face within face, </para>
</listitem>
<listitem>
<para><varname>id1</varname> is an integer: Denotes identifier of edge / face / nodes in error.</para>
</listitem>
<listitem>
<para><varname>id2</varname> is an integer: For errors that involve 2 objects denotes the secondary edge / or node</para>
</listitem>
</orderedlist>
</refsection>
<!-- Optionally add a "See Also" section -->
<refsection>
<title>See Also</title>
<para><xref linkend="ValidateTopology"/></para>
</refsection>
</refentry>
</section>
<section xml:id="Topology_Domains">
<title>Topology Domains</title><info>
<abstract>
<para>This section lists the PostgreSQL domains installed by PostGIS Topology. Domains can be used like object types as return objects of functions or table columns. The distinction between
a domain and a type is that a domain is an existing type with a check constraint bound to it.
</para>
</abstract>
</info>
<refentry xml:id="topoelement">
<refnamediv>
<refname>TopoElement</refname>
<refpurpose>An array of 2 integers generally used to identify a TopoGeometry component.</refpurpose>
</refnamediv>
<refsection>
<title>Description</title>
<para>
An array of 2 integers used to represent one component of a simple or
hierarchical <xref linkend="topogeometry"/>.
</para>
<para>
In the case of a simple TopoGeometry the first element of the array
represents the identifier of a topological primitive and the second
element represents its type (1:node, 2:edge, 3:face). In the case of a
hierarchical TopoGeometry the first element of the array represents the
identifier of a child TopoGeometry and the second element represents
its layer identifier.
</para>
<note><para>
For any given hierarchical TopoGeometry all child TopoGeometry
elements will come from the same child layer, as specified in
the topology.layer record for the layer of the TopoGeometry
being defined.
</para></note>
</refsection>
<refsection>
<title>Examples</title>
<programlisting>
SELECT te[1] AS id, te[2] AS type FROM
( SELECT ARRAY[1,2]::topology.topoelement AS te ) f;
id | type
----+------
1 | 2
</programlisting>
<programlisting>SELECT ARRAY[1,2]::topology.topoelement;
te
-------
{1,2}
</programlisting>
<programlisting>
--Example of what happens when you try to case a 3 element array to topoelement
-- NOTE: topoement has to be a 2 element array so fails dimension check
SELECT ARRAY[1,2,3]::topology.topoelement;
ERROR: value for domain topology.topoelement violates check constraint "dimensions"
</programlisting>
</refsection>
<!-- Optionally add a "See Also" section -->
<refsection>
<title>See Also</title>
<para>
<xref linkend="GetTopoGeomElements"/>,
<xref linkend="topoelementarray"/>,
<xref linkend="topogeometry"/>,
<xref linkend="TopoGeom_addElement"/>,
<xref linkend="TopoGeom_remElement"/>
</para>
</refsection>
</refentry>
<refentry xml:id="topoelementarray">
<refnamediv>
<refname>TopoElementArray</refname>
<refpurpose>An array of TopoElement objects.</refpurpose>
</refnamediv>
<refsection>
<title>Description</title>
<para>An array of 1 or more TopoElement objects, generally used to pass around components of TopoGeometry objects.</para>
</refsection>
<refsection>
<title>Examples</title>
<programlisting>SELECT '{{1,2},{4,3}}'::topology.topoelementarray As tea;
tea
-------
{{1,2},{4,3}}
-- more verbose equivalent --
SELECT ARRAY[ARRAY[1,2], ARRAY[4,3]]::topology.topoelementarray As tea;
tea
-------
{{1,2},{4,3}}
--using the array agg function packaged with topology --
SELECT topology.TopoElementArray_Agg(ARRAY[e,t]) As tea
FROM generate_series(1,4) As e CROSS JOIN generate_series(1,3) As t;
tea
--------------------------------------------------------------------------
{{1,1},{1,2},{1,3},{2,1},{2,2},{2,3},{3,1},{3,2},{3,3},{4,1},{4,2},{4,3}}
</programlisting>
<programlisting>SELECT '{{1,2,4},{3,4,5}}'::topology.topoelementarray As tea;
ERROR: value for domain topology.topoelementarray violates check constraint "dimensions"
</programlisting>
</refsection>
<!-- Optionally add a "See Also" section -->
<refsection>
<title>See Also</title>
<para>
<xref linkend="topoelement"/>,
<xref linkend="GetTopoGeomElementArray"/>,
<xref linkend="TopoElementArray_Agg"/>
</para>
</refsection>
</refentry>
</section>
<section xml:id="Topology_ManagementFunctions">
<title>Topology and TopoGeometry Management</title><info>
<abstract>
<para>This section lists the Topology functions for building new Topology schemas, validating topologies, and managing TopoGeometry Columns</para>
</abstract>
</info>
<refentry xml:id="AddTopoGeometryColumn">
<refnamediv>
<refname>AddTopoGeometryColumn</refname>
<refpurpose>Adds a topogeometry column to an existing table, registers this new column as a layer in topology.layer and returns the new layer_id.</refpurpose>
</refnamediv>
<refsynopsisdiv>
<funcsynopsis>
<funcprototype>
<funcdef>integer <function>AddTopoGeometryColumn</function></funcdef>
<paramdef><type>varchar </type>
<parameter>topology_name</parameter></paramdef>
<paramdef><type>varchar </type>
<parameter>schema_name</parameter></paramdef>
<paramdef><type>varchar </type>
<parameter>table_name</parameter></paramdef>
<paramdef><type>varchar </type>
<parameter>column_name</parameter></paramdef>
<paramdef><type>varchar </type>
<parameter>feature_type</parameter></paramdef>
</funcprototype>
<funcprototype>
<funcdef>integer <function>AddTopoGeometryColumn</function></funcdef>
<paramdef><type>varchar </type>
<parameter>topology_name</parameter></paramdef>
<paramdef><type>varchar </type>
<parameter>schema_name</parameter></paramdef>
<paramdef><type>varchar </type>
<parameter>table_name</parameter></paramdef>
<paramdef><type>varchar </type>
<parameter>column_name</parameter></paramdef>
<paramdef><type>varchar </type>
<parameter>feature_type</parameter></paramdef>
<paramdef><type>integer </type>
<parameter>child_layer</parameter></paramdef>
</funcprototype>
</funcsynopsis>
</refsynopsisdiv>
<refsection>
<title>Description</title>
<para>Each TopoGeometry object belongs to a specific Layer of a specific Topology. Before creating a TopoGeometry object you need to create its TopologyLayer.
A Topology Layer is an association of a feature-table with the topology. It also contain type and hierarchy information. We create a layer using the AddTopoGeometryColumn() function: </para>
<para>This function will both add the requested column to the table and add a record to the topology.layer table with all the given info.</para>
<para>If you don't specify [child_layer] (or set it to NULL) this layer would contain Basic TopoGeometries (composed by primitive topology elements).
Otherwise this layer will contain hierarchical TopoGeometries (composed by TopoGeometries from the child_layer).</para>
<para>Once the layer is created (its id is returned by the AddTopoGeometryColumn function) you're ready to construct TopoGeometry objects in it</para>
<para>Valid <varname>feature_type</varname>s are: POINT, MULTIPOINT, LINE, MULTILINE, POLYGON, MULTIPOLYGON, COLLECTION</para>
<!-- use this format if new function -->
<para role="availability" conformance="1.1">Availability: 1.1</para>
</refsection>
<refsection>
<title>Examples</title>
<programlisting>-- Note for this example we created our new table in the ma_topo schema
-- though we could have created it in a different schema -- in which case topology_name and schema_name would be different
CREATE SCHEMA ma;
CREATE TABLE ma.parcels(gid serial, parcel_id varchar(20) PRIMARY KEY, address text);
SELECT topology.AddTopoGeometryColumn('ma_topo', 'ma', 'parcels', 'topo', 'POLYGON');</programlisting>
<programlisting>
CREATE SCHEMA ri;
CREATE TABLE ri.roads(gid serial PRIMARY KEY, road_name text);
SELECT topology.AddTopoGeometryColumn('ri_topo', 'ri', 'roads', 'topo', 'LINE');
</programlisting>
</refsection>
<!-- Optionally add a "See Also" section -->
<refsection>
<title>See Also</title>
<para>
<xref linkend="DropTopoGeometryColumn"/>,
<xref linkend="toTopoGeom"/>,
<xref linkend="CreateTopology"/>,
<xref linkend="CreateTopoGeom"/>
</para>
</refsection>
</refentry>
<refentry xml:id="RenameTopoGeometryColumn">
<refnamediv>
<refname>RenameTopoGeometryColumn</refname>
<refpurpose>Renames a topogeometry column</refpurpose>
</refnamediv>
<refsynopsisdiv>
<funcsynopsis>
<funcprototype>
<funcdef>topology.layer <function>RenameTopoGeometryColumn</function></funcdef>
<paramdef><type>regclass </type>
<parameter>layer_table</parameter></paramdef>
<paramdef><type>name </type>
<parameter>feature_column</parameter></paramdef>
<paramdef><type>name </type>
<parameter>new_name</parameter></paramdef>
</funcprototype>
</funcsynopsis>
</refsynopsisdiv>
<refsection>
<title>Description</title>
<para>
This function changes the name of an existing TopoGeometry column
ensuring metadata information about it is updated accordingly.
</para>
<!-- use this format if new function -->
<para role="availability" conformance="3.4.0">Availability: 3.4.0</para>
</refsection>
<refsection>
<title>Examples</title>
<programlisting>
SELECT topology.RenameTopoGeometryColumn('public.parcels', 'topogeom', 'tgeom');
</programlisting>
</refsection>
<!-- Optionally add a "See Also" section -->
<refsection>
<title>See Also</title>
<para>
<xref linkend="AddTopoGeometryColumn"/>,
<xref linkend="RenameTopology"/>
</para>
</refsection>
</refentry>
<refentry xml:id="DropTopology">
<refnamediv>
<refname>DropTopology</refname>
<refpurpose>Use with caution: Drops a topology schema and deletes its reference from topology.topology table and references to tables in that schema from the geometry_columns table.</refpurpose>
</refnamediv>
<refsynopsisdiv>
<funcsynopsis>
<funcprototype>
<funcdef>integer <function>DropTopology</function></funcdef>
<paramdef><type>varchar </type> <parameter>topology_schema_name</parameter></paramdef>
</funcprototype>
</funcsynopsis>
</refsynopsisdiv>
<refsection>
<title>Description</title>
<para>Drops a topology schema and deletes its reference from topology.topology table and references to tables in that schema from the geometry_columns table.
This function should be USED WITH CAUTION, as it could destroy data you care about. If the schema does not exist, it just removes reference entries the named schema.</para>
<!-- use this format if new function -->
<para role="availability" conformance="1.1">Availability: 1.1</para>
</refsection>
<refsection>
<title>Examples</title>
<para>Cascade drops the ma_topo schema and removes all references to it in topology.topology and geometry_columns.</para>
<programlisting>SELECT topology.DropTopology('ma_topo');</programlisting>
</refsection>
<!-- Optionally add a "See Also" section -->
<refsection>
<title>See Also</title>
<para><xref linkend="DropTopoGeometryColumn"/></para>
</refsection>
</refentry>
<refentry xml:id="RenameTopology">
<refnamediv>
<refname>RenameTopology</refname>
<refpurpose>Renames a topology</refpurpose>
</refnamediv>
<refsynopsisdiv>
<funcsynopsis>
<funcprototype>
<funcdef>varchar <function>RenameTopology</function></funcdef>
<paramdef><type>varchar </type> <parameter>old_name</parameter></paramdef>
<paramdef><type>varchar </type> <parameter>new_name</parameter></paramdef>
</funcprototype>
</funcsynopsis>
</refsynopsisdiv>
<refsection>
<title>Description</title>
<para>
Renames a topology schema, updating its metadata record in the <varname>topology.topology</varname> table.
</para>
<!-- use this format if new function -->
<para role="availability" conformance="3.4.0">Availability: 3.4.0</para>
</refsection>
<refsection>
<title>Examples</title>
<para>
Rename a topology from <varname>topo_stage</varname> to <varname>topo_prod</varname>.
</para>
<programlisting>SELECT topology.RenameTopology('topo_stage', 'topo_prod');</programlisting>
</refsection>
<!-- Optionally add a "See Also" section -->
<refsection>
<title>See Also</title>
<para>
<xref linkend="CopyTopology"/>,
<xref linkend="RenameTopoGeometryColumn"/>
</para>
</refsection>
</refentry>
<refentry xml:id="DropTopoGeometryColumn">
<refnamediv>
<refname>DropTopoGeometryColumn</refname>
<refpurpose>Drops the topogeometry column from the table named <varname>table_name</varname> in schema <varname>schema_name</varname> and unregisters the columns from topology.layer table.</refpurpose>
</refnamediv>
<refsynopsisdiv>
<funcsynopsis>
<funcprototype>
<funcdef>text <function>DropTopoGeometryColumn</function></funcdef>
<paramdef><type>varchar </type> <parameter>schema_name</parameter></paramdef>
<paramdef><type>varchar </type> <parameter>table_name</parameter></paramdef>
<paramdef><type>varchar </type> <parameter>column_name</parameter></paramdef>
</funcprototype>
</funcsynopsis>
</refsynopsisdiv>
<refsection>
<title>Description</title>
<para>Drops the topogeometry column from the table named <varname>table_name</varname> in schema <varname>schema_name</varname> and unregisters the columns from topology.layer table. Returns summary
of drop status. NOTE: it first sets all values to NULL before dropping to bypass referential integrity checks.</para>
<!-- use this format if new function -->
<para role="availability" conformance="1.1">Availability: 1.1</para>
</refsection>
<refsection>
<title>Examples</title>
<programlisting>SELECT topology.DropTopoGeometryColumn('ma_topo', 'parcel_topo', 'topo');</programlisting>
</refsection>
<!-- Optionally add a "See Also" section -->
<refsection>
<title>See Also</title>
<para><xref linkend="AddTopoGeometryColumn"/></para>
</refsection>
</refentry>
<refentry xml:id="Populate_Topology_Layer">
<refnamediv>
<refname>Populate_Topology_Layer</refname>
<refpurpose>Adds missing entries to topology.layer table by reading metadata from topo tables.</refpurpose>
</refnamediv>
<refsynopsisdiv>
<funcsynopsis>
<funcprototype>
<funcdef>setof record <function>Populate_Topology_Layer</function></funcdef>
<paramdef></paramdef>
</funcprototype>
</funcsynopsis>
</refsynopsisdiv>
<refsection>
<title>Description</title>
<para>Adds missing entries to the <varname>topology.layer</varname> table by inspecting topology constraints on tables.
This function is useful for fixing up entries in topology catalog after restores of schemas with topo data.</para>
<para>It returns the list of entries created. Returned columns are <varname>schema_name</varname>, <varname>table_name</varname>, <varname>feature_column</varname>.</para>
<!-- use this format if new function -->
<para role="availability" conformance="2.3.0">Availability: 2.3.0</para>
</refsection>
<refsection>
<title>Examples</title>
<programlisting>SELECT CreateTopology('strk_topo');
CREATE SCHEMA strk;
CREATE TABLE strk.parcels(gid serial, parcel_id varchar(20) PRIMARY KEY, address text);
SELECT topology.AddTopoGeometryColumn('strk_topo', 'strk', 'parcels', 'topo', 'POLYGON');
-- this will return no records because this feature is already registered
SELECT *
FROM topology.Populate_Topology_Layer();
-- let's rebuild
TRUNCATE TABLE topology.layer;
SELECT *
FROM topology.Populate_Topology_Layer();
SELECT topology_id,layer_id, schema_name As sn, table_name As tn, feature_column As fc
FROM topology.layer;
</programlisting>
<screen> schema_name | table_name | feature_column
-------------+------------+----------------
strk | parcels | topo
(1 row)
topology_id | layer_id | sn | tn | fc
-------------+----------+------+---------+------
2 | 2 | strk | parcels | topo
(1 row)</screen>
</refsection>
<!-- Optionally add a "See Also" section -->
<refsection>
<title>See Also</title>
<para><xref linkend="AddTopoGeometryColumn"/></para>
</refsection>
</refentry>
<refentry xml:id="TopologySummary">
<refnamediv>
<refname>TopologySummary</refname>
<refpurpose>Takes a topology name and provides summary totals of types of objects in topology.</refpurpose>
</refnamediv>
<refsynopsisdiv>
<funcsynopsis>
<funcprototype>
<funcdef>text <function>TopologySummary</function></funcdef>
<paramdef><type>varchar </type> <parameter>topology_schema_name</parameter></paramdef>
</funcprototype>
</funcsynopsis>
</refsynopsisdiv>
<refsection>
<title>Description</title>
<para>Takes a topology name and provides summary totals of types of objects in topology.</para>
<!-- use this format if new function -->
<para role="availability" conformance="2.0.0">Availability: 2.0.0</para>
</refsection>
<refsection>
<title>Examples</title>
<programlisting>SELECT topology.topologysummary('city_data');
topologysummary
--------------------------------------------------------
Topology city_data (329), SRID 4326, precision: 0
22 nodes, 24 edges, 10 faces, 29 topogeoms in 5 layers
Layer 1, type Polygonal (3), 9 topogeoms
Deploy: features.land_parcels.feature
Layer 2, type Puntal (1), 8 topogeoms
Deploy: features.traffic_signs.feature
Layer 3, type Lineal (2), 8 topogeoms
Deploy: features.city_streets.feature
Layer 4, type Polygonal (3), 3 topogeoms
Hierarchy level 1, child layer 1
Deploy: features.big_parcels.feature
Layer 5, type Puntal (1), 1 topogeoms
Hierarchy level 1, child layer 2
Deploy: features.big_signs.feature</programlisting>
</refsection>
<!-- Optionally add a "See Also" section -->
<refsection>
<title>See Also</title>
<para><xref linkend="Topology_Load_Tiger"/></para>
</refsection>
</refentry>
<refentry xml:id="ValidateTopology">
<refnamediv>
<refname>ValidateTopology</refname>
<refpurpose>Returns a set of validatetopology_returntype objects detailing issues with topology.</refpurpose>
</refnamediv>
<refsynopsisdiv>
<funcsynopsis>
<funcprototype>
<funcdef>setof validatetopology_returntype <function>ValidateTopology</function></funcdef>
<paramdef><type>varchar </type> <parameter>toponame</parameter></paramdef>
<paramdef choice="opt"><type>geometry</type> <parameter>bbox</parameter></paramdef>
</funcprototype>
</funcsynopsis>
</refsynopsisdiv>
<refsection>
<title>Description</title>
<para>
Returns a set of <xref linkend="validatetopology_returntype"/> objects
detailing issues with topology, optionally limiting the check to the
area specified by the <varname>bbox</varname> parameter.
</para>
<para>List of possible errors, what they mean and what the returned ids represent are displayed below:</para>
<informaltable rowsep="1" frame="all">
<tgroup cols="4">
<thead>
<row>
<entry>Error</entry>
<entry>id1</entry>
<entry>id2</entry>
<entry>Meaning</entry>
</row>
</thead>
<tbody>
<row>
<entry>coincident nodes</entry>
<entry>Identifier of first node.</entry>
<entry>Identifier of second node.</entry>
<entry>
Two nodes have the same geometry.
</entry>
</row>
<row>
<entry>edge crosses node</entry>
<entry>Identifier of the edge.</entry>
<entry>Identifier of the node.</entry>
<entry>
An edge has a node in its interior.
See <xref linkend="ST_Relate"/>.
</entry>
</row>
<row>
<entry>invalid edge</entry>
<entry>Identifier of the edge.</entry>
<entry/>
<entry>
An edge geometry is invalid.
See <xref linkend="ST_IsValid"/>.
</entry>
</row>
<row>
<entry>edge not simple</entry>
<entry>Identifier of the edge.</entry>
<entry/>
<entry>
An edge geometry has self-intersections.
See <xref linkend="ST_IsSimple"/>.
</entry>
</row>
<row>
<entry>edge crosses edge</entry>
<entry>Identifier of first edge.</entry>
<entry>Identifier of second edge.</entry>
<entry>
Two edges have an interior intersection.
See <xref linkend="ST_Relate"/>.
</entry>
</row>
<row>
<entry>edge start node geometry mismatch</entry>
<entry>Identifier of the edge.</entry>
<entry>
Identifier of the indicated start node.
</entry>
<entry>
The geometry of the node indicated as the starting node for an edge does
not match the first point of the edge geometry.
See <xref linkend="ST_StartPoint"/>.
</entry>
</row>
<row>
<entry>edge end node geometry mismatch</entry>
<entry>Identifier of the edge.</entry>
<entry>
Identifier of the indicated end node.
</entry>
<entry>
The geometry of the node indicated as the ending node for an edge does
not match the last point of the edge geometry.
See <xref linkend="ST_EndPoint"/>.
</entry>
</row>
<row>
<entry>face without edges</entry>
<entry>
Identifier of the orphaned face.
</entry>
<entry/>
<entry>
No edge reports an existing face on either of its sides
(left_face, right_face).
</entry>
</row>
<row>
<entry>face has no rings</entry>
<entry>
Identifier of the partially-defined face.
</entry>
<entry/>
<entry>
Edges reporting a face on their sides do not form a ring.
</entry>
</row>
<row>
<entry>face has wrong mbr</entry>
<entry>
Identifier of the face with wrong mbr cache.
</entry>
<entry/>
<entry>
Minimum bounding rectangle of a face does not match minimum bounding
box of the collection of edges reporting the face on their sides.
</entry>
</row>
<row>
<entry>hole not in advertised face</entry>
<entry>
Signed identifier of an edge, identifying the ring.
See <xref linkend="GetRingEdges"/>.
</entry>
<entry/>
<entry>
A ring of edges reporting a face on its exterior
is contained in different face.
</entry>
</row>
<row>
<entry>not-isolated node has not- containing_face</entry>
<entry>
Identifier of the ill-defined node.
</entry>
<entry/>
<entry>
A node which is reported as being on the boundary of one or more edges
is indicating a containing face.
</entry>
</row>
<row>
<entry>isolated node has containing_face</entry>
<entry>
Identifier of the ill-defined node.
</entry>
<entry/>
<entry>
A node which is not reported as being on the boundary of any edges
is lacking the indication of a containing face.
</entry>
</row>
<row>
<entry>isolated node has wrong containing_face</entry>
<entry>
Identifier of the misrepresented node.
</entry>
<entry/>
<entry>
A node which is not reported as being on the boundary of any edges
indicates a containing face which is not the actual face containing it.
See <xref linkend="GetFaceContainingPoint"/>.
</entry>
</row>
<row>
<entry>invalid next_right_edge</entry>
<entry>
Identifier of the misrepresented edge.
</entry>
<entry>
Signed id of the edge which should be indicated as the next right edge.
</entry>
<entry>
The edge indicated as the next edge encountered walking on the right
side of an edge is wrong.
</entry>
</row>
<row>
<entry>invalid next_left_edge</entry>
<entry>
Identifier of the misrepresented edge.
</entry>
<entry>
Signed id of the edge which should be indicated as the next left edge.
</entry>
<entry>
The edge indicated as the next edge encountered walking on the
left side of an edge is wrong.
</entry>
</row>
<row>
<entry>mixed face labeling in ring</entry>
<entry>
Signed identifier of an edge, identifying the ring.
See <xref linkend="GetRingEdges"/>.
</entry>
<entry/>
<entry>
Edges in a ring indicate conflicting faces on the walking side.
This is also known as a "Side Location Conflict".
</entry>
</row>
<row>
<entry>non-closed ring</entry>
<entry>
Signed identifier of an edge, identifying the ring.
See <xref linkend="GetRingEdges"/>.
</entry>
<entry/>
<entry>
A ring of edges formed by following next_left_edge/next_right_edge
attributes starts and ends on different nodes.
</entry>
</row>
<row>
<entry>face has multiple shells</entry>
<entry>
Identifier of the contended face.
</entry>
<entry>
Signed identifier of an edge, identifying the ring.
See <xref linkend="GetRingEdges"/>.
</entry>
<entry>
More than a one ring of edges indicate the same face on its interior.
</entry>
</row>
</tbody>
</tgroup>
</informaltable>
<!-- use this format if new function -->
<para role="availability" conformance="1.0.0">Availability: 1.0.0</para>
<!-- use this format if not a new function but functionality enhanced -->
<para role="enhanced" conformance="2.0.0">Enhanced: 2.0.0 more efficient edge crossing detection and fixes for false positives that were existent in prior versions.</para>
<para role="changed" conformance="2.2.0">Changed: 2.2.0 values for id1 and id2 were swapped for 'edge crosses node' to be consistent with error description.</para>
<para role="changed" conformance="3.2.0">Changed: 3.2.0 added optional bbox parameter, perform face labeling and edge linking checks.</para>
</refsection>
<refsection>
<title>Examples</title>
<programlisting>SELECT * FROM topology.ValidateTopology('ma_topo');
error | id1 | id2
-------------------+-----+-----
face without edges | 1 |
</programlisting>
</refsection>
<!-- Optionally add a "See Also" section -->
<refsection>
<title>See Also</title>
<para><xref linkend="validatetopology_returntype"/>, <xref linkend="Topology_Load_Tiger"/></para>
</refsection>
</refentry>
<refentry xml:id="ValidateTopologyRelation">
<refnamediv>
<refname>ValidateTopologyRelation</refname>
<refpurpose>Returns info about invalid topology relation records</refpurpose>
</refnamediv>
<refsynopsisdiv>
<funcsynopsis>
<funcprototype>
<funcdef>setof record <function>ValidateTopologyRelation</function></funcdef>
<paramdef><type>varchar </type> <parameter>toponame</parameter></paramdef>
</funcprototype>
</funcsynopsis>
</refsynopsisdiv>
<refsection>
<title>Description</title>
<para>
Returns a set records giving information about invalidities in the
relation table of the topology.
</para>
<!-- use this format if new function -->
<para role="availability" conformance="3.2.0">Availability: 3.2.0</para>
</refsection>
<!-- Optionally add a "See Also" section -->
<refsection>
<title>See Also</title>
<para><xref linkend="ValidateTopology"/></para>
</refsection>
</refentry>
<refentry xml:id="FindTopology">
<refnamediv>
<refname>FindTopology</refname>
<refpurpose>Returns a topology record by different means.</refpurpose>
</refnamediv>
<refsynopsisdiv>
<funcsynopsis>
<funcprototype>
<funcdef>topology <function>FindTopology</function></funcdef>
<paramdef><type>TopoGeometry</type> <parameter>topogeom</parameter></paramdef>
</funcprototype>
<funcprototype>
<funcdef>topology <function>FindTopology</function></funcdef>
<paramdef><type>regclass</type> <parameter>layerTable</parameter></paramdef>
<paramdef><type>name</type> <parameter>layerColumn</parameter></paramdef>
</funcprototype>
<funcprototype>
<funcdef>topology <function>FindTopology</function></funcdef>
<paramdef><type>name</type> <parameter>layerSchema</parameter></paramdef>
<paramdef><type>name</type> <parameter>layerTable</parameter></paramdef>
<paramdef><type>name</type> <parameter>layerColumn</parameter></paramdef>
</funcprototype>
<funcprototype>
<funcdef>topology <function>FindTopology</function></funcdef>
<paramdef><type>text</type> <parameter>topoName</parameter></paramdef>
</funcprototype>
<funcprototype>
<funcdef>topology <function>FindTopology</function></funcdef>
<paramdef><type>int</type> <parameter>id</parameter></paramdef>
</funcprototype>
</funcsynopsis>
</refsynopsisdiv>
<refsection>
<title>Description</title>
<para>Takes a topology identifier or the identifier of
a topology-related object and returns a topology.topology record.</para>
<!-- use this format if new function -->
<para role="availability" conformance="3.2.0">Availability: 3.2.0</para>
</refsection>
<refsection>
<title>Examples</title>
<programlisting>
SELECT name(findTopology('features.land_parcels', 'feature'));
name
-----------
city_data
(1 row)
</programlisting>
</refsection>
<!-- Optionally add a "See Also" section -->
<!-- Optionally add a "See Also" section -->
<refsection>
<title>See Also</title>
<para><xref linkend="FindLayer"/></para>
</refsection>
</refentry>
<refentry xml:id="FindLayer">
<refnamediv>
<refname>FindLayer</refname>
<refpurpose>Returns a topology.layer record by different means.</refpurpose>
</refnamediv>
<refsynopsisdiv>
<funcsynopsis>
<funcprototype>
<funcdef>topology.layer <function>FindLayer</function></funcdef>
<paramdef><type>TopoGeometry</type> <parameter>tg</parameter></paramdef>
</funcprototype>
<funcprototype>
<funcdef>topology.layer <function>FindLayer</function></funcdef>
<paramdef><type>regclass</type> <parameter>layer_table</parameter></paramdef>
<paramdef><type>name</type> <parameter>feature_column</parameter></paramdef>
</funcprototype>
<funcprototype>
<funcdef>topology.layer <function>FindLayer</function></funcdef>
<paramdef><type>name</type> <parameter>schema_name</parameter></paramdef>
<paramdef><type>name</type> <parameter>table_name</parameter></paramdef>
<paramdef><type>name</type> <parameter>feature_column</parameter></paramdef>
</funcprototype>
<funcprototype>
<funcdef>topology.layer <function>FindLayer</function></funcdef>
<paramdef><type>integer</type> <parameter>topology_id</parameter></paramdef>
<paramdef><type>integer</type> <parameter>layer_id</parameter></paramdef>
</funcprototype>
</funcsynopsis>
</refsynopsisdiv>
<refsection>
<title>Description</title>
<para>Takes a layer identifier or the identifier of
a topology-related object and returns a topology.layer record.</para>
<!-- use this format if new function -->
<para role="availability" conformance="3.2.0">Availability: 3.2.0</para>
</refsection>
<refsection>
<title>Examples</title>
<programlisting>
SELECT layer_id(findLayer('features.land_parcels', 'feature'));
layer_id
----------
1
(1 row)
</programlisting>
</refsection>
<!-- Optionally add a "See Also" section -->
<refsection>
<title>See Also</title>
<para><xref linkend="FindTopology"/></para>
</refsection>
</refentry>
</section>
<section xml:id="Topology_StatsManagement" xreflabel="maintaining statistics during topology editing and population">
<title>Topology Statistics Management</title><info>
<abstract>
<para>
This section discusses management of database statistics during
topology building.
</para>
</abstract>
</info>
<para>
Adding elements to a topology triggers many database queries for
finding existing edges that will be split, adding nodes and
updating edges that will node with the new linework. For this reason
it is useful that statistics about the data in the topology tables
are up-to-date.
</para>
<para>
PostGIS Topology population and editing functions do not automatically
update the statistics because a updating stats after each and every
change in a topology would be overkill, so it is the caller's duty
to take care of that.
</para>
<note>
<para>
That the statistics updated by autovacuum
will NOT be visible to transactions which started before autovacuum
process completed, so long-running transactions will need to run
ANALYZE themselves, to use updated statistics.
</para>
</note>
</section>
<section xml:id="Topology_Constructors">
<title>Topology Constructors</title><info>
<abstract>
<para>This section covers the topology functions for creating new topologies.</para>
</abstract>
</info>
<refentry xml:id="CreateTopology">
<refnamediv>
<refname>CreateTopology</refname>
<refpurpose>Creates a new topology schema and registers it in the topology.topology table.</refpurpose>
</refnamediv>
<refsynopsisdiv>
<funcsynopsis>
<funcprototype>
<funcdef>integer <function>CreateTopology</function></funcdef>
<paramdef><type>varchar </type> <parameter>topology_schema_name</parameter></paramdef>
</funcprototype>
<funcprototype>
<funcdef>integer <function>CreateTopology</function></funcdef>
<paramdef><type>varchar </type> <parameter>topology_schema_name</parameter></paramdef>
<paramdef><type>integer </type> <parameter>srid</parameter></paramdef>
</funcprototype>
<funcprototype>
<funcdef>integer <function>CreateTopology</function></funcdef>
<paramdef><type>varchar </type> <parameter>topology_schema_name</parameter></paramdef>
<paramdef><type>integer </type> <parameter>srid</parameter></paramdef>
<paramdef><type>double precision </type> <parameter>prec</parameter></paramdef>
</funcprototype>
<funcprototype>
<funcdef>integer <function>CreateTopology</function></funcdef>
<paramdef><type>varchar </type> <parameter>topology_schema_name</parameter></paramdef>
<paramdef><type>integer </type> <parameter>srid</parameter></paramdef>
<paramdef><type>double precision </type> <parameter>prec</parameter></paramdef>
<paramdef><type>boolean </type> <parameter>hasz</parameter></paramdef>
</funcprototype>
</funcsynopsis>
</refsynopsisdiv>
<refsection>
<title>Description</title>
<para>Creates a new topology schema with name <varname>topology_name</varname>
and registers it in the <varname>topology.topology</varname> table.
Topologies must be uniquely named.
The topology tables (<varname>edge_data</varname>, <varname>face</varname>, <varname>node</varname>,and <varname>relation</varname> are created in the schema.
It returns the id of the topology.
</para>
<para>The <varname>srid</varname> is the <link linkend="spatial_ref_sys">spatial reference system</link> SRID for the topology.
</para>
<para>The tolerance <varname>prec</varname> is measured in the units of the spatial reference system.
The tolerance defaults to 0.
</para>
<para><varname>hasz</varname> defaults to false if not specified. </para>
<para>This is similar to the SQL/MM <xref linkend="ST_InitTopoGeo"/> but has more functionality.</para>
<!-- use this format if new function -->
<para role="availability" conformance="1.1">Availability: 1.1</para>
<para role="enhanced" conformance="2.0">Enhanced: 2.0 added the signature accepting hasZ</para>
</refsection>
<refsection>
<title>Examples</title>
<para>Create a topology schema called <varname>ma_topo</varname> that stores edges and nodes in Massachusetts State Plane-meters (SRID = 26986).
The tolerance represents 0.5 meters since the spatial reference system is meter-based.</para>
<programlisting>SELECT topology.CreateTopology('ma_topo', 26986, 0.5);</programlisting>
<para>Create a topology for Rhode Island called <varname>ri_topo</varname> in spatial reference system State Plane-feet (SRID = 3438)</para>
<programlisting>SELECT topology.CreateTopology('ri_topo', 3438) AS topoid;
topoid
------
2</programlisting>
</refsection>
<!-- Optionally add a "See Also" section -->
<refsection>
<title>See Also</title>
<para><xref linkend="spatial_ref_sys"/>, <xref linkend="ST_InitTopoGeo"/>, <xref linkend="Topology_Load_Tiger"/></para>
</refsection>
</refentry>
<refentry xml:id="CopyTopology">
<refnamediv>
<refname>CopyTopology</refname>
<refpurpose>Makes a copy of a topology (nodes, edges, faces, layers and TopoGeometries) into a new schema</refpurpose>
</refnamediv>
<refsynopsisdiv>
<funcsynopsis>
<funcprototype>
<funcdef>integer <function>CopyTopology</function></funcdef>
<paramdef><type>varchar </type> <parameter>existing_topology_name</parameter></paramdef>
<paramdef><type>varchar </type> <parameter>new_name</parameter></paramdef>
</funcprototype>
</funcsynopsis>
</refsynopsisdiv>
<refsection>
<title>Description</title>
<para>
Creates a new topology with name <varname>new_name</varname>, with SRID and precision copied from <varname>existing_topology_name</varname>
The nodes, edges and faces in <varname>existing_topology_name</varname> are copied into the new topology,
as well as Layers and their associated TopoGeometries.
</para>
<note><para>
The new rows in the <varname>topology.layer</varname> table contain synthetic values for schema_name, table_name and feature_column.
This is because the TopoGeometry objects exist only as a definition and are not yet available in a user-defined table.
</para></note>
<!-- use this format if new function -->
<para role="availability" conformance="2.0.0">Availability: 2.0.0</para>
</refsection>
<refsection>
<title>Examples</title>
<para>
Make a backup of a topology called <varname>ma_topo</varname>.
</para>
<programlisting>SELECT topology.CopyTopology('ma_topo', 'ma_topo_backup');</programlisting>
</refsection>
<!-- Optionally add a "See Also" section -->
<refsection>
<title>See Also</title>
<para>
<xref linkend="spatial_ref_sys"/>,
<xref linkend="CreateTopology"/>,
<xref linkend="RenameTopology"/>
</para>
</refsection>
</refentry>
<refentry xml:id="ST_InitTopoGeo">
<refnamediv>
<refname>ST_InitTopoGeo</refname>
<refpurpose>Creates a new topology schema and registers it in the topology.topology table.</refpurpose>
</refnamediv>
<refsynopsisdiv>
<funcsynopsis>
<funcprototype>
<funcdef>text <function>ST_InitTopoGeo</function></funcdef>
<paramdef><type>varchar </type> <parameter>topology_schema_name</parameter></paramdef>
</funcprototype>
</funcsynopsis>
</refsynopsisdiv>
<refsection>
<title>Description</title>
<para>This is the SQL-MM equivalent of <xref linkend="CreateTopology"/>.
It lacks options for spatial reference system and tolerance.
it returns a text description of the topology creation, instead of the topology id.</para>
<!-- use this format if new function -->
<para role="availability" conformance="1.1">Availability: 1.1</para>
<para>&sqlmm_compliant; SQL-MM 3 Topo-Geo and Topo-Net 3: Routine Details: X.3.17</para>
</refsection>
<refsection>
<title>Examples</title>
<programlisting>SELECT topology.ST_InitTopoGeo('topo_schema_to_create') AS topocreation;
astopocreation
------------------------------------------------------------
Topology-Geometry 'topo_schema_to_create' (id:7) created.
</programlisting>
</refsection>
<!-- Optionally add a "See Also" section -->
<refsection>
<title>See Also</title>
<para><xref linkend="CreateTopology"/></para>
</refsection>
</refentry>
<refentry xml:id="ST_CreateTopoGeo">
<refnamediv>
<refname>ST_CreateTopoGeo</refname>
<refpurpose>
Adds a collection of geometries to a given empty topology and returns a message detailing success.
</refpurpose>
</refnamediv>
<refsynopsisdiv>
<funcsynopsis>
<funcprototype>
<funcdef>text <function>ST_CreateTopoGeo</function></funcdef>
<paramdef><type>varchar </type> <parameter>atopology</parameter></paramdef>
<paramdef><type>geometry </type> <parameter>acollection</parameter></paramdef>
</funcprototype>
</funcsynopsis>
</refsynopsisdiv>
<refsection>
<title>Description</title>
<para>
Adds a collection of geometries to a given empty topology and returns a message detailing success.
</para>
<para>Useful for populating an empty topology.</para>
<!-- use this format if new function -->
<para role="availability" conformance="2.0">Availability: 2.0 </para>
<para>&sqlmm_compliant; SQL-MM: Topo-Geo and Topo-Net 3: Routine Details -- X.3.18</para>
</refsection>
<refsection>
<title>Examples</title>
<programlisting>
-- Populate topology --
SELECT topology.ST_CreateTopoGeo('ri_topo',
ST_GeomFromText('MULTILINESTRING((384744 236928,384750 236923,384769 236911,384799 236895,384811 236890,384833 236884,
384844 236882,384866 236881,384879 236883,384954 236898,385087 236932,385117 236938,
385167 236938,385203 236941,385224 236946,385233 236950,385241 236956,385254 236971,
385260 236979,385268 236999,385273 237018,385273 237037,385271 237047,385267 237057,
385225 237125,385210 237144,385192 237161,385167 237192,385162 237202,385159 237214,
385159 237227,385162 237241,385166 237256,385196 237324,385209 237345,385234 237375,
385237 237383,385238 237399,385236 237407,385227 237419,385213 237430,385193 237439,
385174 237451,385170 237455,385169 237460,385171 237475,385181 237503,385190 237521,
385200 237533,385206 237538,385213 237541,385221 237542,385235 237540,385242 237541,
385249 237544,385260 237555,385270 237570,385289 237584,385292 237589,385291 237596,385284 237630))',3438)
);
st_createtopogeo
----------------------------
Topology ri_topo populated
-- create tables and topo geometries --
CREATE TABLE ri.roads(gid serial PRIMARY KEY, road_name text);
SELECT topology.AddTopoGeometryColumn('ri_topo', 'ri', 'roads', 'topo', 'LINE');
</programlisting>
</refsection>
<!-- Optionally add a "See Also" section -->
<refsection>
<title>See Also</title>
<para>
<xref linkend="TopoGeo_LoadGeometry"/>,
<xref linkend="AddTopoGeometryColumn"/>,
<xref linkend="CreateTopology"/>,
<xref linkend="DropTopology"/>
</para>
</refsection>
</refentry>
<refentry xml:id="TopoGeo_AddPoint">
<refnamediv>
<refname>TopoGeo_AddPoint</refname>
<refpurpose>
Adds a point to an existing topology using a tolerance and possibly splitting an existing edge.
</refpurpose>
</refnamediv>
<refsynopsisdiv>
<funcsynopsis>
<funcprototype>
<funcdef>integer <function>TopoGeo_AddPoint</function></funcdef>
<paramdef><type>varchar </type> <parameter>atopology</parameter></paramdef>
<paramdef><type>geometry </type> <parameter>apoint</parameter></paramdef>
<paramdef choice="opt"><type>float8 </type> <parameter>tolerance</parameter></paramdef>
</funcprototype>
</funcsynopsis>
</refsynopsisdiv>
<refsection>
<title>Description</title>
<para>
Adds a point to an existing topology and returns its identifier.
The given point will snap to existing nodes or edges within given tolerance.
An existing edge may be split by the snapped point.
</para>
<!-- use this format if new function -->
<para role="availability" conformance="2.0.0">Availability: 2.0.0</para>
</refsection>
<!-- Optionally add a "See Also" section -->
<refsection>
<title>See Also</title>
<para>
<xref linkend="TopoGeo_AddLineString"/>,
<xref linkend="TopoGeo_AddPolygon"/>,
<xref linkend="TopoGeo_LoadGeometry"/>,
<xref linkend="AddNode"/>,
<xref linkend="CreateTopology"/>
</para>
</refsection>
</refentry>
<refentry xml:id="TopoGeo_AddLineString">
<refnamediv>
<refname>TopoGeo_AddLineString</refname>
<refpurpose>
Adds a linestring to an existing topology using a tolerance and possibly splitting existing edges/faces.
</refpurpose>
</refnamediv>
<refsynopsisdiv>
<funcsynopsis>
<funcprototype>
<funcdef>SETOF integer <function>TopoGeo_AddLineString</function></funcdef>
<paramdef><type>varchar </type> <parameter>atopology</parameter></paramdef>
<paramdef><type>geometry </type> <parameter>aline</parameter></paramdef>
<paramdef choice="opt"><type>float8 </type> <parameter>tolerance</parameter></paramdef>
</funcprototype>
</funcsynopsis>
</refsynopsisdiv>
<refsection>
<title>Description</title>
<para>
Adds a linestring to an existing topology and returns a set of signed edge identifiers forming it up
(negative identifies mean the edge goes in the opposite direction of
the input linestring).
The given line will snap to existing nodes or edges within given tolerance.
Existing edges and faces may be split by the line. New nodes and faces may be added.
</para>
<note><para>
Updating statistics about topologies being loaded via this function is
up to caller, see <xref linkend="Topology_StatsManagement"/>.
</para></note>
<!-- use this format if new function -->
<para role="availability" conformance="2.0.0">Availability: 2.0.0</para>
<para role="enhanced" conformance="3.2.0">Enhanced: 3.2.0 added support for returning signed identifier.</para>
</refsection>
<!-- Optionally add a "See Also" section -->
<refsection>
<title>See Also</title>
<para>
<xref linkend="TopoGeo_AddPoint"/>,
<xref linkend="TopoGeo_AddPolygon"/>,
<xref linkend="TopoGeo_LoadGeometry"/>,
<xref linkend="AddEdge"/>,
<xref linkend="CreateTopology"/>
</para>
</refsection>
</refentry>
<refentry xml:id="TopoGeo_AddPolygon">
<refnamediv>
<refname>TopoGeo_AddPolygon</refname>
<refpurpose>Adds a polygon to an existing topology using a tolerance and possibly splitting existing edges/faces. Returns face identifiers.</refpurpose>
</refnamediv>
<refsynopsisdiv>
<funcsynopsis>
<funcprototype>
<funcdef>SETOF integer <function>TopoGeo_AddPolygon</function></funcdef>
<paramdef><type>varchar </type> <parameter>atopology</parameter></paramdef>
<paramdef><type>geometry </type> <parameter>apoly</parameter></paramdef>
<paramdef choice="opt"><type>float8 </type> <parameter>tolerance</parameter></paramdef>
</funcprototype>
</funcsynopsis>
</refsynopsisdiv>
<refsection>
<title>Description</title>
<para>
Adds a polygon to an existing topology and returns a set of face identifiers forming it up.
The boundary of the given polygon will snap to existing nodes or edges within given tolerance.
Existing edges and faces may be split by the boundary of the new polygon.
</para>
<note><para>
Updating statistics about topologies being loaded via this function is
up to caller, see <xref linkend="Topology_StatsManagement"/>.
</para></note>
<!-- use this format if new function -->
<para role="availability" conformance="2.0.0">Availability: 2.0.0</para>
</refsection>
<!-- Optionally add a "See Also" section -->
<refsection>
<title>See Also</title>
<para>
<xref linkend="TopoGeo_AddPoint"/>,
<xref linkend="TopoGeo_AddLineString"/>,
<xref linkend="TopoGeo_LoadGeometry"/>,
<xref linkend="AddFace"/>,
<xref linkend="CreateTopology"/>
</para>
</refsection>
</refentry>
<refentry xml:id="TopoGeo_LoadGeometry">
<refnamediv>
<refname>TopoGeo_LoadGeometry</refname>
<refpurpose>Load a geometry into an existing topology, snapping and splitting as needed.</refpurpose>
</refnamediv>
<refsynopsisdiv>
<funcsynopsis>
<funcprototype>
<funcdef>void <function>TopoGeo_LoadGeometry</function></funcdef>
<paramdef><type>varchar </type> <parameter>atopology</parameter></paramdef>
<paramdef><type>geometry </type> <parameter>ageom</parameter></paramdef>
<paramdef choice="opt"><type>float8 </type> <parameter>tolerance</parameter></paramdef>
</funcprototype>
</funcsynopsis>
</refsynopsisdiv>
<refsection>
<title>Description</title>
<para>
Loads a geometry into an existing topology.
The given geometry will snap to existing nodes or edges within given tolerance.
Existing edges and faces may be split as a consequence of the load.
</para>
<note><para>
Updating statistics about topologies being loaded via this function is
up to caller, see <xref linkend="Topology_StatsManagement"/>.
</para></note>
<!-- use this format if new function -->
<para role="availability" conformance="3.5.0">Availability: 3.5.0</para>
</refsection>
<!-- Optionally add a "See Also" section -->
<refsection>
<title>See Also</title>
<para>
<xref linkend="TopoGeo_AddPoint"/>,
<xref linkend="TopoGeo_AddLineString"/>,
<xref linkend="TopoGeo_AddPolygon"/>,
<xref linkend="CreateTopology"/>
</para>
</refsection>
</refentry>
</section>
<section xml:id="Topology_Editing">
<title>Topology Editors</title><info>
<abstract>
<para>This section covers topology functions for adding, moving, deleting, and splitting edges, faces, and nodes. All of these functions are defined by ISO SQL/MM.</para>
</abstract>
</info>
<refentry xml:id="ST_AddIsoNode">
<refnamediv>
<refname>ST_AddIsoNode</refname>
<refpurpose>Adds an isolated node to a face in a topology and returns the nodeid of the new node. If face is null, the node is still created.</refpurpose>
</refnamediv>
<refsynopsisdiv>
<funcsynopsis>
<funcprototype>
<funcdef>integer <function>ST_AddIsoNode</function></funcdef>
<paramdef><type>varchar </type> <parameter>atopology</parameter></paramdef>
<paramdef><type>integer </type> <parameter>aface</parameter></paramdef>
<paramdef><type>geometry </type> <parameter>apoint</parameter></paramdef>
</funcprototype>
</funcsynopsis>
</refsynopsisdiv>
<refsection>
<title>Description</title>
<para>Adds an isolated node with point location <varname>apoint</varname> to an existing face with faceid <varname>aface</varname> to a topology <varname>atopology</varname> and returns the nodeid of the new node.</para>
<para>If the spatial reference system (srid) of the point geometry is not the same as the topology, the <varname>apoint</varname> is not a point geometry, the point is null, or the point intersects an existing edge
(even at the boundaries) then an exception is thrown. If the point already exists as a node, an exception is thrown.</para>
<para>If <varname>aface</varname> is not null and the <varname>apoint</varname> is not within the face, then an exception is thrown.</para>
<!-- use this format if new function -->
<para role="availability" conformance="1.1">Availability: 1.1 </para>
<para>&sqlmm_compliant; SQL-MM: Topo-Net Routines: X+1.3.1</para>
</refsection>
<refsection>
<title>Examples</title>
<para/>
<!-- TODO -->
</refsection>
<!-- Optionally add a "See Also" section -->
<refsection>
<title>See Also</title>
<para><xref linkend="AddNode"/>, <xref linkend="CreateTopology"/>, <xref linkend="DropTopology"/>, <xref linkend="ST_Intersects"/></para>
</refsection>
</refentry>
<refentry xml:id="ST_AddIsoEdge">
<refnamediv>
<refname>ST_AddIsoEdge</refname>
<refpurpose>Adds an isolated edge defined by geometry <varname>alinestring</varname> to a topology connecting two existing isolated nodes <varname>anode</varname> and <varname>anothernode</varname> and returns the edge id of the new edge.</refpurpose>
</refnamediv>
<refsynopsisdiv>
<funcsynopsis>
<funcprototype>
<funcdef>integer <function>ST_AddIsoEdge</function></funcdef>
<paramdef><type>varchar </type> <parameter>atopology</parameter></paramdef>
<paramdef><type>integer </type> <parameter>anode</parameter></paramdef>
<paramdef><type>integer </type> <parameter>anothernode</parameter></paramdef>
<paramdef><type>geometry </type> <parameter>alinestring</parameter></paramdef>
</funcprototype>
</funcsynopsis>
</refsynopsisdiv>
<refsection>
<title>Description</title>
<para>Adds an isolated edge defined by geometry <varname>alinestring</varname> to a topology connecting two existing isolated nodes <varname>anode</varname> and <varname>anothernode</varname> and returns the edge id of the new edge.</para>
<para>If the spatial reference system (srid) of the <varname>alinestring</varname> geometry is not the same as the topology, any of the input arguments are null, or the nodes are contained in more than one face, or the nodes are start or end nodes of an existing edge,
then an exception is thrown.</para>
<para>If the <varname>alinestring</varname> is not within the face of the face the <varname>anode</varname> and <varname>anothernode</varname> belong to, then an exception is thrown.</para>
<para>If the <varname>anode</varname> and <varname>anothernode</varname> are not the start and end points of the <varname>alinestring</varname> then an exception is thrown.</para>
<!-- use this format if new function -->
<para role="availability" conformance="1.1">Availability: 1.1 </para>
<para>&sqlmm_compliant; SQL-MM: Topo-Geo and Topo-Net 3: Routine Details: X.3.4</para>
</refsection>
<refsection>
<title>Examples</title>
<para/>
<!-- TODO -->
</refsection>
<!-- Optionally add a "See Also" section -->
<refsection>
<title>See Also</title>
<para><xref linkend="ST_AddIsoNode"/>, <xref linkend="ST_IsSimple"/>, <xref linkend="ST_Within"/></para>
</refsection>
</refentry>
<refentry xml:id="ST_AddEdgeNewFaces">
<refnamediv>
<refname>ST_AddEdgeNewFaces</refname>
<refpurpose>Add a new edge and, if in doing so it splits a face, delete the original face and replace it with two new faces.</refpurpose>
</refnamediv>
<refsynopsisdiv>
<funcsynopsis>
<funcprototype>
<funcdef>integer <function>ST_AddEdgeNewFaces</function></funcdef>
<paramdef><type>varchar </type> <parameter>atopology</parameter></paramdef>
<paramdef><type>integer </type> <parameter>anode</parameter></paramdef>
<paramdef><type>integer </type> <parameter>anothernode</parameter></paramdef>
<paramdef><type>geometry </type> <parameter>acurve</parameter></paramdef>
</funcprototype>
</funcsynopsis>
</refsynopsisdiv>
<refsection>
<title>Description</title>
<para>
Add a new edge and, if in doing so it splits a face, delete the original
face and replace it with two new faces.
Returns the id of the newly added edge.
</para>
<para>
Updates all existing joined edges and relationships accordingly.
</para>
<para>If any arguments are null, the given nodes are unknown (must already exist in the <varname>node</varname> table of the topology schema) ,
the <varname>acurve</varname> is not a <varname>LINESTRING</varname>, the <varname>anode</varname> and <varname>anothernode</varname> are not the start
and endpoints of <varname>acurve</varname> then an error is thrown.</para>
<para>If the spatial reference system (srid) of the <varname>acurve</varname> geometry is not the same as the topology an exception is thrown.</para>
<!-- use this format if new function -->
<para role="availability" conformance="2.0">Availability: 2.0 </para>
<para>&sqlmm_compliant; SQL-MM: Topo-Geo and Topo-Net 3: Routine Details: X.3.12</para>
</refsection>
<refsection>
<title>Examples</title>
<para/>
<!--TODO: Need examples -->
</refsection>
<!-- Optionally add a "See Also" section -->
<refsection>
<title>See Also</title>
<para><xref linkend="ST_RemEdgeNewFace"/></para>
<para><xref linkend="ST_AddEdgeModFace"/></para>
</refsection>
</refentry>
<refentry xml:id="ST_AddEdgeModFace">
<refnamediv>
<refname>ST_AddEdgeModFace</refname>
<refpurpose>Add a new edge and, if in doing so it splits a face, modify the original face and add a new face.</refpurpose>
</refnamediv>
<refsynopsisdiv>
<funcsynopsis>
<funcprototype>
<funcdef>integer <function>ST_AddEdgeModFace</function></funcdef>
<paramdef><type>varchar </type> <parameter>atopology</parameter></paramdef>
<paramdef><type>integer </type> <parameter>anode</parameter></paramdef>
<paramdef><type>integer </type> <parameter>anothernode</parameter></paramdef>
<paramdef><type>geometry </type> <parameter>acurve</parameter></paramdef>
</funcprototype>
</funcsynopsis>
</refsynopsisdiv>
<refsection>
<title>Description</title>
<para>
Add a new edge and, if doing so splits a face, modify the original
face and add a new one.
</para>
<note><para>
If possible, the new face will be created on left side of the new edge.
This will not be possible if the face on the left side will need to
be the Universe face (unbounded).
</para></note>
<para>
Returns the id of the newly added edge.
</para>
<para>
Updates all existing joined edges and relationships accordingly.
</para>
<para>If any arguments are null, the given nodes are unknown (must already exist in the <varname>node</varname> table of the topology schema) ,
the <varname>acurve</varname> is not a <varname>LINESTRING</varname>, the <varname>anode</varname> and <varname>anothernode</varname> are not the start
and endpoints of <varname>acurve</varname> then an error is thrown.</para>
<para>If the spatial reference system (srid) of the <varname>acurve</varname> geometry is not the same as the topology an exception is thrown.</para>
<!-- use this format if new function -->
<para role="availability" conformance="2.0">Availability: 2.0 </para>
<para>&sqlmm_compliant; SQL-MM: Topo-Geo and Topo-Net 3: Routine Details: X.3.13</para>
</refsection>
<refsection>
<title>Examples</title>
<para/>
<!--TODO: Need examples -->
</refsection>
<!-- Optionally add a "See Also" section -->
<refsection>
<title>See Also</title>
<para><xref linkend="ST_RemEdgeModFace"/></para>
<para><xref linkend="ST_AddEdgeNewFaces"/></para>
</refsection>
</refentry>
<refentry xml:id="ST_RemEdgeNewFace">
<refnamediv>
<refname>ST_RemEdgeNewFace</refname>
<refpurpose>
Removes an edge and, if the removed edge separated two faces,
delete the original faces and replace them with a new face.
</refpurpose>
</refnamediv>
<refsynopsisdiv>
<funcsynopsis>
<funcprototype>
<funcdef>integer <function>ST_RemEdgeNewFace</function></funcdef>
<paramdef><type>varchar </type> <parameter>atopology</parameter></paramdef>
<paramdef><type>integer </type> <parameter>anedge</parameter></paramdef>
</funcprototype>
</funcsynopsis>
</refsynopsisdiv>
<refsection>
<title>Description</title>
<para>
Removes an edge and, if the removed edge separated two faces,
delete the original faces and replace them with a new face.
</para>
<para>
Returns the id of a newly created face or NULL, if no new face is created.
No new face is created when the removed edge is dangling or isolated or
confined with the universe face (possibly making the universe flood into
the face on the other side).
</para>
<para>
Updates all existing joined edges and relationships accordingly.
</para>
<para>
Refuses to remove an edge participating in the definition of an
existing TopoGeometry.
Refuses to heal two faces if any TopoGeometry is defined by only
one of them (and not the other).
</para>
<para>
If any arguments are null, the given edge is unknown (must already exist in
the <varname>edge</varname> table of the topology schema), the topology
name is invalid then an error is thrown.
</para>
<!-- use this format if new function -->
<para role="availability" conformance="2.0">Availability: 2.0 </para>
<para>&sqlmm_compliant; SQL-MM: Topo-Geo and Topo-Net 3: Routine Details: X.3.14</para>
</refsection>
<refsection>
<title>Examples</title>
<para/>
<!--TODO: Need examples -->
</refsection>
<!-- Optionally add a "See Also" section -->
<refsection>
<title>See Also</title>
<para><xref linkend="ST_RemEdgeModFace"/></para>
<para><xref linkend="ST_AddEdgeNewFaces"/></para>
</refsection>
</refentry>
<refentry xml:id="ST_RemEdgeModFace">
<refnamediv>
<refname>ST_RemEdgeModFace</refname>
<refpurpose>
Removes an edge, and if the edge separates two faces
deletes one face and modifies the other face to cover the space of both.
</refpurpose>
</refnamediv>
<refsynopsisdiv>
<funcsynopsis>
<funcprototype>
<funcdef>integer <function>ST_RemEdgeModFace</function></funcdef>
<paramdef><type>varchar </type> <parameter>atopology</parameter></paramdef>
<paramdef><type>integer </type> <parameter>anedge</parameter></paramdef>
</funcprototype>
</funcsynopsis>
</refsynopsisdiv>
<refsection>
<title>Description</title>
<para>
Removes an edge, and if the removed edge separates two faces
deletes one face and modifies the other face to cover the space of both.
Preferentially keeps the face on the right, to be consistent with
<xref linkend="ST_AddEdgeModFace"/>.
Returns the id of the face which is preserved.
</para>
<para>
Updates all existing joined edges and relationships accordingly.
</para>
<para>
Refuses to remove an edge participating in the definition of an
existing TopoGeometry.
Refuses to heal two faces if any TopoGeometry is defined by only
one of them (and not the other).
</para>
<para>
If any arguments are null, the given edge is unknown (must already exist in
the <varname>edge</varname> table of the topology schema), the topology
name is invalid then an error is thrown.
</para>
<!-- use this format if new function -->
<para role="availability" conformance="2.0">Availability: 2.0 </para>
<para>&sqlmm_compliant; SQL-MM: Topo-Geo and Topo-Net 3: Routine Details: X.3.15</para>
</refsection>
<refsection>
<title>Examples</title>
<para/>
<!--TODO: Need examples -->
</refsection>
<!-- Optionally add a "See Also" section -->
<refsection>
<title>See Also</title>
<para><xref linkend="ST_AddEdgeModFace"/></para>
<para><xref linkend="ST_RemEdgeNewFace"/></para>
</refsection>
</refentry>
<refentry xml:id="ST_ChangeEdgeGeom">
<refnamediv>
<refname>ST_ChangeEdgeGeom</refname>
<refpurpose>
Changes the shape of an edge without affecting the topology structure.
</refpurpose>
</refnamediv>
<refsynopsisdiv>
<funcsynopsis>
<funcprototype>
<funcdef>text <function>ST_ChangeEdgeGeom</function></funcdef>
<paramdef><type>varchar </type> <parameter>atopology</parameter></paramdef>
<paramdef><type>integer </type> <parameter>anedge</parameter></paramdef>
<paramdef><type>geometry </type> <parameter>acurve</parameter></paramdef>
</funcprototype>
</funcsynopsis>
</refsynopsisdiv>
<refsection>
<title>Description</title>
<para>
Changes the shape of an edge without affecting the topology structure.
</para>
<para>
If any arguments are null, the given edge does not exist in
the <varname>edge</varname> table of the topology schema, the
<varname>acurve</varname> is not a <varname>LINESTRING</varname>, or the modification would
change the underlying topology then an error is thrown.
</para>
<para>If the spatial reference system (srid) of the <varname>acurve</varname> geometry is not the same as the topology an exception is thrown.</para>
<para>If the new <varname>acurve</varname> is not simple, then an error is thrown.</para>
<para>
If moving the edge from old to new position would hit an obstacle then
an error is thrown.
</para>
<!-- use this format if new function -->
<para role="availability" conformance="1.1.0">Availability: 1.1.0</para>
<!-- use this format if not a new function but functionality enhanced -->
<para>
Enhanced: 2.0.0 adds topological consistency enforcement
</para>
<para>&sqlmm_compliant; SQL-MM: Topo-Geo and Topo-Net 3: Routine Details X.3.6</para>
</refsection>
<refsection>
<title>Examples</title>
<programlisting>SELECT topology.ST_ChangeEdgeGeom('ma_topo', 1,
ST_GeomFromText('LINESTRING(227591.9 893900.4,227622.6 893844.3,227641.6 893816.6, 227704.5 893778.5)', 26986) );
----
Edge 1 changed</programlisting>
</refsection>
<!-- Optionally add a "See Also" section -->
<refsection>
<title>See Also</title>
<para><xref linkend="ST_AddEdgeModFace"/></para>
<para><xref linkend="ST_RemEdgeModFace"/></para>
<para><xref linkend="ST_ModEdgeSplit"/></para>
</refsection>
</refentry>
<refentry xml:id="ST_ModEdgeSplit">
<refnamediv>
<refname>ST_ModEdgeSplit</refname>
<refpurpose>Split an edge by creating a new node along an existing edge, modifying the original edge and adding a new edge.</refpurpose>
</refnamediv>
<refsynopsisdiv>
<funcsynopsis>
<funcprototype>
<funcdef>integer <function>ST_ModEdgeSplit</function></funcdef>
<paramdef><type>varchar </type> <parameter>atopology</parameter></paramdef>
<paramdef><type>integer </type> <parameter>anedge</parameter></paramdef>
<paramdef><type>geometry </type> <parameter>apoint</parameter></paramdef>
</funcprototype>
</funcsynopsis>
</refsynopsisdiv>
<refsection>
<title>Description</title>
<para>
Split an edge by creating a new node along an existing edge,
modifying the original edge and adding a new edge.
Updates all existing joined edges and relationships accordingly.
Returns the identifier of the newly added node.
</para>
<!-- use this format if new function -->
<para role="availability" conformance="1.1">Availability: 1.1 </para>
<para role="changed" conformance="2.0">Changed: 2.0 - In prior versions, this was misnamed ST_ModEdgesSplit</para>
<para>&sqlmm_compliant; SQL-MM: Topo-Geo and Topo-Net 3: Routine Details: X.3.9</para>
</refsection>
<refsection>
<title>Examples</title>
<programlisting>
-- Add an edge --
SELECT topology.AddEdge('ma_topo', ST_GeomFromText('LINESTRING(227592 893910, 227600 893910)', 26986) ) As edgeid;
-- edgeid-
3
-- Split the edge --
SELECT topology.ST_ModEdgeSplit('ma_topo', 3, ST_SetSRID(ST_Point(227594,893910),26986) ) As node_id;
node_id
-------------------------
7
</programlisting>
</refsection>
<!-- Optionally add a "See Also" section -->
<refsection>
<title>See Also</title>
<para>
<xref linkend="ST_NewEdgesSplit"/>,
<xref linkend="ST_ModEdgeHeal"/>,
<xref linkend="ST_NewEdgeHeal"/>,
<xref linkend="AddEdge"/>
</para>
</refsection>
</refentry>
<refentry xml:id="ST_ModEdgeHeal">
<refnamediv>
<refname>ST_ModEdgeHeal</refname>
<refpurpose>
Heals two edges by deleting the node connecting them, modifying the first edge
and deleting the second edge. Returns the id of the deleted node.
</refpurpose>
</refnamediv>
<refsynopsisdiv>
<funcsynopsis>
<funcprototype>
<funcdef>int <function>ST_ModEdgeHeal</function></funcdef>
<paramdef><type>varchar </type> <parameter>atopology</parameter></paramdef>
<paramdef><type>integer </type> <parameter>anedge</parameter></paramdef>
<paramdef><type>integer </type> <parameter>anotheredge</parameter></paramdef>
</funcprototype>
</funcsynopsis>
</refsynopsisdiv>
<refsection>
<title>Description</title>
<para>
Heals two edges by deleting the node connecting them, modifying the first edge
and deleting the second edge.
Returns the id of the deleted node.
Updates all existing joined edges and relationships accordingly.
</para>
<!-- use this format if new function -->
<para role="availability" conformance="2.0">Availability: 2.0</para>
<para>&sqlmm_compliant; SQL-MM: Topo-Geo and Topo-Net 3: Routine Details: X.3.9</para>
</refsection>
<!-- Optionally add a "See Also" section -->
<refsection>
<title>See Also</title>
<para>
<xref linkend="ST_ModEdgeSplit"/>
<xref linkend="ST_NewEdgesSplit"/>
</para>
</refsection>
</refentry>
<refentry xml:id="ST_NewEdgeHeal">
<refnamediv>
<refname>ST_NewEdgeHeal</refname>
<refpurpose>
Heals two edges by deleting the node connecting them, deleting both edges,
and replacing them with an edge whose direction is the same as the first
edge provided.
</refpurpose>
</refnamediv>
<refsynopsisdiv>
<funcsynopsis>
<funcprototype>
<funcdef>int <function>ST_NewEdgeHeal</function></funcdef>
<paramdef><type>varchar </type> <parameter>atopology</parameter></paramdef>
<paramdef><type>integer </type> <parameter>anedge</parameter></paramdef>
<paramdef><type>integer </type> <parameter>anotheredge</parameter></paramdef>
</funcprototype>
</funcsynopsis>
</refsynopsisdiv>
<refsection>
<title>Description</title>
<para>
Heals two edges by deleting the node connecting them, deleting both edges,
and replacing them with an edge whose direction is the same as the first
edge provided.
Returns the id of the new edge replacing the healed ones.
Updates all existing joined edges and relationships accordingly.
</para>
<!-- use this format if new function -->
<para role="availability" conformance="2.0">Availability: 2.0</para>
<para>&sqlmm_compliant; SQL-MM: Topo-Geo and Topo-Net 3: Routine Details: X.3.9</para>
</refsection>
<!-- Optionally add a "See Also" section -->
<refsection>
<title>See Also</title>
<para>
<xref linkend="ST_ModEdgeHeal"/>
<xref linkend="ST_ModEdgeSplit"/>
<xref linkend="ST_NewEdgesSplit"/>
</para>
</refsection>
</refentry>
<refentry xml:id="ST_MoveIsoNode">
<refnamediv>
<refname>ST_MoveIsoNode</refname>
<refpurpose>Moves an isolated node in a topology from one point to another. If new <varname>apoint</varname> geometry exists as a node an error is thrown. Returns description of move.</refpurpose>
</refnamediv>
<refsynopsisdiv>
<funcsynopsis>
<funcprototype>
<funcdef>text <function>ST_MoveIsoNode</function></funcdef>
<paramdef><type>varchar </type> <parameter>atopology</parameter></paramdef>
<paramdef><type>integer </type> <parameter>anode</parameter></paramdef>
<paramdef><type>geometry </type> <parameter>apoint</parameter></paramdef>
</funcprototype>
</funcsynopsis>
</refsynopsisdiv>
<refsection>
<title>Description</title>
<para>Moves an isolated node in a topology from one point to another. If new <varname>apoint</varname> geometry exists as a node an error is thrown.</para>
<para>If any arguments are null, the
<varname>apoint</varname> is not a point, the existing node is not
isolated (is a start or end point of an existing edge), new node
location intersects an existing edge (even at the end points) or the
new location is in a different face (since 3.2.0) then an exception is thrown.
</para>
<para>If the spatial reference system (srid) of the point geometry is not the same as the topology an exception is thrown.</para>
<!-- use this format if new function -->
<para role="availability" conformance="2.0.0">Availability: 2.0.0 </para>
<para>
Enhanced: 3.2.0 ensures the nod cannot be moved in a different face
</para>
<para>&sqlmm_compliant; SQL-MM: Topo-Net Routines: X.3.2</para>
</refsection>
<refsection>
<title>Examples</title>
<programlisting>
-- Add an isolated node with no face --
SELECT topology.ST_AddIsoNode('ma_topo', NULL, ST_GeomFromText('POINT(227579 893916)', 26986) ) As nodeid;
nodeid
--------
7
-- Move the new node --
SELECT topology.ST_MoveIsoNode('ma_topo', 7, ST_GeomFromText('POINT(227579.5 893916.5)', 26986) ) As descrip;
descrip
----------------------------------------------------
Isolated Node 7 moved to location 227579.5,893916.5</programlisting>
</refsection>
<!-- Optionally add a "See Also" section -->
<refsection>
<title>See Also</title>
<para><xref linkend="ST_AddIsoNode"/></para>
</refsection>
</refentry>
<refentry xml:id="ST_NewEdgesSplit">
<refnamediv>
<refname>ST_NewEdgesSplit</refname>
<refpurpose>Split an edge by creating a new node along an existing edge, deleting the original edge and replacing it with two new edges. Returns the id of the new node created that joins the new edges.</refpurpose>
</refnamediv>
<refsynopsisdiv>
<funcsynopsis>
<funcprototype>
<funcdef>integer <function>ST_NewEdgesSplit</function></funcdef>
<paramdef><type>varchar </type> <parameter>atopology</parameter></paramdef>
<paramdef><type>integer </type> <parameter>anedge</parameter></paramdef>
<paramdef><type>geometry </type> <parameter>apoint</parameter></paramdef>
</funcprototype>
</funcsynopsis>
</refsynopsisdiv>
<refsection>
<title>Description</title>
<para>
Split an edge with edge id <varname>anedge</varname> by creating a
new node with point location <varname>apoint</varname> along current
edge, deleting the original edge and replacing it with two new edges.
Returns the id of the new node created that joins the new edges.
Updates all existing joined edges and relationships accordingly.
</para>
<para>If the spatial reference system (srid) of the point geometry is not the same as the topology, the <varname>apoint</varname> is not a point geometry, the point is null, the point already exists as a node, the edge does not correspond to an existing edge or the point is not within the edge then an exception is thrown.</para>
<!-- use this format if new function -->
<para role="availability" conformance="1.1">Availability: 1.1 </para>
<para>&sqlmm_compliant; SQL-MM: Topo-Net Routines: X.3.8</para>
</refsection>
<refsection>
<title>Examples</title>
<programlisting>
-- Add an edge --
SELECT topology.AddEdge('ma_topo', ST_GeomFromText('LINESTRING(227575 893917,227592 893900)', 26986) ) As edgeid;
-- result-
edgeid
------
2
-- Split the new edge --
SELECT topology.ST_NewEdgesSplit('ma_topo', 2, ST_GeomFromText('POINT(227578.5 893913.5)', 26986) ) As newnodeid;
newnodeid
---------
6</programlisting>
</refsection>
<!-- Optionally add a "See Also" section -->
<refsection>
<title>See Also</title>
<para>
<xref linkend="ST_ModEdgeSplit"/>
<xref linkend="ST_ModEdgeHeal"/>
<xref linkend="ST_NewEdgeHeal"/>
<xref linkend="AddEdge"/>
</para>
</refsection>
</refentry>
<refentry xml:id="ST_RemoveIsoNode">
<refnamediv>
<refname>ST_RemoveIsoNode</refname>
<refpurpose>Removes an isolated node and returns description of action. If the node is not isolated (is start or end of an edge), then an exception is thrown.</refpurpose>
</refnamediv>
<refsynopsisdiv>
<funcsynopsis>
<funcprototype>
<funcdef>text <function>ST_RemoveIsoNode</function></funcdef>
<paramdef><type>varchar </type> <parameter>atopology</parameter></paramdef>
<paramdef><type>integer </type> <parameter>anode</parameter></paramdef>
</funcprototype>
</funcsynopsis>
</refsynopsisdiv>
<refsection>
<title>Description</title>
<para>Removes an isolated node and returns description of action. If the node is not isolated (is start or end of an edge), then an exception is thrown.</para>
<!-- use this format if new function -->
<para role="availability" conformance="1.1">Availability: 1.1 </para>
<para>&sqlmm_compliant; SQL-MM: Topo-Geo and Topo-Net 3: Routine Details: X+1.3.3</para>
</refsection>
<refsection>
<title>Examples</title>
<programlisting>
-- Remove an isolated node with no face --
SELECT topology.ST_RemoveIsoNode('ma_topo', 7 ) As result;
result
-------------------------
Isolated node 7 removed
</programlisting>
</refsection>
<!-- Optionally add a "See Also" section -->
<refsection>
<title>See Also</title>
<para><xref linkend="ST_AddIsoNode"/></para>
</refsection>
</refentry>
<refentry xml:id="ST_RemoveIsoEdge">
<refnamediv>
<refname>ST_RemoveIsoEdge</refname>
<refpurpose>Removes an isolated edge and returns description of action. If the edge is not isolated, then an exception is thrown.</refpurpose>
</refnamediv>
<refsynopsisdiv>
<funcsynopsis>
<funcprototype>
<funcdef>text <function>ST_RemoveIsoEdge</function></funcdef>
<paramdef><type>varchar </type> <parameter>atopology</parameter></paramdef>
<paramdef><type>integer </type> <parameter>anedge</parameter></paramdef>
</funcprototype>
</funcsynopsis>
</refsynopsisdiv>
<refsection>
<title>Description</title>
<para>Removes an isolated edge and returns description of action. If the edge is not isolated, then an exception is thrown.</para>
<!-- use this format if new function -->
<para role="availability" conformance="1.1">Availability: 1.1 </para>
<para>&sqlmm_compliant; SQL-MM: Topo-Geo and Topo-Net 3: Routine Details: X+1.3.3</para>
</refsection>
<refsection>
<title>Examples</title>
<programlisting>
-- Remove an isolated node with no face --
SELECT topology.ST_RemoveIsoNode('ma_topo', 7 ) As result;
result
-------------------------
Isolated node 7 removed
</programlisting>
</refsection>
<!-- Optionally add a "See Also" section -->
<refsection>
<title>See Also</title>
<para><xref linkend="ST_AddIsoNode"/></para>
</refsection>
</refentry>
</section>
<section xml:id="Topology_Accessors">
<title>Topology Accessors</title>
<refentry xml:id="GetEdgeByPoint">
<refnamediv>
<refname>GetEdgeByPoint</refname>
<refpurpose>Finds the edge-id of an edge that intersects a given point.</refpurpose>
</refnamediv>
<refsynopsisdiv>
<funcsynopsis>
<funcprototype>
<funcdef>integer <function>GetEdgeByPoint</function></funcdef>
<paramdef><type>varchar </type> <parameter>atopology</parameter></paramdef>
<paramdef><type>geometry </type> <parameter>apoint</parameter></paramdef>
<paramdef><type>float8 </type> <parameter>tol1</parameter></paramdef>
</funcprototype>
</funcsynopsis>
</refsynopsisdiv>
<refsection>
<title>Description</title>
<para>Retrieves the id of an edge that intersects a Point.</para>
<para>The function returns an integer (id-edge) given a topology, a POINT and a tolerance. If tolerance = 0 then the point has to intersect the edge.</para>
<para>If <varname>apoint</varname> doesn't intersect an edge, returns 0 (zero).</para>
<para>If use tolerance > 0 and there is more than one edge near the point then an exception is thrown.</para>
<note>
<para>If tolerance = 0, the function uses ST_Intersects otherwise uses ST_DWithin.</para>
</note>
<para>Performed by the GEOS module.</para>
<para role="availability" conformance="2.0.0">Availability: 2.0.0</para>
</refsection>
<refsection>
<title>Examples</title>
<para>These examples use edges we created in <xref linkend="AddEdge"/></para>
<programlisting>SELECT topology.GetEdgeByPoint('ma_topo',geom, 1) As with1mtol, topology.GetEdgeByPoint('ma_topo',geom,0) As withnotol
FROM ST_GeomFromEWKT('SRID=26986;POINT(227622.6 893843)') As geom;
with1mtol | withnotol
-----------+-----------
2 | 0
</programlisting>
<programlisting>SELECT topology.GetEdgeByPoint('ma_topo',geom, 1) As nearnode
FROM ST_GeomFromEWKT('SRID=26986;POINT(227591.9 893900.4)') As geom;
-- get error --
ERROR: Two or more edges found</programlisting>
</refsection>
<!-- Optionally add a "See Also" section -->
<refsection>
<title>See Also</title>
<para>
<xref linkend="AddEdge"/>,
<xref linkend="GetNodeByPoint"/>,
<xref linkend="GetFaceByPoint"/>
</para>
</refsection>
</refentry>
<refentry xml:id="GetFaceByPoint">
<refnamediv>
<refname>GetFaceByPoint</refname>
<refpurpose>Finds face intersecting a given point.</refpurpose>
</refnamediv>
<refsynopsisdiv>
<funcsynopsis>
<funcprototype>
<funcdef>integer <function>GetFaceByPoint</function></funcdef>
<paramdef><type>varchar </type> <parameter>atopology</parameter></paramdef>
<paramdef><type>geometry </type> <parameter>apoint</parameter></paramdef>
<paramdef><type>float8 </type> <parameter>tol1</parameter></paramdef>
</funcprototype>
</funcsynopsis>
</refsynopsisdiv>
<refsection>
<title>Description</title>
<para>
Finds a face referenced by a Point, with given tolerance.
</para>
<para>
The function will effectively look for a face intersecting a
circle having the point as center and the tolerance as radius.
</para>
<para>
If no face intersects the given query location, 0 is returned (universal face).
</para>
<para>
If more than one face intersect the query location an exception is thrown.
</para>
<para role="availability" conformance="2.0.0">Availability: 2.0.0</para>
<para role="enhanced" conformance="3.2.0">Enhanced: 3.2.0 more efficient implementation and clearer contract, stops working with invalid topologies.</para>
</refsection>
<refsection>
<title>Examples</title>
<programlisting>SELECT topology.GetFaceByPoint('ma_topo',geom, 10) As with1mtol, topology.GetFaceByPoint('ma_topo',geom,0) As withnotol
FROM ST_GeomFromEWKT('POINT(234604.6 899382.0)') As geom;
with1mtol | withnotol
-----------+-----------
1 | 0</programlisting>
<programlisting>SELECT topology.GetFaceByPoint('ma_topo',geom, 1) As nearnode
FROM ST_GeomFromEWKT('POINT(227591.9 893900.4)') As geom;
-- get error --
ERROR: Two or more faces found</programlisting>
</refsection>
<!-- Optionally add a "See Also" section -->
<refsection>
<title>See Also</title>
<para>
<xref linkend="GetFaceContainingPoint"/>,
<xref linkend="AddFace"/>,
<xref linkend="GetNodeByPoint"/>,
<xref linkend="GetEdgeByPoint"/>
</para>
</refsection>
</refentry>
<refentry xml:id="GetFaceContainingPoint">
<refnamediv>
<refname>GetFaceContainingPoint</refname>
<refpurpose>Finds the face containing a point.</refpurpose>
</refnamediv>
<refsynopsisdiv>
<funcsynopsis>
<funcprototype>
<funcdef>integer <function>GetFaceContainingPoint</function></funcdef>
<paramdef><type>text </type> <parameter>atopology</parameter></paramdef>
<paramdef><type>geometry </type> <parameter>apoint</parameter></paramdef>
</funcprototype>
</funcsynopsis>
</refsynopsisdiv>
<refsection>
<title>Description</title>
<para>Returns the id of the face containing a point.</para>
<para>An exception is thrown if the point falls on a face boundary.</para>
<note>
<para>The function relies on a valid topology, using edge linking and face labeling.</para>
</note>
<para role="availability" conformance="3.2.0">Availability: 3.2.0</para>
</refsection>
<refsection>
<title>See Also</title>
<para>
<xref linkend="ST_GetFaceGeometry"/>
</para>
</refsection>
</refentry>
<refentry xml:id="GetNodeByPoint">
<refnamediv>
<refname>GetNodeByPoint</refname>
<refpurpose>Finds the node-id of a node at a point location.</refpurpose>
</refnamediv>
<refsynopsisdiv>
<funcsynopsis>
<funcprototype>
<funcdef>integer <function>GetNodeByPoint</function></funcdef>
<paramdef><type>varchar </type> <parameter>atopology</parameter></paramdef>
<paramdef><type>geometry </type> <parameter>apoint</parameter></paramdef>
<paramdef><type>float8 </type> <parameter>tol1</parameter></paramdef>
</funcprototype>
</funcsynopsis>
</refsynopsisdiv>
<refsection>
<title>Description</title>
<para>Retrieves the id of a node at a point location.</para>
<para>The function returns an integer (id-node) given a topology, a POINT and a tolerance. If tolerance = 0 means exact intersection, otherwise retrieves the node from an interval.</para>
<para>If <varname>apoint</varname> doesn't intersect a node, returns 0 (zero).</para>
<para>If use tolerance > 0 and there is more than one node near the point then an exception is thrown.</para>
<note>
<para>If tolerance = 0, the function uses ST_Intersects otherwise uses ST_DWithin.</para>
</note>
<para>Performed by the GEOS module.</para>
<para role="availability" conformance="2.0.0">Availability: 2.0.0</para>
</refsection>
<refsection>
<title>Examples</title>
<para>These examples use edges we created in <xref linkend="AddEdge"/></para>
<programlisting>SELECT topology.GetNodeByPoint('ma_topo',geom, 1) As nearnode
FROM ST_GeomFromEWKT('SRID=26986;POINT(227591.9 893900.4)') As geom;
nearnode
----------
2
</programlisting>
<programlisting>SELECT topology.GetNodeByPoint('ma_topo',geom, 1000) As too_much_tolerance
FROM ST_GeomFromEWKT('SRID=26986;POINT(227591.9 893900.4)') As geom;
----get error--
ERROR: Two or more nodes found
</programlisting>
</refsection>
<!-- Optionally add a "See Also" section -->
<refsection>
<title>See Also</title>
<para>
<xref linkend="AddEdge"/>,
<xref linkend="GetEdgeByPoint"/>,
<xref linkend="GetFaceByPoint"/>
</para>
</refsection>
</refentry>
<refentry xml:id="GetTopologyID">
<refnamediv>
<refname>GetTopologyID</refname>
<refpurpose>Returns the id of a topology in the topology.topology table given the name of the topology.</refpurpose>
</refnamediv>
<refsynopsisdiv>
<funcsynopsis>
<funcprototype>
<funcdef>integer <function>GetTopologyID</function></funcdef>
<paramdef><type>varchar</type> <parameter>toponame</parameter></paramdef>
</funcprototype>
</funcsynopsis>
</refsynopsisdiv>
<refsection>
<title>Description</title>
<para>Returns the id of a topology in the topology.topology table given the name of the topology.</para>
<!-- use this format if new function -->
<para role="availability" conformance="1.1">Availability: 1.1</para>
</refsection>
<refsection>
<title>Examples</title>
<programlisting>SELECT topology.GetTopologyID('ma_topo') As topo_id;
topo_id
---------
1</programlisting>
</refsection>
<!-- Optionally add a "See Also" section -->
<refsection>
<title>See Also</title>
<para>
<xref linkend="CreateTopology"/>,
<xref linkend="DropTopology"/>,
<xref linkend="GetTopologyName"/>,
<xref linkend="GetTopologySRID"/>
</para>
</refsection>
</refentry>
<refentry xml:id="GetTopologySRID">
<refnamediv>
<refname>GetTopologySRID</refname>
<refpurpose>Returns the SRID of a topology in the topology.topology table given the name of the topology.</refpurpose>
</refnamediv>
<refsynopsisdiv>
<funcsynopsis>
<funcprototype>
<funcdef>integer <function>GetTopologyID</function></funcdef>
<paramdef><type>varchar</type> <parameter>toponame</parameter></paramdef>
</funcprototype>
</funcsynopsis>
</refsynopsisdiv>
<refsection>
<title>Description</title>
<para>Returns the spatial reference id of a topology in the topology.topology table given the name of the topology.</para>
<!-- use this format if new function -->
<para role="availability" conformance="2.0.0">Availability: 2.0.0</para>
</refsection>
<refsection>
<title>Examples</title>
<programlisting>SELECT topology.GetTopologySRID('ma_topo') As SRID;
SRID
-------
4326</programlisting>
</refsection>
<!-- Optionally add a "See Also" section -->
<refsection>
<title>See Also</title>
<para>
<xref linkend="CreateTopology"/>,
<xref linkend="DropTopology"/>,
<xref linkend="GetTopologyName"/>,
<xref linkend="GetTopologyID"/>
</para>
</refsection>
</refentry>
<refentry xml:id="GetTopologyName">
<refnamediv>
<refname>GetTopologyName</refname>
<refpurpose>Returns the name of a topology (schema) given the id of the topology.</refpurpose>
</refnamediv>
<refsynopsisdiv>
<funcsynopsis>
<funcprototype>
<funcdef>varchar <function>GetTopologyName</function></funcdef>
<paramdef><type>integer</type> <parameter>topology_id</parameter></paramdef>
</funcprototype>
</funcsynopsis>
</refsynopsisdiv>
<refsection>
<title>Description</title>
<para>Returns the topology name (schema) of a topology from the topology.topology table given the topology id of the topology.</para>
<!-- use this format if new function -->
<para role="availability" conformance="1.1">Availability: 1.1</para>
</refsection>
<refsection>
<title>Examples</title>
<programlisting>SELECT topology.GetTopologyName(1) As topo_name;
topo_name
-----------
ma_topo</programlisting>
</refsection>
<!-- Optionally add a "See Also" section -->
<refsection>
<title>See Also</title>
<para>
<xref linkend="CreateTopology"/>,
<xref linkend="DropTopology"/>,
<xref linkend="GetTopologyID"/>,
<xref linkend="GetTopologySRID"/>
</para>
</refsection>
</refentry>
<refentry xml:id="ST_GetFaceEdges">
<refnamediv>
<refname>ST_GetFaceEdges</refname>
<refpurpose>Returns a set of ordered edges that bound <varname>aface</varname>.</refpurpose>
</refnamediv>
<refsynopsisdiv>
<funcsynopsis>
<funcprototype>
<funcdef>getfaceedges_returntype <function>ST_GetFaceEdges</function></funcdef>
<paramdef><type>varchar </type> <parameter>atopology</parameter></paramdef>
<paramdef><type>integer </type> <parameter>aface</parameter></paramdef>
</funcprototype>
</funcsynopsis>
</refsynopsisdiv>
<refsection>
<title>Description</title>
<para>Returns a set of ordered edges that bound <varname>aface</varname>. Each output consists of a sequence and edgeid. Sequence numbers start with value 1.</para>
<para>
Enumeration of each ring edges start from the edge with smallest identifier.
Order of edges follows a left-hand-rule (bound face is on the left of each directed edge).
</para>
<!-- use this format if new function -->
<para role="availability" conformance="2.0">Availability: 2.0 </para>
<para>&sqlmm_compliant; SQL-MM 3 Topo-Geo and Topo-Net 3: Routine Details: X.3.5</para>
</refsection>
<refsection>
<title>Examples</title>
<programlisting>
-- Returns the edges bounding face 1
SELECT (topology.ST_GetFaceEdges('tt', 1)).*;
-- result --
sequence | edge
----------+------
1 | -4
2 | 5
3 | 7
4 | -6
5 | 1
6 | 2
7 | 3
(7 rows)
</programlisting>
<programlisting>
-- Returns the sequence, edge id
-- and geometry of the edges that bound face 1
-- If you just need geom and seq, can use ST_GetFaceGeometry
SELECT t.seq, t.edge, geom
FROM topology.ST_GetFaceEdges('tt',1) As t(seq,edge)
INNER JOIN tt.edge AS e ON abs(t.edge) = e.edge_id;
</programlisting>
</refsection>
<!-- Optionally add a "See Also" section -->
<refsection>
<title>See Also</title>
<para>
<xref linkend="GetRingEdges"/>,
<xref linkend="AddFace"/>,
<xref linkend="ST_GetFaceGeometry"/>
</para>
</refsection>
</refentry>
<refentry xml:id="ST_GetFaceGeometry">
<refnamediv>
<refname>ST_GetFaceGeometry</refname>
<refpurpose>Returns the polygon in the given topology with the specified face id.</refpurpose>
</refnamediv>
<refsynopsisdiv>
<funcsynopsis>
<funcprototype>
<funcdef>geometry <function>ST_GetFaceGeometry</function></funcdef>
<paramdef><type>varchar </type> <parameter>atopology</parameter></paramdef>
<paramdef><type>integer </type> <parameter>aface</parameter></paramdef>
</funcprototype>
</funcsynopsis>
</refsynopsisdiv>
<refsection>
<title>Description</title>
<para>Returns the polygon in the given topology with the specified face id. Builds the polygon from the edges making up the face.</para>
<!-- use this format if new function -->
<para role="availability" conformance="1.1">Availability: 1.1 </para>
<para>&sqlmm_compliant; SQL-MM 3 Topo-Geo and Topo-Net 3: Routine Details: X.3.16</para>
</refsection>
<refsection>
<title>Examples</title>
<programlisting>
-- Returns the wkt of the polygon added with AddFace
SELECT ST_AsText(topology.ST_GetFaceGeometry('ma_topo', 1)) As facegeomwkt;
-- result --
facegeomwkt
--------------------------------------------------------------------------------
POLYGON((234776.9 899563.7,234896.5 899456.7,234914 899436.4,234946.6 899356.9,
234872.5 899328.7,234891 899285.4,234992.5 899145,234890.6 899069,
234755.2 899255.4,234612.7 899379.4,234776.9 899563.7))
</programlisting>
</refsection>
<!-- Optionally add a "See Also" section -->
<refsection>
<title>See Also</title>
<para><xref linkend="AddFace"/></para>
</refsection>
</refentry>
<refentry xml:id="GetRingEdges">
<refnamediv>
<refname>GetRingEdges</refname>
<refpurpose>
Returns the ordered set of signed edge identifiers met by walking on an
a given edge side.
</refpurpose>
</refnamediv>
<refsynopsisdiv>
<funcsynopsis>
<funcprototype>
<funcdef>getfaceedges_returntype <function>GetRingEdges</function></funcdef>
<paramdef><type>varchar </type> <parameter>atopology</parameter></paramdef>
<paramdef><type>integer </type> <parameter>aring</parameter></paramdef>
<paramdef choice="opt"><type>integer </type> <parameter>max_edges=null</parameter></paramdef>
</funcprototype>
</funcsynopsis>
</refsynopsisdiv>
<refsection>
<title>Description</title>
<para>
Returns the ordered set of signed edge identifiers met by walking on an
a given edge side.
Each output consists of a sequence and a signed edge id.
Sequence numbers start with value 1.
</para>
<para>
If you pass a positive edge id, the walk starts on the left side
of the corresponding edge and follows the edge direction.
If you pass a negative edge id, the walk starts on the right side
of it and goes backward.
</para>
<para>
If <varname>max_edges</varname> is not null no more than those records
are returned by that function. This is meant to be a safety parameter
when dealing with possibly invalid topologies.
</para>
<note><para>
This function uses edge ring linking metadata.
</para></note>
<!-- use this format if new function -->
<para role="availability" conformance="2.0.0">Availability: 2.0.0 </para>
</refsection>
<!-- Optionally add a "See Also" section -->
<refsection>
<title>See Also</title>
<para>
<xref linkend="ST_GetFaceEdges"/>,
<xref linkend="GetNodeEdges"/>
</para>
</refsection>
</refentry>
<refentry xml:id="GetNodeEdges">
<refnamediv>
<refname>GetNodeEdges</refname>
<refpurpose>
Returns an ordered set of edges incident to the given node.
</refpurpose>
</refnamediv>
<refsynopsisdiv>
<funcsynopsis>
<funcprototype>
<funcdef>getfaceedges_returntype <function>GetNodeEdges</function></funcdef>
<paramdef><type>varchar </type> <parameter>atopology</parameter></paramdef>
<paramdef><type>integer </type> <parameter>anode</parameter></paramdef>
</funcprototype>
</funcsynopsis>
</refsynopsisdiv>
<refsection>
<title>Description</title>
<para>
Returns an ordered set of edges incident to the given node.
Each output consists of a sequence and a signed edge id.
Sequence numbers start with value 1.
A positive edge starts at the given node.
A negative edge ends into the given node.
Closed edges will appear twice (with both signs).
Order is clockwise starting from northbound.
</para>
<note>
<para>
This function computes ordering rather than deriving from metadata
and is thus usable to build edge ring linking.
</para>
</note>
<!-- use this format if new function -->
<para role="availability" conformance="2.0">Availability: 2.0 </para>
</refsection>
<!-- Optionally add a "See Also" section -->
<refsection>
<title>See Also</title>
<para>
<xref linkend="getfaceedges_returntype"/>,
<xref linkend="GetRingEdges"/>,
<xref linkend="ST_Azimuth"/>
</para>
</refsection>
</refentry>
</section>
<section xml:id="Topology_Processing">
<title>Topology Processing</title><info>
<abstract>
<para>This section covers the functions for processing topologies in non-standard ways.</para>
</abstract>
</info>
<refentry xml:id="TopologyPolygonize">
<refnamediv>
<refname>Polygonize</refname>
<refpurpose>Finds and registers all faces defined by topology edges.</refpurpose>
</refnamediv>
<refsynopsisdiv>
<funcsynopsis>
<funcprototype>
<funcdef>text <function>Polygonize</function></funcdef>
<paramdef><type>varchar </type> <parameter>toponame</parameter></paramdef>
</funcprototype>
</funcsynopsis>
</refsynopsisdiv>
<refsection>
<title>Description</title>
<para>Registers all faces that can be built out a topology edge primitives.</para>
<para>The target topology is assumed to contain no self-intersecting edges.</para>
<note><para>Already known faces are recognized, so it is safe to call Polygonize multiple times on the same topology.</para></note>
<note><para>
This function does not use nor set the next_left_edge and next_right_edge fields of the edge table.
</para></note>
<!-- use this format if new function -->
<para role="availability" conformance="2.0.0">Availability: 2.0.0</para>
</refsection>
<!-- Optionally add a "See Also" section -->
<refsection>
<title>See Also</title>
<para><xref linkend="AddFace"/>, <xref linkend="ST_Polygonize"/></para>
</refsection>
</refentry>
<refentry xml:id="AddNode">
<refnamediv>
<refname>AddNode</refname>
<refpurpose>Adds a point node to the node table in the specified topology schema and returns the nodeid of new node. If point already exists as node, the existing nodeid is returned.</refpurpose>
</refnamediv>
<refsynopsisdiv>
<funcsynopsis>
<funcprototype>
<funcdef>integer <function>AddNode</function></funcdef>
<paramdef><type>varchar </type> <parameter>toponame</parameter></paramdef>
<paramdef><type>geometry </type> <parameter>apoint</parameter></paramdef>
<paramdef choice="opt"><type>boolean </type> <parameter>allowEdgeSplitting=false</parameter></paramdef>
<paramdef choice="opt"><type>boolean </type> <parameter>computeContainingFace=false</parameter></paramdef>
</funcprototype>
</funcsynopsis>
</refsynopsisdiv>
<refsection>
<title>Description</title>
<para>
Adds a point node to the node table in the specified topology schema.
The <xref linkend="AddEdge"/> function automatically adds start and end
points of an edge when called so not necessary to explicitly add nodes
of an edge.
</para>
<para>
If any edge crossing the node is found either an exception is raised or
the edge is split, depending on the <varname>allowEdgeSplitting</varname>
parameter value.
</para>
<para>
If <varname>computeContainingFace</varname> is true a newly added node would
get the correct containing face computed.
</para>
<note><para>If the <varname>apoint</varname> geometry already exists as a node, the node is not added but the existing nodeid is returned.</para></note>
<!-- use this format if new function -->
<para role="availability" conformance="2.0.0">Availability: 2.0.0</para>
</refsection>
<refsection>
<title>Examples</title>
<programlisting>SELECT topology.AddNode('ma_topo', ST_GeomFromText('POINT(227641.6 893816.5)', 26986) ) As nodeid;
-- result --
nodeid
--------
4
</programlisting>
</refsection>
<!-- Optionally add a "See Also" section -->
<refsection>
<title>See Also</title>
<para><xref linkend="AddEdge"/>, <xref linkend="CreateTopology"/></para>
</refsection>
</refentry>
<refentry xml:id="AddEdge">
<refnamediv>
<refname>AddEdge</refname>
<refpurpose>Adds a linestring edge to the edge table and associated start and end points to the point nodes table of the specified topology schema using the specified linestring geometry and returns the edgeid of the new (or existing) edge.</refpurpose>
</refnamediv>
<refsynopsisdiv>
<funcsynopsis>
<funcprototype>
<funcdef>integer <function>AddEdge</function></funcdef>
<paramdef><type>varchar </type> <parameter>toponame</parameter></paramdef>
<paramdef><type>geometry </type> <parameter>aline</parameter></paramdef>
</funcprototype>
</funcsynopsis>
</refsynopsisdiv>
<refsection>
<title>Description</title>
<para>Adds an edge to the edge table and associated nodes to the nodes table of the specified <varname>toponame</varname> schema using the specified linestring geometry and returns the edgeid of the new or existing record.
The newly added edge has "universe" face on both sides and links to itself.</para>
<note><para>If the <varname>aline</varname> geometry crosses, overlaps, contains or is contained by an existing linestring edge, then an error is thrown and the edge is not added.</para></note>
<note><para>The geometry of <varname>aline</varname> must have the same <varname>srid</varname> as defined for the topology otherwise an invalid spatial reference sys error will be thrown.</para></note>
<para>Performed by the GEOS module.</para>
<warning><para><xref linkend="AddEdge"/> is deprecated as of 3.5.0. Use <xref linkend="TopoGeo_AddLineString"/> instead.</para></warning>
<para role="availability" conformance="2.0.0">Availability: 2.0.0</para>
</refsection>
<refsection>
<title>Examples</title>
<programlisting>SELECT topology.AddEdge('ma_topo', ST_GeomFromText('LINESTRING(227575.8 893917.2,227591.9 893900.4)', 26986) ) As edgeid;
-- result-
edgeid
--------
1
SELECT topology.AddEdge('ma_topo', ST_GeomFromText('LINESTRING(227591.9 893900.4,227622.6 893844.2,227641.6 893816.5,
227704.5 893778.5)', 26986) ) As edgeid;
-- result --
edgeid
--------
2
SELECT topology.AddEdge('ma_topo', ST_GeomFromText('LINESTRING(227591.2 893900, 227591.9 893900.4,
227704.5 893778.5)', 26986) ) As edgeid;
-- gives error --
ERROR: Edge intersects (not on endpoints) with existing edge 1
</programlisting>
</refsection>
<!-- Optionally add a "See Also" section -->
<refsection>
<title>See Also</title>
<para>
<xref linkend="TopoGeo_AddLineString"/>,
<xref linkend="CreateTopology"/>,
<xref linkend="spatial_ref_sys"/>
</para>
</refsection>
</refentry>
<refentry xml:id="AddFace">
<refnamediv>
<refname>AddFace</refname>
<refpurpose>Registers a face primitive to a topology and gets its identifier.</refpurpose>
</refnamediv>
<refsynopsisdiv>
<funcsynopsis>
<funcprototype>
<funcdef>integer <function>AddFace</function></funcdef>
<paramdef><type>varchar </type> <parameter>toponame</parameter></paramdef>
<paramdef><type>geometry </type> <parameter>apolygon</parameter></paramdef>
<paramdef choice="opt"><type>boolean </type> <parameter>force_new=false</parameter></paramdef>
</funcprototype>
</funcsynopsis>
</refsynopsisdiv>
<refsection>
<title>Description</title>
<para>
Registers a face primitive to a topology and gets its identifier.
</para>
<para>
For a newly added face, the edges forming its boundaries and the ones
contained in the face will be updated to have correct values in the
left_face and right_face fields.
Isolated nodes contained in the face will also be updated to have a correct
containing_face field value.
</para>
<note><para>
This function does not use nor set the next_left_edge and next_right_edge fields of the edge table.
</para></note>
<para>The target topology is assumed to be valid (containing no self-intersecting edges). An exception is raised if: The polygon boundary is not fully defined by existing edges or the polygon overlaps an existing face.</para>
<para>
If the <varname>apolygon</varname> geometry already exists as a face, then:
if <varname>force_new</varname> is false (the default) the
face id of the existing face is returned;
if <varname>force_new</varname> is true a new id will be assigned to
the newly registered face.
</para>
<note><para>
When a new registration of an existing face is performed (force_new=true),
no action will be taken to resolve dangling references to the existing
face in the edge, node an relation tables, nor will the MBR field of the
existing face record be updated. It is up to the caller to deal with that.
</para></note>
<note><para>The <varname>apolygon</varname> geometry must have the same <varname>srid</varname> as defined for the topology otherwise an invalid spatial reference sys error will be thrown.</para></note>
<!-- use this format if new function -->
<para role="availability" conformance="2.0.0">Availability: 2.0.0</para>
</refsection>
<refsection>
<title>Examples</title>
<programlisting><![CDATA[
-- first add the edges we use generate_series as an iterator (the below
-- will only work for polygons with < 10000 points because of our max in gs)
SELECT topology.AddEdge('ma_topo', ST_MakeLine(ST_PointN(geom,i), ST_PointN(geom, i + 1) )) As edgeid
FROM (SELECT ST_NPoints(geom) AS npt, geom
FROM
(SELECT ST_Boundary(ST_GeomFromText('POLYGON((234896.5 899456.7,234914 899436.4,234946.6 899356.9,234872.5 899328.7,
234891 899285.4,234992.5 899145, 234890.6 899069,234755.2 899255.4,
234612.7 899379.4,234776.9 899563.7,234896.5 899456.7))', 26986) ) As geom
) As geoms) As facen CROSS JOIN generate_series(1,10000) As i
WHERE i < npt;
-- result --
edgeid
--------
3
4
5
6
7
8
9
10
11
12
(10 rows)
-- then add the face -
SELECT topology.AddFace('ma_topo',
ST_GeomFromText('POLYGON((234896.5 899456.7,234914 899436.4,234946.6 899356.9,234872.5 899328.7,
234891 899285.4,234992.5 899145, 234890.6 899069,234755.2 899255.4,
234612.7 899379.4,234776.9 899563.7,234896.5 899456.7))', 26986) ) As faceid;
-- result --
faceid
--------
1
]]></programlisting>
</refsection>
<!-- Optionally add a "See Also" section -->
<refsection>
<title>See Also</title>
<para><xref linkend="AddEdge"/>, <xref linkend="CreateTopology"/>, <xref linkend="spatial_ref_sys"/></para>
</refsection>
</refentry>
<refentry xml:id="TP_ST_Simplify">
<refnamediv>
<refname>ST_Simplify</refname>
<refpurpose>Returns a "simplified" geometry version of the given TopoGeometry using
the Douglas-Peucker algorithm.</refpurpose>
</refnamediv>
<refsynopsisdiv>
<funcsynopsis>
<funcprototype>
<funcdef>geometry <function>ST_Simplify</function></funcdef>
<paramdef><type>TopoGeometry</type> <parameter>tg</parameter></paramdef>
<paramdef><type>float8</type> <parameter>tolerance</parameter></paramdef>
</funcprototype>
</funcsynopsis>
</refsynopsisdiv>
<refsection>
<title>Description</title>
<para>Returns a "simplified" geometry version of the given TopoGeometry using
the Douglas-Peucker algorithm on each component edge.</para>
<note><para>The returned geometry may be non-simple or non-valid.</para>
<para>Splitting component edges may help retaining simplicity/validity.</para></note>
<para>Performed by the GEOS module.</para>
<para role="availability" conformance="2.1.0">Availability: 2.1.0</para>
</refsection>
<refsection>
<title>See Also</title>
<para>Geometry <xref linkend="ST_Simplify"/>, <xref linkend="ST_IsSimple"/>, <xref linkend="ST_IsValid"/>, <xref linkend="ST_ModEdgeSplit"/></para>
</refsection>
</refentry>
<refentry xml:id="TP_RemoveUnusedPrimitives">
<refnamediv>
<refname>RemoveUnusedPrimitives</refname>
<refpurpose>Removes topology primitives which not needed to define existing TopoGeometry objects.</refpurpose>
</refnamediv>
<refsynopsisdiv>
<funcsynopsis>
<funcprototype>
<funcdef>int <function>RemoveUnusedPrimitives</function></funcdef>
<paramdef><type>text</type> <parameter>topology_name</parameter></paramdef>
<paramdef><type>geometry</type> <parameter>bbox</parameter></paramdef>
</funcprototype>
</funcsynopsis>
</refsynopsisdiv>
<refsection>
<title>Description</title>
<para>
Finds all primitives (nodes, edges, faces) that are not
strictly needed to represent existing TopoGeometry objects and removes
them, maintaining topology validity (edge linking, face labeling)
and TopoGeometry space occupation.
</para>
<para>
No new primitive identifiers are created, but rather existing primitives
are expanded to include merged faces (upon removing edges) or healed edges
(upon removing nodes).
</para>
<para role="availability" conformance="3.3.0">Availability: 3.3.0</para>
</refsection>
<refsection>
<title>See Also</title>
<para>
<xref linkend="ST_ModEdgeHeal"/>,
<xref linkend="ST_RemEdgeModFace"/>
</para>
</refsection>
</refentry>
</section>
<section xml:id="TopoGeometry_Constructors">
<title>TopoGeometry Constructors</title><info>
<abstract>
<para>This section covers the topology functions for creating new topogeometries.</para>
</abstract>
</info>
<refentry xml:id="CreateTopoGeom">
<refnamediv>
<refname>CreateTopoGeom</refname>
<refpurpose>Creates a new topo geometry object from topo element array - tg_type: 1:[multi]point, 2:[multi]line, 3:[multi]poly, 4:collection</refpurpose>
</refnamediv>
<refsynopsisdiv>
<funcsynopsis>
<funcprototype>
<funcdef>topogeometry <function>CreateTopoGeom</function></funcdef>
<paramdef><type>varchar </type> <parameter>toponame</parameter></paramdef>
<paramdef><type>integer </type> <parameter>tg_type</parameter></paramdef>
<paramdef><type>integer</type> <parameter>layer_id</parameter></paramdef>
<paramdef><type>topoelementarray</type> <parameter>tg_objs</parameter></paramdef>
</funcprototype>
<funcprototype>
<funcdef>topogeometry <function>CreateTopoGeom</function></funcdef>
<paramdef><type>varchar </type> <parameter>toponame</parameter></paramdef>
<paramdef><type>integer </type> <parameter>tg_type</parameter></paramdef>
<paramdef><type>integer</type> <parameter>layer_id</parameter></paramdef>
</funcprototype>
</funcsynopsis>
</refsynopsisdiv>
<refsection>
<title>Description</title>
<para>Creates a topogeometry object for layer denoted by <varname>layer_id</varname> and registers it in the relations table in the <varname>toponame</varname> schema.</para>
<para><varname>tg_type</varname> is an integer: 1:[multi]point (punctal), 2:[multi]line (lineal), 3:[multi]poly (areal), 4:collection. <varname>layer_id</varname> is the layer id in the topology.layer table.</para>
<para>punctal layers are formed from set of nodes, lineal layers are formed from a set of edges, areal layers are formed from a set of faces,
and collections can be formed from a mixture of nodes, edges, and faces.</para>
<para>Omitting the array of components generates an empty TopoGeometry object.</para>
<!-- use this format if new function -->
<para role="availability" conformance="1.1">Availability: 1.1</para>
</refsection>
<refsection>
<title>Examples: Form from existing edges</title>
<para>Create a topogeom in ri_topo schema for layer 2 (our ri_roads), of type (2) LINE, for the first edge (we loaded in <varname>ST_CreateTopoGeo</varname>).</para>
<programlisting>INSERT INTO ri.ri_roads(road_name, topo) VALUES('Unknown', topology.CreateTopoGeom('ri_topo',2,2,'{{1,2}}'::topology.topoelementarray);</programlisting>
</refsection>
<refsection>
<title>Examples: Convert an areal geometry to best guess topogeometry</title>
<para>Lets say we have geometries that should be formed from a collection of faces. We have for example blockgroups table
and want to know the topo geometry of each block group. If our data was perfectly aligned, we could do this:</para>
<programlisting>
-- create our topo geometry column --
SELECT topology.AddTopoGeometryColumn(
'topo_boston',
'boston', 'blockgroups', 'topo', 'POLYGON');
-- addtopgeometrycolumn --
1
-- update our column assuming
-- everything is perfectly aligned with our edges
UPDATE boston.blockgroups AS bg
SET topo = topology.CreateTopoGeom('topo_boston'
,3,1
, foo.bfaces)
FROM (SELECT b.gid, topology.TopoElementArray_Agg(ARRAY[f.face_id,3]) As bfaces
FROM boston.blockgroups As b
INNER JOIN topo_boston.face As f ON b.geom && f.mbr
WHERE ST_Covers(b.geom, topology.ST_GetFaceGeometry('topo_boston', f.face_id))
GROUP BY b.gid) As foo
WHERE foo.gid = bg.gid;
</programlisting>
<programlisting>
--the world is rarely perfect allow for some error
--count the face if 50% of it falls
-- within what we think is our blockgroup boundary
UPDATE boston.blockgroups AS bg
SET topo = topology.CreateTopoGeom('topo_boston'
,3,1
, foo.bfaces)
FROM (SELECT b.gid, topology.TopoElementArray_Agg(ARRAY[f.face_id,3]) As bfaces
FROM boston.blockgroups As b
INNER JOIN topo_boston.face As f ON b.geom && f.mbr
WHERE ST_Covers(b.geom, topology.ST_GetFaceGeometry('topo_boston', f.face_id))
OR
( ST_Intersects(b.geom, topology.ST_GetFaceGeometry('topo_boston', f.face_id))
AND ST_Area(ST_Intersection(b.geom, topology.ST_GetFaceGeometry('topo_boston', f.face_id) ) ) >
ST_Area(topology.ST_GetFaceGeometry('topo_boston', f.face_id))*0.5
)
GROUP BY b.gid) As foo
WHERE foo.gid = bg.gid;
-- and if we wanted to convert our topogeometry back
-- to a denormalized geometry aligned with our faces and edges
-- cast the topo to a geometry
-- The really cool thing is my new geometries
-- are now aligned with my tiger street centerlines
UPDATE boston.blockgroups SET new_geom = topo::geometry;
</programlisting>
</refsection>
<!-- Optionally add a "See Also" section -->
<refsection>
<title>See Also</title>
<para>
<xref linkend="AddTopoGeometryColumn"/>,
<xref linkend="toTopoGeom"/>
<xref linkend="ST_CreateTopoGeo"/>,
<xref linkend="ST_GetFaceGeometry"/>,
<xref linkend="topoelementarray"/>,
<xref linkend="TopoElementArray_Agg"/>
</para>
</refsection>
</refentry>
<refentry xml:id="toTopoGeom">
<refnamediv>
<refname>toTopoGeom</refname>
<refpurpose>Converts a simple Geometry into a topo geometry.</refpurpose>
</refnamediv>
<refsynopsisdiv>
<funcsynopsis>
<funcprototype>
<funcdef>topogeometry <function>toTopoGeom</function></funcdef>
<paramdef><type>geometry </type> <parameter>geom</parameter></paramdef>
<paramdef><type>varchar </type> <parameter>toponame</parameter></paramdef>
<paramdef><type>integer</type> <parameter>layer_id</parameter></paramdef>
<paramdef choice="opt"><type>float8</type> <parameter>tolerance</parameter></paramdef>
</funcprototype>
<funcprototype>
<funcdef>topogeometry <function>toTopoGeom</function></funcdef>
<paramdef><type>geometry </type> <parameter>geom</parameter></paramdef>
<paramdef><type>topogeometry </type> <parameter>topogeom</parameter></paramdef>
<paramdef choice="opt"><type>float8</type> <parameter>tolerance</parameter></paramdef>
</funcprototype>
</funcsynopsis>
</refsynopsisdiv>
<refsection>
<title>Description</title>
<para>
Converts a simple Geometry into a <xref linkend="topogeometry"/>.
</para>
<para>
Topological primitives required to represent the input geometry will be
added to the underlying topology, possibly splitting existing ones,
and they will be associated with the output TopoGeometry in the
<varname>relation</varname> table.
</para>
<para>
Existing TopoGeometry objects (with the possible exception of
<varname>topogeom</varname>, if given) will retain their shapes.
</para>
<para>
When <varname>tolerance</varname> is given it will be used to snap the
input geometry to existing primitives.
</para>
<para>
In the first form a new TopoGeometry will be created for the given
layer (<varname>layer_id</varname>) of the given topology (<varname>toponame</varname>).
</para>
<para>
In the second form the primitives resulting from the conversion will be
added to the pre-existing TopoGeometry (<varname>topogeom</varname>),
possibly adding space to its final shape. To have the new shape completely
replace the old one see <xref linkend="clearTopoGeom"/>.
</para>
<!-- use this format if new function -->
<para role="availability" conformance="2.0">Availability: 2.0</para>
<para role="enhanced" conformance="2.1.0">Enhanced: 2.1.0 adds the version taking an existing TopoGeometry.</para>
</refsection>
<refsection>
<title>Examples</title>
<para>This is a full self-contained workflow</para>
<programlisting> -- do this if you don't have a topology setup already
-- creates topology not allowing any tolerance
SELECT topology.CreateTopology('topo_boston_test', 2249);
-- create a new table
CREATE TABLE nei_topo(gid serial primary key, nei varchar(30));
--add a topogeometry column to it
SELECT topology.AddTopoGeometryColumn('topo_boston_test', 'public', 'nei_topo', 'topo', 'MULTIPOLYGON') As new_layer_id;
new_layer_id
-----------
1
--use new layer id in populating the new topogeometry column
-- we add the topogeoms to the new layer with 0 tolerance
INSERT INTO nei_topo(nei, topo)
SELECT nei, topology.toTopoGeom(geom, 'topo_boston_test', 1)
FROM neighborhoods
WHERE gid BETWEEN 1 and 15;
--use to verify what has happened --
SELECT * FROM
topology.TopologySummary('topo_boston_test');
-- summary--
Topology topo_boston_test (5), SRID 2249, precision 0
61 nodes, 87 edges, 35 faces, 15 topogeoms in 1 layers
Layer 1, type Polygonal (3), 15 topogeoms
Deploy: public.nei_topo.topo</programlisting>
<programlisting><![CDATA[
-- Shrink all TopoGeometry polygons by 10 meters
UPDATE nei_topo SET topo = ST_Buffer(clearTopoGeom(topo), -10);
-- Get the no-one-lands left by the above operation
-- I think GRASS calls this "polygon0 layer"
SELECT ST_GetFaceGeometry('topo_boston_test', f.face_id)
FROM topo_boston_test.face f
WHERE f.face_id > 0 -- don't consider the universe face
AND NOT EXISTS ( -- check that no TopoGeometry references the face
SELECT * FROM topo_boston_test.relation
WHERE layer_id = 1 AND element_id = f.face_id
);
]]></programlisting>
</refsection>
<!-- Optionally add a "See Also" section -->
<refsection>
<title>See Also</title>
<para>
<xref linkend="CreateTopology"/>,
<xref linkend="AddTopoGeometryColumn"/>,
<xref linkend="CreateTopoGeom"/>,
<xref linkend="TopologySummary"/>,
<xref linkend="clearTopoGeom"/>
</para>
</refsection>
</refentry>
<refentry xml:id="TopoElementArray_Agg">
<refnamediv>
<refname>TopoElementArray_Agg</refname>
<refpurpose>Returns a <varname>topoelementarray</varname> for a set of element_id, type arrays (topoelements).</refpurpose>
</refnamediv>
<refsynopsisdiv>
<funcsynopsis>
<funcprototype>
<funcdef>topoelementarray <function>TopoElementArray_Agg</function></funcdef>
<paramdef><type>topoelement set</type> <parameter>tefield</parameter></paramdef>
</funcprototype>
</funcsynopsis>
</refsynopsisdiv>
<refsection>
<title>Description</title>
<para>Used to create a <xref linkend="topoelementarray"/> from a set of <xref linkend="topoelement"/>.</para>
<!-- use this format if new function -->
<para role="availability" conformance="2.0.0">Availability: 2.0.0</para>
</refsection>
<refsection>
<title>Examples</title>
<programlisting>SELECT topology.TopoElementArray_Agg(ARRAY[e,t]) As tea
FROM generate_series(1,3) As e CROSS JOIN generate_series(1,4) As t;
tea
--------------------------------------------------------------------------
{{1,1},{1,2},{1,3},{1,4},{2,1},{2,2},{2,3},{2,4},{3,1},{3,2},{3,3},{3,4}}</programlisting>
</refsection>
<refsection>
<title>See Also</title>
<para><xref linkend="topoelement"/>, <xref linkend="topoelementarray"/></para>
</refsection>
</refentry>
<refentry xml:id="TopoElement">
<refnamediv>
<refname>TopoElement</refname>
<refpurpose>Converts a topogeometry to a topoelement.</refpurpose>
</refnamediv>
<refsynopsisdiv>
<funcsynopsis>
<funcprototype>
<funcdef>topoelement <function>TopoElement</function></funcdef>
<paramdef><type>topogeometry </type> <parameter>topo</parameter></paramdef>
</funcprototype>
</funcsynopsis>
</refsynopsisdiv>
<refsection>
<title>Description</title>
<para>Converts a <xref linkend="topogeometry"/> to a <xref linkend="topoelement"/>.</para>
<!-- use this format if new function -->
<para role="availability" conformance="3.4.0">Availability: 3.4.0</para>
</refsection>
<refsection>
<title>Examples</title>
<para>This is a full self-contained workflow</para>
<programlisting>-- do this if you don't have a topology setup already
-- Creates topology not allowing any tolerance
SELECT TopoElement(topo)
FROM neighborhoods;</programlisting>
<programlisting>-- using as cast
SELECT topology.TopoElementArray_Agg(topo::topoelement)
FROM neighborhoods
GROUP BY city;</programlisting>
</refsection>
<!-- Optionally add a "See Also" section -->
<refsection>
<title>See Also</title>
<para><xref linkend="TopoElementArray_Agg"/>, <xref linkend="topogeometry"/>, <xref linkend="topoelement"/></para>
</refsection>
</refentry>
</section>
<section xml:id="TopoGeometry_Editors">
<title>TopoGeometry Editors</title><info>
<abstract>
<para>This section covers the topology functions for editing existing topogeometries.</para>
</abstract>
</info>
<refentry xml:id="clearTopoGeom">
<refnamediv>
<refname>clearTopoGeom</refname>
<refpurpose>Clears the content of a topo geometry.</refpurpose>
</refnamediv>
<refsynopsisdiv>
<funcsynopsis>
<funcprototype>
<funcdef>topogeometry <function>clearTopoGeom</function></funcdef>
<paramdef><type>topogeometry </type> <parameter>topogeom</parameter></paramdef>
</funcprototype>
</funcsynopsis>
</refsynopsisdiv>
<refsection>
<title>Description</title>
<para>
Clears the content a <xref linkend="topogeometry"/>
turning it into an empty one. Mostly useful in conjunction with <xref linkend="toTopoGeom"/> to replace the shape of existing
objects and any dependent object in higher hierarchical levels.
</para>
<!-- use this format if new function -->
<para role="availability" conformance="2.1">Availability: 2.1</para>
</refsection>
<refsection>
<title>Examples</title>
<programlisting>
-- Shrink all TopoGeometry polygons by 10 meters
UPDATE nei_topo SET topo = ST_Buffer(clearTopoGeom(topo), -10);
</programlisting>
</refsection>
<!-- Optionally add a "See Also" section -->
<refsection>
<title>See Also</title>
<para>
<xref linkend="toTopoGeom"/>
</para>
</refsection>
</refentry>
<refentry xml:id="TopoGeom_addElement">
<refnamediv>
<refname>TopoGeom_addElement</refname>
<refpurpose>Adds an element to the definition of a TopoGeometry.</refpurpose>
</refnamediv>
<refsynopsisdiv>
<funcsynopsis>
<funcprototype>
<funcdef>topogeometry <function>TopoGeom_addElement</function></funcdef>
<paramdef><type>topogeometry </type> <parameter>tg</parameter></paramdef>
<paramdef><type>topoelement </type> <parameter>el</parameter></paramdef>
</funcprototype>
</funcsynopsis>
</refsynopsisdiv>
<refsection>
<title>Description</title>
<para>
Adds a <xref linkend="topoelement"/> to the definition of a
TopoGeometry object. Does not error out if the element is already
part of the definition.
</para>
<!-- use this format if new function -->
<para role="availability" conformance="2.3">Availability: 2.3</para>
</refsection>
<refsection>
<title>Examples</title>
<programlisting>
-- Add edge 5 to TopoGeometry tg
UPDATE mylayer SET tg = TopoGeom_addElement(tg, '{5,2}');
</programlisting>
</refsection>
<!-- Optionally add a "See Also" section -->
<refsection>
<title>See Also</title>
<para>
<xref linkend="TopoGeom_remElement"/>,
<xref linkend="CreateTopoGeom"/>
</para>
</refsection>
</refentry>
<refentry xml:id="TopoGeom_remElement">
<refnamediv>
<refname>TopoGeom_remElement</refname>
<refpurpose>Removes an element from the definition of a TopoGeometry.</refpurpose>
</refnamediv>
<refsynopsisdiv>
<funcsynopsis>
<funcprototype>
<funcdef>topogeometry <function>TopoGeom_remElement</function></funcdef>
<paramdef><type>topogeometry </type> <parameter>tg</parameter></paramdef>
<paramdef><type>topoelement </type> <parameter>el</parameter></paramdef>
</funcprototype>
</funcsynopsis>
</refsynopsisdiv>
<refsection>
<title>Description</title>
<para>
Removes a <xref linkend="topoelement"/> from the definition of a
TopoGeometry object.
</para>
<!-- use this format if new function -->
<para role="availability" conformance="2.3">Availability: 2.3</para>
</refsection>
<refsection>
<title>Examples</title>
<programlisting>
-- Remove face 43 from TopoGeometry tg
UPDATE mylayer SET tg = TopoGeom_remElement(tg, '{43,3}');
</programlisting>
</refsection>
<!-- Optionally add a "See Also" section -->
<refsection>
<title>See Also</title>
<para>
<xref linkend="TopoGeom_addElement"/>,
<xref linkend="CreateTopoGeom"/>
</para>
</refsection>
</refentry>
<refentry xml:id="TopoGeom_addTopoGeom">
<refnamediv>
<refname>TopoGeom_addTopoGeom</refname>
<refpurpose>Adds element of a TopoGeometry to the definition of another TopoGeometry.</refpurpose>
</refnamediv>
<refsynopsisdiv>
<funcsynopsis>
<funcprototype>
<funcdef>topogeometry <function>TopoGeom_addTopoGeom</function></funcdef>
<paramdef><type>topogeometry </type> <parameter>tgt</parameter></paramdef>
<paramdef><type>topogeometry </type> <parameter>src</parameter></paramdef>
</funcprototype>
</funcsynopsis>
</refsynopsisdiv>
<refsection>
<title>Description</title>
<para>
Adds the elements of a <xref linkend="topogeometry"/> to the definition of
another TopoGeometry, possibly changing its cached type (type attribute)
to a collection, if needed to hold all elements in the source object.
</para>
<para>
The two TopoGeometry objects need be defined against the *same*
topology and, if hierarchically defined, need be composed by elements
of the same child layer.
</para>
<!-- use this format if new function -->
<para role="availability" conformance="3.2">Availability: 3.2</para>
</refsection>
<refsection>
<title>Examples</title>
<programlisting>
-- Set an "overall" TopoGeometry value to be composed by all
-- elements of specific TopoGeometry values
UPDATE mylayer SET tg_overall = TopoGeom_addTopogeom(
TopoGeom_addTopoGeom(
clearTopoGeom(tg_overall),
tg_specific1
),
tg_specific2
);
</programlisting>
</refsection>
<!-- Optionally add a "See Also" section -->
<refsection>
<title>See Also</title>
<para>
<xref linkend="TopoGeom_addElement"/>,
<xref linkend="clearTopoGeom"/>,
<xref linkend="CreateTopoGeom"/>
</para>
</refsection>
</refentry>
<refentry xml:id="toTopoGeom_editor_proxy">
<refnamediv>
<refname>toTopoGeom</refname>
<refpurpose>Adds a geometry shape to an existing topo geometry.</refpurpose>
</refnamediv>
<refsection>
<title>Description</title>
<para>
Refer to <xref linkend="toTopoGeom"/>.
</para>
</refsection>
</refentry>
</section>
<section xml:id="TopoGeom_Accessors">
<title>TopoGeometry Accessors</title>
<refentry xml:id="GetTopoGeomElementArray">
<refnamediv>
<refname>GetTopoGeomElementArray</refname>
<refpurpose>Returns a <varname>topoelementarray</varname> (an array of topoelements) containing the topological elements and type of the given TopoGeometry (primitive elements).</refpurpose>
</refnamediv>
<refsynopsisdiv>
<funcsynopsis>
<funcprototype>
<funcdef>topoelementarray <function>GetTopoGeomElementArray</function></funcdef>
<paramdef><type>varchar </type> <parameter>toponame</parameter></paramdef>
<paramdef><type>integer </type> <parameter>layer_id</parameter></paramdef>
<paramdef><type>integer</type> <parameter>tg_id</parameter></paramdef>
</funcprototype>
</funcsynopsis>
<funcsynopsis>
<funcprototype>
<funcdef>topoelementarray <function>GetTopoGeomElementArray</function></funcdef>
<paramdef><type>topogeometry </type> <parameter>tg</parameter></paramdef>
</funcprototype>
</funcsynopsis>
</refsynopsisdiv>
<refsection>
<title>Description</title>
<para>Returns a <xref linkend="topoelementarray"/> containing the topological elements and type of the given TopoGeometry (primitive elements). This is similar to GetTopoGeomElements except it returns the elements as an array rather
than as a dataset.</para>
<para>tg_id is the topogeometry id of the topogeometry object in the topology in the layer denoted by <varname>layer_id</varname> in the topology.layer table.</para>
<!-- use this format if new function -->
<para role="availability" conformance="1.1">Availability: 1.1</para>
</refsection>
<refsection>
<title>Examples</title>
<para/>
<!-- TODO: -->
</refsection>
<!-- Optionally add a "See Also" section -->
<refsection>
<title>See Also</title>
<para><xref linkend="GetTopoGeomElements"/>, <xref linkend="topoelementarray"/></para>
</refsection>
</refentry>
<refentry xml:id="GetTopoGeomElements">
<refnamediv>
<refname>GetTopoGeomElements</refname>
<refpurpose>Returns a set of <varname>topoelement</varname> objects containing the topological element_id,element_type of the given TopoGeometry (primitive elements).</refpurpose>
</refnamediv>
<refsynopsisdiv>
<funcsynopsis>
<funcprototype>
<funcdef>setof topoelement <function>GetTopoGeomElements</function></funcdef>
<paramdef><type>varchar </type> <parameter>toponame</parameter></paramdef>
<paramdef><type>integer </type> <parameter>layer_id</parameter></paramdef>
<paramdef><type>integer</type> <parameter>tg_id</parameter></paramdef>
</funcprototype>
</funcsynopsis>
<funcsynopsis>
<funcprototype>
<funcdef>setof topoelement <function>GetTopoGeomElements</function></funcdef>
<paramdef><type>topogeometry </type> <parameter>tg</parameter></paramdef>
</funcprototype>
</funcsynopsis>
</refsynopsisdiv>
<refsection>
<title>Description</title>
<para>Returns a set of element_id,element_type (topoelements) corresponding to primitive topology elements <xref linkend="topoelement"/> (1: nodes, 2: edges, 3: faces) that a given topogeometry object in <varname>toponame</varname> schema is composed of.</para>
<para>tg_id is the topogeometry id of the topogeometry object in the topology in the layer denoted by <varname>layer_id</varname> in the topology.layer table.</para>
<!-- use this format if new function -->
<para role="availability" conformance="2.0.0">Availability: 2.0.0</para>
</refsection>
<refsection>
<title>Examples</title>
<para/>
<!-- TODO: -->
</refsection>
<!-- Optionally add a "See Also" section -->
<refsection>
<title>See Also</title>
<para>
<xref linkend="GetTopoGeomElementArray"/>,
<xref linkend="topoelement"/>,
<xref linkend="TopoGeom_addElement"/>,
<xref linkend="TopoGeom_remElement"/>
</para>
</refsection>
</refentry>
<refentry xml:id="TG_ST_SRID">
<refnamediv>
<refname>ST_SRID</refname>
<refpurpose>Returns the spatial reference identifier for a topogeometry.</refpurpose>
</refnamediv>
<refsynopsisdiv>
<funcsynopsis>
<funcprototype>
<funcdef>integer <function>ST_SRID</function></funcdef>
<paramdef><type>topogeometry </type> <parameter>tg</parameter></paramdef>
</funcprototype>
</funcsynopsis>
</refsynopsisdiv>
<refsection>
<title>Description</title>
<para>Returns the spatial reference identifier for the ST_Geometry as defined in spatial_ref_sys table. <xref linkend="spatial_ref_sys"/></para>
<para><note><para>spatial_ref_sys
table is a table that catalogs all spatial reference systems known to PostGIS and is used for transformations from one spatial
reference system to another. So verifying you have the right spatial reference system identifier is important if you plan to ever transform your geometries.</para></note></para>
<para role="availability" conformance="3.2.0">Availability: 3.2.0</para>
<para>&sqlmm_compliant; SQL-MM 3: 14.1.5</para>
</refsection>
<refsection>
<title>Examples</title>
<programlisting>SELECT ST_SRID(ST_GeomFromText('POINT(-71.1043 42.315)',4326));
--result
4326
</programlisting>
</refsection>
<refsection>
<title>See Also</title>
<para><xref linkend="spatial_ref_sys"/>, <xref linkend="ST_SetSRID"/>, <xref linkend="ST_Transform"/>, <xref linkend="ST_SRID"/></para>
</refsection>
</refentry>
</section>
<section xml:id="TopoGeometry_Outputs">
<title>TopoGeometry Outputs</title>
<refentry xml:id="AsGML">
<refnamediv>
<refname>AsGML</refname>
<refpurpose>Returns the GML representation of a topogeometry.</refpurpose>
</refnamediv>
<refsynopsisdiv>
<funcsynopsis>
<funcprototype>
<funcdef>text <function>AsGML</function></funcdef>
<paramdef><type>topogeometry </type> <parameter>tg</parameter></paramdef>
</funcprototype>
<funcprototype>
<funcdef>text <function>AsGML</function></funcdef>
<paramdef><type>topogeometry </type> <parameter>tg</parameter></paramdef>
<paramdef><type>text </type> <parameter>nsprefix_in</parameter></paramdef>
</funcprototype>
<funcprototype>
<funcdef>text <function>AsGML</function></funcdef>
<paramdef><type>topogeometry </type> <parameter>tg</parameter></paramdef>
<paramdef><type>regclass </type> <parameter>visitedTable</parameter></paramdef>
</funcprototype>
<funcprototype>
<funcdef>text <function>AsGML</function></funcdef>
<paramdef><type>topogeometry </type> <parameter>tg</parameter></paramdef>
<paramdef><type>regclass </type> <parameter>visitedTable</parameter></paramdef>
<paramdef><type>text </type> <parameter>nsprefix</parameter></paramdef>
</funcprototype>
<funcprototype>
<funcdef>text <function>AsGML</function></funcdef>
<paramdef><type>topogeometry </type> <parameter>tg</parameter></paramdef>
<paramdef><type>text </type> <parameter>nsprefix_in</parameter></paramdef>
<paramdef><type>integer </type> <parameter>precision</parameter></paramdef>
<paramdef><type>integer </type> <parameter>options</parameter></paramdef>
</funcprototype>
<funcprototype>
<funcdef>text <function>AsGML</function></funcdef>
<paramdef><type>topogeometry </type> <parameter>tg</parameter></paramdef>
<paramdef><type>text </type> <parameter>nsprefix_in</parameter></paramdef>
<paramdef><type>integer </type> <parameter>precision</parameter></paramdef>
<paramdef><type>integer </type> <parameter>options</parameter></paramdef>
<paramdef><type>regclass </type> <parameter>visitedTable</parameter></paramdef>
</funcprototype>
<funcprototype>
<funcdef>text <function>AsGML</function></funcdef>
<paramdef><type>topogeometry </type> <parameter>tg</parameter></paramdef>
<paramdef><type>text </type> <parameter>nsprefix_in</parameter></paramdef>
<paramdef><type>integer </type> <parameter>precision</parameter></paramdef>
<paramdef><type>integer </type> <parameter>options</parameter></paramdef>
<paramdef><type>regclass </type> <parameter>visitedTable</parameter></paramdef>
<paramdef><type>text </type> <parameter>idprefix</parameter></paramdef>
</funcprototype>
<funcprototype>
<funcdef>text <function>AsGML</function></funcdef>
<paramdef><type>topogeometry </type> <parameter>tg</parameter></paramdef>
<paramdef><type>text </type> <parameter>nsprefix_in</parameter></paramdef>
<paramdef><type>integer </type> <parameter>precision</parameter></paramdef>
<paramdef><type>integer </type> <parameter>options</parameter></paramdef>
<paramdef><type>regclass </type> <parameter>visitedTable</parameter></paramdef>
<paramdef><type>text </type> <parameter>idprefix</parameter></paramdef>
<paramdef><type>int </type> <parameter>gmlversion</parameter></paramdef>
</funcprototype>
</funcsynopsis>
</refsynopsisdiv>
<refsection>
<title>Description</title>
<para>Returns the GML representation of a topogeometry in version GML3 format. If no <varname>nsprefix_in</varname> is specified then <varname>gml</varname> is used. Pass in an empty string for nsprefix to get a non-qualified name space. The precision (default: 15) and options (default 1) parameters, if given, are passed untouched to the underlying call to ST_AsGML.</para>
<para>
The <varname>visitedTable</varname> parameter, if given, is used for keeping track of the visited Node and Edge elements so to use cross-references (xlink:xref) rather than duplicating definitions. The table is expected to have (at least) two integer fields: 'element_type' and 'element_id'. The calling user must have both read and write privileges on the given table.
For best performance, an index should be defined on
<varname>element_type</varname> and <varname>element_id</varname>,
in that order. Such index would be created automatically by adding a unique
constraint to the fields. Example:
<programlisting>
CREATE TABLE visited (
element_type integer, element_id integer,
unique(element_type, element_id)
);
</programlisting>
</para>
<para>The <varname>idprefix</varname> parameter, if given, will be prepended to Edge and Node tag identifiers.</para>
<para>The <varname>gmlver</varname> parameter, if given, will be passed to the underlying ST_AsGML. Defaults to 3.</para>
<!-- use this format if new function -->
<para role="availability" conformance="2.0.0">Availability: 2.0.0 </para>
</refsection>
<refsection>
<title>Examples</title>
<para>This uses the topo geometry we created in <xref linkend="CreateTopoGeom"/></para>
<programlisting><![CDATA[
SELECT topology.AsGML(topo) As rdgml
FROM ri.roads
WHERE road_name = 'Unknown';
-- rdgml--
<gml:TopoCurve>
<gml:directedEdge>
<gml:Edge gml:id="E1">
<gml:directedNode orientation="-">
<gml:Node gml:id="N1"/>
</gml:directedNode>
<gml:directedNode></gml:directedNode>
<gml:curveProperty>
<gml:Curve srsName="urn:ogc:def:crs:EPSG::3438">
<gml:segments>
<gml:LineStringSegment>
<gml:posList srsDimension="2">384744 236928 384750 236923 384769 236911 384799 236895 384811 236890
384833 236884 384844 236882 384866 236881 384879 236883 384954 236898 385087 236932 385117 236938
385167 236938 385203 236941 385224 236946 385233 236950 385241 236956 385254 236971
385260 236979 385268 236999 385273 237018 385273 237037 385271 237047 385267 237057 385225 237125
385210 237144 385192 237161 385167 237192 385162 237202 385159 237214 385159 237227 385162 237241
385166 237256 385196 237324 385209 237345 385234 237375 385237 237383 385238 237399 385236 237407
385227 237419 385213 237430 385193 237439 385174 237451 385170 237455 385169 237460 385171 237475
385181 237503 385190 237521 385200 237533 385206 237538 385213 237541 385221 237542 385235 237540 385242 237541
385249 237544 385260 237555 385270 237570 385289 237584 385292 237589 385291 237596 385284 237630</gml:posList>
</gml:LineStringSegment>
</gml:segments>
</gml:Curve>
</gml:curveProperty>
</gml:Edge>
</gml:directedEdge>
</gml:TopoCurve>
]]></programlisting>
<para>Same exercise as previous without namespace</para>
<programlisting><![CDATA[
SELECT topology.AsGML(topo,'') As rdgml
FROM ri.roads
WHERE road_name = 'Unknown';
-- rdgml--
<TopoCurve>
<directedEdge>
<Edge id="E1">
<directedNode orientation="-">
<Node id="N1"/>
</directedNode>
<directedNode></directedNode>
<curveProperty>
<Curve srsName="urn:ogc:def:crs:EPSG::3438">
<segments>
<LineStringSegment>
<posList srsDimension="2">384744 236928 384750 236923 384769 236911 384799 236895 384811 236890
384833 236884 384844 236882 384866 236881 384879 236883 384954 236898 385087 236932 385117 236938
385167 236938 385203 236941 385224 236946 385233 236950 385241 236956 385254 236971
385260 236979 385268 236999 385273 237018 385273 237037 385271 237047 385267 237057 385225 237125
385210 237144 385192 237161 385167 237192 385162 237202 385159 237214 385159 237227 385162 237241
385166 237256 385196 237324 385209 237345 385234 237375 385237 237383 385238 237399 385236 237407
385227 237419 385213 237430 385193 237439 385174 237451 385170 237455 385169 237460 385171 237475
385181 237503 385190 237521 385200 237533 385206 237538 385213 237541 385221 237542 385235 237540 385242 237541
385249 237544 385260 237555 385270 237570 385289 237584 385292 237589 385291 237596 385284 237630</posList>
</LineStringSegment>
</segments>
</Curve>
</curveProperty>
</Edge>
</directedEdge>
</TopoCurve>
]]></programlisting>
</refsection>
<!-- Optionally add a "See Also" section -->
<refsection>
<title>See Also</title>
<para><xref linkend="CreateTopoGeom"/>, <xref linkend="ST_CreateTopoGeo"/></para>
</refsection>
</refentry>
<refentry xml:id="AsTopoJSON">
<refnamediv>
<refname>AsTopoJSON</refname>
<refpurpose>Returns the TopoJSON representation of a topogeometry.</refpurpose>
</refnamediv>
<refsynopsisdiv>
<funcsynopsis>
<funcprototype>
<funcdef>text <function>AsTopoJSON</function></funcdef>
<paramdef><type>topogeometry </type> <parameter>tg</parameter></paramdef>
<paramdef><type>regclass </type> <parameter>edgeMapTable</parameter></paramdef>
</funcprototype>
</funcsynopsis>
</refsynopsisdiv>
<refsection>
<title>Description</title>
<para>Returns the TopoJSON representation of a topogeometry. If <varname>edgeMapTable</varname> is not null, it will be used as a lookup/storage mapping of edge identifiers to arc indices. This is to be able to allow for a compact "arcs" array in the final document.
</para>
<para>
The table, if given, is expected to have an "arc_id" field of type "serial" and an "edge_id" of type integer; the code will query the table for "edge_id" so it is recommended to add an index on that field.
</para>
<note>
<para>
Arc indices in the TopoJSON output are 0-based but they are 1-based
in the "edgeMapTable" table.
</para>
</note>
<para>
A full TopoJSON document will be need to contain, in
addition to the snippets returned by this function,
the actual arcs plus some headers. See the <link xlink:href="http://github.com/mbostock/topojson-specification/blob/master/README.md">TopoJSON specification</link>.
</para>
<!-- use this format if new function -->
<para role="availability" conformance="2.1.0">Availability: 2.1.0 </para>
<para role="enhanced" conformance="2.2.1">Enhanced: 2.2.1 added support for puntal inputs</para>
</refsection>
<!-- Optionally add a "See Also" section -->
<refsection>
<title>See Also</title>
<para><xref linkend="ST_AsGeoJSON"/></para>
</refsection>
<refsection>
<title>Examples</title>
<programlisting>
CREATE TEMP TABLE edgemap(arc_id serial, edge_id int unique);
-- header
SELECT '{ "type": "Topology", "transform": { "scale": [1,1], "translate": [0,0] }, "objects": {'
-- objects
UNION ALL SELECT '"' || feature_name || '": ' || AsTopoJSON(feature, 'edgemap')
FROM features.big_parcels WHERE feature_name = 'P3P4';
-- arcs
WITH edges AS (
SELECT m.arc_id, e.geom FROM edgemap m, city_data.edge e
WHERE e.edge_id = m.edge_id
), points AS (
SELECT arc_id, (st_dumppoints(geom)).* FROM edges
), compare AS (
SELECT p2.arc_id,
CASE WHEN p1.path IS NULL THEN p2.geom
ELSE ST_Translate(p2.geom, -ST_X(p1.geom), -ST_Y(p1.geom))
END AS geom
FROM points p2 LEFT OUTER JOIN points p1
ON ( p1.arc_id = p2.arc_id AND p2.path[1] = p1.path[1]+1 )
ORDER BY arc_id, p2.path
), arcsdump AS (
SELECT arc_id, (regexp_matches( ST_AsGeoJSON(geom), '\[.*\]'))[1] as t
FROM compare
), arcs AS (
SELECT arc_id, '[' || array_to_string(array_agg(t), ',') || ']' as a FROM arcsdump
GROUP BY arc_id
ORDER BY arc_id
)
SELECT '}, "arcs": [' UNION ALL
SELECT array_to_string(array_agg(a), E',\n') from arcs
-- footer
UNION ALL SELECT ']}'::text as t;
-- Result:
{ "type": "Topology", "transform": { "scale": [1,1], "translate": [0,0] }, "objects": {
"P3P4": { "type": "MultiPolygon", "arcs": [[[-1]],[[6,5,-5,-4,-3,1]]]}
}, "arcs": [
[[25,30],[6,0],[0,10],[-14,0],[0,-10],[8,0]],
[[35,6],[0,8]],
[[35,6],[12,0]],
[[47,6],[0,8]],
[[47,14],[0,8]],
[[35,22],[12,0]],
[[35,14],[0,8]]
]}
</programlisting>
</refsection>
</refentry>
</section>
<section xml:id="Topology_Relationships">
<title>Topology Spatial Relationships</title><info>
<abstract>
<para>This section lists the Topology functions used to check relationships between topogeometries and topology primitives</para>
</abstract>
</info>
<refentry xml:id="TG_Equals">
<refnamediv>
<refname>Equals</refname>
<refpurpose>Returns true if two topogeometries are composed of the same topology primitives.</refpurpose>
</refnamediv>
<refsynopsisdiv>
<funcsynopsis>
<funcprototype>
<funcdef>boolean <function>Equals</function></funcdef>
<paramdef><type>topogeometry </type> <parameter>tg1</parameter></paramdef>
<paramdef><type>topogeometry </type> <parameter>tg2</parameter></paramdef>
</funcprototype>
</funcsynopsis>
</refsynopsisdiv>
<refsection>
<title>Description</title>
<para>Returns true if two topogeometries are composed of the same topology primitives: faces, edges, nodes.</para>
<!-- optionally mention that this function uses indexes if appropriate -->
<note>
<para>This function not supported for topogeometries that are geometry collections. It also can not compare topogeometries from different topologies.</para>
</note>
<!-- use this format if new function -->
<para role="availability" conformance="1.1.0">Availability: 1.1.0 </para>
<!-- Optionally mention 3d support -->
<para>&Z_support;</para>
</refsection>
<refsection>
<title>Examples</title>
<programlisting><!--TODO: Need example --></programlisting>
</refsection>
<!-- Optionally add a "See Also" section -->
<refsection>
<title>See Also</title>
<para><xref linkend="GetTopoGeomElements"/>, <xref linkend="ST_Equals"/></para>
</refsection>
</refentry>
<refentry xml:id="TG_Intersects">
<refnamediv>
<refname>Intersects</refname>
<refpurpose>Returns true if any pair of primitives from the two topogeometries intersect.</refpurpose>
</refnamediv>
<refsynopsisdiv>
<funcsynopsis>
<funcprototype>
<funcdef>boolean <function>Intersects</function></funcdef>
<paramdef><type>topogeometry </type> <parameter>tg1</parameter></paramdef>
<paramdef><type>topogeometry </type> <parameter>tg2</parameter></paramdef>
</funcprototype>
</funcsynopsis>
</refsynopsisdiv>
<refsection>
<title>Description</title>
<para>
Returns true if any pair of primitives from the
two topogeometries intersect.
</para>
<!-- optionally mention that this function uses indexes if appropriate -->
<note>
<para>This function not supported for topogeometries that are geometry collections. It also can not compare topogeometries from different topologies.
Also not currently supported for hierarchical topogeometries (topogeometries composed of other topogeometries).</para>
</note>
<!-- use this format if new function -->
<para role="availability" conformance="1.1.0">Availability: 1.1.0 </para>
<!-- Optionally mention 3d support -->
<para>&Z_support;</para>
</refsection>
<refsection>
<title>Examples</title>
<programlisting><!--TODO: Need example --></programlisting>
</refsection>
<!-- Optionally add a "See Also" section -->
<refsection>
<title>See Also</title>
<para><xref linkend="ST_Intersects"/></para>
</refsection>
</refentry>
</section>
<section xml:id="Topology_Import_Export">
<title>Importing and exporting Topologies</title>
<para>
Once you have created topologies, and maybe associated topological layers,
you might want to export them into a file-based format for backup or transfer
into another database.
</para>
<para>
Using the standard dump/restore tools of PostgreSQL is
problematic because topologies are composed by a set of tables (4 for
primitives, an arbitrary number for layers) and records in metadata tables
(topology.topology and topology.layer). Additionally, topology identifiers
are not univoque across databases so that parameter of your topology
will need to be changes upon restoring it.
</para>
<para>
In order to simplify export/restore of topologies a pair of
executables are provided: <filename>pgtopo_export</filename>
and <filename>pgtopo_import</filename>. Example usage:
</para>
<programlisting>
pgtopo_export dev_db topo1 | pgtopo_import topo1 | psql staging_db
</programlisting>
<section xml:id="pgtopo_export">
<title>Using the Topology exporter</title>
<para>
The <filename>pgtopo_export</filename> script takes the name of a
database and a topology and outputs a dump file which can be used
to import the topology (and associated layers) into a new database.
</para>
<para>
By default <filename>pgtopo_export</filename> writes the
dump file to the standard output so that it can be piped to
<filename>pgtopo_import</filename> or redirected to a file
(refusing to write to terminal). You can optionally specify
an output filename with the <code>-f</code> commandline switch.
</para>
<para>
By default <filename>pgtopo_export</filename> includes a dump
of all layers defined against the given topology. This may be more
data than you need, or may be non-working (in case your layer tables
have complex dependencies) in which case you can request skipping the
layers with the <code>--skip-layers</code> switch and deal with those
separately.
</para>
<para>
Invoking <filename>pgtopo_export</filename> with the
<code>--help</code> (or <code>-h</code> for short) switch
will always print short usage string.
</para>
<para>
The dump file format is a compressed tar archive of a
<filename>pgtopo_export</filename> directory containing
at least a <filename>pgtopo_dump_version</filename> file with
format version info. As of version <code>1</code> the directory
contains tab-delimited CSV files with data of the topology
primitive tables (node, edge_data, face, relation), the
topology and layer records associated with it and
(unless <code>--skip-layers</code> is given) a custom-format
PostgreSQL dump of tables reported as being layers of the given
topology.
</para>
</section> <!-- pgtopo_export -->
<section xml:id="pgtopo_import">
<title>Using the Topology importer</title>
<para>
The <filename>pgtopo_import</filename> script takes a
<code>pgtopo_export</code> format topology dump and a
name to give to the topology to be created and outputs
an SQL script reconstructing the topology and associated
layers.
</para>
<para>
The generated SQL file will contain statements that create
a topology with the given name, load primitive data in it,
restores and registers all topology layers by properly
linking all TopoGeometry values to their correct topology.
</para>
<para>
By default <filename>pgtopo_import</filename> reads the dump
from the standard input so that it can be used in conjunction
with <filename>pgtopo_export</filename> in a pipeline.
You can optionally specify an input filename with the
<code>-f</code> commandline switch.
</para>
<para>
By default <filename>pgtopo_import</filename> includes in the output
SQL file the code to restore all layers found in the dump.
</para>
<para>
This may be unwanted or non-working in case your target database already
have tables with the same name as the ones in the dump. In that case
you can request skipping the layers with the <code>--skip-layers</code>
switch and deal with those separately (or later).
</para>
<para>
SQL to only load and link layers to a named topology can be generated
using the <code>--only-layers</code> switch. This can be useful to load
layers AFTER resolving the naming conflicts or to link layers to a
different topology (say a spatially-simplified version of the starting
topology).
</para>
</section> <!-- pgtopo_import -->
</section> <!-- Importing and exporting Topologies -->
</chapter>
|