1. 获取Map中选择的元素(Element)
View Code
IGraphicsContainer m_GraphicsContainer =axMapControl1.Map as IGraphicsContainer;
m_GraphicsContainer.Reset();
IGraphicsContainerSelect pGraphicSelect = m_GraphicsContainer as IGraphicsContainerSelect;
//pGraphicSelect.SelectedElements.Reset();
int a = pGraphicSelect.ElementSelectionCount;
IEnumElement m_EnumEle=pGraphicSelect.SelectedElements;
m_EnumEle.Reset();
IElement m_Element = m_EnumEle.Next();
IElementProperties m_ElementProperties = m_Element as IElementProperties;
while (m_Element != null)
{
comboBox1.SelectedItem = m_ElementProperties.Name;
propertyGrid1.SelectedObject = (Stra)m_ElementProperties.CustomProperty;
m_Element = m_EnumEle.Next();
m_ElementProperties = m_Element as IElementProperties;
}
2. 获取MapControl中选择的要素(Feature)
View Code
IMap m_Map = pMapCtrl.Map; ESRI.ArcGIS.esriSystem.IUID uid = new ESRI.ArcGIS.esriSystem.UIDClass(); uid.Value = "{E156D7E5-22AF-11D3-9F99-00C04F6BC78E}"; ESRI.ArcGIS.Carto.IEnumLayer enumLayer = m_Map.get_Layers(((ESRI.ArcGIS.esriSystem.UID)(uid)), true); enumLayer.Reset(); ESRI.ArcGIS.Carto.ILayer layer = enumLayer.Next(); int j = -1; IFeatureLayer pCurrentLyr = null; while (!(layer == null)) { j++; if (layer.Name == "Holes") { pCurrentLyr = layer as IFeatureLayer; break; } layer = enumLayer.Next(); } IQueryFilter queryFilter = new QueryFilterClass(); IFeatureSelection pFeatSelection = pCurrentLyr as IFeatureSelection; ISelectionSet selectionSet = pFeatSelection.SelectionSet; ICursor cursor = null; selectionSet.Search(queryFilter, true, out cursor); IFeatureCursor featureCursor = cursor as IFeatureCursor; IFeature feature; int i = 0; string holeid=""; while ((feature = featureCursor.NextFeature()) != null) { if (i==0) { holeid= feature.get_Value(2).ToString(); break; } }
3. 打开AccessWorkspaceFactory中的栅格数据集
View Code
1 string strFeatName = pFeatDlg.FileName;//自己定义的对话框
2 IWorkspaceFactory m_WorkspaceFactory = new AccessWorkspaceFactory();
3 IWorkspace m_Workspce = m_WorkspaceFactory.OpenFromFile(MineFrm.m_WorkspacePath, 0);
4 IRasterWorkspaceEx m_RasterWorkspace = m_Workspce as IRasterWorkspaceEx;//Access工作空间需要用这个接口跳转
5 IRasterDataset pRasterDataset = null;
6 pRasterDataset = m_RasterWorkspace.OpenRasterDataset(strFeatName);
7 IRasterLayer pRasterLayer = new RasterLayerClass();
8 pRasterLayer.CreateFromDataset(pRasterDataset);
9 ILayer player = pRasterLayer as ILayer;
10 player.Name = pRasterLayer.Name;
11 map = axMapControl1.Map;
12 map.AddLayer(player);
4. 获取栅格类型的Surface
首先定义一个UIDClass:
ESRI.ArcGIS.esriSystem.IUID uid2 = new ESRI.ArcGIS.esriSystem.UIDClass();
uid2.Value = "{D02371C7-35F7-11D2-B1F2-00C04F8EDEFF}" ;//= IRasterLayer
View Code
1 IRasterLayer m_RasterLayer=null;
2 ESRI.ArcGIS.Carto.IEnumLayer enumLayer = m_Map.get_Layers(((ESRI.ArcGIS.esriSystem.UID)(uid2)), true); // Explicit Cast
3 enumLayer.Reset();
4 ESRI.ArcGIS.Carto.ILayer layer = enumLayer.Next();
5 int i = -1;
6
7 while (!(layer == null))
8 {
9 i++;
10 if (i == listSruface.SelectedIndex)//这里是为了获取ListBox中选择项对应的图层,不在通过图层名称获取图层,通过遍历添加,再遍历选择
11 {
12 m_RasterLayer = layer as IRasterLayer;
13 }
14
15 layer = enumLayer.Next();
16 }
17 IRasterSurface m_RasterSurface = new RasterSurfaceClass();
18 MessageBox.Show(m_RasterLayer.BandCount.ToString());
19 //m_RasterSurface.PutRaster(m_RasterLayer.Raster, 0);
20 IRasterBandCollection pBands;
21 pBands = m_RasterLayer.Raster as IRasterBandCollection;
22 m_RasterSurface.RasterBand = pBands.Item(0);
23
24 ISurface m_Surface = m_RasterSurface as ISurface;
25 IGeometry pGeoPolyline;
26 m_Surface.InterpolateShape(m_CutLine as IGeometry, out pGeoPolyline, ref mis);
27 IPolyline pPolyline = pGeoPolyline as IPolyline;
28 IGraphicsContainer pGraphicContainer = m_PreViewMapCtrl.ActiveView as IGraphicsContainer;
29 ISimpleLineSymbol pSimpleLineSymbol = new SimpleLineSymbolClass();
30 pSimpleLineSymbol.Width = 1;
31 pSimpleLineSymbol.Style = esriSimpleLineStyle.esriSLSSolid;
32 IColor pColor = ColorAndIcolor.ConvertColorToIColor(Color.Red);
33 pSimpleLineSymbol.Color = pColor;
34 IElement pEleAxisX = null;//X轴线
35 ILineElement pLineEleX = new LineElementClass();
36 pLineEleX.Symbol = pSimpleLineSymbol;
37 pEleAxisX = pLineEleX as IElement;
38 pEleAxisX.Geometry = pPolyline;
39 pGraphicContainer.AddElement(pEleAxisX, 0);
40 m_PreViewMapCtrl.Extent = pGeoPolyline.Envelope;
41 m_PreViewMapCtrl.ActiveView.Refresh();
5.从FeatureClass中读取要素IFeature
View Code
IList<IPolyline> m_Polylines = new List<IPolyline>();//存放线要素 IQueryFilter pQueryFilter = new QueryFilterClass(); //pQueryFilter.SubFields = "LineId,Shape,StartPointId,EndPointId"; //过滤字段 // .WhereClause = "SUBTYPE = 'INDSTL'" IFeatureCursor pCur = m_FeatSelect.Search(null, false);//查找字段 int iLineTypeIndex = m_FeatSelect.FindField("Type"); IFeature pFeat = pCur.NextFeature(); int show = 0; while (pFeat != null) { show++; if (double.Parse(pFeat.get_Value(iLineTypeIndex).ToString())>0) { IPolyline pPoline = pFeat.Shape as IPolyline; m_Polylines.Add(pPoline); } pFeat = pCur.NextFeature(); }
6.读取ITable中的IRow
View Code
1 IQueryFilter pQueryFilter = new QueryFilterClass(); 2 pQueryFilter.WhereClause = sFinallySql; 3 //int i = m_Table.RowCount(pQueryFilter); 4 //MessageBox.Show(i.ToString()); 5 pList = new List<Rooms>(); 6 ICursor pcur = m_Table.Search(pQueryFilter, true); 7 IRow pRow = pcur.NextRow(); 8 9 while (pRow != null) 10 { 11 int k = pRow.Fields.FieldCount; 12 Rooms m_Room = new Rooms(); 13 m_Room.RoomId = pRow.get_Value(roomidIndex).ToString(); 14 m_Room.RoomName = pRow.get_Value(roomNameIndex).ToString(); 15 m_Room.RoonEnglish = pRow.get_Value(engIndex).ToString(); 16 m_Room.Deprt = pRow.get_Value(deaprtIndex).ToString(); 17 m_Room.RoomType = pRow.get_Value(typeIndex).ToString(); 18 m_Room.Useage = pRow.get_Value(usageIndex).ToString(); 19 m_Room.LocationSchool = pRow.get_Value(localIndex).ToString(); 20 if (pRow.get_Value(areaIndex).ToString() != null && pRow.get_Value(areaIndex).ToString() != "") 21 { 22 m_Room.Area_1 = double.Parse(pRow.get_Value(areaIndex).ToString()); 23 } 24 25 m_Room.User_1 = pRow.get_Value(userIndex).ToString(); 26 pList.Add(m_Room); 27 pRow = pcur.NextRow(); 28 } 29 dataGridView1.DataSource = pList; 30 for (int i = 0; i < dataGridView1.Columns.Count; i++) 31 dataGridView1.Columns[i].HeaderText = plistheader[i];