• 【225】ArcEngine 实现要素添加 & 删除


    参考:ArcGIS Engine效率探究——要素的添加和删除、属性的读取和更新

    删除要素

                    //添加图层,显示在最上面
                    axMapControl1.AddShapeFile(@"D:1-业务工作8-综合业务平台综合业务平台数据船载", "cjsj.shp");
                    //删除 shapefile 中的要素
                    //获取第一个图层
                    ILayer pLayer = axMapControl1.get_Layer(0);
                    //以矢量图层的形式获取
                    IFeatureLayer pFLayer = pLayer as IFeatureLayer;
                    //获取要素集
                    IFeatureClass pFC = pFLayer.FeatureClass;
                    //查询全部要素
                    IFeatureCursor pFCursor = pFC.Search(null, false);
                    IFeature pfeature = pFCursor.NextFeature();
                    //遍历所有要素,并删除
                    while (pfeature != null)
                    {
                        pfeature.Delete();
                        pfeature = pFCursor.NextFeature();
                    }
    

    添加要素,dtzh 为 DataTable 对象

                    for (int i = 0; i < dtzh.Rows.Count; i++)
                    {
                        //定义一个点,并加入经纬度
                        IPoint pPoint = new PointClass();
                        double lon = Double.Parse(dtzh.Rows[i]["经度"].ToString());
                        double lat = Double.Parse(dtzh.Rows[i]["纬度"].ToString());
                        pPoint.PutCoords(lon, lat);
    
                        //将点添加到要素集中,并存储
                        IFeature pFeature = pFC.CreateFeature();
                        pFeature.Shape = pPoint;
                        pFeature.Store();
    
                        //获取索引值
                        int i_id = pFC.FindField("Id");
                        int i_time = pFC.FindField("Time");
                        int i_cjsj = pFC.FindField("采集时间");
                        int i_lon = pFC.FindField("经度");
                        int i_lat = pFC.FindField("纬度");
                        int i_fo = pFC.FindField("Fo");
                        int i_fm = pFC.FindField("Fm");
                        int i_fv = pFC.FindField("Fv");
                        int i_bv = pFC.FindField("BV");
                        int i_yield = pFC.FindField("Yield");
    
                        //为要素添加属性值
                        pFeature.set_Value(i_id, i);
                        pFeature.set_Value(i_time, dtzh.Rows[i]["Time"].ToString());
                        pFeature.set_Value(i_cjsj, dtzh.Rows[i]["采集时间"].ToString());
                        pFeature.set_Value(i_lon, Double.Parse(dtzh.Rows[i]["经度"].ToString()));
                        pFeature.set_Value(i_lat, Double.Parse(dtzh.Rows[i]["纬度"].ToString()));
                        pFeature.set_Value(i_fo, Int32.Parse(dtzh.Rows[i]["Fo"].ToString()));
                        pFeature.set_Value(i_fm, Int32.Parse(dtzh.Rows[i]["Fm"].ToString()));
                        pFeature.set_Value(i_fv, Int32.Parse(dtzh.Rows[i]["Fv"].ToString()));
                        pFeature.set_Value(i_bv, Int32.Parse(dtzh.Rows[i]["Blank Value"].ToString()));
                        pFeature.set_Value(i_yield, dtzh.Rows[i]["Yield"].ToString());
    
                        pFeature.Store();
                    }
    

    显示地图经纬度坐标

            private void axMapControl1_OnMouseMove(object sender, IMapControlEvents2_OnMouseMoveEvent e)
            {
                tssl_lonlat.Text = String.Format("经纬度:东经{0:0.000}°  北纬{1:0.000}°", e.mapX, e.mapY);
                tssl_lonlat.Visible = true;
            }
    
  • 相关阅读:
    Linux多网卡的时候执行机器Ip
    Base64加密算法
    MD5中Java和Js配套实现
    Maven依赖war开发,找不到war里头的class解决方案
    Java文件上传下载
    ①SpringBoot入门教学篇
    Java开发过程中乱码问题理解
    git切换到新的远程地址
    使用tablayout和recyclerview的时候,报重复添加Fragment错误
    项目组件化,找不到控件, or 控件为null
  • 原文地址:https://www.cnblogs.com/alex-bn-lee/p/5820900.html
Copyright © 2020-2023  润新知