Arcgis engine 指定图层创建点要素

  1. 原文:http://blog.sina.com.cn/s/blog_5c9288aa0100t71j.html


  2. 转自:http://blog.csdn.net/lxl_sports/article/details/5703796
  3. 这段代码的作用:  
  4. 在指定的图层上创建一个点要素,点要素的位置是通过X,Y坐标指定的,下面是具体的注释 。其中 和IFeatureClassWrite接口有关的代码不要好像也可以实现这个功能,这里是直接通过IFeature添加要素的,不是通过IRow.  
  5. The IFeatureClassWrite interface provides low-level write access to feature class data.  Any associated object behavior is not triggered. In general, IFeatureClassWrite should only be used when implementing custom features that bypass IRow::Store.  
  6.   
  7.   
  8. pLayer = this.axMapControl1.get_Layer(i);//所要加的层  
  9.             IFeatureLayer pFeatureLyr = pLayer as IFeatureLayer;//将ILayer转换为IFeaturelayer,为了对图层上的要素进行编辑  
  10.             IFeatureClass pFeatCls = pFeatureLyr.FeatureClass;//定义一个要素集合,并获取图层的要素集合  
  11.             IFeatureClassWrite fr = (IFeatureClassWrite)pFeatCls;//定义一个实现新增要素的接口实例,并该实例作用于当前图层的要素集  
  12.             IWorkspaceEdit w = (pFeatCls as IDataset).Workspace as IWorkspaceEdit;//定义一个工作编辑工作空间,用于开启前图层的编辑状态  
  13.             IFeature f;//定义一个IFeature实例,用于添加到当前图层上  
  14.             w.StartEditing(true);//开启编辑状态  
  15.             w.StartEditOperation();//开启编辑操作  
  16.             IPoint p;//定义一个点,用来作为IFeature实例的形状属性,即shape属性  
  17.             //下面是设置点的坐标和参考系  
  18.             p = new PointClass();  
  19.             p.SpatialReference = this.axMapControl1.SpatialReference;  
  20.             p.X = 600;  
  21.             p.Y = 500;  
  22.               
  23.             //将IPoint设置为IFeature的shape属性时,需要通过中间接口IGeometry转换  
  24.             IGeometry peo;  
  25.             peo = p;  
  26.             f = pFeatCls.CreateFeature();//实例化IFeature对象, 这样IFeature对象就具有当前图层上要素的字段信息  
  27.             f.Shape = peo;//设置IFeature对象的形状属性  
  28.             f.set_Value(3, "house1");//设置IFeature对象的索引是3的字段值  
  29.             f.Store();//保存IFeature对象  
  30.             fr.WriteFeature(f);//将IFeature对象,添加到当前图层上  
  31.             w.StopEditOperation();//停止编辑操作  
  32.             w.StopEditing(true);//关闭编辑状态,并保存修改  
  33.             this.axMapControl1.Refresh();//刷新地图  
  • 1
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值