ArcEngine½Ó¿Ú´óÈ« ÏÂÔØ±¾ÎÄ

64. int layerCount = axMapControl1.LayerCount; 65. for (int i = 0; i < layerCount; i++) 66. {

67. pLayer = axMapControl1.get_Layer(i); 68. pFeatureLayer = (IFeatureLayer)pLayer; 69. pFeatureClass = pFeatureLayer.FeatureClass;

70. pFeatureCursor = pFeatureClass.Search((IQueryFilter)pSpatialFilter,

false);

71. pFeature = pFeatureCursor.NextFeature(); 72. while (pFeature != null) 73. {

74. listView1.Items.Add(pLayer.Name); 75. } 76. } 77. } 78. } 79. }

39.¹ØÓÚ¸ü¸Ä·ûºÅµÄ´úÂë 1. 2. 3. 4. 5. 6. 7. 8. 9. 10. 11. 12. 13. 14. 15. 16. 17. 18. 19. 20.

private void axTOC1_OnDoubleClick(object sender, ITOCControlEvents_OnDoubleClickEvent e) {

esriTOCControlItem itemType = esriTOCControlItem.esriTOCControlItemNone; IBasicMap basicMap = null; ILayer layer = null; object unk = null; object data = null;

axTOC1.HitTest(e.x, e.y, ref itemType, ref basicMap, ref layer, ref unk, ref data);

if (e.button == 1) {

if (itemType == esriTOCControlItem.esriTOCControlItemLegendClass) {

//È¡µÃͼÀý

ILegendClass pLegendClass = ((ILegendGroup)unk).get_Class((int)data);

//´´½¨·ûºÅÑ¡ÔñÆ÷SymbolSelectorʵÀý

FormSymbolControl SymbolSelectorFrm = new FormSymbolControl(pLegendClass, layer);

if (SymbolSelectorFrm.ShowDialog() == DialogResult.OK) {

//¾Ö²¿¸üÐÂÖ÷Map¿Ø¼þ

//m_mapControl.ActiveView.PartialRefresh(esriViewDrawPhase.esriViewGeography, null, null);

21. 22. 23. 24. 25. 26. 27. 28. 29. }

39. ¹ØÓÚÏÔʾÊôÐԵĴúÂë 40. ///

41. /// Ìî³äDataTableÖеÄÊý¾Ý 42. /// 43. /// 44. /// 45. ///

46. public static DataTable CreateDataTable(ILayer pLayer, string tableName) 47. {

48. //´´½¨¿ÕDataTable

49. DataTable pDataTable = CreateDataTableByLayer(pLayer, tableName); 50. //´´½¨DataTableµÄÐжÔÏó 51. DataRow pDataRow = null; 52. //È¡µÃͼ²ãÀàÐÍ

53. string shapeType = getShapeType(pLayer); 54. //´ÓILayer²éѯµ½ITable

55. ITable pTable = pLayer as ITable;

56. ICursor pCursor = pTable.Search(null, false); 57. //È¡µÃITableÖеÄÐÐÐÅÏ¢

58. IRow pRow = pCursor.NextRow(); 59. int n = 0;

60. while (pRow != null) 61. {

62. //н¨DataTableµÄÐжÔÏó

63. pDataRow = pDataTable.NewRow();

64. for (int i = 0; i < pRow.Fields.FieldCount; i++) 65. {

axMap1.ActiveView.PartialRefresh(esriViewDrawPhase.esriViewGeography, null, null);

//ÉèÖÃеķûºÅ

pLegendClass.Symbol = SymbolSelectorFrm.pSymbol; //¸üÐÂÖ÷Map¿Ø¼þºÍͼ²ã¿Ø¼þ this.axMap1.ActiveView.Refresh(); this.axTOC1.Refresh(); } } }

66. //Èç¹û×Ö¶ÎÀàÐÍΪesriFieldTypeGeometry£¬Ôò¸ù¾Ýͼ²ãÀàÐÍÉèÖÃ×Ö¶ÎÖµ 67. if (pRow.Fields.get_Field(i).Type ==

esriFieldType.esriFieldTypeGeometry) 68. {

69. pDataRow = shapeType; 70. }

71. //µ±Í¼²ãÀàÐÍΪAnotationʱ£¬ÒªËØÀàÖлáÓÐesriFieldTypeBlobÀàÐ͵ÄÊý¾Ý£¬ 72. //Æä´æ´¢µÄÊDZê×¢ÄÚÈÝ£¬Èç´ËÇé¿öÐ轫¶ÔÓ¦µÄ×Ö¶ÎÖµÉèÖÃΪElement 73. else if (pRow.Fields.get_Field(i).Type ==

esriFieldType.esriFieldTypeBlob) 74. {

75. pDataRow = \76. } 77. else 78. {

79. pDataRow = pRow.get_Value(i); 80. } 81. }

82. //Ìí¼ÓDataRowµ½DataTable 83. pDataTable.Rows.Add(pDataRow); 84. pDataRow = null; 85. n++;

86. pRow = pCursor.NextRow(); 87. ////Ϊ±£Ö¤Ð§ÂÊ£¬Ò»´ÎÖ»×°ÔØ×î¶àÌõ¼Ç¼ 88. //if (n == 2000) 89. //{

90. // pRow = null; 91. //} 92. //else 93. //{

94. // pRow = pCursor.NextRow(); 95. //} 96. }

97. return pDataTable; }

41.¹ØÓÚIFeature±äÁ¿Ìí¼Ó½øListÊý×éÀïµÄÎÊÌâ 1. 2.

List listFeature = new List(); try

3. 4. 5. 6. 7. 8. 9. 10. 11. 12. 13.

{

pFC_TER_LN =

pFeatureWorkspace.OpenFeatureClass(\} catch {

richTextBox1.SelectionStart = richTextBox1.Text.Length;

richTextBox1.SelectedText = \µØÐÎͼ£º\e + \ÖÐûÓÐTER_LN_lͼ²ã£¡\\n\

richTextBox1.Refresh(); continue; }

for (int i = 0; i < pFC_TER_LN.FeatureCount([color=Red]null[/color]); i++) ///½«¸Ãͼ²ãµÄÿ¸öFeatureÌáÈ¡³öÀ´ÒÔ¹©±à¼­Ê±ÒÀ´Î¸³Öµ£¬²¢ÇÒ¿ÉÒÔÉèÖÃFeatureCount·½·¨µÄ²ÎÊýΪһ¸öIQueryFilterÀàÐ͵ıäÁ¿£¬¾Í¿ÉÒÔʵÏÖÄãËùÒªÇóµÄ·½·¨ÁË£¬ÓÃSearch()·½·¨£¬Ó¦¸ÃÊDz»¿ÉÒԵģ¬Ï£ÍûÄãÃÇÊÔһϡ£ 14. 15. 16. }

{

pFeatrue = pFC_TER_LN.GetFeature(i); listFeature.Add(pFeatrue);

42.¹ØÓÚIDataStatistics½Ó¿Ú£¨esriGeodatabase£©

IDataStatistics½Ó¿ÚµÄµÚÒ»¸öÊôÐÔStatistics£¨Ö»¶Á£¬·µ»ØÒ»¸öIStatisticsResultsÀàÐ͵ıäÁ¿£¬¿ÉÒÔÓøñäÁ¿È¥ÇóÖ¸¶¨ÓòµÄÊýѧֵ£©

IDataStatistics½Ó¿ÚµÄµÚ¶þ¸öÊôÐÔUniqueValues£¨Ö»¶Á£¬·µ»ØÒ»¸öIEnumVariantSimpleÀàÐ͵ıäÁ¿£¬¸Ã±äÁ¿¿ÉÒÔ±éÀúÖ¸¶¨ÓòµÄËùÓÐValue£©

IDataStatistics½Ó¿ÚµÄµÚÈý¸öÊôÐÔUniqueValueCount£¨Ö»¶Á£¬·µ»ØÖ¸¶¨ÓòµÄÖµµÄÊýÁ¿£© IDataStatistics½Ó¿ÚµÄµÚËĸöÊôÐÔField£¨¶Áд£¬¶ÁÈ¡»òÕßÉèÖÃÖ¸¶¨Óò£¬²ÎÊýΪStringÀàÐ͵ÄÓòÃûµÄÃû³Æ£©

IDataStatistics½Ó¿ÚµÄµÚÎå¸öÊôÐÔCursor£¨Ö»Ð´£¬ÔÚ×ö¶ÔÓòµÄ²éѯ¼°¸÷ÖÖ²Ù×÷֮ǰһ¶¨ÒªÉèÖÃÒ»¸öÓαêµÄ²ÎÊý£¬¿ÉÒÔÈ¥ÉèÖÃQueryFilterÀ´¹ýÂË£© Àý×Ó´úÂ룺

The following code uses a DataStatistics object to create a list of unique values in the \field and also display the mean of these values (notice that the cursor must be reset to obtain the mean value after accessing the unique values):

1.

Dim pMxDoc As esriArcMapUI.IMxDocument, pFLayer As esriCarto.IFeatureLayer,

pData As esriGeoDatabase.IDataStatistics 2. Dim pCursor As esriGeoDatabase.ICursor, pStatResults As esriSystem.IStatisticsResults 3. 4.

Set pMxDoc = ThisDocument

Set pFLayer = pMxDoc.FocusMap.Layer(0)