码迷,mamicode.com
首页 > 其他好文 > 详细

arcgis engine删除数据及数据导入速度较快的方法

时间:2014-08-19 12:22:24      阅读:263      评论:0      收藏:0      [点我收藏+]

标签:style   blog   http   color   os   io   数据   ar   

    最近利用arcgis engine开发一款用于审核软件,需要先进行图形库的建立,还有些原始数据经过一些处理形成需要的数据。

  代码实现的过程中发现数据进行过处理以后,数据量比较大,几万条的Feature一条条写入sde库速度让人无法忍受。然后在网上查了不少资料,发现多数类似于shape导入sde的时候都是用游标一条条插入的。但是也找到了一个方法,虽然也需要一些时间,但是总体比游标快太多了,记录在此。

 

bubuko.com,布布扣
 1 /// <summary>
 2         /// 图层导入数据集
 3         /// </summary>
 4         /// <param name="lName">源图层的IName</param>
 5         /// <param name="inWorkspace">源图层所在的工作空间</param>
 6         /// <param name="featureDataset">目标数据集</param>
 7         /// <returns>返回导入成功(true),失败(false)</returns>
 8         private bool ImportLayerIntoDataset(IName lName, IWorkspace inWorkspace, IFeatureDataset featureDataset, string strOutFeatureName)
 9         {
10             try
11             {
12                 IFeatureClass inFeatureClass = (IFeatureClass)lName.Open();
13                 IFeatureClassName inFeatureClassName = (IFeatureClassName)lName;
14 
15                 IFeatureClassName outFeatureClassName = new FeatureClassNameClass();
16                 IDatasetName outDatasetName = (IDatasetName)outFeatureClassName;
17                 IDataset outWorkspaceDataset = (IDataset)featureDataset.Workspace;
18                 IWorkspaceName outWorkspaceName = (IWorkspaceName)outWorkspaceDataset.FullName;
19                 outDatasetName.WorkspaceName = outWorkspaceName;
20                 outDatasetName.Name = "SDE." + strOutFeatureName;
21 
22                 IFieldChecker fieldChecker = new FieldCheckerClass();
23                 IFields outFeatureClassFields;
24                 IFields inFeatureClassFields = inFeatureClass.Fields;
25                 IEnumFieldError enumFieldError;
26                 fieldChecker.InputWorkspace = inWorkspace;
27                 fieldChecker.ValidateWorkspace = featureDataset.Workspace;
28 
29                 fieldChecker.Validate(inFeatureClassFields, out enumFieldError, out outFeatureClassFields);
30                 IField geometryField;
31                 geometryField = outFeatureClassFields.get_Field(outFeatureClassFields.FindField(inFeatureClass.ShapeFieldName));
32                 IGeometryDef geometryDef = geometryField.GeometryDef;
33                 IQueryFilter qf = new QueryFilterClass();
34                 qf.WhereClause = "";
35                 IFeatureDataConverter fctofc = new FeatureDataConverterClass();
36                 IEnumInvalidObject enumErrors = fctofc.ConvertFeatureClass(inFeatureClassName, qf, (IFeatureDatasetName)featureDataset.FullName, outFeatureClassName, geometryDef, outFeatureClassFields, "", 1000, 0);
37 
38                 return true;
39             }
40             catch (Exception ex)
41             {
42                 MessageBox.Show(ex.Message);
43                 return false;
44             }
45         } 
图层导入数据集

     ConvertFeatureClass在文档中的解释为:Converts a featureClass to a Personal Geodatabase/Geodatabase featureClass.

bubuko.com,布布扣
1 IDataset pDataset = pFeatureClass as IDataset;
2 IName pName = pDataset.FullName;
3 
4 IWorkspace pWorkspace = pDataset.Workspace;
获取上述函数的参数

      通过IFeatureClass上述方式即可获得函数的参数。

      另:由于做删除数据的时候,脑子秀逗了下,忘记解锁数据了,导致删除后图形能在图上显示,但是数据表里没有数据了。当时查找了各种删除数据的方式,主要也是游标的方式一条条的删除。但是看到有人介绍了好几种删除的方式,只记下了一种,也算是删除速度最快的一种。

bubuko.com,布布扣
1 string strSQL="delete from " + pFeatureClass.AliasName + " where XMBH = ‘" + strProjectID + "";
2 IDataset pDataset = pFeatureClass as IDataset;
3 pDataset.Workspace.ExecuteSQL(strSQL);
批量删除数据

 

                                                                                                                                                                   -------记录GIS学习的小心得

 

arcgis engine删除数据及数据导入速度较快的方法,布布扣,bubuko.com

arcgis engine删除数据及数据导入速度较快的方法

标签:style   blog   http   color   os   io   数据   ar   

原文地址:http://www.cnblogs.com/xjnn/p/3921474.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!