ArcEngine代码整理(2)

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];

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
提供的源码资源涵盖了安卓应用、小程序、Python应用和Java应用等多个领域,每个领域都包含了丰富的实例和项目。这些源码都是基于各自平台的最新技术和标准编写,确保了在对应环境下能够无缝运行。同时,源码配备了详细的注释和文档,帮助用户快速理解代码结构和实现逻辑。 适用人群: 这些源码资源特别适合大学生群体。无论你是计算机相关专业的学生,还是对其他领域编程感兴趣的学生,这些资源都能为你提供宝贵的学习和实践机会。通过学习和运行这些源码,你可以掌握各平台开发的基础知识,提升编程能力和项目实战经验。 使用场景及目标: 在学习阶段,你可以利用这些源码资源进行课程实践、课外项目或毕业设计。通过分析和运行源码,你将深入了解各平台开发的技术细节和最佳实践,逐步培养起自己的项目开发和问题解决能力。此外,在求职或创业过程,具备跨平台开发能力的大学生将更具竞争力。 其他说明: 为了确保源码资源的可运行性和易用性,特别注意了以下几点:首先,每份源码都提供了详细的运行环境和依赖说明,确保用户能够轻松搭建起开发环境;其次,源码的注释和文档都非常完善,方便用户快速上手和理解代码;最后,我会定期更新这些源码资源,以适应各平台技术的最新发展和市场需求。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值