Insert Features using IFeatureclass.createfeature method

本文介绍了一种在ArcGIS中将一个要素类中的选择集特征批量插入到另一个要素类的方法。该方法通过使用IFeatureClass接口的CreateFeature方法创建新要素,并通过Feature.Store方法将这些要素保存到目标要素类中。此过程适用于小规模的数据迁移,但当数据量较大时,效率较低。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

 将input featureclass里的选择集feature插入到output featureclass里

 使用IFeatureClass.createfeature和feature.store方法來逐個添加新要素,適用于簡單的少量的插入操作。

 數據量較大時,其效率過低。

 
ExpandedBlockStart.gifContractedBlock.gif
Public Sub t_InsertRecords()Sub t_InsertRecords()Sub t_InsertRecords()Sub t_InsertRecords(pFeatclsNm As IFeatureClassName, _
                           pInputFCName 
As IFeatureClassName, _
                           pQFilt 
As IQueryFilter)
  
' +++ Note: this function assumes that the schema between the input feature class and
  ' the destination feature class are the same. If they are not, then this
  ' function will always report errors.
  
  
' get the feature classes from the name
  Dim pFName As IName
  
Dim pInputName As IName
  
  
Set pFName = pFeatclsNm
  
Set pInputName = pInputFCName
  
  
Dim pFeatcls As IFeatureClass
  
Dim pInputFCls As IFeatureClass
  
Set pFeatcls = pFName.Open
  
Set pInputFCls = pInputName.Open
 
  
' get the workspace and start editing
  Dim pDataset As IDataset
  
Set pDataset = pFeatcls
  
  
Dim pWorkspace As IWorkspace
  
Set pWorkspace = pDataset.Workspace
  
  
Dim pWorkspaceEdit As IWorkspaceEdit
  
Set pWorkspaceEdit = pWorkspace
  
  pWorkspaceEdit.StartEditing 
False
  pWorkspaceEdit.StartEditOperation
       
  
' open a cursor on the input feature class with the given query filter
  Dim pFeatCursor As IFeatureCursor
  
Set pFeatCursor = pInputFCls.Search(pQFilt, False)
  
  
' loop through the input features in the cursor, and insert
  ' them into the destination feature class. This is slow since we must use
  ' IFeature::Store to mimic an edit session.
  Dim pFeat As IFeature
  
Dim pRow As IRow
  
Dim pFlds As IFields
  
Dim lSFld As Long
  
Dim i As Long
  
  
Set pRow = pFeatCursor.NextFeature
  
Do Until pRow Is Nothing
    
Set pFeat = pFeatcls.CreateFeature
    
Set pFlds = pFeat.Fields
    
For i = 0 To pFlds.FieldCount - 1
        lSFld 
= pRow.Fields.FindField(pFlds.Field(i).Name)
        pFeat.Value(i) 
= pRow.Value(lSFld)
    
Next i
    pFeat.Store
    
' get next row
    Set pRow = pFeatCursor.NextFeature
  
Loop
  
  pWorkspaceEdit.StopEditOperation
  pWorkspaceEdit.StopEditing 
True
End Sub



 

转载于:https://www.cnblogs.com/iswszheng/archive/2009/03/18/1415503.html

using System; using System.Drawing; using System.Linq; using System.Text; using System.Collections; using System.ComponentModel; using System.Windows.Forms; using System.Data; using System.IO; using System.Runtime.InteropServices; using MapControlApplication1; using ESRI.ArcGIS.esriSystem; using ESRI.ArcGIS.Carto; using ESRI.ArcGIS.Controls; using ESRI.ArcGIS.ADF; using ESRI.ArcGIS.SystemUI; using AE_test; using ESRI.ArcGIS.Display; using ESRI.ArcGIS.DataSourcesRaster; using ESRI.ArcGIS.Geodatabase; using ESRI.ArcGIS.Geometry; using ESRI.ArcGIS.Desktop.AddIns; namespace MapControlApplication1 { public delegate void AfterDrawGeometry(IGeometry geometry); public class DrawPolygoncs : ITool { private IGeometry _polygon=null;//定义一个几何对象,作为绘制结果 private INewPolygonFeedback _polyFeedback=null;//定义一个多边形反馈对象 private IPoint _startPoint=null;//多边形起始结点 private IPoint _endPoint=null;//多边形终止结点 private bool _drawStart=false;//多边形绘制开始标记 public event AfterDrawGeometry eventAfterDrawGeometry; protected AxMapControl myMapControl=null; protected ESRI.ArcGIS.Controls.IHookHelper myHook; //返回结果多边形 public IGeometry Polygon { get{ return _polygon;} } public override void OnCreate(object hook) { myHook.Hook= hook; if(myHook == null) myHook=new ESRI.ArcGIS.Controls.HookHelperClass(); if(_drawStart) { (myHook.Hook as IMapControl3).CurrentTool=this; _polyFeedback = new NewPolygonFeedbackClass(); _polyFeedback.Display=myHook.ActiveView.ScreenDisplay; } } public override void OnClick()//单击鼠标开始绘图或添加结点 { _polygon=null;//每次重设多边形为空值 _drawStart=true;//开始绘制标记置为true (myHook.Hook as IMapControl).CurrentTool=this; _polyFeedback=new NewPolygonFeedbackClass(); _polyFeedback.Display=myHook. ActiveView. ScreenDisplay; } public override void OnMouseDown(int Button, int Shift, int X, int Y) { if(Button ==1) { if(_startPoint == null)//如果是多边形第一个结点 { _startPoint =(myHook.FocusMap as IActiveView).ScreenDisplay. DisplayTransformation.ToMapPoint(X,Y); _polyFeedback.Start(_startPoint);//开始多边形绘制 } else { _endPoint =(myHook.FocusMap as IActiveView).ScreenDisplay. DisplayTransformation.ToMapPoint(X,Y); _polyFeedback.AddPoint(_endPoint);//添加多边形绘制结点 } } } public override void OnMouseMove(int Button, int Shift, int X, int Y) { if(_startPoint !=null) { IPoint movePoint=(myHook.FocusMap as IActiveView).ScreenDisplay. DisplayTransformation.ToMapPoint(X,Y); _polyFeedback.MoveTo(movePoint);//鼠标移动过程中实时显示反馈效果 } } public override void Refresh(int hDC) { base.Refresh(hDC); if (_polyFeedback !=null) { (_polyFeedback as IDisplayFeedback).Refresh(hDC);//实时显示反馈效果 } } public override void OnDblClick()//双击鼠标结束绘图 { _polygon=_polyFeedback.Stop(); _startPoint=null; _drawStart=false; } int ITool.Cursor { get { return 0; } // 返回默认光标 } bool ITool.Deactivate() { return true; // 允许工具取消激活 } bool ITool.OnContextMenu(int x, int y) { return false; // 不处理右键菜单 } void ITool.OnDblClick() { OnDblClick(); // 调用自定义的双击事件 } public void OnKeyDown(int keyCode, int shift) { throw new NotImplementedException(); } public void OnKeyUp(int keyCode, int shift) { throw new NotImplementedException(); } public void OnMouseUp(int button, int shift, int x, int y) { throw new NotImplementedException(); } } }
最新发布
06-12
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值