实例介绍
【实例截图】
【核心代码】
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 | #region using引用 using System; using System.Windows.Forms; using ESRI.ArcGIS.Controls; using ESRI.ArcGIS.Carto; using ESRI.ArcGIS.Display; using ESRI.ArcGIS.Geometry; using ESRI.ArcGIS.esriSystem; using System.IO; using ESRI.ArcGIS.SystemUI; using AddData; using MapOperation; using QueryAndStatistics; using ESRI.ArcGIS.Geodatabase; using ESRI.ArcGIS.Geoprocessor; using 测量; using 打印; using _17; using _23; using HunanForestsInformation; using System.Collections.Generic; using EngineWindowsApplication2; using 符号化.Class; using ESRI.ArcGIS.DataSourcesFile; #endregion namespace 课设 { public partial class Form2 : Form { public Form2() { InitializeComponent(); } #region 变量定义 private string sMxdPath = Application.StartupPath; private IMap pMap = null ; private IActiveView pActiveView = null ; private List<ILayer> plstLayers = null ; private IFeatureLayer pCurrentLyr = null ; private IEngineEditor pEngineEditor = null ; private IEngineEditTask pEngineEditTask = null ; private IEngineEditLayers pEngineEditLayers = null ; #endregion #region 获取路径 public string getPath( string path) { int t; for (t = 0; t < path.Length; t ) { if (path.Substring(t, 7) == "设计类综合实习" ) { break ; } } string name = path.Substring(0, t 7); return name; } #endregion #region 主地图控件 /// <summary> /// 主地图控件OnMapReplaced事件 ///当主地图显示控件的地图更换时,鹰眼中的地图也跟随更换 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void buju() { //axMapControl3.SpatialReference = axMapControl1.SpatialReference; for ( int i = axMapControl1.LayerCount - 1; i >= 0; i--) { //使鹰眼视图与数据视图的图层上下顺序保持一致 ILayer pLayer = axMapControl1.get_Layer(i); if (pLayer is IGroupLayer || pLayer is ICompositeLayer) { ICompositeLayer pCompositeLayer = (ICompositeLayer)pLayer; for ( int j = pCompositeLayer.Count - 1; j >= 0; j--) { ILayer pSubLayer = pCompositeLayer.get_Layer(j); IFeatureLayer pFeatureLayer = pSubLayer as IFeatureLayer; //if (pFeatureLayer != null) //{ // //由于鹰眼地图较小,所以过滤点图层不添加 // if (pFeatureLayer.FeatureClass.ShapeType != esriGeometryType.esriGeometryPoint // && pFeatureLayer.FeatureClass.ShapeType != esriGeometryType.esriGeometryMultipoint) // { // axMapControl2.AddLayer(pLayer); // } //} } } else { IFeatureLayer pFeatureLayer = pLayer as IFeatureLayer; if (pFeatureLayer != null ) { if (pFeatureLayer.FeatureClass.ShapeType != esriGeometryType.esriGeometryPoint && pFeatureLayer.FeatureClass.ShapeType != esriGeometryType.esriGeometryMultipoint) axMapControl2.AddLayer(pLayer); } } } } private void SynchronizeEagleEye() { if (axMapControl2.LayerCount > 0) { axMapControl2.ClearLayers(); } //设置鹰眼和主地图的坐标系统一致 axMapControl2.SpatialReference = axMapControl1.SpatialReference; for ( int i = axMapControl1.LayerCount - 1; i >= 0; i--) { //使鹰眼视图与数据视图的图层上下顺序保持一致 ILayer pLayer = axMapControl1.get_Layer(i); if (pLayer is IGroupLayer || pLayer is ICompositeLayer) { ICompositeLayer pCompositeLayer = (ICompositeLayer)pLayer; for ( int j = pCompositeLayer.Count - 1; j >= 0; j--) { ILayer pSubLayer = pCompositeLayer.get_Layer(j); IFeatureLayer pFeatureLayer = pSubLayer as IFeatureLayer; if (pFeatureLayer != null ) { //由于鹰眼地图较小,所以过滤点图层不添加 if (pFeatureLayer.FeatureClass.ShapeType != esriGeometryType.esriGeometryPoint && pFeatureLayer.FeatureClass.ShapeType != esriGeometryType.esriGeometryMultipoint) { axMapControl2.AddLayer(pLayer); } } } } else { IFeatureLayer pFeatureLayer = pLayer as IFeatureLayer; if (pFeatureLayer != null ) { if (pFeatureLayer.FeatureClass.ShapeType != esriGeometryType.esriGeometryPoint && pFeatureLayer.FeatureClass.ShapeType != esriGeometryType.esriGeometryMultipoint) axMapControl2.AddLayer(pLayer); } } //设置鹰眼地图全图显示 axMapControl2.Extent = axMapControl1.FullExtent; pEnv = axMapControl1.Extent as IEnvelope; DrawRectangle(pEnv); axMapControl2.ActiveView.Refresh(); } } #endregion #region 鹰眼地图控件 /// <summary> /// 初始化鹰眼地图控件 /// </summary> //private void axmp3() //{ // axMapControl3.Extent = axMapControl1.Extent; // pEnv1 = axMapControl3.Extent; // DrawRectangle(pEnv1); //} private void InitEagleEyeMap() { axMapControl2.Extent = axMapControl1.FullExtent; pEnv = axMapControl2.Extent; DrawRectangle(pEnv); } /// <summary> /// 鹰眼地图控件OnMouseDown事件 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void axMapControl2_OnMouseDown_1( object sender, IMapControlEvents2_OnMouseDownEvent e) { if (axMapControl2.Map.LayerCount > 0) { //按下鼠标左键移动矩形框 if (e.button == 1) { //如果指针落在鹰眼的矩形框中,标记可移动 if (e.mapX > pEnv.XMin && e.mapY > pEnv.YMin && e.mapX < pEnv.XMax && e.mapY < pEnv.YMax) { bCanDrag = true ; } pMoveRectPoint = new PointClass(); pMoveRectPoint.PutCoords(e.mapX, e.mapY); //记录点击的第一个点的坐标 } //按下鼠标右键绘制矩形框 else if (e.button == 2) { IEnvelope pEnvelope = axMapControl2.TrackRectangle(); IPoint pTempPoint = new PointClass(); pTempPoint.PutCoords(pEnvelope.XMin pEnvelope.Width / 2, pEnvelope.YMin pEnvelope.Height / 2); axMapControl1.Extent = pEnvelope; //矩形框的高宽和数据试图的高宽不一定成正比,这里做一个中心调整 axMapControl1.CenterAt(pTempPoint); } } } /// <summary> /// 鹰眼地图控件OnMouseMove事件,移动矩形框 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void axMapControl2_OnMouseMove_1( object sender, IMapControlEvents2_OnMouseMoveEvent e) { if (axMapControl1.LayerCount != 0) { if (e.mapX > pEnv.XMin && e.mapY > pEnv.YMin && e.mapX < pEnv.XMax && e.mapY < pEnv.YMax) { //如果鼠标移动到矩形框中,鼠标换成小手,表示可以拖动 axMapControl2.MousePointer = esriControlsMousePointer.esriPointerHand; if (e.button == 2) //如果在内部按下鼠标右键,将鼠标演示设置为默认样式 { axMapControl2.MousePointer = esriControlsMousePointer.esriPointerDefault; } } else { //在其他位置将鼠标设为默认的样式 axMapControl2.MousePointer = esriControlsMousePointer.esriPointerDefault; } if (bCanDrag) { double Dx, Dy; //记录鼠标移动的距离 Dx = e.mapX - pMoveRectPoint.X; Dy = e.mapY - pMoveRectPoint.Y; pEnv.Offset(Dx, Dy); //根据偏移量更改 pEnv 位置 pMoveRectPoint.PutCoords(e.mapX, e.mapY); DrawRectangle(pEnv); axMapControl1.Extent = pEnv; } } } /// <summary> /// 设置地图控件中心点 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void axMapControl2_OnMouseUp_1( object sender, IMapControlEvents2_OnMouseUpEvent e) { if (e.button == 1 && pMoveRectPoint != null ) { if (e.mapX == pMoveRectPoint.X && e.mapY == pMoveRectPoint.Y) { axMapControl1.CenterAt(pMoveRectPoint); } bCanDrag = false ; } } /// <summary> /// 在鹰眼地图上面画矩形框 /// </summary> /// <param name="pEnvelope"></param> private void DrawRectangle(IEnvelope pEnvelope) { //在绘制前,清除鹰眼中之前绘制的矩形框 IGraphicsContainer pGraphicsContainer = axMapControl2.Map as IGraphicsContainer; //IGraphicsContainer pGC = axMapControl3.Map as IGraphicsContainer; IActiveView pActiveView = pGraphicsContainer as IActiveView; pGraphicsContainer.DeleteAllElements(); //得到当前视图范围 IRectangleElement pRectangleElement = new RectangleElementClass(); IElement pElement = pRectangleElement as IElement; pElement.Geometry = pEnvelope; //设置矩形框(实质为中间透明度面) IRgbColor pColor = new RgbColorClass(); pColor = GetRgbColor(255, 0, 0); pColor.Transparency = 255; ILineSymbol pOutLine = new SimpleLineSymbolClass(); pOutLine.Width = 2; pOutLine.Color = pColor; IFillSymbol pFillSymbol = new SimpleFillSymbolClass(); pColor = new RgbColorClass(); pColor.Transparency = 0; pFillSymbol.Color = pColor; pFillSymbol.Outline = pOutLine; //向鹰眼中添加矩形框 IFillShapeElement pFillShapeElement = pElement as IFillShapeElement; pFillShapeElement.Symbol = pFillSymbol; pGraphicsContainer.AddElement((IElement)pFillShapeElement, 0); //刷新 pActiveView.PartialRefresh(esriViewDrawPhase.esriViewGraphics, null , null ); } /// <summary> /// 获取RGB颜色 /// </summary> /// <param name="intR">红</param> /// <param name="intG">绿</param> /// <param name="intB">蓝</param> /// <returns></returns> private IRgbColor GetRgbColor( int intR, int intG, int intB) { IRgbColor pRgbColor = null ; if (intR < 0 || intR > 255 || intG < 0 || intG > 255 || intB < 0 || intB > 255) { return pRgbColor; } pRgbColor = new RgbColorClass(); pRgbColor.Red = intR; pRgbColor.Green = intG; pRgbColor.Blue = intB; return pRgbColor; } #endregion #region 鹰眼代码 private bool bCanDrag; //鹰眼地图上的矩形框可移动的标志 private IPoint pMoveRectPoint; //记录在移动鹰眼地图上的矩形框时鼠标的位置 private IEnvelope pEnv; //记录数据视图的Extent private void tabControl1_Selecting( object sender, TabControlCancelEventArgs e) { EagleEye eagleEye = new EagleEye(axMapControl1,axMapControl2,axPageLayoutControl1); if (e.TabPage.Name == "地图" ) eagleEye.ActiveMapControl(); else eagleEye.ActivePageLayouControl(); } private void axMapControl1_OnMapReplaced( object sender, IMapControlEvents2_OnMapReplacedEvent e) { SynchronizeEagleEye(); //comboBox1.Items.Clear(); //for (int i = 0; i < axMapControl1.LayerCount; i ) //{ // ILayer pLayer = axMapControl1.get_Layer(i); // comboBox1.Items.Add(pLayer.Name); //} } private void axMapControl1_OnExtentUpdated( object sender, IMapControlEvents2_OnExtentUpdatedEvent e) { //得到当前视图范围 pEnv = (IEnvelope)e.newEnvelope; DrawRectangle(pEnv); } private void tabPage2_Click( object sender, EventArgs e) { IObjectCopy pOC = new ObjectCopyClass(); object copyFormMap = axMapControl1.Map; object copiedMap = pOC.Copy(copyFormMap); //复制地图到copiedMap中 object copyToMap = axPageLayoutControl1.ActiveView.FocusMap; pOC.Overwrite(copiedMap, ref copyToMap); //复制地图 axPageLayoutControl1.ActiveView.Refresh(); } private void axMapControl1_OnAfterScreenDraw( object sender, IMapControlEvents2_OnAfterScreenDrawEvent e) { IActiveView pAV = (IActiveView)axPageLayoutControl1.ActiveView.FocusMap; IDisplayTransformation dTf = pAV.ScreenDisplay.DisplayTransformation; dTf.VisibleBounds = axMapControl1.Extent; axPageLayoutControl1.ActiveView.Refresh(); EagleEye eagleEye = new EagleEye(axMapControl1, axMapControl2, axPageLayoutControl1); eagleEye.CopyToPageLayout(); } #endregion #region 测量代码 #region 量测 //长度、面积量算 private Form3 frmMeasureResult = null ; //量算结果窗体 string pMouseOperate = null ; private INewLineFeedback pNewLineFeedback; //追踪线对象 private INewPolygonFeedback pNewPolygonFeedback; //追踪面对象 private IPoint pPointPt = null ; //鼠标点击点 private IPoint pMovePt = null ; //鼠标移动时的当前点 private double dToltalLength = 0; //量测总长度 private double dSegmentLength = 0; //片段距离 private IPointCollection pAreaPointCol = new MultipointClass(); //面积量算时画的点进行存储; private string sMapUnits = "未知单位" ; //地图单位变量 private object missing = Type.Missing; bool measure = false ; private void 测量ToolStripMenuItem_Click( object sender, EventArgs e) { } private void 距离测量ToolStripMenuItem_Click_1( object sender, EventArgs e) { measure = true ; axMapControl1.CurrentTool = null ; pMouseOperate = "MeasureLength" ; axMapControl1.MousePointer = esriControlsMousePointer.esriPointerCrosshair; if (frmMeasureResult == null || frmMeasureResult.IsDisposed) { frmMeasureResult = new Form3(); frmMeasureResult.frmClosed = new Form3.FormClosedEventHandler(frmMeasureResult_frmColsed); frmMeasureResult.label2.Text = "" ; frmMeasureResult.Text = "距离量测" ; frmMeasureResult.Show(); } else { frmMeasureResult.Activate(); } } //测量结果窗口关闭响应事件 private void frmMeasureResult_frmColsed() { //清空线对象 if (pNewLineFeedback != null ) { pNewLineFeedback.Stop(); pNewLineFeedback = null ; } //清空面对象 if (pNewPolygonFeedback != null ) { pNewPolygonFeedback.Stop(); pNewPolygonFeedback = null ; pAreaPointCol.RemovePoints(0, pAreaPointCol.PointCount); //清空点集中所有点 } //清空量算画的线、面对象 axMapControl1.ActiveView.PartialRefresh(esriViewDrawPhase.esriViewForeground, null , null ); //结束量算功能 pMouseOperate = string .Empty; axMapControl1.MousePointer = esriControlsMousePointer.esriPointerDefault; } private void 面积测量ToolStripMenuItem_Click( object sender, EventArgs e) { measure = true ; axMapControl1.CurrentTool = null ; pMouseOperate = "MeasureArea" ; axMapControl1.MousePointer = esriControlsMousePointer.esriPointerCrosshair; if (frmMeasureResult == null || frmMeasureResult.IsDisposed) { frmMeasureResult = new Form3(); frmMeasureResult.frmClosed = new Form3.FormClosedEventHandler(frmMeasureResult_frmColsed); frmMeasureResult.label2.Text = "" ; frmMeasureResult.Text = "面积量测" ; frmMeasureResult.Show(); } else { frmMeasureResult.Activate(); } } #endregion private void axMapControl1_OnMouseDown( object sender, IMapControlEvents2_OnMouseDownEvent e) { if (export) { axMapControl1.ActiveView.GraphicsContainer.DeleteAllElements(); axMapControl1.ActiveView.Refresh(); IPolygon pPolygon = DrawPolygon(axMapControl1); if (pPolygon == null ) return ; ExportMap.AddElement(pPolygon, axMapControl1.ActiveView); if (fm2 == null || fm2.IsDisposed) { fm2 = new FormExportMap(axMapControl1); } fm2.IsRegion = true ; fm2.GetGeometry = pPolygon as IGeometry; fm2.Show(); fm2.Activate(); export = false ; } if (measure) { //屏幕坐标点转化为地图坐标点 pPointPt = (axMapControl1.Map as IActiveView).ScreenDisplay.DisplayTransformation.ToMapPoint(e.x, e.y); if (e.button == 1) { IActiveView pActiveView = axMapControl1.ActiveView; IEnvelope pEnvelope = new EnvelopeClass(); switch (pMouseOperate) { #region 距离量算 case "MeasureLength" : //判断追踪线对象是否为空,若是则实例化并设置当前鼠标点为起始点 if (pNewLineFeedback == null ) { //实例化追踪线对象 pNewLineFeedback = new NewLineFeedbackClass(); pNewLineFeedback.Display = (axMapControl1.Map as IActiveView).ScreenDisplay; //设置起点,开始动态线绘制 pNewLineFeedback.Start(pPointPt); dToltalLength = 0; } else //如果追踪线对象不为空,则添加当前鼠标点 { pNewLineFeedback.AddPoint(pPointPt); } //pGeometry = m_PointPt; if (dSegmentLength != 0) { dToltalLength = dToltalLength dSegmentLength; } break ; #endregion #region 面积量算 case "MeasureArea" : if (pNewPolygonFeedback == null ) { //实例化追踪面对象 pNewPolygonFeedback = new NewPolygonFeedback(); pNewPolygonFeedback.Display = (axMapControl1.Map as IActiveView).ScreenDisplay; ; pAreaPointCol.RemovePoints(0, pAreaPointCol.PointCount); //开始绘制多边形 pNewPolygonFeedback.Start(pPointPt); pAreaPointCol.AddPoint(pPointPt, ref missing, ref missing); } else { pNewPolygonFeedback.AddPoint(pPointPt); pAreaPointCol.AddPoint(pPointPt, ref missing, ref missing); } break ; #endregion } } } } private void axMapControl1_OnMouseMove( object sender, IMapControlEvents2_OnMouseMoveEvent e) { try { double Lpdx = e.mapX; double Lpdy = e.mapY; string strCoordinate = "X = " Lpdy.ToString() "; " "Y = " Lpdx.ToString(); toolStripStatusLabel_Coordinate.Text = strCoordinate; } catch (Exception ex) { MessageBox.Show(ex.Message, "提示" , MessageBoxButtons.OK, MessageBoxIcon.Information); } if (measure) { sMapUnits = GetMapUnit(axMapControl1.Map.MapUnits); pMovePt = (axMapControl1.Map as IActiveView).ScreenDisplay.DisplayTransformation.ToMapPoint(e.x, e.y); #region 长度量算 if (pMouseOperate == "MeasureLength" ) { if (pNewLineFeedback != null ) { pNewLineFeedback.MoveTo(pMovePt); } double deltaX = 0; //两点之间X差值 double deltaY = 0; //两点之间Y差值 if ((pPointPt != null ) && (pNewLineFeedback != null )) { deltaX = pMovePt.X - pPointPt.X; deltaY = pMovePt.Y - pPointPt.Y; dSegmentLength = Math.Round(Math.Sqrt((deltaX * deltaX) (deltaY * deltaY)), 3); dToltalLength = dToltalLength dSegmentLength; if (frmMeasureResult != null ) { frmMeasureResult.label2.Text = String.Format( "当前线段长度:{0:.###}{1};\r\n总长度为: {2:.###}{1}" , dSegmentLength, sMapUnits, dToltalLength); dToltalLength = dToltalLength - dSegmentLength; //鼠标移动到新点重新开始计算 } frmMeasureResult.frmClosed = new Form3.FormClosedEventHandler(frmMeasureResult_frmColsed); } } #endregion #region 面积量算 if (pMouseOperate == "MeasureArea" ) { if (pNewPolygonFeedback != null ) { pNewPolygonFeedback.MoveTo(pMovePt); } IPointCollection pPointCol = new Polygon(); IPolygon pPolygon = new PolygonClass(); IGeometry pGeo = null ; ITopologicalOperator pTopo = null ; for ( int i = 0; i <= pAreaPointCol.PointCount - 1; i ) { pPointCol.AddPoint(pAreaPointCol.get_Point(i), ref missing, ref missing); } pPointCol.AddPoint(pMovePt, ref missing, ref missing); if (pPointCol.PointCount < 3) return ; pPolygon = pPointCol as IPolygon; if ((pPolygon != null )) { pPolygon.Close(); pGeo = pPolygon as IGeometry; pTopo = pGeo as ITopologicalOperator; //使几何图形的拓扑正确 pTopo.Simplify(); pGeo.Project(axMapControl1.Map.SpatialReference); IArea pArea = pGeo as IArea; frmMeasureResult.label2.Text = String.Format( "总面积为:{0:.####}平方{1};\r\n总长度为:{2:.####}{1}" , pArea.Area, sMapUnits, pPolygon.Length); pPolygon = null ; } } #endregion } } private string GetMapUnit(esriUnits _esriMapUnit) { string sMapUnits = string .Empty; switch (_esriMapUnit) { case esriUnits.esriCentimeters: sMapUnits = "厘米" ; break ; case esriUnits.esriDecimalDegrees: sMapUnits = "十进制" ; break ; case esriUnits.esriDecimeters: sMapUnits = "分米" ; break ; case esriUnits.esriFeet: sMapUnits = "尺" ; break ; case esriUnits.esriInches: sMapUnits = "英寸" ; break ; case esriUnits.esriKilometers: sMapUnits = "千米" ; break ; case esriUnits.esriMeters: sMapUnits = "米" ; break ; case esriUnits.esriMiles: sMapUnits = "英里" ; break ; case esriUnits.esriMillimeters: sMapUnits = "毫米" ; break ; case esriUnits.esriNauticalMiles: sMapUnits = "海里" ; break ; case esriUnits.esriPoints: sMapUnits = "点" ; break ; case esriUnits.esriUnitsLast: sMapUnits = "UnitsLast" ; break ; case esriUnits.esriUnknownUnits: sMapUnits = "未知单位" ; break ; case esriUnits.esriYards: sMapUnits = "码" ; break ; default : break ; } return sMapUnits; } private void axMapControl1_OnDoubleClick( object sender, IMapControlEvents2_OnDoubleClickEvent e) { if (measure) { #region 长度量算 if (pMouseOperate == "MeasureLength" ) { if (frmMeasureResult != null ) { frmMeasureResult.label2.Text = "线段总长度为:" dToltalLength sMapUnits; } if (pNewLineFeedback != null ) { pNewLineFeedback.Stop(); pNewLineFeedback = null ; //清空所画的线对象 (axMapControl1.Map as IActiveView).PartialRefresh(esriViewDrawPhase.esriViewForeground, null , null ); } dToltalLength = 0; dSegmentLength = 0; measure = false ; } #endregion #region 面积量算 if (pMouseOperate == "MeasureArea" ) { if (pNewPolygonFeedback != null ) { pNewPolygonFeedback.Stop(); pNewPolygonFeedback = null ; //清空所画的线对象 (axMapControl1.Map as IActiveView).PartialRefresh(esriViewDrawPhase.esriViewForeground, null , null ); } pAreaPointCol.RemovePoints(0, pAreaPointCol.PointCount); //清空点集中所有点 measure = false ; } #endregion } } #endregion private void Form1_Load( object sender, EventArgs e) { CenterToScreen(); axToolbarControl1.AddItem( "esriControls.ControlsMapZoomInTool" , -1, -1, true , 0, esriCommandStyles.esriCommandStyleIconOnly); axToolbarControl1.AddItem( "esriControls.ControlsMapZoomOutTool" , -1, -1, false , 0, esriCommandStyles.esriCommandStyleIconOnly); axToolbarControl1.AddItem( "esriControls.ControlsMapFullExtentCommand" , -1, -1, false , 0, esriCommandStyles.esriCommandStyleIconOnly); } #region 数据操作 #region 加载地图 private void 加载PersonGeodatabase数据ToolStripMenuItem_Click( object sender, EventArgs e) { LoadDataClass ldc = new LoadDataClass(axMapControl1); ldc.AddPersonGeodatabase(); } private void 加载MXDToolStripMenuItem_Click( object sender, EventArgs e) { LoadDataClass ldc = new LoadDataClass(axMapControl1); ldc.LoadMxFile(); } private void 加载shape文件ToolStripMenuItem_Click( object sender, EventArgs e) { LoadDataClass ldc = new LoadDataClass(axMapControl1); ldc.AddShapefile(); } private void 加载raster数据ToolStripMenuItem_Click( object sender, EventArgs e) { LoadDataClass ldc = new LoadDataClass(axMapControl1); ldc.AddRaster(); } private void 加载CAD数据ToolStripMenuItem_Click( object sender, EventArgs e) { LoadDataClass ldc = new LoadDataClass(axMapControl1); ldc.AddCADByLayer(); } private void 加载FileGeodatabase数据ToolStripMenuItem_Click( object sender, EventArgs e) { LoadDataClass ldc = new LoadDataClass(axMapControl1); ldc.AddFileDatabase(); } private void 加载ArcSED数据ToolStripMenuItem_Click( object sender, EventArgs e) { LoadDataClass ldc = new LoadDataClass(axMapControl1); ldc.AddSDEByDirect(); } #endregion private void 保存文档ToolStripMenuItem_Click( object sender, EventArgs e) { LoadDataClass ldc = new LoadDataClass(axMapControl1); ldc.SaveMap(); MessageBox.Show( "保存成功!" ); } private void 文档另存为ToolStripMenuItem_Click( object sender, EventArgs e) { LoadDataClass ldc = new LoadDataClass(axMapControl1); ldc.SaveAsMap(); MessageBox.Show( "另存成功!" ); } #region 导出地图 FormExportMap fm2 = null ; //string pMouseOperate = null; bool export = false ; public IPolygon DrawPolygon(AxMapControl mapCtrl) { IGeometry pGeometry = null ; if (mapCtrl == null ) return null ; IRubberBand rb = new RubberPolygonClass(); pGeometry = rb.TrackNew(mapCtrl.ActiveView.ScreenDisplay, null ); return pGeometry as IPolygon; } private void 导出地图ToolStripMenuItem_Click( object sender, EventArgs e) { } private void 全域导出ToolStripMenuItem_Click( object sender, EventArgs e) { export = true ; if (fm2 == null || fm2.IsDisposed) { fm2 = new FormExportMap(axMapControl1); } fm2.IsRegion = false ; fm2.GetGeometry = axMapControl1.ActiveView.Extent; fm2.Show(); fm2.Activate(); export = false ; } private void 区域导出ToolStripMenuItem_Click( object sender, EventArgs e) { export = true ; axMapControl1.CurrentTool = null ; axMapControl1.MousePointer = esriControlsMousePointer.esriPointerCrosshair; pMouseOperate = "ExportRegion" ; } #endregion #endregion private void 清除选择ToolStripMenuItem_Click( object sender, EventArgs e) { IActiveView pActiveView = axMapControl1.ActiveView; pActiveView.FocusMap.ClearSelection(); pActiveView.PartialRefresh(esriViewDrawPhase.esriViewGeoSelection, null , pActiveView.Extent); } #region 空间查询 bool query = false ; private void 属性查询ToolStripMenuItem_Click( object sender, EventArgs e) { query = true ; //新创建属性查询窗体 FormQueryByAttribute formQueryByAttribute = new FormQueryByAttribute(); //将当前主窗体中MapControl控件中的Map对象赋值给FormQueryByAttribute窗体的CurrentMap属性 formQueryByAttribute.CurrentMap = axMapControl1.Map; //显示属性查询窗体 formQueryByAttribute.Show(); } private void 空间查询ToolStripMenuItem1_Click( object sender, EventArgs e) { query = true ; //新创建空间查询窗体 FormQueryBySpatial formQueryBySpatial = new FormQueryBySpatial(); //将当前主窗体中MapControl控件中的Map对象赋值给FormSelection窗体的CurrentMap属性 formQueryBySpatial.CurrentMap = axMapControl1.Map; //显示空间查询窗体 formQueryBySpatial.Show(); } private void 缩放至要素ToolStripMenuItem_Click( object sender, EventArgs e) { if (query) { IRgbColor rgb; ISymbol pSymbol = null ; ISelectionEnvironment iSelectionEnvironment = new SelectionEnvironmentClass(); iSelectionEnvironment.DefaultColor = new RgbColorClass() { Red = 255, Blue = 0, Green = 0 }; System.Windows.Forms.Application.DoEvents(); ICommand pCommand = new ESRI.ArcGIS.Controls.ControlsZoomToSelectedCommandClass(); pCommand.OnCreate(axMapControl1.Object); pCommand.OnClick(); axMapControl1.ActiveView.ScreenDisplay.UpdateWindow(); ISelection selection = axMapControl1.Map.FeatureSelection; IEnumFeature enumFeature = (IEnumFeature)selection; enumFeature.Reset(); IFeature pFeature = enumFeature.Next(); //ArrayClass array = new ArrayClass(); //while (pFeature != null) //{ // array.Add(pFeature); // pFeature = enumFeature.Next(); //} switch (pFeature.Shape.GeometryType) { case ESRI.ArcGIS.Geometry.esriGeometryType.esriGeometryPolygon: ISimpleFillSymbol pfillSymbol = new SimpleFillSymbol(); rgb = new RgbColorClass() { Red = 255, Blue = 0, Green = 0 }; pfillSymbol.Color = rgb; pSymbol = pfillSymbol as ISymbol; break ; case ESRI.ArcGIS.Geometry.esriGeometryType.esriGeometryPolyline: ISimpleLineSymbol plineSymbol = new SimpleLineSymbol(); rgb = new RgbColorClass() { Red = 255, Blue = 0, Green = 0 }; plineSymbol.Color = rgb; pSymbol = plineSymbol as ISymbol; break ; case ESRI.ArcGIS.Geometry.esriGeometryType.esriGeometryPoint: ISimpleMarkerSymbol pMarkerSymbol = new SimpleMarkerSymbol(); rgb = new RgbColorClass() { Red = 255, Blue = 0, Green = 0 }; pMarkerSymbol.Color = rgb; pSymbol = pMarkerSymbol as ISymbol; break ; default : break ; } axMapControl1.FlashShape(pFeature.Shape, 5, 1000, pSymbol); query = false ; //IActiveView.Refresh()并不会立刻启动 redraw 方法来重新绘制窗口,要想立刻绘制,需要显式调用ScreenDIsplay.UpdateWindow()方法。 } else MessageBox.Show( "请先选择查询方式选择要素。" ); } #endregion #region 打印 frmPrintPreview print; public bool printf = false ; private void 打印ToolStripMenuItem_Click( object sender, EventArgs e) { printf = true ; print = new frmPrintPreview(axPageLayoutControl1); print.fm1 = this ; print.ShowDialog(); } #endregion #region GP工具 bool GP= false ; private void 添加shp图层ToolStripMenuItem1_Click( object sender, EventArgs e) { GP = true ; OpenFileDialog ofd = new OpenFileDialog(); ofd.Multiselect = true ; ofd.CheckFileExists = true ; ofd.Title = "打开图片" ; ofd.Filter = "*.shp|*.shp" ; ofd.ShowDialog(); if (ofd.FileName == "" ) return ; int Index = ofd.FileName.LastIndexOf( "\\" ); string pFilePath = ofd.FileName.Substring(0, Index); string pFileName = ofd.FileName.Substring(Index 1); IMap map = new Map(); map.Name = "shp" ; axMapControl1.DocumentFilename = string .Empty; axMapControl1.Map = map; axMapControl1.AddShapeFile(pFilePath, pFileName); axMapControl1.ActiveView.Refresh(); } private void 缓冲区分析ToolStripMenuItem_Click( object sender, EventArgs e) { if (GP) { try { //缓冲区分析-GP工具调用 Geoprocessor gp = new Geoprocessor(); gp.OverwriteOutput = true ; ESRI.ArcGIS.AnalysisTools.Buffer pBuffer = new ESRI.ArcGIS.AnalysisTools.Buffer(); //获取缓冲区分析图层 ILayer pLayer = this .axMapControl1.get_Layer(0); IFeatureLayer featLayer = pLayer as IFeatureLayer; pBuffer.in_features = featLayer; string filepath = @"E:\" ; //设置生成结果存储路径 pBuffer.out_feature_class = filepath "\\" pLayer.Name ".shp" ; //设置缓冲区距离 pBuffer.buffer_distance_or_field = "5000 Meters" ; pBuffer.dissolve_option = "ALL" ; //执行缓冲区分析 gp.Execute(pBuffer, null ); //将生成结果添加到地图中 this .axMapControl1.AddShapeFile(filepath, pLayer.Name); MessageBox.Show( "缓冲区已生成,文件保存至路径'E\'" ); this .axMapControl1.MoveLayerTo(1, 0); } catch (Exception ex) { //MessageBox.Show("请输入有效数据"); MessageBox.Show(ex.Message); } } else MessageBox.Show( "请先添加.shp图层。" ); } private void shape转CADToolStripMenuItem_Click( object sender, EventArgs e) { if (GP) { FrmShapeToCAD pFrmShapeToCAD = new FrmShapeToCAD( this .axMapControl1); pFrmShapeToCAD.ShowDialog(); if (pFrmShapeToCAD.DialogResult == DialogResult.OK) { this .axMapControl1.Refresh(); this .axTOCControl1.Refresh(); } } else MessageBox.Show( "请先添加.shp图层。" ); } private void shp导入GeodatabaseToolStripMenuItem1_Click( object sender, EventArgs e) { //首先打开ShapeFile数据 IWorkspaceFactory pWorkspaceFactory = new ShapefileWorkspaceFactory(); OpenFileDialog openFileDialog1 = new OpenFileDialog(); openFileDialog1.Filter = "ShapeFile(*.shp)|*.shp" ; openFileDialog1.Multiselect = false ; DialogResult pDialogResult = openFileDialog1.ShowDialog(); if (pDialogResult != DialogResult.OK) return ; string pPath = openFileDialog1.FileName; string pFolder = System.IO.Path.GetDirectoryName(pPath); string pFileName = System.IO.Path.GetFileName(pPath); //获得ShapeFile数据的工作空间 IWorkspaceName sourceWorkspaceName = new WorkspaceNameClass(); sourceWorkspaceName.WorkspaceFactoryProgID = "esriDataSourcesFile.ShapefileWorkspaceFactory" ; sourceWorkspaceName.PathName = pFolder; IName sourceWorkspaceIName = (IName)sourceWorkspaceName; IWorkspace sourceWorkspace = (IWorkspace)sourceWorkspaceIName.Open(); // 打开目标存储File GeodataBase然后并打开此文件数据库工作空间 IWorkspaceName targetWorkspaceName = new WorkspaceNameClass { WorkspaceFactoryProgID = "esriDataSourcesGDB.FileGDBWorkspaceFactory" , PathName = pFolder @"\FileGDB.gdb" }; IName targetWorkspaceIName = (IName)targetWorkspaceName; IWorkspace targetWorkspace = null ; try { targetWorkspace = (IWorkspace)targetWorkspaceIName.Open(); } catch (Exception ex) { MessageBox.Show( this , "未能正确读取目标工作空间,请确保读取ShapeFile数据路径下有FileGDB.gdb空间数据库(直接将数据压缩文件解压即可)!" , "运行提示" ); } // 将ShapeFile数据转化为IDatasetName数据集 IFeatureClassName sourceFeatureClassName = new FeatureClassNameClass(); IDatasetName sourceDatasetName = (IDatasetName)sourceFeatureClassName; sourceDatasetName.Name = pFileName.Split( '.' )[0]; sourceDatasetName.WorkspaceName = sourceWorkspaceName; // 为目标转化图层创建数据集 IFeatureClassName targetFeatureClassName = new FeatureClassNameClass(); IDatasetName targetDatasetName = (IDatasetName)targetFeatureClassName; targetDatasetName.Name = pFileName.Split( '.' )[0]; targetDatasetName.WorkspaceName = targetWorkspaceName; // 打开源ShapeFile数据获得IFeatureClass IName sourceName = (IName)sourceFeatureClassName; IFeatureClass sourceFeatureClass = (IFeatureClass)sourceName.Open(); // 获得源ShapeFile数据的所有字段 IFieldChecker fieldChecker = new FieldCheckerClass(); IFields sourceFields = sourceFeatureClass.Fields; IFields targetFields = null ; IEnumFieldError enumFieldError = null ; // 设置字段检验参数 fieldChecker.InputWorkspace = sourceWorkspace; fieldChecker.ValidateWorkspace = targetWorkspace; // 检验字段集合是否符合转换要求 fieldChecker.Validate(sourceFields, out enumFieldError, out targetFields); if (enumFieldError != null ) { MessageBox.Show( "数据在进行字段转换过程中出现错误!" ); } // 获ShapeFile数据图形要素字段 String shapeFieldName = sourceFeatureClass.ShapeFieldName; int shapeFieldIndex = sourceFeatureClass.FindField(shapeFieldName); IField shapeField = sourceFields.get_Field(shapeFieldIndex); // 进行图形要素克隆 IGeometryDef geometryDef = shapeField.GeometryDef; IClone geometryDefClone = (IClone)geometryDef; IClone targetGeometryDefClone = geometryDefClone.Clone(); IGeometryDef targetGeometryDef = (IGeometryDef)targetGeometryDefClone; // 利用IGeometryDefEdit进行目标要素图层属性设置 IGeometryDefEdit targetGeometryDefEdit = (IGeometryDefEdit)targetGeometryDef; targetGeometryDefEdit.GridCount_2 = 1; targetGeometryDefEdit.set_GridSize(0, 0.75); // 选择特定条件要素 IQueryFilter queryFilter = new QueryFilterClass(); queryFilter.WhereClause = "PROVINCE = 37" ; queryFilter.SubFields = "*" ; // 通过IFeatureDataConverter进行数据转换 try { IFeatureDataConverter featureDataConverter = new FeatureDataConverterClass(); IEnumInvalidObject enumInvalidObject = featureDataConverter.ConvertFeatureClass (sourceFeatureClassName, queryFilter, null , targetFeatureClassName, targetGeometryDef, targetFields, "" , 1000, 0); // Check for errors. IInvalidObjectInfo invalidObjectInfo = null ; enumInvalidObject.Reset(); while ((invalidObjectInfo = enumInvalidObject.Next()) != null ) { //输出转换过程日志 MessageBox.Show( "数据在进行" invalidObjectInfo.InvalidObjectID "要素转换过程中出现错误!" ); } MessageBox.Show( "转换成功结束!" ); } catch { MessageBox.Show( "在目标文件夹中存在同名称图层,请先删除!" , "消息" , MessageBoxButtons.OKCancel, MessageBoxIcon.Information); } } #endregion #region contextMenuScript private void axTOCControl1_OnMouseDown( object sender, ITOCControlEvents_OnMouseDownEvent e) { ESRI.ArcGIS.Geometry.Point pMoveLayerPoint = new ESRI.ArcGIS.Geometry.Point(); //鼠标在TOC中左键按下时点的位置 ILayer pLyr = null ; System.Object pIndex = null ; IBasicMap pMap = null ; System.Object pOther = null ; esriTOCControlItem pItem = new esriTOCControlItem(); try { //调用HitTest方法() axTOCControl1.HitTest(e.x, e.y, ref pItem, ref pMap, ref pLyr, ref pOther, ref pIndex); if (e.button == 1) { switch (pItem) //pItem是判断鼠标点击部位的关键 { case esriTOCControlItem.esriTOCControlItemLayer: if (pLyr == null ) return ; //如果没有点击到图层 else if (pLyr is IAnnotationSublayer) //如果点击的是注记层,则退出 return ; else { pMoveLayerPoint.PutCoords(e.x, e.y); axMapControl1.CustomProperty = pLyr; } //if (pLyr is IFeatureLayer) ;//矢量图层 //if (pLyr is IRasterLayer) ;//栅格图层 //MessageBox.Show("您点击了图层\"" pLyr.Name "\"的名称"); break ; case esriTOCControlItem.esriTOCControlItemLegendClass: MessageBox.Show( "您点击了图层\"" pLyr.Name "\"的图例" ); break ; case esriTOCControlItem.esriTOCControlItemMap: MessageBox.Show( "您点击了名称为\"" pMap.Name "\"的Map" "对象的名称,它包含\"" pMap.LayerCount "\"个图层" ); break ; case esriTOCControlItem.esriTOCControlItemNone: MessageBox.Show( "您点击了TocControl控件的空白处。" ); break ; default : break ; } } else if (e.button == 2) { axMapControl1.CustomProperty = pLyr; if (pLyr != null && pItem == esriTOCControlItem.esriTOCControlItemLayer) contextMenuStrip1.Show(axTOCControl1, e.x, e.y); //if (pItem == esriTOCControlItem.esriTOCControlItemMap) // contextMenuStrip1.Show(axTOCControl1, e.x, e.y); } } catch (Exception ex) { MessageBox.Show(ex.Message); } } private ESRI.ArcGIS.Geometry.Point pMoveLayerPoint = new ESRI.ArcGIS.Geometry.Point(); //鼠标在TOC中左键按下时点的位置 private FormAttribute frmAttribute = null ; //图层属性窗体 private void 属性表ToolStripMenuItem_Click( object sender, EventArgs e) { IFeatureLayer pFeatureLayer = axMapControl1.CustomProperty as IFeatureLayer; if (pFeatureLayer == null ) return ; if (frmAttribute == null || frmAttribute.IsDisposed) frmAttribute = new FormAttribute(); frmAttribute.CurFeatureLayer = pFeatureLayer; frmAttribute.InitUI(); frmAttribute.ShowDialog(); } private void 缩放到图层ToolStripMenuItem_Click( object sender, EventArgs e) { ILayer pLayer = axMapControl1.CustomProperty as ILayer; if (pLayer == null ) return ; (axMapControl1.Map as IActiveView).Extent = pLayer.AreaOfInterest; (axMapControl1.Map as IActiveView).PartialRefresh(esriViewDrawPhase.esriViewGeography, null , null ); } private void 删除图层ToolStripMenuItem_Click( object sender, EventArgs e) { try { ILayer pLayer = axMapControl1.CustomProperty as ILayer; if (pLayer == null ) return ; DialogResult result = MessageBox.Show( "是否删除[" pLayer.Name "]图层" , "提示" , MessageBoxButtons.OKCancel, MessageBoxIcon.Information); if (result == DialogResult.OK) axMapControl1.Map.DeleteLayer(pLayer); axMapControl1.ActiveView.Refresh(); } catch (Exception ex) { MessageBox.Show(ex.Message); } } private void 统计ToolStripMenuItem_Click( object sender, EventArgs e) { FormStatistics fm = new FormStatistics(); //将当前主窗体中MapControl控件中的Map对象赋值给FormStatistics窗体的CurrentMap属性 fm.CurrentMap = axMapControl1.Map; //显示统计窗体 fm.Show(); } #region 标注 private frmAnnotation frmAnnotation = null ; // 注记 private OperateMap m_OperateMap = new OperateMap(); private void 图层标注ToolStripMenuItem_Click( object sender, EventArgs e) { try { if (frmAnnotation == null || frmAnnotation.IsDisposed) { frmAnnotation = new frmAnnotation(); frmAnnotation.Annotation = new frmAnnotation.AnnotationEventHandler(frmAnnotation_Annotation); } frmAnnotation.Map = axMapControl1.Map; frmAnnotation.InitUI(); frmAnnotation.ShowDialog(); } catch (Exception ex) { MessageBox.Show(ex.Message); } } void frmAnnotation_Annotation( string sFeatClsName, string sFieldName) { IFeatureLayer pFeatLyr = m_OperateMap.GetFeatLyrByName(axMapControl1.Map, sFeatClsName); Annotation(pFeatLyr, sFieldName); } /// <summary> /// 注记 /// </summary> /// <param name="pFeatLyr">注记图层名称</param> /// <param name="sFieldName">注记字段</param> private void Annotation(IFeatureLayer pFeatLyr, string sFieldName) { try { IGeoFeatureLayer pGeoFeatLyer = pFeatLyr as IGeoFeatureLayer; IAnnotateLayerPropertiesCollection pAnnoProps = pGeoFeatLyer.AnnotationProperties; pAnnoProps.Clear(); //设置标注记体格式 ITextSymbol pTextSymbol = new TextSymbolClass(); stdole.StdFont pFont = new stdole.StdFontClass(); pFont.Name = "verdana" ; pFont.Size = 10; pTextSymbol.Font = pFont as stdole.IFontDisp; //设置注记放置格式 ILineLabelPosition pPosition = new LineLabelPositionClass(); pPosition.Parallel = false ; pPosition.Perpendicular = true ; ILineLabelPlacementPriorities pPlacement = new LineLabelPlacementPrioritiesClass(); IBasicOverposterLayerProperties pBasic = new BasicOverposterLayerPropertiesClass(); pBasic.FeatureType = esriBasicOverposterFeatureType.esriOverposterPolyline; pBasic.LineLabelPlacementPriorities = pPlacement; //设置标注文本摆设路径权重 pBasic.LineLabelPosition = pPosition; //控制文本的排放位置 ILabelEngineLayerProperties pLableEngine = new LabelEngineLayerPropertiesClass(); pLableEngine.Symbol = pTextSymbol; pLableEngine.BasicOverposterLayerProperties = pBasic; //设置标注文本的放置方式,以及处理文字间冲突的处理方式等 pLableEngine.Expression = "[" sFieldName "]" ; //输入VBScript或JavaScript语言,设置要标注的字段 IAnnotateLayerProperties pAnnoLayerProps = pLableEngine as IAnnotateLayerProperties; pAnnoProps.Add(pAnnoLayerProps); pGeoFeatLyer.DisplayAnnotation = true ; axMapControl1.Refresh(esriViewDrawPhase.esriViewBackground, null , null ); axMapControl1.Update(); } catch (Exception ex) { MessageBox.Show(ex.Message); } } #endregion private void Form2_FormClosing( object sender, FormClosingEventArgs e) { } #endregion #region 符号化 private OperateMap_1 m_OperateMap_1 = null ; public string filepath = System.AppDomain.CurrentDomain.SetupInformation.ApplicationBase; #region 点状要素符号化 private void 简单类型符号化ToolStripMenuItem_Click( object sender, EventArgs e) { try { //获取目标图层 ILayer pLayer = new FeatureLayerClass(); pLayer = axMapControl1.get_Layer(0); IGeoFeatureLayer pGeoFeatLyr = pLayer as IGeoFeatureLayer; //设置点符号 ISimpleMarkerSymbol pMarkerSymbol = new SimpleMarkerSymbol(); pMarkerSymbol.Style = esriSimpleMarkerStyle.esriSMSSquare; //设置点符号样式为方形 IRgbColor pRgbColor = new RgbColor(); pRgbColor = GetRgbColor(225, 100, 100); pMarkerSymbol.Color = pRgbColor; //设置点符号颜色 ISymbol pSymbol = (ISymbol)pMarkerSymbol; //更改符号样式 ISimpleRenderer pSimpleRenderer = new SimpleRendererClass(); pSimpleRenderer.Symbol = pSymbol; pGeoFeatLyr.Renderer = pSimpleRenderer as IFeatureRenderer; axMapControl1.Refresh(); axTOCControl1.Update(); } catch { MessageBox.Show( "请输入有效图层!" , "提示" , MessageBoxButtons.OK, MessageBoxIcon.Information); } } private void 箭头类型符号化ToolStripMenuItem_Click( object sender, EventArgs e) { try { //获取目标图层 ILayer pLayer = new FeatureLayerClass(); pLayer = axMapControl1.get_Layer(0); IGeoFeatureLayer pGeoFeatLyr = pLayer as IGeoFeatureLayer; //设置点符号 IArrowMarkerSymbol pArrowMarkerSymbol = new ArrowMarkerSymbolClass(); IRgbColor pRgbColor = new RgbColor(); pRgbColor = GetRgbColor(255, 100, 0); pArrowMarkerSymbol.Angle = 90; pArrowMarkerSymbol.Color = pRgbColor; pArrowMarkerSymbol.Length = 20; //设置简单顶点到底边的距离 pArrowMarkerSymbol.Width = 10; //设置箭头底边宽度 pArrowMarkerSymbol.XOffset = 0; pArrowMarkerSymbol.YOffset = 0; pArrowMarkerSymbol.Style = esriArrowMarkerStyle.esriAMSPlain; //设置点符号样式 //更改符号样式 ISimpleRenderer pSimpleRenderer = new SimpleRendererClass(); pSimpleRenderer.Symbol = pArrowMarkerSymbol as ISymbol; pGeoFeatLyr.Renderer = pSimpleRenderer as IFeatureRenderer; axMapControl1.Refresh(); axTOCControl1.Update(); } catch { MessageBox.Show( "请输入有效图层" , "提示" , MessageBoxButtons.OK, MessageBoxIcon.Information); } } private void 字符型点符号化ToolStripMenuItem_Click( object sender, EventArgs e) { try { //获取目标图层 ILayer pLayer = new FeatureLayerClass(); pLayer = axMapControl1.get_Layer(0); IGeoFeatureLayer pGeoFeatLyr = pLayer as IGeoFeatureLayer; //设置点符号 ICharacterMarkerSymbol pCharacterMarkerSymbol = new CharacterMarkerSymbol(); stdole.IFontDisp pFontDisp = (stdole.IFontDisp)( new stdole.StdFontClass()); IRgbColor pRgbColor = new RgbColor(); pRgbColor = GetRgbColor(255, 0, 0); pFontDisp.Name = "arial" ; //设置字体样式 pFontDisp.Italic = true ; //设置是否采用斜体字符 pCharacterMarkerSymbol.Angle = 0; pCharacterMarkerSymbol.CharacterIndex = 65; pCharacterMarkerSymbol.Color = pRgbColor; pCharacterMarkerSymbol.Font = pFontDisp; pCharacterMarkerSymbol.Size = 10; pCharacterMarkerSymbol.XOffset = 3; pCharacterMarkerSymbol.YOffset = 3; //更改符号样式 ISimpleRenderer pSimpleRenderer = new SimpleRendererClass(); pSimpleRenderer.Symbol = pCharacterMarkerSymbol as ISymbol; pGeoFeatLyr.Renderer = pSimpleRenderer as IFeatureRenderer; axMapControl1.Refresh(); axTOCControl1.Update(); } catch { MessageBox.Show( "请输入有效图层" , "提示" , MessageBoxButtons.OK, MessageBoxIcon.Information); } } private void 图片型点符号化ToolStripMenuItem_Click( object sender, EventArgs e) { try { //获取目标图层 ILayer pLayer = new FeatureLayerClass(); pLayer = axMapControl1.get_Layer(0); IGeoFeatureLayer pGeoFeatLyr = pLayer as IGeoFeatureLayer; //设置点符号 IPictureMarkerSymbol pPictureMarkerSymbol = new PictureMarkerSymbolClass(); string fileName = filepath "city.bmp" ; pPictureMarkerSymbol.CreateMarkerSymbolFromFile(esriIPictureType.esriIPictureBitmap, fileName); //图片类型和图片来源 pPictureMarkerSymbol.Angle = 0; pPictureMarkerSymbol.Size = 10; pPictureMarkerSymbol.XOffset = 0; pPictureMarkerSymbol.YOffset = 0; //更改符号样式 ISimpleRenderer pSimpleRenderer = new SimpleRendererClass(); pSimpleRenderer.Symbol = pPictureMarkerSymbol as ISymbol; pGeoFeatLyr.Renderer = pSimpleRenderer as IFeatureRenderer; axMapControl1.Refresh(); axTOCControl1.Update(); } catch { MessageBox.Show( "请输入有效图层" , "提示" , MessageBoxButtons.OK, MessageBoxIcon.Information); } } private void 叠加型点符号化ToolStripMenuItem_Click( object sender, EventArgs e) { try { //获取目标图层 ILayer pLayer = new FeatureLayerClass(); pLayer = axMapControl1.get_Layer(0); IGeoFeatureLayer pGeoFeatLyr = pLayer as IGeoFeatureLayer; //设置点符号 IMultiLayerMarkerSymbol pMultiLayerMarkerSymbol = new MultiLayerMarkerSymbolClass(); IPictureMarkerSymbol pPictureMarkerSymbol = new PictureMarkerSymbolClass(); ICharacterMarkerSymbol pCharacterMarkerSymbol = new CharacterMarkerSymbol(); stdole.IFontDisp fontDisp = (stdole.IFontDisp)( new stdole.StdFontClass()); IRgbColor pGgbColor = new RgbColor(); pGgbColor = GetRgbColor(0, 0, 0); fontDisp.Name = "arial" ; fontDisp.Size = 12; fontDisp.Italic = true ; //创建字符符号 pCharacterMarkerSymbol.Angle = 0; pCharacterMarkerSymbol.CharacterIndex = 97; //字母a pCharacterMarkerSymbol.Color = pGgbColor; pCharacterMarkerSymbol.Font = fontDisp; pCharacterMarkerSymbol.Size = 24; //创建图片符号 string fileName = filepath "city.bmp" ; pPictureMarkerSymbol.CreateMarkerSymbolFromFile(esriIPictureType.esriIPictureBitmap, fileName); pPictureMarkerSymbol.Angle = 0; pPictureMarkerSymbol.BitmapTransparencyColor = pGgbColor; pPictureMarkerSymbol.Size = 10; //添加图片、字符符号到组合符号中 pMultiLayerMarkerSymbol.AddLayer(pCharacterMarkerSymbol); pMultiLayerMarkerSymbol.AddLayer(pPictureMarkerSymbol); pMultiLayerMarkerSymbol.Angle = 0; pMultiLayerMarkerSymbol.Size = 20; pMultiLayerMarkerSymbol.XOffset = 5; pMultiLayerMarkerSymbol.YOffset = 5; //更改符号样式 ISimpleRenderer pSimpleRenderer = new SimpleRendererClass(); pSimpleRenderer.Symbol = pMultiLayerMarkerSymbol as ISymbol; pGeoFeatLyr.Renderer = pSimpleRenderer as IFeatureRenderer; axMapControl1.Refresh(); axTOCControl1.Update(); } catch { MessageBox.Show( "请输入有效图层" , "提示" , MessageBoxButtons.OK, MessageBoxIcon.Information); } } #endregion #region 线状要素符号化 private void 简单线符号ToolStripMenuItem_Click( object sender, EventArgs e) { try { //获取目标图层 ILayer pLayer = new FeatureLayerClass(); pLayer = axMapControl1.get_Layer(3); IGeoFeatureLayer pGeoFeatLyr = pLayer as IGeoFeatureLayer; //设置线符号 ISimpleLineSymbol simpleLineSymbol = new SimpleLineSymbolClass(); simpleLineSymbol.Width = 0; //定义线的宽度 simpleLineSymbol.Style = esriSimpleLineStyle.esriSLSInsideFrame; //定义线的样式 simpleLineSymbol.Color = GetRgbColor(255, 100, 0); //定义线的颜色 ISymbol symbol = simpleLineSymbol as ISymbol; //更改符号样式 ISimpleRenderer pSimpleRenderer = new SimpleRendererClass(); pSimpleRenderer.Symbol = symbol; pGeoFeatLyr.Renderer = pSimpleRenderer as IFeatureRenderer; axMapControl1.Refresh(); axTOCControl1.Update(); } catch (Exception ex) { } } private void 制图线符号化ToolStripMenuItem_Click( object sender, EventArgs e) { try { //获取目标图层 ILayer pLayer = new FeatureLayerClass(); pLayer = axMapControl1.get_Layer(3); IGeoFeatureLayer pGeoFeatLyr = pLayer as IGeoFeatureLayer; //设置线符号 ICartographicLineSymbol pCartographicLineSymbol = new CartographicLineSymbolClass(); pCartographicLineSymbol.Cap = esriLineCapStyle.esriLCSRound; //设置线要素首尾端点形状为圆形 pCartographicLineSymbol.Join = esriLineJoinStyle.esriLJSRound; //设置线要素转折点出的样式为圆滑 pCartographicLineSymbol.Width = 2; //设置线要素符号模板 ILineProperties pLineProperties; pLineProperties = pCartographicLineSymbol as ILineProperties; pLineProperties.Offset = 0; double [] dob = new double [6]; dob[0] = 0; dob[1] = 1; dob[2] = 2; dob[3] = 3; dob[4] = 4; dob[5] = 5; ITemplate pTemplate = new TemplateClass(); pTemplate.Interval = 1; for ( int i = 0; i < dob.Length; i = 2) { pTemplate.AddPatternElement(dob[i], dob[i 1]); } pLineProperties.Template = pTemplate; IRgbColor pRgbColor = GetRgbColor(0, 255, 0); pCartographicLineSymbol.Color = pRgbColor; //更改符号样式 ISimpleRenderer pSimpleRenderer = new SimpleRendererClass(); pSimpleRenderer.Symbol = pCartographicLineSymbol as ISymbol; pGeoFeatLyr.Renderer = pSimpleRenderer as IFeatureRenderer; axMapControl1.Refresh(); axTOCControl1.Update(); } catch { } } private void 多图层线符号化ToolStripMenuItem_Click( object sender, EventArgs e) { try { //获取目标图层 ILayer pLayer = new FeatureLayerClass(); pLayer = axMapControl1.get_Layer(3); IGeoFeatureLayer pGeoFeatLyr = pLayer as IGeoFeatureLayer; //设置线符号 IMultiLayerLineSymbol pMultiLayerLineSymbol = new MultiLayerLineSymbolClass(); ISimpleLineSymbol pSimpleLineSymbol = new SimpleLineSymbolClass(); pSimpleLineSymbol.Style = esriSimpleLineStyle.esriSLSDashDotDot; pSimpleLineSymbol.Width = 2; IRgbColor pRgbColor = GetRgbColor(255, 0, 0); pSimpleLineSymbol.Color = pRgbColor; //ISymbol pSymbol = pSimpleLineSymbol as ISymbol; //pSymbol.ROP2 = esriRasterOpCode.esriROPNotXOrPen; //设置线要素的颜色为 ICartographicLineSymbol pCartographicLineSymbol = new CartographicLineSymbolClass(); pCartographicLineSymbol.Cap = esriLineCapStyle.esriLCSRound; pCartographicLineSymbol.Join = esriLineJoinStyle.esriLJSRound; pCartographicLineSymbol.Width = 2; ILineProperties pLineProperties; pLineProperties = pCartographicLineSymbol as ILineProperties; pLineProperties.Offset = 0; double [] dob = new double [6]; dob[0] = 0; dob[1] = 1; dob[2] = 2; dob[3] = 3; dob[4] = 4; dob[5] = 5; ITemplate pTemplate = new TemplateClass(); pTemplate.Interval = 1; for ( int i = 0; i < dob.Length; i = 2) { pTemplate.AddPatternElement(dob[i], dob[i 1]); } pLineProperties.Template = pTemplate; pRgbColor = GetRgbColor(0, 255, 0); pCartographicLineSymbol.Color = pRgbColor; pMultiLayerLineSymbol.AddLayer(pSimpleLineSymbol); pMultiLayerLineSymbol.AddLayer(pCartographicLineSymbol); //更改符号样式 ISimpleRenderer pSimpleRenderer = new SimpleRendererClass(); pSimpleRenderer.Symbol = pMultiLayerLineSymbol as ISymbol; pGeoFeatLyr.Renderer = pSimpleRenderer as IFeatureRenderer; axMapControl1.Refresh(); axTOCControl1.Update(); } catch { } } private void 图片线符号化ToolStripMenuItem_Click( object sender, EventArgs e) { try { //获取目标图层 ILayer pLayer = new FeatureLayerClass(); pLayer = axMapControl1.get_Layer(3); IGeoFeatureLayer pGeoFeatLyr = pLayer as IGeoFeatureLayer; //设置线符号 IPictureLineSymbol pictureLineSymbol = new PictureLineSymbolClass(); //创建图片符号 string fileName = filepath "city.bmp" ; pictureLineSymbol.CreateLineSymbolFromFile(esriIPictureType.esriIPictureBitmap, fileName); IRgbColor rgbColor = GetRgbColor(255, 0, 0); pictureLineSymbol.Color = rgbColor; pictureLineSymbol.Offset = 0; pictureLineSymbol.Width = 3; pictureLineSymbol.Rotate = false ; //更改符号样式 ISimpleRenderer pSimpleRenderer = new SimpleRendererClass(); pSimpleRenderer.Symbol = pictureLineSymbol as ISymbol; pGeoFeatLyr.Renderer = pSimpleRenderer as IFeatureRenderer; axMapControl1.Refresh(); axTOCControl1.Update(); } catch { } } private void 离散型符号ToolStripMenuItem_Click( object sender, EventArgs e) { try { //获取目标图层 ILayer pLayer = new FeatureLayerClass(); pLayer = axMapControl1.get_Layer(3); IGeoFeatureLayer pGeoFeatLyr = pLayer as IGeoFeatureLayer; //设置线符号 IHashLineSymbol pHashLineSymbol = new HashLineSymbolClass(); ILineProperties pLineProperties = pHashLineSymbol as ILineProperties; pLineProperties.Offset = 0; double [] dob = new double [6]; dob[0] = 0; dob[1] = 1; dob[2] = 2; dob[3] = 3; dob[4] = 4; dob[5] = 5; ITemplate pTemplate = new TemplateClass(); pTemplate.Interval = 1; for ( int i = 0; i < dob.Length; i = 2) { pTemplate.AddPatternElement(dob[i], dob[i 1]); } pLineProperties.Template = pTemplate; pHashLineSymbol.Width = 2; pHashLineSymbol.Angle = 45; //设置单一线段的倾斜角度 IRgbColor pColor = new RgbColor(); pColor = GetRgbColor(0, 0, 255); pHashLineSymbol.Color = pColor; //更改符号样式 ISimpleRenderer pSimpleRenderer = new SimpleRendererClass(); pSimpleRenderer.Symbol = pHashLineSymbol as ISymbol; pGeoFeatLyr.Renderer = pSimpleRenderer as IFeatureRenderer; axMapControl1.Refresh(); axTOCControl1.Update(); } catch { } } #endregion #region 面状要素符号化 private void 简单填充符号ToolStripMenuItem_Click( object sender, EventArgs e) { try { //获取目标图层 ILayer pLayer = new FeatureLayerClass(); pLayer = axMapControl1.get_Layer(5); IGeoFeatureLayer pGeoFeatLyr = pLayer as IGeoFeatureLayer; //设置面填充符号 ISimpleFillSymbol pSimpleFillSymbol = new SimpleFillSymbolClass(); pSimpleFillSymbol.Style = esriSimpleFillStyle.esriSFSVertical; //设置面填充为垂直线填充 pSimpleFillSymbol.Color = GetRgbColor(150, 150, 150); //更改符号样式 ISimpleRenderer pSimpleRenderer = new SimpleRendererClass(); pSimpleRenderer.Symbol = pSimpleFillSymbol as ISymbol; pGeoFeatLyr.Renderer = pSimpleRenderer as IFeatureRenderer; axMapControl1.Refresh(); axTOCControl1.Update(); } catch { } } private void 线填充符号ToolStripMenuItem_Click( object sender, EventArgs e) { try { //获取目标图层 ILayer pLayer = new FeatureLayerClass(); pLayer = axMapControl1.get_Layer(5); IGeoFeatureLayer pGeoFeatLyr = pLayer as IGeoFeatureLayer; //设置面填充符号 ISimpleLineSymbol pSimpleLineSymbol = new SimpleLineSymbolClass(); pSimpleLineSymbol.Style = esriSimpleLineStyle.esriSLSDashDotDot; //定义线的样式 pSimpleLineSymbol.Width = 2; //定义线的宽度 IRgbColor pRgbColor = GetRgbColor(255, 0, 0); pSimpleLineSymbol.Color = pRgbColor; //定义线的颜色 ILineFillSymbol pLineFillSymbol = new LineFillSymbol(); pLineFillSymbol.Angle = 45; pLineFillSymbol.Separation = 10; pLineFillSymbol.Offset = 5; pLineFillSymbol.LineSymbol = pSimpleLineSymbol; //更改符号样式 ISimpleRenderer pSimpleRenderer = new SimpleRendererClass(); pSimpleRenderer.Symbol = pLineFillSymbol as ISymbol; pGeoFeatLyr.Renderer = pSimpleRenderer as IFeatureRenderer; axMapControl1.Refresh(); axTOCControl1.Update(); } catch { } } private void 点填充符号ToolStripMenuItem_Click( object sender, EventArgs e) { try { //获取目标图层 ILayer pLayer = new FeatureLayerClass(); pLayer = axMapControl1.get_Layer(5); IGeoFeatureLayer pGeoFeatLyr = pLayer as IGeoFeatureLayer; //设置面填充符号 IArrowMarkerSymbol pArrowMarkerSymbol = new ArrowMarkerSymbolClass(); //设置填充点点符号样式 IRgbColor pRgbColor = GetRgbColor(255, 0, 0); pArrowMarkerSymbol.Color = pRgbColor as IColor; pArrowMarkerSymbol.Length = 2; pArrowMarkerSymbol.Width = 2; pArrowMarkerSymbol.Style = esriArrowMarkerStyle.esriAMSPlain; IMarkerFillSymbol pMarkerFillSymbol = new MarkerFillSymbolClass(); pMarkerFillSymbol.MarkerSymbol = pArrowMarkerSymbol; pRgbColor = GetRgbColor(255, 0, 0); pMarkerFillSymbol.Color = pRgbColor; pMarkerFillSymbol.Style = esriMarkerFillStyle.esriMFSGrid; IFillProperties pFillProperties = pMarkerFillSymbol as IFillProperties; pFillProperties.XOffset = 2; pFillProperties.YOffset = 2; pFillProperties.XSeparation = 5; pFillProperties.YSeparation = 5; //更改符号样式 ISimpleRenderer pSimpleRenderer = new SimpleRendererClass(); pSimpleRenderer.Symbol = pFillProperties as ISymbol; pGeoFeatLyr.Renderer = pSimpleRenderer as IFeatureRenderer; axMapControl1.Refresh(); axTOCControl1.Update(); } catch { } } private void 渐变色填充符号ToolStripMenuItem_Click( object sender, EventArgs e) { try { //获取目标图层 ILayer pLayer = new FeatureLayerClass(); pLayer = axMapControl1.get_Layer(5); IGeoFeatureLayer pGeoFeatLyr = pLayer as IGeoFeatureLayer; //设置面填充符号 IGradientFillSymbol pGradientFillSymbol = new GradientFillSymbolClass(); IAlgorithmicColorRamp pAlgorithcColorRamp = new AlgorithmicColorRampClass(); //设置颜色带 pAlgorithcColorRamp.FromColor = GetRgbColor(255, 0, 0); //颜色带的起始颜色 pAlgorithcColorRamp.ToColor = GetRgbColor(0, 255, 0); //颜色带的终点颜色 pAlgorithcColorRamp.Algorithm = esriColorRampAlgorithm.esriHSVAlgorithm; pGradientFillSymbol.ColorRamp = pAlgorithcColorRamp; //填充颜色带 pGradientFillSymbol.GradientAngle = 90; //设置填充方向 pGradientFillSymbol.GradientPercentage = 1; //控制色彩饱和度 pGradientFillSymbol.IntervalCount = 5; //设置填充颜色带的数目 pGradientFillSymbol.Style = esriGradientFillStyle.esriGFSLinear; //设置颜色填充带样式为线性填充 //更改符号样式 ISimpleRenderer pSimpleRenderer = new SimpleRendererClass(); pSimpleRenderer.Symbol = pGradientFillSymbol as ISymbol; pGeoFeatLyr.Renderer = pSimpleRenderer as IFeatureRenderer; axMapControl1.Refresh(); axTOCControl1.Update(); } catch { } } private void 图片填充符号ToolStripMenuItem_Click( object sender, EventArgs e) { try { //获取目标图层 ILayer pLayer = new FeatureLayerClass(); pLayer = axMapControl1.get_Layer(5); IGeoFeatureLayer pGeoFeatLyr = pLayer as IGeoFeatureLayer; //设置面填充符号 IPictureFillSymbol pictureFillSymbol = new PictureFillSymbolClass(); string fileName = filepath "states.bmp" ; pictureFillSymbol.CreateFillSymbolFromFile(esriIPictureType.esriIPictureBitmap, fileName); ISimpleLineSymbol simpleLineSymbol = new SimpleLineSymbolClass(); simpleLineSymbol.Style = esriSimpleLineStyle.esriSLSDashDotDot; simpleLineSymbol.Color = GetRgbColor(255, 0, 0); ISymbol symbol = pictureFillSymbol as ISymbol; pictureFillSymbol.Outline = simpleLineSymbol; //设置面要素边线颜色 pictureFillSymbol.Angle = 0; //设置图片显示方向 //更改符号样式 ISimpleRenderer pSimpleRenderer = new SimpleRendererClass(); pSimpleRenderer.Symbol = pictureFillSymbol as ISymbol; pGeoFeatLyr.Renderer = pSimpleRenderer as IFeatureRenderer; axMapControl1.Refresh(); axTOCControl1.Update(); } catch { } } private void 多层填充符号ToolStripMenuItem_Click( object sender, EventArgs e) { try { //获取目标图层 ILayer pLayer = new FeatureLayerClass(); pLayer = axMapControl1.get_Layer(5); IGeoFeatureLayer pGeoFeatLyr = pLayer as IGeoFeatureLayer; //设置渐变色填充面符号 IMultiLayerFillSymbol pMultiLayerFillSymbol = new MultiLayerFillSymbolClass(); IGradientFillSymbol pGradientFillSymbol = new GradientFillSymbolClass(); IAlgorithmicColorRamp pAlgorithcColorRamp = new AlgorithmicColorRampClass(); pAlgorithcColorRamp.FromColor = GetRgbColor(255, 0, 0); pAlgorithcColorRamp.ToColor = GetRgbColor(0, 255, 0); pAlgorithcColorRamp.Algorithm = esriColorRampAlgorithm.esriHSVAlgorithm; pGradientFillSymbol.ColorRamp = pAlgorithcColorRamp; pGradientFillSymbol.GradientAngle = 45; pGradientFillSymbol.GradientPercentage = 0.9; pGradientFillSymbol.Style = esriGradientFillStyle.esriGFSLinear; //设置线填充面符号 ISimpleLineSymbol pSimpleLineSymbol = new SimpleLineSymbolClass(); pSimpleLineSymbol.Style = esriSimpleLineStyle.esriSLSDashDotDot; pSimpleLineSymbol.Width = 2; IRgbColor pRgbColor = GetRgbColor(255, 0, 0); pSimpleLineSymbol.Color = pRgbColor; ILineFillSymbol pLineFillSymbol = new LineFillSymbol(); pLineFillSymbol.Angle = 45; pLineFillSymbol.Separation = 10; pLineFillSymbol.Offset = 5; pLineFillSymbol.LineSymbol = pSimpleLineSymbol; //组合填充符号 pMultiLayerFillSymbol.AddLayer(pGradientFillSymbol); pMultiLayerFillSymbol.AddLayer(pLineFillSymbol); //更改符号样式 ISimpleRenderer pSimpleRenderer = new SimpleRendererClass(); pSimpleRenderer.Symbol = pMultiLayerFillSymbol as ISymbol; pGeoFeatLyr.Renderer = pSimpleRenderer as IFeatureRenderer; axMapControl1.Refresh(); axTOCControl1.Update(); } catch { } } #endregion #endregion private void 导出为shp格式ToolStripMenuItem_Click( object sender, EventArgs e) { SaveFileDialog dlg = new SaveFileDialog(); if (DialogResult.OK == dlg.ShowDialog()) { string file = dlg.FileName.Substring(0, dlg.FileName.LastIndexOf( "\\" )); if (!System.IO.Directory.Exists(file)) { System.IO.Directory.CreateDirectory(file); } try { ILayer pLayer = axMapControl1.Map.get_Layer(0); if (pLayer != null ) { IFeatureLayer pFeatureLayer = pLayer as IFeatureLayer; if (pFeatureLayer.Visible) { ExportFeature(pFeatureLayer.FeatureClass,dlg.FileName); } } MessageBox.Show( "导出成功" ); } catch { MessageBox.Show( "导出失败!" ); } } } private void ExportShp() { SaveFileDialog dlg = new SaveFileDialog(); if (DialogResult.OK == dlg.ShowDialog()) { string file = dlg.FileName.Substring(0, dlg.FileName.LastIndexOf( "\\" )); if (!System.IO.Directory.Exists(file)) { System.IO.Directory.CreateDirectory(file); } try { ILayer pLayer = axMapControl1.Map.get_Layer(1); if (pLayer != null ) { IFeatureLayer pFeatureLayer = pLayer as IFeatureLayer; if (pFeatureLayer.Visible) { ExportFeature(pFeatureLayer.FeatureClass, dlg.FileName); } } MessageBox.Show( "导出成功" ); } catch { MessageBox.Show( "导出失败!" ); } } } public void ExportFeature(IFeatureClass pInFeatureClass, string pPath) { // create a new Access workspace factory IWorkspaceFactory pWorkspaceFactory = new ShapefileWorkspaceFactoryClass(); string parentPath=pPath.Substring(0, pPath.LastIndexOf( "\\" )); string fileName= pPath.Substring(pPath.LastIndexOf( "\\" ) 1, pPath.Length - pPath.LastIndexOf( "\\" ) - 1); IWorkspaceName pWorkspaceName = pWorkspaceFactory.Create(parentPath,fileName, null , 0); // Cast for IName IName name = (IName)pWorkspaceName; //Open a reference to the access workspace through the name object IWorkspace pOutWorkspace = (IWorkspace)name.Open(); IDataset pInDataset = pInFeatureClass as IDataset; IFeatureClassName pInFCName = pInDataset.FullName as IFeatureClassName; IWorkspace pInWorkspace = pInDataset.Workspace; IDataset pOutDataset = pOutWorkspace as IDataset; IWorkspaceName pOutWorkspaceName = pOutDataset.FullName as IWorkspaceName; IFeatureClassName pOutFCName = new FeatureClassNameClass(); IDatasetName pDatasetName = pOutFCName as IDatasetName; pDatasetName.WorkspaceName = pOutWorkspaceName; pDatasetName.Name = pInFeatureClass.AliasName; IFieldChecker pFieldChecker = new FieldCheckerClass(); pFieldChecker.InputWorkspace = pInWorkspace; pFieldChecker.ValidateWorkspace = pOutWorkspace; IFields pFields = pInFeatureClass.Fields; IFields pOutFields; IEnumFieldError pEnumFieldError; pFieldChecker.Validate(pFields, out pEnumFieldError, out pOutFields); IFeatureDataConverter pFeatureDataConverter = new FeatureDataConverterClass(); pFeatureDataConverter.ConvertFeatureClass(pInFCName, null , null , pOutFCName, null , pOutFields, "" , 100, 0); } } } |
标签: 开发
相关软件
小贴士
感谢您为本站写下的评论,您的评论对其它用户来说具有重要的参考价值,所以请认真填写。
- 类似“顶”、“沙发”之类没有营养的文字,对勤劳贡献的楼主来说是令人沮丧的反馈信息。
- 相信您也不想看到一排文字/表情墙,所以请不要反馈意义不大的重复字符,也请尽量不要纯表情的回复。
- 提问之前请再仔细看一遍楼主的说明,或许是您遗漏了。
- 请勿到处挖坑绊人、招贴广告。既占空间让人厌烦,又没人会搭理,于人于己都无利。
关于好例子网
本站旨在为广大IT学习爱好者提供一个非营利性互相学习交流分享平台。本站所有资源都可以被免费获取学习研究。本站资源来自网友分享,对搜索内容的合法性不具有预见性、识别性、控制性,仅供学习研究,请务必在下载后24小时内给予删除,不得用于其他任何用途,否则后果自负。基于互联网的特殊性,平台无法对用户传输的作品、信息、内容的权属或合法性、安全性、合规性、真实性、科学性、完整权、有效性等进行实质审查;无论平台是否已进行审查,用户均应自行承担因其传输的作品、信息、内容而可能或已经产生的侵权或权属纠纷等法律责任。本站所有资源不代表本站的观点或立场,基于网友分享,根据中国法律《信息网络传播权保护条例》第二十二与二十三条之规定,若资源存在侵权或相关问题请联系本站客服人员,点此联系我们。关于更多版权及免责申明参见 版权及免责申明
网友评论
我要评论