/// <summary> /// 删除要素 /// </summary> /// <param name="shpFile"></param> /// <param name="Rowsname"></param> /// <returns></returns> public bool DeleFeature(string shpFile, string Rowsname) { bool result; IFeatureClass allVillage = null; try { string fieldName = Rowsname.Substring(0, Rowsname.IndexOf("=")); allVillage = EngineAPI.OpenFeatureClass(shpFile); //属性查询 IQueryFilter queryFilter = new QueryFilterClass(); queryFilter.WhereClause = Rowsname; // IFeatureCursor updateCursor = allVillage.Update(queryFilter, false); IFeature feature = updateCursor.NextFeature(); int m = 0; while (feature != null) { m++; updateCursor.DeleteFeature(); feature = updateCursor.NextFeature(); } result = true; } catch (Exception ex) { MessageBox.Show(ex.Message, "提示信息"); result = false; } return(result); }
public bool DeleFeature(IFeatureClass allVillage, string Rowsname) { bool result; try { //属性查询 IQueryFilter queryFilter = new QueryFilterClass(); queryFilter.WhereClause = Rowsname; // IFeatureCursor updateCursor = allVillage.Update(queryFilter, false); IFeature feature = updateCursor.NextFeature(); int m = 0; while (feature != null) { m++; updateCursor.DeleteFeature(); feature = updateCursor.NextFeature(); } result = true; } catch (Exception ex) { MessageBox.Show(ex.Message, "提示信息"); result = false; } return(result); }
//删除图层的所有元素 public void DeleteFeatureByIFeatureCursor(IFeatureClass pFeatureclass) { IQueryFilter pQueryFilter = new QueryFilterClass(); //pQueryFilter.WhereClause = strWhereClause; IFeatureCursor pFeatureCursor = pFeatureclass.Update(pQueryFilter, false); IFeature pFeature = pFeatureCursor.NextFeature(); while (pFeature != null) { pFeatureCursor.DeleteFeature(); pFeature = pFeatureCursor.NextFeature(); } }
private void deleteFields(ref StringCollection sc) { featCursor = this.mySelf.Update(null, false); f = featCursor.NextFeature(); while (f != null) { if (sc.Contains(f.OID.ToString())) { featCursor.DeleteFeature(); } f = featCursor.NextFeature(); } }
/// <summary> /// 高效删除,常用 /// </summary> /// <param name="featureCls"></param> /// <param name="geometry"></param> public void DeleteHigh(IFeatureClass featureCls, IGeometry geometry) { using (var comReleaser = new ComReleaser()) { IFeatureCursor updateCursor = featureCls.Update(null, true); IFeature feature = updateCursor.NextFeature(); var value = "223"; while (feature != null) { updateCursor.DeleteFeature(); feature = updateCursor.NextFeature(); } } }
private void DeleteTooSmallPolygons(IFeatureClass fc) { IQueryFilter qf = new QueryFilterClass(); qf.WhereClause = "Delete = 'true'"; IFeatureCursor delCurr = fc.Update(qf, true); IFeature feat = delCurr.NextFeature(); while (feat != null) { delCurr.DeleteFeature(); feat = delCurr.NextFeature(); } System.Runtime.InteropServices.Marshal.ReleaseComObject(delCurr); System.Runtime.InteropServices.Marshal.ReleaseComObject(qf); }
/// <summary> /// 删除要素类中符合条件的元素 /// </summary> /// <param name="pFeatureClass"></param> /// <param name="whereClause"></param> /// <param name="pGeometry"></param> public static void DeleteAllFeature(IFeatureClass pFeatureClass, string whereClause, IGeometry pGeometry) { ISpatialFilter pSpatialFilter = new SpatialFilterClass(); pSpatialFilter.WhereClause = whereClause; if (pGeometry != null) { pSpatialFilter.Geometry = pGeometry; } IFeatureCursor pCursor = pFeatureClass.Update(pSpatialFilter as IQueryFilter, false); IFeature pFeature = pCursor.NextFeature(); while (pFeature != null) { pCursor.DeleteFeature(); pFeature = pCursor.NextFeature(); } }
/// <summary> /// 删除feature图元 /// </summary> /// <param name="intObjID"></param> /// <param name="strLayerName"></param> /// <param name="map"></param> public void DelFeature(int intObjID, string strLayerName, AxMapControl map) { IFeatureLayer pfeaLayer; for (int intI = 0; intI < map.LayerCount; intI++) { try { pfeaLayer = map.get_Layer(intI) as IFeatureLayer; if (pfeaLayer != null && pfeaLayer.FeatureClass.AliasName == strLayerName) { //定义一个地物类,把要编辑的图层转化为定义的地物类 IFeatureClass fc = pfeaLayer.FeatureClass; //先定义一个编辑的工作空间,然后把转化为数据集,最后转化为编辑工作空间, IWorkspaceEdit w = (fc as IDataset).Workspace as IWorkspaceEdit; //开始事务操作 w.StartEditing(false); //开始编辑 w.StartEditOperation(); IQueryFilter queryFilter = new QueryFilterClass(); queryFilter.WhereClause = "OBJECTID=" + intObjID; IFeatureCursor updateCursor = pfeaLayer.FeatureClass.Update(queryFilter, false); IFeature feature = updateCursor.NextFeature(); int m = 0; while (feature != null) { m++; updateCursor.DeleteFeature(); feature = updateCursor.NextFeature(); } //结束编辑 w.StopEditOperation(); //结束事务操作 w.StopEditing(true); break; } } catch { } } }
/// <summary> /// 删除要素 by UpdateCursor更新游标方法 大于500,000条记录时用 /// </summary> public virtual bool DeleteFeaturesByUpdateCursor(IQueryFilter qf) { int fCount = 0; IFeatureCursor pFeatureCursor = this.featureClass.Update(qf, false); IFeature pFeature = pFeatureCursor.NextFeature(); while (pFeature != null) { fCount += 1; if (fCount % 1000 == 0) { Application.DoEvents(); } pFeatureCursor.DeleteFeature(); pFeature = pFeatureCursor.NextFeature(); } TokayWorkspace.ComRelease(pFeatureCursor); pFeatureCursor = null; return(true); }
public static void DeleteTuFuKuang() { IFeatureLayer tufulayer = ArcGisUtils.GetFeatureLayer("TuFu"); if (tufulayer != null) { IFeatureClass tufuFeatureClass = tufulayer.FeatureClass; IFeatureCursor curs = tufuFeatureClass.Update(new QueryFilterClass(), true); IFeature feautre = curs.NextFeature(); while (feautre != null) { curs.DeleteFeature(); feautre = curs.NextFeature(); } mapForm.axMapControl1.ActiveView.Refresh(); } else { MessageBox.Show("没有这个图层:TuFu"); } }
private void button3_Click(object sender, EventArgs e) { string sql = "delete from build where id=" + textBox1.Text.Trim() + ""; Dao.dml(sql); clearContent(); textBox1.Text = ""; //设定筛选条件获得满足要求的所有Feature IQueryFilter queryFilter = new QueryFilterClass(); queryFilter.WhereClause = ""; IFeatureCursor cursor = me.FeatureClass.Search(queryFilter, false); IFeature feature = cursor.NextFeature(); //获取想要获取的字段值的fieldName的id号 string name = ""; int index = 0; while (feature != null) { if (Convert.ToString(feature.get_Value(1)) == textBox2.Text.Trim()) { cursor.DeleteFeature(); } feature = cursor.NextFeature(); } MessageBox.Show("删除成功!"); //更新表格内容 DataSet dataset = null; dataset = Dao.query("select*from build"); dataGridView1.DataSource = dataset.Tables[0]; }
public void GetTowerCoverage(Towers pTowers) { IFeatureWorkspace pFeatureWorkspace = (IFeatureWorkspace)_workspace; IFeatureClass pRangeFC = pFeatureWorkspace.OpenFeatureClass("TowerRanges"); IWorkspaceEdit pWorkspaceEdit = (IWorkspaceEdit)_workspace; try { pWorkspaceEdit.StartEditing(true); pWorkspaceEdit.StartEditOperation(); IFeatureCursor pRangeCursor = pRangeFC.Update(null, false); //IFeature pFeature = pRangeCursor.NextFeature(); while (pRangeCursor.NextFeature() != null) { //pFeature.Delete(); //pFeature = pRangeCursor.NextFeature(); pRangeCursor.DeleteFeature(); } foreach (Tower pTower in pTowers.Items) { //Tower pTower = tm.GetTowerByID("T04"); double towerRange = pTower.towerCoverage; ITopologicalOperator pTopo = (ITopologicalOperator)pTower.towerLocation; IPolygon range3Bars = (IPolygon)pTopo.Buffer(towerRange / 3); IPolygon range2BarsWhole = (IPolygon)pTopo.Buffer(towerRange * 2 / 3); ITopologicalOperator p2BarTopo = (ITopologicalOperator)range2BarsWhole; IPolygon range2BarsDonut = (IPolygon)p2BarTopo.Difference(range3Bars); IPolygon range1BarWhole = (IPolygon)pTopo.Buffer(towerRange); ITopologicalOperator p1BarTopo = (ITopologicalOperator)range1BarWhole; IPolygon range1BarDonut = (IPolygon)p1BarTopo.Difference(range2BarsWhole); //IFeatureWorkspace pFWorkspace = (IFeatureWorkspace)pWorkspaceEdit; //IFeatureClass pTowerRangeFC = pFWorkspace.OpenFeatureClass("TowerRanges"); IFeature pFeature = pRangeFC.CreateFeature(); pFeature.set_Value(pFeature.Fields.FindField("TOWERID"), pTower.ID); pFeature.set_Value(pFeature.Fields.FindField("RANGE"), 3); pFeature.Shape = range3Bars; pFeature.Store(); IFeature p2BarsFeature = pRangeFC.CreateFeature(); p2BarsFeature.set_Value(pFeature.Fields.FindField("TOWERID"), pTower.ID); p2BarsFeature.set_Value(pFeature.Fields.FindField("RANGE"), 2); p2BarsFeature.Shape = range2BarsDonut; p2BarsFeature.Store(); IFeature p1BarsFeature = pRangeFC.CreateFeature(); p1BarsFeature.set_Value(pFeature.Fields.FindField("TOWERID"), pTower.ID); p1BarsFeature.set_Value(pFeature.Fields.FindField("RANGE"), 1); p1BarsFeature.Shape = range1BarDonut; p1BarsFeature.Store(); } pWorkspaceEdit.StopEditOperation(); pWorkspaceEdit.StopEditing(true); } catch (Exception ex) { pWorkspaceEdit.AbortEditOperation(); MessageBox.Show(ex.ToString()); } }
private void OpenCADFile(string filePath, string outputFilePath) { try { Debug.WriteLine("Start Time: " + DateTime.Now.ToShortTimeString()); System.Windows.Forms.Cursor.Current = Cursors.WaitCursor; String nameOfPath = System.IO.Path.GetDirectoryName(filePath); String nameOfCADFile = System.IO.Path.GetFileName(filePath); #region Open CAD Workspace from File Path //Set the workspace. ESRI.ArcGIS.Geodatabase.IWorkspaceFactory pWorkspaceFact = new ESRI.ArcGIS.DataSourcesFile.CadWorkspaceFactory(); ESRI.ArcGIS.Geodatabase.IWorkspaceFactory defaultWorkspaceFact = new FileGDBWorkspaceFactory(); //Open the workspace. ESRI.ArcGIS.Geodatabase.IWorkspace pWorkspace = pWorkspaceFact.OpenFromFile(nameOfPath, 0); //Get the CADDrawingWorkspace. ESRI.ArcGIS.DataSourcesFile.ICadDrawingWorkspace pCadDwgWorkspace; pCadDwgWorkspace = (ESRI.ArcGIS.DataSourcesFile.ICadDrawingWorkspace)pWorkspace; //Open the CadDrawingDataset. ESRI.ArcGIS.DataSourcesFile.ICadDrawingDataset pCadDwgDataset; pCadDwgDataset = pCadDwgWorkspace.OpenCadDrawingDataset(nameOfCADFile); //Set the feature workspace. ESRI.ArcGIS.Geodatabase.IFeatureWorkspace pFeatureWorkspace = (ESRI.ArcGIS.Geodatabase.IFeatureWorkspace)pWorkspace; //Open the Feature Class. #endregion #region Getting Polygon, polylines, and annotation from Cad file ESRI.ArcGIS.Geodatabase.IFeatureClass pFeatClass = pFeatureWorkspace.OpenFeatureClass(System.String.Concat(nameOfCADFile, ":Polygon")); ESRI.ArcGIS.Geodatabase.IFeatureClass pFeatClass_Plyline = pFeatureWorkspace.OpenFeatureClass(System.String.Concat(nameOfCADFile, ":Polyline")); ESRI.ArcGIS.Geodatabase.IFeatureClass pFeatClass_Anno = pFeatureWorkspace.OpenFeatureClass(System.String.Concat(nameOfCADFile, ":Annotation")); #endregion UID CLSID_def = new UIDClass(); CLSID_def.Value = "esriGeoDatabase.Feature"; #region Creating Layers from Feature Classes //Polygons ESRI.ArcGIS.Carto.IFeatureLayer pFeatLayer = new ESRI.ArcGIS.Carto.CadFeatureLayer() as ESRI.ArcGIS.Carto.IFeatureLayer; pFeatLayer.FeatureClass = pFeatClass; pFeatLayer.Name = "Polygons"; ESRI.ArcGIS.DataSourcesFile.ICadDrawingLayers pCadDwgLayers = (ESRI.ArcGIS.DataSourcesFile.ICadDrawingLayers)pFeatLayer; //Annotation ESRI.ArcGIS.Carto.IFeatureLayer pFeatLayer_Anno = new ESRI.ArcGIS.Carto.CadFeatureLayer() as ESRI.ArcGIS.Carto.IFeatureLayer; pFeatLayer_Anno.FeatureClass = pFeatClass_Anno; pFeatLayer_Anno.Name = "Annotation"; ESRI.ArcGIS.DataSourcesFile.ICadDrawingLayers pCadDwgLayers_Anno = (ESRI.ArcGIS.DataSourcesFile.ICadDrawingLayers)pFeatLayer_Anno; //Polylines ESRI.ArcGIS.Carto.IFeatureLayer pFeatLayer_Plyline = new ESRI.ArcGIS.Carto.CadFeatureLayer() as ESRI.ArcGIS.Carto.IFeatureLayer; pFeatLayer_Plyline.FeatureClass = pFeatClass_Plyline; pFeatLayer_Plyline.Name = "Polylines"; ESRI.ArcGIS.DataSourcesFile.ICadDrawingLayers pCadDwgLayers_Plyline = (ESRI.ArcGIS.DataSourcesFile.ICadDrawingLayers)pFeatLayer_Plyline; #endregion #region Creating In-Memory workspace IWorkspaceFactory WF = new InMemoryWorkspaceFactory(); ESRI.ArcGIS.esriSystem.IName name = WF.Create("", "MyWorkspace", null, 0) as ESRI.ArcGIS.esriSystem.IName; IWorkspace inMemWorkspace = (IWorkspace)name.Open(); IFeatureWorkspace featureWorkspace = (IFeatureWorkspace)inMemWorkspace; #endregion #region Creating new Fields IObjectClassDescription objectClassDescription = new FeatureClassDescription(); // create the fields using the required fields method IFields exportFields = new Fields(); IFieldsEdit fieldsEdit = (IFieldsEdit)exportFields; //OID IField field = new Field(); IField oidField = new Field(); IFieldEdit oidFieldEdit = (IFieldEdit)oidField; oidFieldEdit.Name_2 = "OID"; oidFieldEdit.Type_2 = esriFieldType.esriFieldTypeOID; fieldsEdit.AddField(oidField); // Create a geometry definition (and spatial reference) for the feature class IGeometryDef geometryDef = new GeometryDef(); IGeometryDefEdit geometryDefEdit = (IGeometryDefEdit)geometryDef; geometryDefEdit.GeometryType_2 = esriGeometryType.esriGeometryPolygon; IGeoDataset dataSet = (IGeoDataset)pFeatClass.FeatureDataset; ISpatialReferenceFactory spatialReferenceFactory = new SpatialReferenceEnvironment(); ISpatialReference spatialReference = dataSet.SpatialReference; ISpatialReferenceResolution spatialReferenceResolution = (ISpatialReferenceResolution)spatialReference; spatialReferenceResolution.ConstructFromHorizon(); ISpatialReferenceTolerance spatialReferenceTolerance = (ISpatialReferenceTolerance)spatialReference; spatialReferenceTolerance.SetDefaultXYTolerance(); geometryDefEdit.SpatialReference_2 = spatialReference; // Add a geometry field to the fields collection. This is where the geometry definition is applied. IField geometryField = new Field(); IFieldEdit geometryFieldEdit = (IFieldEdit)geometryField; geometryFieldEdit.Name_2 = "Shape"; geometryFieldEdit.Type_2 = esriFieldType.esriFieldTypeGeometry; geometryFieldEdit.GeometryDef_2 = geometryDef; fieldsEdit.AddField(geometryField); #endregion #region Creating New Shapefile for Final output UID CLSID = new UIDClass(); CLSID.Value = "esriGeoDatabase.Feature"; //using the In-Memory Workspace created above IFeatureClass output = featureWorkspace.CreateFeatureClass("myPolygons", pFeatClass.Fields, CLSID, null, esriFeatureType.esriFTSimple, "Shape", null); IFeatureClass polylines_cleaned = featureWorkspace.CreateFeatureClass("polylines_cleaned", pFeatClass_Plyline.Fields, CLSID, null, esriFeatureType.esriFTSimple, "Shape", null); IFeatureClass annotation_cleaned = featureWorkspace.CreateFeatureClass("annotation_cleaned", pFeatClass_Anno.Fields, CLSID, null, esriFeatureType.esriFTSimple, "Shape", null); #endregion #region Appending features from CADWorkspaceFeatureClass to In-Memory FeatureClass Because Update cursor not in Cad workspace Geoprocessor GP = new Geoprocessor(); //Polylines ESRI.ArcGIS.DataManagementTools.Append append = new Append(); append.inputs = pFeatClass_Plyline; append.target = polylines_cleaned; GP.Execute(append, null); //System.Runtime.InteropServices.Marshal.ReleaseComObject(pFeatClass_Plyline); GC.Collect(); //Annotation append = new Append(); append.inputs = pFeatClass_Anno; append.target = annotation_cleaned; GP.Execute(append, null); System.Runtime.InteropServices.Marshal.ReleaseComObject(pFeatClass_Anno); GC.Collect(); //Polygons to output append = new Append(); append.inputs = pFeatClass; append.target = output; GP.Execute(append, null); System.Runtime.InteropServices.Marshal.ReleaseComObject(pFeatClass); GC.Collect(); #endregion #region Query Filter to Filter Layers string queryString = ""; //using the checked box list and comma seperated list to create where clause string //Adding Items from Check Box List foreach (var checkedItem in checkedListBox1.CheckedItems) { queryString = queryString + "Layer NOT LIKE '" + checkedItem.ToString() + "' AND "; } //Adding Items from Comma separated string if (textBox_commaSeparated.Text.Length > 0) { foreach (var item in textBox_commaSeparated.Text.Split(',')) { queryString = queryString + "Layer NOT LIKE '" + item.ToString() + "' AND "; } } //Removing Last 'AND' FROM queryString if (queryString.Length > 0) //if Atleast one item added { queryString = queryString.Remove(queryString.Length - 4); } IQueryFilter queryFilter = new QueryFilter(); queryFilter.SubFields = ""; if (queryString.Length > 0) { queryFilter.WhereClause = queryString; } else { queryFilter.WhereClause = "1=1"; } #endregion #region Removing Null Geometries string ignoreList = queryString.Replace("Layer NOT LIKE '", "").Replace("' AND ", ",").Replace("' ", ""); Debug.WriteLine("lines Count before:" + polylines_cleaned.FeatureCount(new QueryFilter()).ToString()); //From Polylines_cleaned IFeatureCursor updateCursor = polylines_cleaned.Update(new QueryFilter(), false); IFeature feat = updateCursor.NextFeature(); while (feat != null) { string lyr = Convert.ToString(feat.get_Value(feat.Fields.FindField("Layer"))); lyr = lyr.ToUpper(); if (feat.Shape.IsEmpty || ignoreList.ToUpper().Split(',').ToList <string>().Any(l => lyr.Contains(l))) { updateCursor.DeleteFeature(); } feat = updateCursor.NextFeature(); } System.Runtime.InteropServices.Marshal.ReleaseComObject(updateCursor); //System.Runtime.InteropServices.Marshal.ReleaseComObject(feat); GC.Collect(); Debug.WriteLine("lines Count After:" + polylines_cleaned.FeatureCount(new QueryFilter()).ToString()); //From output Debug.WriteLine("polygons Count before:" + output.FeatureCount(new QueryFilter()).ToString()); updateCursor = output.Update(new QueryFilter(), false); feat = updateCursor.NextFeature(); while (feat != null) { string lyr = Convert.ToString(feat.get_Value(feat.Fields.FindField("Layer"))); lyr = lyr.ToUpper(); if (feat.Shape.IsEmpty || ignoreList.ToUpper().Split(',').ToList <string>().Any(l => lyr.Contains(l))) { updateCursor.DeleteFeature(); } feat = updateCursor.NextFeature(); } System.Runtime.InteropServices.Marshal.ReleaseComObject(updateCursor); GC.Collect(); Debug.WriteLine("polygons Count after:" + output.FeatureCount(new QueryFilter()).ToString()); //From Annotation Debug.WriteLine("Annotation Count before:" + annotation_cleaned.FeatureCount(new QueryFilter()).ToString()); updateCursor = annotation_cleaned.Update(new QueryFilter(), false); feat = updateCursor.NextFeature(); while (feat != null) { string lyr = Convert.ToString(feat.get_Value(feat.Fields.FindField("Layer"))); lyr = lyr.ToUpper(); if (feat.Shape.IsEmpty || ignoreList.ToUpper().Split(',').ToList <string>().Any(l => lyr.Contains(l))) { updateCursor.DeleteFeature(); } feat = updateCursor.NextFeature(); } System.Runtime.InteropServices.Marshal.ReleaseComObject(updateCursor); GC.Collect(); Debug.WriteLine("Annotation Count after:" + annotation_cleaned.FeatureCount(new QueryFilter()).ToString()); #endregion #region Convert lines feature class to feature Cursor IFeatureCursor linesFCursor = polylines_cleaned.Search(new QueryFilter(), false); #endregion #region Deleting all columns of polygons to match with output IFields _fieldsP = output.Fields; IFieldsEdit _fieldsEditP = (IFieldsEdit)_fieldsP; for (int i = 0; i < output.Fields.FieldCount; i++) { IField _field = output.Fields.get_Field(i); if (_field.Name != "Shape" && _field.Name != "FID") { output.DeleteField(_field); if (i < output.Fields.FieldCount) { i--; } } } System.Runtime.InteropServices.Marshal.ReleaseComObject(_fieldsP); System.Runtime.InteropServices.Marshal.ReleaseComObject(_fieldsEditP); GC.Collect(); #endregion #region Setting Envelop information IEnvelope envelop = new Envelope() as IEnvelope; IGeoDataset dataSetEnv = (IGeoDataset)pFeatClass_Plyline.FeatureDataset; envelop.SpatialReference = dataSet.SpatialReference; envelop.PutCoords(dataSet.Extent.XMin, dataSet.Extent.YMin, dataSet.Extent.XMax, dataSet.Extent.YMax); #endregion #region Construct Polygons from Lines Cursor (usting Feature Construct) IFeatureConstruction featureConstruct = new FeatureConstruction() as IFeatureConstruction; ISelectionSet selectionSet = null; //atureConstruct.ConstructPolygonsFromFeaturesFromCursor(null,output,envelop,false,false,linesFCursor,null,0.001,null); featureConstruct.AutoCompleteFromFeaturesFromCursor(output, envelop, linesFCursor, null, -1, null, out selectionSet); #endregion System.Runtime.InteropServices.Marshal.ReleaseComObject(featureConstruct); System.Runtime.InteropServices.Marshal.ReleaseComObject(linesFCursor); GC.Collect(); Debug.WriteLine("polygons Count after PolygonConstruct :" + output.FeatureCount(new QueryFilter()).ToString()); #region SPATIAL JOIN GP = new Geoprocessor(); ESRI.ArcGIS.AnalysisTools.SpatialJoin spatialJoin = new ESRI.ArcGIS.AnalysisTools.SpatialJoin(); spatialJoin.join_features = annotation_cleaned; spatialJoin.target_features = output; spatialJoin.join_operation = "JOIN_ONE_TO_MANY"; spatialJoin.join_type = "KEEP_ALL"; spatialJoin.match_option = "CONTAINS"; spatialJoin.out_feature_class = outputFilePath; GP.Execute(spatialJoin, null); System.Runtime.InteropServices.Marshal.ReleaseComObject(annotation_cleaned); GC.Collect(); #endregion #region Remove All Fields of Annotation except Text ShapefileWorkspaceFactory wsf = new ShapefileWorkspaceFactory(); IFeatureWorkspace work = (IFeatureWorkspace)wsf.OpenFromFile(System.IO.Path.GetDirectoryName(outputFilePath), 0); IFeatureClass output_AfterJoin_FClasss = work.OpenFeatureClass(System.IO.Path.GetFileNameWithoutExtension(outputFilePath)); IFields _fields = output_AfterJoin_FClasss.Fields; IFieldsEdit _fieldsEdit = (IFieldsEdit)_fields; for (int i = 0; i < _fields.FieldCount; i++) { IField _field = output_AfterJoin_FClasss.Fields.get_Field(i); if (_field.Name != "Text_" && _field.Name != "Text" && _field.Name != "Shape" && _field.Name != "FID") { output_AfterJoin_FClasss.DeleteField(_field); i--; } else { if (field.Name == "Text_" || _field.Name == "Text") { IFieldEdit fieldEdit = (IFieldEdit)_field; fieldEdit.Name_2 = "PlotNumber"; fieldEdit.AliasName_2 = "PlotNumber"; } } } System.Runtime.InteropServices.Marshal.ReleaseComObject(_fields); System.Runtime.InteropServices.Marshal.ReleaseComObject(_fieldsEdit); GC.Collect(); #endregion System.Windows.Forms.Cursor.Current = Cursors.Default; Debug.WriteLine("End Time: " + DateTime.Now.ToShortTimeString()); MessageBox.Show("Import Complete!"); } catch { MessageBox.Show("Error Importing. Something wrong with the CAD File"); } }
//删除现状库中原有数据,将更新数据写到现状数据库中 private void DoUpdateOfFeatureClass(IFeatureClass pCurFeatureClass, IFeatureClass pUptFeatureClass, IGeometry pGeometry) { if (pCurFeatureClass == null) { return; } if (pUptFeatureClass == null) { return; } ISpatialFilter pFilter = new SpatialFilterClass(); pFilter.Geometry = pGeometry; pFilter.SpatialRel = esriSpatialRelEnum.esriSpatialRelContains; //更新范围包含的地物 IWorkspace pTagetWorkspace = null; try { pTagetWorkspace = (pCurFeatureClass as IDataset).Workspace; } catch { } //(pTagetWorkspace as IWorkspaceEdit).StartEditing(false); IWorkspaceEdit wsEdit = pTagetWorkspace as IWorkspaceEdit; if (wsEdit.IsBeingEdited() == true) { wsEdit.StopEditing(true); } wsEdit.StartEditing(false); wsEdit.StartEditOperation(); //删除现状库中地物 IFeatureCursor pFeaCursor = pCurFeatureClass.Update(pFilter, false); if (pFeaCursor != null) { IFeature pFea = pFeaCursor.NextFeature(); while (pFea != null) { pFeaCursor.DeleteFeature(); pFea = pFeaCursor.NextFeature(); } //pFeaCursor.Flush(); System.Runtime.InteropServices.Marshal.ReleaseComObject(pFeaCursor); pFeaCursor = null; } //从更新库向现状库写地物 IFeatureCursor pUptFeacursor = pUptFeatureClass.Search(pFilter, false); if (pUptFeacursor != null) { Exception err0 = null; NewFeatures(pCurFeatureClass, pUptFeacursor, "QSRQ", DateTime.Today.ToShortDateString() as object, true, null, out err0); if (err0 == null) { wsEdit.StopEditOperation(); wsEdit.StopEditing(true); } else { wsEdit.StopEditOperation(); wsEdit.StopEditing(false); } } else { wsEdit.StopEditOperation(); wsEdit.StopEditing(true); } }