///// <summary> ///// 检查图层编码 ///// </summary> ///// <param name="pFeatureLayer">待检查的图层</param> //public static DataTable CheckLayers(IFeatureLayer pFeatureLayer) //{ // DataTable dt = null; // if (pFeatureLayer.FeatureClass.ShapeType == esriGeometryType.esriGeometryPoint) // { // ClsCommonEnti pcommonEnti = new ClsCommonEnti(); // //pcommonEnti.CreatGridCode(mapMain.Map, cbxCodeLayer); // } // else if (pFeatureLayer.FeatureClass.ShapeType == esriGeometryType.esriGeometryPolyline) // { // ClsRoadEnti pRoadEnti = new ClsRoadEnti(); // //pRoadEnti.CreatGridCodeRoad(mapMain.Map, cbxCodeLayer); // } // else if (pFeatureLayer.FeatureClass.ShapeType == esriGeometryType.esriGeometryPolygon) // { // ClsResEnti pResEnti = new ClsResEnti(); // //pResEnti.CreatGridCodeRES(mapMain.Map, cbxCodeLayer); // } //} /// <summary> /// 道路编码函数 /// </summary> /// <param name="pFeatureLayer"></param> /// <param name="pField"></param> /// <param name="pRoadCode"></param> /// <param name="pENEIID"></param> private static void CreatRoadCode(IFeatureLayer pFeatureLayer, IField pField, string pRoadCode, string pENEIID) { if (pField.AliasName.Contains(pRoadCode)) { //遍历Feature IDataset pDataset = pFeatureLayer.FeatureClass as IDataset; IWorkspaceEdit pWorkspaceEdit = null; if (pDataset != null) { pWorkspaceEdit = pDataset.Workspace as IWorkspaceEdit; if (pWorkspaceEdit != null || pWorkspaceEdit.IsBeingEdited() == false) { pWorkspaceEdit.StartEditing(true); pWorkspaceEdit.StartEditOperation(); } IFeatureCursor pFeatureCursor = pFeatureLayer.Search(null, false); //test int test = pFeatureLayer.FeatureClass.FeatureCount(null); IFeature pFeature = pFeatureCursor.NextFeature(); while (pFeature != null) { //获取单条Feature的某个字段值 int test2 = pFeature.Fields.FindFieldByAliasName(pRoadCode); string pRoad = pFeature.get_Value(pFeature.Fields.FindFieldByAliasName(pRoadCode)).ToString(); if (pRoad.Length > 1 && pRoad.Length < 6) { if (pRoad.Length == 5) { pFeature.set_Value(pFeature.Fields.FindField(pENEIID), pRoad + 330521); pFeature.Store(); } else { string _Count = null; for (int k = 0; k < 5 - pRoad.Length; k++) { _Count += "_"; } pRoad = pRoad + _Count; pFeature.set_Value(pFeature.Fields.FindField(pENEIID), pRoad + 330521); pFeature.Store(); } } pFeature = pFeatureCursor.NextFeature(); } pWorkspaceEdit.StopEditing(true); pWorkspaceEdit.StopEditOperation(); } } }
//线图层存为shp(未使用)方法3 static void PointToLineShp() { //打开poi的shp文件,设置属性(order) IWorkspaceFactory pWSF = new ShapefileWorkspaceFactoryClass(); IFeatureWorkspace pWS = (IFeatureWorkspace)pWSF.OpenFromFile(@"res\poi_shp_jw", 0); IFeatureClass pFeatureclass = pWS.OpenFeatureClass("poi.shp"); IFeatureCursor pCursor = pFeatureclass.Search(null, false); IPolyline pPolyline = new PolylineClass(); IPointCollection pPolycollect = pPolyline as IPointCollection; IDataset dataset = (IDataset)pFeatureclass;//属性表可编辑状态 IWorkspace workspace = dataset.Workspace; IWorkspaceEdit workspaceEdit = (IWorkspaceEdit)workspace; workspaceEdit.StartEditing(true); workspaceEdit.StartEditOperation(); for (int d = 0; d < VerNum; d++) { if (d != startPoiID) { //逐条设置order,生成shp int ss = 0;//节点id int e = 0; while (pCursor != null) { IFeature pFeature = pCursor.NextFeature(); IFields pFields = pFeature.Fields; // IField pField = pFeature.Fields; IClass pClass = pFeatureclass as IClass; if (pFeature != null) { for (e = 0; e < h[ss] + 2; e++) { if (PathRouteTem[d, e] == ss) { return; } } IGeometry pGeometry = pFeature.Shape; object objmiss = Type.Missing; pFeature.set_Value(10, PathRouteTem[d, e]); ss++; } else { pCursor = null; } } } } }
private void btnImport_Click(object sender, EventArgs e) { ISpatialReferenceDialog2 pSpatialReferenceDialog2 = new SpatialReferenceDialogClass(); _spatialReference = pSpatialReferenceDialog2.DoModalCreate(true, true, true, 0); if (_spatialReference == null) { return; } IWorkspaceEdit pWorkspaceEdit = _targetWorkspace as IWorkspaceEdit; if (pWorkspaceEdit == null) { return; } pWorkspaceEdit.StartEditing(true); pWorkspaceEdit.StartEditOperation(); try { _pointList = new List <CustomPoint>(); _pointFeatureClassList = new List <CustomFeatureClass>(); _lineFeatureClassList = new List <CustomFeatureClass>(); if (chkHasCoordInfo.Checked == false) { GetSurveyPointList(); } ExcelToPointFeatureClass(); ExcelToLineFeatureClass(); foreach (CustomFeatureClass customFeatureClass in _pointFeatureClassList) { WorkspaceHelper.LoadFeatureClass(_map, customFeatureClass.FeatureClass); } foreach (CustomFeatureClass customFeatureClass in _lineFeatureClassList) { WorkspaceHelper.LoadFeatureClass(_map, customFeatureClass.FeatureClass); } } catch (Exception exception) { MessageBox.Show(exception.Message); } finally { pWorkspaceEdit.StopEditOperation(); pWorkspaceEdit.StopEditing(true); foreach (Process p in Process.GetProcessesByName("Excel")) { if (string.IsNullOrEmpty(p.MainWindowTitle)) { p.Kill(); } } } }
/// <summary> /// /// 在当前图层添加要素 /// /// </summary> /// <param name="geometry">几何要素</param> public void AddFeature(IGeometry geometry) { //判断当前编辑图层是否为空 if (mCurrentLayer == null) { return; } IFeatureClass pFeatureClass = mCurrentLayer.FeatureClass; //几何要素与要素类类型一致 if (pFeatureClass.ShapeType != geometry.GeometryType || geometry == null) { return; } //判断编辑状态 if (!mIsEditing) { MessageBox.Show("请先开启编辑", "提示"); return; } try { //开始编辑操作 mWorkspaceEdit.StartEditOperation(); //创建要素并保存 IFeature pFeature; pFeature = pFeatureClass.CreateFeature(); pFeature.Shape = geometry; pFeature.Store(); //结束编辑操作 mWorkspaceEdit.StopEditOperation(); //高亮显示添加要素 mMap.ClearSelection(); mMap.SelectFeature(mCurrentLayer as ILayer, pFeature); ((IActiveView)mMap).PartialRefresh(esriViewDrawPhase.esriViewGeoSelection, null, null); mHasEditing = true; } catch (Exception ex) { MessageBox.Show(ex.Message); } }
/// <summary> /// 插入新要素 /// </summary> /// <param name="featureLayer">图层</param> /// <param name="geom">插入要素几何图形</param> /// <param name="ID">要素ID(绑定ID)</param> /// <returns></returns> public static bool InsertNewFeature(IFeatureLayer featureLayer, IGeometry geom, string ID) { IWorkspaceEdit workspaceEdit = null; IFeatureCursor featureCursor = null; try { IFeatureClass featureClass = featureLayer.FeatureClass; IDataset dataset = (IDataset)featureClass; IWorkspace workspace = dataset.Workspace; workspaceEdit = workspace as IWorkspaceEdit; workspaceEdit.StartEditing(true); workspaceEdit.StartEditOperation(); IFeatureBuffer featureBuffer = featureClass.CreateFeatureBuffer(); DataEditCommon.ZMValue(featureBuffer, geom); //几何图形Z值处理 featureBuffer.Shape = geom; int iFieldID = featureBuffer.Fields.FindField("ID"); featureBuffer.Value[iFieldID] = ID.ToString(); //开始插入要素 featureCursor = featureClass.Insert(true); object featureOID = featureCursor.InsertFeature(featureBuffer); //保存要素 featureCursor.Flush(); IFeature feature = featureCursor.NextFeature(); workspaceEdit.StopEditOperation(); workspaceEdit.StopEditing(true); return(true); } catch (Exception ex) { MessageBox.Show(ex.Message); workspaceEdit.AbortEditOperation(); workspaceEdit.StopEditing(false); return(false); } finally { if (featureCursor != null) { System.Runtime.InteropServices.Marshal.ReleaseComObject(featureCursor); //释放指针 } } }
public static bool CheckNullField(ILayer pLayer, string pField) { int i = 0, j = 0; IFeatureLayer pFeatureLayer = null; if (pLayer is IFeatureLayer) { pFeatureLayer = pLayer as IFeatureLayer; IDataset pDataset = pFeatureLayer.FeatureClass as IDataset; IWorkspaceEdit pWorkspaceEdit = null; if (pDataset != null) { pWorkspaceEdit = pDataset.Workspace as IWorkspaceEdit; if (pWorkspaceEdit != null || pWorkspaceEdit.IsBeingEdited() == false) { pWorkspaceEdit.StartEditing(true); pWorkspaceEdit.StartEditOperation(); } IFeatureCursor pFeatureCursor = pFeatureLayer.Search(new QueryFilterClass(), false); IFeature pFeature = pFeatureCursor.NextFeature(); i = pFeatureLayer.FeatureClass.FeatureCount(null); while (pFeature != null) { //test int index = pFeature.Fields.FindField(pField); //test int test = pFeature.get_Value(index).ToString().Trim().Length; if (pFeature.get_Value(index).ToString().Trim().Length == 0) { j++; } pFeature = pFeatureCursor.NextFeature(); } pWorkspaceEdit.StopEditing(true); pWorkspaceEdit.StopEditOperation(); } } if (j > 0) { return(true); } else { return(false); } }
/// <summary> /// Start Edit (without undo, redo capability) then Start Operation. /// </summary> /// <param name="workspace"></param> public static void StartEditAndOperation(IWorkspace workspace) { IWorkspaceEdit iWorkspaceEdit = workspace as IWorkspaceEdit; bool withUndoRedo = false; if (!iWorkspaceEdit.IsBeingEdited()) { iWorkspaceEdit.StartEditing(withUndoRedo); iWorkspaceEdit.StartEditOperation(); } }
public static void StartOperation(IWorkspace workspace) { IWorkspaceEdit iWorkspaceEdit = workspace as IWorkspaceEdit; if (!iWorkspaceEdit.IsBeingEdited()) { throw new InvalidOperationException("Workspace is not start edit yet."); } iWorkspaceEdit.StartEditOperation(); }
/// <summary> /// 对非图形要素的操作使用该函数开启会话 /// </summary> public static void StartEditOperation() { IWorkspaceEdit pEditor = _pWorkspace as IWorkspaceEdit; if (!pEditor.IsBeingEdited()) { throw new Exception("请开启编辑会话"); } pEditor.StartEditOperation(); }
private bool StartEditOp() { bool retVal = false; if (!m_WorkspaceEdit.IsBeingEdited()) { m_WorkspaceEdit.StartEditing(false); retVal = true; } m_WorkspaceEdit.StartEditOperation(); return(retVal); }
/// <summary> /// 开始工作空间编辑,执行完指定操作后保存并停止编辑 /// </summary> /// <param name="workspace">需要执行编辑的工作空间</param> /// <param name="action">具体的编辑操作</param> /// <param name="withUndoEdit">是否在编辑过程中支持回滚(撤消/重做)操作,远程数据库不支持此功能</param> /// <remarks></remarks> public static void StartEdit(this IWorkspace workspace, Action action, bool withUndoEdit = false) { IWorkspaceEdit workspaceEdit = (IWorkspaceEdit)workspace; workspaceEdit.StartEditing(withUndoEdit); workspaceEdit.StartEditOperation(); action(); workspaceEdit.StopEditOperation(); workspaceEdit.StopEditing(true); }
private void UpdateFeature(IFeature pFeature, IGeometry pGeometry) //修改要素后,更新要素 { //检查是否在编辑操作中 IDataset pDataset = (IDataset)pFeature.Class; IWorkspaceEdit pWorkspaceEdit = (IWorkspaceEdit)pDataset.Workspace; //保存当前编辑的要素 pWorkspaceEdit.StartEditOperation(); pFeature.Shape = pGeometry; pFeature.Store(); pWorkspaceEdit.StopEditOperation(); }
/// <summary> /// 构造小区的一个立体覆盖网格 /// </summary> /// <param name="cellName"></param> /// <param name="lac"></param> /// <param name="ci"></param> /// <param name="gxid"></param> /// <param name="gyid"></param> /// <param name="level"></param> /// <param name="x1"></param> /// <param name="y1"></param> /// <param name="x2"></param> /// <param name="y2"></param> /// <param name="z"></param> /// <param name="recePower"></param> /// <param name="pathLoss"></param> public void constructGrid3D(string cellName, int lac, int ci, int gxid, int gyid, int level, double x1, double y1, double x2, double y2, double z, double recePower, double pathLoss) { IDataset dataset = (IDataset)pFeatureLayer.FeatureClass; IWorkspace workspace = dataset.Workspace; //Cast for an IWorkspaceEdit IWorkspaceEdit workspaceEdit = (IWorkspaceEdit)workspace; //start an edit session and operation workspaceEdit.StartEditing(true); workspaceEdit.StartEditOperation(); IFeatureCursor pFeatureCursor = pFeatureClass.Insert(true); IFeatureBuffer pFeatureBuffer; Geometric.Point p = GridHelper.getInstance().GridToGeo(gxid, gyid); double lon = p.X; double lat = p.Y; IPoint pointA = GeometryUtilities.ConstructPoint3D(x1, y1, z); IPoint pointB = GeometryUtilities.ConstructPoint3D(x2, y1, z); IPoint pointC = GeometryUtilities.ConstructPoint3D(x2, y2, z); IPoint pointD = GeometryUtilities.ConstructPoint3D(x1, y2, z); IGeometryCollection pGeometryColl = GeometryUtilities.ConstructPolygon(new IPoint[] { pointA, pointB, pointC, pointD }); pFeatureBuffer = pFeatureClass.CreateFeatureBuffer(); pFeatureBuffer.Shape = pGeometryColl as IGeometry; pFeatureBuffer.set_Value(this.GXIDIndex, gxid); pFeatureBuffer.set_Value(this.GYIDIndex, gyid); pFeatureBuffer.set_Value(this.LevelIndex, level); pFeatureBuffer.set_Value(this.eNodeBIndex, lac); pFeatureBuffer.set_Value(this.CIIndex, ci); pFeatureBuffer.set_Value(this.cellNameIndex, cellName); pFeatureBuffer.set_Value(this.RecePowerIndex, recePower); pFeatureBuffer.set_Value(this.PathLossIndex, pathLoss); pFeatureBuffer.set_Value(this.LongitudeIndex, lon); pFeatureBuffer.set_Value(this.LatitudeIndex, lat); pFeatureCursor.InsertFeature(pFeatureBuffer); //一次性提交 pFeatureCursor.Flush(); //stop editing workspaceEdit.StopEditOperation(); workspaceEdit.StopEditing(true); //IFeatureClassManage pFeatureClassManage = (IFeatureClassManage)pFeatureClass; //pFeatureClassManage.UpdateExtent(); GISMapApplication.Instance.RefreshLayer(pFeatureLayer); //GISMapApplication.Instance.FullExtent(pFeatureLayer.AreaOfInterest); }
//根据读取出来的坐标,创建新要素 private void CreateFeatures(IFeatureClass targetClass, List <List <Vertex> > polygons, string TBBHFieldName) { //编辑器 IWorkspaceEdit m_WorkspaceEdit = (targetClass as IDataset).Workspace as IWorkspaceEdit; m_WorkspaceEdit.StartEditing(true); m_WorkspaceEdit.StartEditOperation(); //一个一个多边形地处理,对应一个要素 foreach (List <Vertex> polygon in polygons) { IFeature newFeature = targetClass.CreateFeature(); Ring ring = new RingClass(); object missing = Type.Missing; //把每个顶点添加到环 foreach (Vertex vertex in polygon) { IPoint pt = new PointClass(); double X = vertex.X; double Y = vertex.Y; pt.PutCoords(X, Y); ring.AddPoint(pt, ref missing, ref missing); } //投影 IGeometry geometry = ring as IGeometry; IGeoDataset pGeoDataset = targetClass as IGeoDataset; if (pGeoDataset.SpatialReference != null) { geometry.Project(pGeoDataset.SpatialReference); } else { geometry.Project(pMapControl.SpatialReference); } //环构成多边形 IGeometryCollection newPolygon = new PolygonClass(); newPolygon.AddGeometry(geometry, ref missing, ref missing); IPolygon newPolygon2 = newPolygon as IPolygon; newPolygon2.SimplifyPreserveFromTo(); newFeature.Shape = newPolygon2 as IGeometry; //加上TBBH属性 int fieldIndex = newFeature.Fields.FindField(TBBHFieldName); newFeature.set_Value(fieldIndex, polygon[0].TBBH);//取任意一个顶点的tbbh newFeature.Store(); } //保存 m_WorkspaceEdit.StopEditOperation(); m_WorkspaceEdit.StopEditing(true); IFeatureLayer pFeatureLayer = new FeatureLayerClass(); pFeatureLayer.FeatureClass = targetClass; }
public override void OnMouseUp(int int_0, int int_1, int int_2, int int_3) { IEnvelope envelope; IGeometry geometry; if (CmdSelectTopology.m_TopologyGraph != null) { this.bool_0 = false; if (this.idisplayFeedback_0 != null) { IPoint mapPoint = this._context.ActiveView.ScreenDisplay.DisplayTransformation.ToMapPoint(int_2, int_3); IWorkspaceEdit editWorkspace = Yutai.ArcGIS.Common.Editor.Editor.EditWorkspace; editWorkspace.StartEditOperation(); try { IAffineTransformation2D affineTransformation2DClass = new AffineTransformation2D() as IAffineTransformation2D; affineTransformation2DClass.Move(mapPoint.X - this.ipoint_0.X, mapPoint.Y - this.ipoint_0.Y); CmdSelectTopology.m_TopologyGraph.TransformSelection(esriTransformDirection.esriTransformForward, affineTransformation2DClass, false); CmdSelectTopology.m_TopologyGraph.Post(out envelope); this._context.ActiveView.Refresh(); } catch (Exception exception) { CErrorLog.writeErrorLog(this, exception, ""); } editWorkspace.StopEditOperation(); this.idisplayFeedback_0 = null; } else if (this.inewEnvelopeFeedback_0 != null) { geometry = this.inewEnvelopeFeedback_0.Stop(); CmdSelectTopology.m_TopologyGraph.SelectByGeometry(3, esriTopologySelectionResultEnum.esriTopologySelectionResultNew, geometry); this.inewEnvelopeFeedback_0 = null; } else { double searchTolerance = 3.5; if (this._context.Hook is IApplication) { searchTolerance = (double)(this._context.Hook as IApplication).SelectionEnvironment.SearchTolerance; } searchTolerance = Common.ConvertPixelsToMapUnits((IActiveView)this._context.FocusMap, searchTolerance); geometry = ((ITopologicalOperator)this.ipoint_0).Buffer(searchTolerance); CmdSelectTopology.m_TopologyGraph.SelectByGeometry(1, esriTopologySelectionResultEnum.esriTopologySelectionResultNew, geometry); if (CmdSelectTopology.m_TopologyGraph.NodeSelection.Count == 0) { CmdSelectTopology.m_TopologyGraph.SelectByGeometry(2, esriTopologySelectionResultEnum.esriTopologySelectionResultNew, geometry); } } this._context.ActiveView.Refresh(); } }
/// <summary> /// 对表MatchedPolygonFCSettingDif进行判断处理 /// </summary> /// <param name="workspace"></param> /// <param name="table"></param> /// <param name="featureWorkspace"></param> /// <returns></returns> private ITable TableExist(IWorkspace2 workspace, ITable table, IFeatureWorkspace featureWorkspace) { IFields fields; //匹配参数表是否存在,存在则打开表并删除相关记录 if (workspace.get_NameExists(esriDatasetType.esriDTTable, ClsConstant.polygonSettingTable)) { table = featureWorkspace.OpenTable(ClsConstant.polygonSettingTable); IWorkspaceEdit workspaceEdit = workspace as IWorkspaceEdit; workspaceEdit.StartEditing(true); workspaceEdit.StartEditOperation(); ICursor cursor = table.Search(null, false); IRow r = cursor.NextRow(); while (r != null) { r.Delete(); r = cursor.NextRow(); } workspaceEdit.StopEditOperation(); workspaceEdit.StopEditing(true); //ClsDeleteTables.DeleteFeatureClass(gdbPath, ClsConstant.lineSettingTable); //fields = CreateMatchedPolylineFCSettingFields(workspace); //UID uid = new UIDClass(); //uid.Value = "esriGeoDatabase.Object"; //IFieldChecker fieldChecker = new FieldCheckerClass(); //IEnumFieldError enumFieldError = null; //IFields validatedFields = null; //fieldChecker.ValidateWorkspace = (IWorkspace)workspace; //fieldChecker.Validate(fields, out enumFieldError, out validatedFields); //table = featureWorkspace.CreateTable(ClsConstant.lineSettingTable, validatedFields, uid, null, ""); } //匹配参数表是否存在,不存在则创建表 else { //返回MatchedPolygonFCSettingDif的所有字段集 fields = CreateMatchedPolygonFCSettingFields(workspace); UID uid = new UIDClass(); uid.Value = "esriGeoDatabase.Object"; IFieldChecker fieldChecker = new FieldCheckerClass(); IEnumFieldError enumFieldError = null; IFields validatedFields = null; fieldChecker.ValidateWorkspace = (IWorkspace)workspace; fieldChecker.Validate(fields, out enumFieldError, out validatedFields); //创建表MatchedPolygonFCSettingDif table = featureWorkspace.CreateTable(ClsConstant.polygonSettingTable, validatedFields, uid, null, ""); } return(table); }
public override void OnClick() { if (_AppHk == null) { return; } if (_AppHk.MapControl == null) { return; } IFeatureLayer tmpFeatureLayer = getEditLayer.isExistLayer(_AppHk.MapControl.Map) as IFeatureLayer; if (tmpFeatureLayer == null) { MessageBox.Show("请设置编辑图层!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information); return; } IWorkspaceEdit iWE = (tmpFeatureLayer.FeatureClass as IDataset).Workspace as IWorkspaceEdit; if (!iWE.IsBeingEdited()) { iWE.StartEditing(false); } ISelectionSet iSS = (tmpFeatureLayer as IFeatureSelection).SelectionSet; ICursor iCursor; iSS.Search(null, false, out iCursor); IFeatureCursor iFC = iCursor as IFeatureCursor; IFeature tmpFeature = iFC.NextFeature(); if (tmpFeature == null) { MessageBox.Show("请选择编辑图层上要删除的图元!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information); return; } if (MessageBox.Show("是否删除选择的图元!", "提示", MessageBoxButtons.YesNo, MessageBoxIcon.Information) != DialogResult.Yes) { return; } iWE.StartEditOperation(); while (tmpFeature != null) { tmpFeature.Delete(); tmpFeature = iFC.NextFeature(); } iWE.StopEditOperation(); Plugin.LogTable.Writelog(Caption); //iWE.StopEditing(true); iWE = null; _AppHk.MapControl.ActiveView.Refresh(); }
protected override void OnMouseDown(ESRI.ArcGIS.Desktop.AddIns.Tool.MouseEventArgs arg) { IMxDocument pMxDoc = ArcMap.Application.Document as IMxDocument; //get line from drawing IRubberBand pRubber = new RubberLine(); //IPolyline pPloyline = pRubber.TrackNew(pMxDoc.ActivatedView.ScreenDisplay, null) as IPolyline; //get lines from hard coded IPolyline pPloyline; //create points IPoint pPoint1 = new Point(); pPoint1.X = -92.675984; pPoint1.Y = 194.232396; IPoint pPoint2 = new Point(); pPoint2.X = -78.115341; pPoint2.Y = 133.077697; IPoint pPoint3 = new Point(); pPoint3.X = 13.616707; pPoint3.Y = 0.090495; IPointCollection pPointCollection = new Polyline(); pPointCollection.AddPoint(pPoint1); pPointCollection.AddPoint(pPoint2); pPointCollection.AddPoint(pPoint3); IFeatureLayer pFLayer = pMxDoc.FocusMap.Layer[0] as IFeatureLayer; IDataset pDS = pFLayer.FeatureClass as IDataset; IWorkspaceEdit pWSE = pDS.Workspace as IWorkspaceEdit; pWSE.StartEditing(false); pWSE.StartEditOperation(); IFeature pFeature = pFLayer.FeatureClass.CreateFeature(); pFeature.Shape = pPointCollection as IGeometry; pFeature.Store(); pWSE.StopEditOperation(); pWSE.StopEditing(true); pMxDoc.ActivatedView.Refresh(); }
//将线添加到图层 private void AddFeature(IFeatureLayer pFeatureLayer, List <IPolyline> lineList, List <IPoint> ptsList, List <double> lineLengthList) { IFeatureClass pFeatureClass = pFeatureLayer.FeatureClass; IDataset pDataset = (IDataset)pFeatureClass; IWorkspace pWorkspace = pDataset.Workspace; //for (int i = 0; i < lineList.Count; i++) //{ // if (lineList[i].Length > 0) // { // IFeature pFeature = pFeatureClass.CreateFeature(); // pFeature.Shape = lineList[i]; // double sLength = Math.Round((ptsList[i + 1].X - ptsList[i].X) * (ptsList[i + 1].X - ptsList[i].X) + (ptsList[i + 1].Y - ptsList[i].Y) * (ptsList[i + 1].Y - ptsList[i].Y) + (ptsList[i + 1].Z - ptsList[i].Z) * (ptsList[i + 1].Z - ptsList[i].Z),4); // pFeature.set_Value(pFeature.Fields.FindField("length"), sLength); // pFeature.Store(); // } //} //开始空间编辑 IWorkspaceEdit pWorkspaceEdit = (IWorkspaceEdit)pWorkspace; pWorkspaceEdit.StartEditing(true); pWorkspaceEdit.StartEditOperation(); IFeatureBuffer pFeatureBuffer = pFeatureClass.CreateFeatureBuffer(); IFeatureCursor pFeatureCursor; //开始插入新的实体对象 for (int i = 0; i < lineList.Count; i++) { IGeometry geometry = lineList[i]; pFeatureCursor = pFeatureClass.Insert(true); pFeatureBuffer.Shape = geometry; double sLength = Math.Round((ptsList[i + 1].X - ptsList[i].X) * (ptsList[i + 1].X - ptsList[i].X) + (ptsList[i + 1].Y - ptsList[i].Y) * (ptsList[i + 1].Y - ptsList[i].Y) + (ptsList[i + 1].Z - ptsList[i].Z) * (ptsList[i + 1].Z - ptsList[i].Z), 4); lineLengthList.Add(sLength); pFeatureBuffer.set_Value(pFeatureBuffer.Fields.FindField("length"), sLength); if (sLength > System.Convert.ToSingle(textBoxX4.Text.ToString())) { pFeatureBuffer.set_Value(pFeatureBuffer.Fields.FindField("质量"), "坏点"); } else { pFeatureBuffer.set_Value(pFeatureBuffer.Fields.FindField("质量"), "好点"); } object featureOID = pFeatureCursor.InsertFeature(pFeatureBuffer); //保存实体 pFeatureCursor.Flush(); //结束空间编辑 pWorkspaceEdit.StopEditOperation(); pWorkspaceEdit.StopEditing(true); System.Runtime.InteropServices.Marshal.ReleaseComObject(pFeatureCursor); } }
private void TimeCostRun(object p) { Hashtable para = p as Hashtable; string shapeFilePath = para["shapeFilePath"].ToString(); string typeField = para["typeField"].ToString(); string targetField = para["targetField"].ToString(); var wait = para["wait"] as ProgressWait; _shapeOp.FilePath = shapeFilePath; IFeatureClass pFeatureClass = _shapeOp.OpenFeatureClass(); IDataset pDataset = pFeatureClass as IDataset; string landType = string.Empty; try { IWorkspaceEdit pWorkspaceEdit = pDataset.Workspace as IWorkspaceEdit; IFeatureCursor pFeatureCursor = pFeatureClass.Search(null, false); pWorkspaceEdit.StartEditing(true); pWorkspaceEdit.StartEditOperation(); IFeature pFeature; int count = 0; int totalCount = pFeatureClass.FeatureCount(null); while (count != totalCount && (pFeature = pFeatureCursor.NextFeature()) != null) { count++; wait.SetProgress((double)count / totalCount); landType = pFeature.Value[pFeature.Fields.FindField(typeField)].ToString().Trim(); pFeature.Value[pFeature.Fields.FindField(targetField)] = ((CellSize) / 1000) / _speed[landType] * 60; pFeature.Store(); } wait.SetWaitCaption("正在存储数据"); pWorkspaceEdit.StopEditOperation(); pWorkspaceEdit.StopEditing(true); Marshal.ReleaseComObject(pFeatureCursor); para["ret"] = true; } catch (ArgumentException e) { _log.Error(e.Message + e.StackTrace); para["ret"] = false; } catch (Exception e) { _log.Error(e.Message + e.StackTrace); para["ret"] = false; } finally { wait.CloseWait(); } }
//将线添加到图层 private void AddFeatureEar(IGeometry geometry, double earv) { string pLineFile = txtOutFile.Text; string pFilePath = System.IO.Path.GetDirectoryName(pLineFile); string pFileName = System.IO.Path.GetFileName(pLineFile); //打开工作空间 IWorkspaceFactory pWSF = new ShapefileWorkspaceFactoryClass(); IFeatureWorkspace pWS = (IFeatureWorkspace)pWSF.OpenFromFile(pFilePath, 0); //写入实体对象 IFeatureLayer pFeatureLayer = new FeatureLayerClass(); pFeatureLayer.FeatureClass = pWS.OpenFeatureClass(pFileName); IFeatureClass pFeatureClass = pFeatureLayer.FeatureClass; IDataset pDataset = (IDataset)pFeatureClass; IWorkspace pWorkspace = pDataset.Workspace; //开始空间编辑 IWorkspaceEdit pWorkspaceEdit = (IWorkspaceEdit)pWorkspace; pWorkspaceEdit.StartEditing(true); pWorkspaceEdit.StartEditOperation(); IFeatureBuffer pFeatureBuffer = pFeatureClass.CreateFeatureBuffer(); IFeatureCursor pFeatureCursor; //开始插入新的实体对象 pFeatureCursor = pFeatureClass.Insert(true); pFeatureBuffer.Shape = geometry; int index = pFeatureBuffer.Fields.FindField("EarthVector"); if (index >= 0) { pFeatureBuffer.set_Value(pFeatureBuffer.Fields.FindField("EarthVector"), earv); } index = pFeatureBuffer.Fields.FindField("Type"); if (index >= 0) { pFeatureBuffer.set_Value(pFeatureBuffer.Fields.FindField("Type"), "Ear"); } object featureOID = pFeatureCursor.InsertFeature(pFeatureBuffer); //保存实体 pFeatureCursor.Flush(); //结束空间编辑 pWorkspaceEdit.StopEditOperation(); pWorkspaceEdit.StopEditing(true); System.Runtime.InteropServices.Marshal.ReleaseComObject(pFeatureCursor); }
public void StoreFeature(IFeature pFeature) { IWorkspaceEdit pWorkspaceEdit = clsEditorMain.EditWorkspace as IWorkspaceEdit; if (clsEditorMain.EditFeatureLayer == null) { return; } pWorkspaceEdit.StartEditOperation(); pFeature.Store(); pWorkspaceEdit.StopEditOperation(); m_pAV.PartialRefresh(esriViewDrawPhase.esriViewGeography, pFeature, null); //RefreshModifyFeature ( pFeature ); }
/// <summary> /// 更新数据 /// </summary> /// <param name="lyr">图层</param> /// <param name="fea">要素对象</param> /// <param name="attributes">属性集合</param> /// <param name="pGeo">空间对象</param> /// <returns>成功失败标志</returns> public bool UpdateFeature(IFeatureLayer lyr, IFeature fea, Dictionary <string, string> attributes, IGeometry pGeo) { bool bres = false; try { IFeatureClass Featureclass = lyr.FeatureClass; IWorkspaceEdit workspace = (IWorkspaceEdit)(Featureclass as IDataset).Workspace; workspace.StartEditing(false); workspace.StartEditOperation(); int index = Featureclass.Fields.FindField(GIS_Const.FIELD_SHAPE); IGeometryDef geometryDef = fea.Fields.get_Field(index).GeometryDef as IGeometryDef; if (geometryDef.HasZ) { IZAware pZAware = (IZAware)pGeo; pZAware.ZAware = true; fea.Shape = pGeo; foreach (string key in attributes.Keys) { int findex = fea.Fields.FindField(key); if (findex != -1) { fea.set_Value(findex, attributes[key]); } } fea.Store(); } else { fea.Shape = pGeo; foreach (string key in attributes.Keys) { int findex = fea.Fields.FindField(key); if (findex != -1) { fea.set_Value(findex, attributes[key]); } } fea.Store(); } workspace.StopEditOperation(); workspace.StopEditing(true); bres = true; } catch (Exception ei) { Log.Debug("[GIS] Update Feature: " + ei.ToString()); } return(bres); }
private void InsertPointBefore_ItemClick(object sender, ItemClickEventArgs e) { try { IPointCollection pGeometry; IEnvelope envelope = this.m_pGeometry.Envelope; double dx = CommonHelper.ConvertPixelsToMapUnits(this.m_pMap as IActiveView, 6.0); envelope.Expand(dx, dx, false); if (this.m_pGeometry.GeometryType == esriGeometryType.esriGeometryMultipoint) { pGeometry = this.m_pGeometry as IPointCollection; } else { IGeometryCollection geometrys = this.m_pGeometry as IGeometryCollection; pGeometry = geometrys.get_Geometry(this.listBox1.SelectedIndex) as IPointCollection; } int i = this.listView1.SelectedIndices[0]; IPoint point = pGeometry.get_Point(i - 1); IPoint point2 = pGeometry.get_Point(i); IPoint inPoint = new PointClass(); inPoint.PutCoords((point.X + point2.X) / 2.0, (point.Y + point2.Y) / 2.0); if (this.m_HasZ) { inPoint.Z = (point.Z + point2.Z) / 2.0; } if (this.m_HasM) { inPoint.M = (point.M + point2.M) / 2.0; } object before = i; object after = Missing.Value; pGeometry.AddPoint(inPoint, ref before, ref after); this.ResetListView(); (this.m_pMap as IActiveView).PartialRefresh(esriViewDrawPhase.esriViewGeoSelection, null, envelope); IWorkspaceEdit workspace = (this.m_pEditFeature.Class as IDataset).Workspace as IWorkspaceEdit; workspace.StartEditOperation(); this.m_pEditFeature.Shape = this.m_pGeometry; this.m_pEditFeature.Store(); workspace.StopEditOperation(); envelope = this.m_pGeometry.Envelope; envelope.Expand(dx, dx, false); (this.m_pMap as IActiveView).PartialRefresh(esriViewDrawPhase.esriViewGeoSelection, null, envelope); this.SetStatus(); } catch (Exception exception) { Logger.Current.Error("", exception, ""); } }
private void TrimPolyline(IFeature trimFeature, IFeature targetFeature, IPoint secondPoint) { IGeometry preservedGeom = null; IGeometry leftGeom = null; IGeometry rightGeom = null; double distanceOnCurve = 0; double nearestDistance = 0; bool isRightSide = false; IPoint outPoint = new PointClass(); IFeatureClass featureClass = trimFeature.Class as IFeatureClass; IDataset dataset = featureClass as IDataset; IWorkspaceEdit workspaceEdit = dataset.Workspace as IWorkspaceEdit; if (!(workspaceEdit.IsBeingEdited())) { return; } try { IGeometry targetGeometry = targetFeature.ShapeCopy; IGeometry trimGeometry = trimFeature.ShapeCopy; ITopologicalOperator2 topo = trimGeometry as ITopologicalOperator2; topo.IsKnownSimple_2 = false; topo.Simplify(); ITopologicalOperator2 topo2 = targetGeometry as ITopologicalOperator2; topo2.IsKnownSimple_2 = false; topo2.Simplify(); topo.Cut(targetGeometry as IPolyline, out leftGeom, out rightGeom); ICurve curve = targetGeometry as ICurve; curve.QueryPointAndDistance(esriSegmentExtension.esriNoExtension, secondPoint, false, outPoint, ref distanceOnCurve, ref nearestDistance, ref isRightSide); if (isRightSide) { preservedGeom = leftGeom; } else { preservedGeom = rightGeom; } workspaceEdit.StartEditOperation(); trimFeature.Shape = preservedGeom; trimFeature.Store(); workspaceEdit.StopEditOperation(); FlashGeometry(trimGeometry as IGeometry, 3, 10); } catch (Exception ex) { workspaceEdit.AbortEditOperation(); MessageBox.Show("线要素延伸失败!!" + ex.Message, "信息提示", MessageBoxButtons.OK, MessageBoxIcon.Information); } }
public bool DeleteTemplate(string templateName) { try { IObjectTemplate objectTemplate = _templates.FirstOrDefault(c => c.Name == templateName); if (objectTemplate == null || objectTemplate.ID <= 0) { return(true); } if (_workspace == null) { Connect(); } ITable pTable = _workspace.OpenTable("YT_TEMPLATE_FEATURECLASS"); IWorkspaceEdit pWksEdit = _workspace as IWorkspaceEdit; pWksEdit.StartEditing(true); pWksEdit.StartEditOperation(); IRow pRow = pTable.GetRow(objectTemplate.ID); if (pRow != null) { pRow.Delete(); } //pTable = _workspace.OpenTable("YT_TEMPLATE_FIELD"); //foreach (IYTField ytField in objectTemplate.Fields) //{ // if (ytField.ID > 0) // { // pRow = pTable.GetRow(ytField.ID); // if(pRow != null) pRow.Delete(); // } //} pWksEdit.StopEditOperation(); pWksEdit.StopEditing(true); DisConnect(); return(true); } catch (Exception ex) { MessageService.Current.Warn("系统发生错误:" + ex.Message); return(false); throw; } }
private void UpdateFeature(IFeature selectedFeature, IPointCollection4 polylinePoints) { IPointCollection4 geometry; esriGeometryType geometryType = selectedFeature.Shape.GeometryType; switch (geometryType) { case esriGeometryType.esriGeometryMultipoint: geometry = new MultipointClass(); break; case esriGeometryType.esriGeometryPolyline: geometry = new PolylineClass(); break; case esriGeometryType.esriGeometryPolygon: geometry = new PolygonClass(); break; default: geometry = null; break; } if (geometry == null) { return; } geometry.AddPointCollection(polylinePoints); IFeatureClass featureClass = selectedFeature.Class as IFeatureClass; IDataset dataset = featureClass as IDataset; IWorkspaceEdit workspaceEdit = dataset.Workspace as IWorkspaceEdit; if (!(workspaceEdit.IsBeingEdited())) { return; } try { workspaceEdit.StartEditOperation(); selectedFeature.Shape = geometry as IGeometry; selectedFeature.Store(); workspaceEdit.StopEditOperation(); } catch (Exception ex) { workspaceEdit.AbortEditOperation(); MessageBox.Show("移动要素顶点失败!!" + ex.Message, "信息提示", MessageBoxButtons.OK, MessageBoxIcon.Information); } }
/// <summary> /// Start Editing operation /// </summary> /// <param name="ipWorkspace">IWorkspace</param> public static void StartEditOperation(IWorkspace ipWorkspace) { IWorkspaceEdit ipWsEdit = ipWorkspace as IWorkspaceEdit; try { ipWsEdit.StartEditOperation(); } catch (Exception ex) { ipWsEdit.AbortEditOperation(); throw (ex); } }
//将线添加到图层 private void AddFeature(IGeometry geometry) { string pLineFile = txtLineFilePath.Text; string pFilePath = System.IO.Path.GetDirectoryName(pLineFile); string pFileName = System.IO.Path.GetFileName(pLineFile); //打开工作空间 IWorkspaceFactory pWSF = new ShapefileWorkspaceFactoryClass(); IFeatureWorkspace pWS = (IFeatureWorkspace)pWSF.OpenFromFile(pFilePath, 0); //写入实体对象 IFeatureLayer pFeatureLayer = new FeatureLayerClass(); pFeatureLayer.FeatureClass = pWS.OpenFeatureClass(pFileName); IFeatureClass pFeatureClass = pFeatureLayer.FeatureClass; IDataset pDataset = (IDataset)pFeatureClass; IWorkspace pWorkspace = pDataset.Workspace; //开始空间编辑 IWorkspaceEdit pWorkspaceEdit = (IWorkspaceEdit)pWorkspace; pWorkspaceEdit.StartEditing(true); pWorkspaceEdit.StartEditOperation(); IFeatureBuffer pFeatureBuffer = pFeatureClass.CreateFeatureBuffer(); IFeatureCursor pFeatureCursor; ////清除图层原有实体对象 //pFeatureCursor = pFeatureClass.Update(null, true); //IFeature pFeature; //pFeature = pFeatureCursor.NextFeature(); //while (pFeature != null) //{ // pFeatureCursor.DeleteFeature(); // pFeature = pFeatureCursor.NextFeature(); //} //开始插入新的实体对象 pFeatureCursor = pFeatureClass.Insert(true); pFeatureBuffer.Shape = geometry; object featureOID = pFeatureCursor.InsertFeature(pFeatureBuffer); //保存实体 pFeatureCursor.Flush(); //结束空间编辑 pWorkspaceEdit.StopEditOperation(); pWorkspaceEdit.StopEditing(true); System.Runtime.InteropServices.Marshal.ReleaseComObject(pFeatureCursor); }
private void moveFeature(int x, int y) { IFeatureLayer curLayer = getEditLayer.isExistLayer(m_MapControl.Map) as IFeatureLayer; IWorkspaceEdit iWE = (curLayer.FeatureClass as IDataset).Workspace as IWorkspaceEdit; if (!iWE.IsBeingEdited()) { iWE.StartEditing(false); } IFeatureSelection curLayerSn = curLayer as IFeatureSelection; ISelectionSet pSS = curLayerSn.SelectionSet; if (pSS.Count != 1) { return; } ISelectionSet iSS = (curLayer as IFeatureSelection).SelectionSet; ICursor iCursor; iSS.Search(null, false, out iCursor); IFeatureCursor iFC = iCursor as IFeatureCursor; IFeature tmpFeature = iFC.NextFeature(); IPoint pPnt = m_MapControl.ActiveView.ScreenDisplay.DisplayTransformation.ToMapPoint(x, y); IGeometry pGeometry = tmpFeature.ShapeCopy; if (pGeometry.GeometryType == esriGeometryType.esriGeometryPoint) { pGeometry = pPnt; } else if (pGeometry.GeometryType == esriGeometryType.esriGeometryPolyline || pGeometry.GeometryType == esriGeometryType.esriGeometryPolygon) { double offX = 0, offY = 0; offX = pGeometry.Envelope.XMin + pGeometry.Envelope.Width / 2 - pPnt.X; offY = pGeometry.Envelope.YMin + pGeometry.Envelope.Height / 2 - pPnt.Y; ITransform2D iT2D = pGeometry as ITransform2D; iT2D.Move(-offX, -offY); } iWE.StartEditOperation(); tmpFeature.Shape = pGeometry; tmpFeature.Store(); iWE.StopEditOperation(); //iWE.StopEditing(true); iWE = null; curLayerSn.Clear(); curLayerSn.Add(tmpFeature); m_MapControl.ActiveView.Refresh(); }
public bool InsertNewRow(ITable table,IWorkspaceEdit workspace) { using (ComReleaser comReleaser = new ComReleaser()) { try { multiWspEdit.StartMultiuserEditing(esriMultiuserEditSessionMode.esriMESMVersioned); workspace.StartEditOperation(); _currentRow = table.CreateRow(); _currentRow.Store(); workspace.StopEditOperation(); workspace.StopEditing(true); return true; } catch { workspace.StopEditOperation(); workspace.StopEditing(false); return false; } } }
public void ProcessFeature(IWorkspaceEdit iwe, IFeatureLayer ifl_active, IRow rw) { double value = double.NaN; if (CoordinateSystem == "") { CoordinateSystem = ((IFeature)rw).Shape.SpatialReference.Name; } if (this.LinearUnit == null || this.LinearUnit == "") { if (fieldTier == 2) { LinearUnit = rw.get_Value(GetFieldUnitIndex()).ToString(); } if (this.LinearUnit == null || this.LinearUnit.Trim() == "") { LinearUnit = GetSpatialReferenceLinearUnit(((IFeature)rw).Shape.SpatialReference); } } if (LinearUnit.IndexOf("meter", 0, StringComparison.CurrentCultureIgnoreCase) > -1) { if (useArealUnit) { currentAreaUnit = esriAreaUnits.esriSquareMeters; LinearUnit = "Square Meters"; } else { currentLinearUnit = esriUnits.esriMeters; } } else if (LinearUnit.IndexOf("foot", 0, StringComparison.CurrentCultureIgnoreCase) > -1) { if (useArealUnit) { currentAreaUnit = esriAreaUnits.esriSquareFeet; LinearUnit = "Square Feet"; } else { currentLinearUnit = esriUnits.esriFeet; } } else if (LinearUnit.IndexOf("acre", 0, StringComparison.CurrentCultureIgnoreCase) > -1) { currentAreaUnit = esriAreaUnits.esriAcres; currentLinearUnit = esriUnits.esriUnknownUnits; LinearUnit = "Acres"; } if (doReCalcValues || !double.TryParse(rw.get_Value(GetFieldIndex()).ToString(), out value) || value == double.NaN || value == 0.0) { value = DoMeasure(rw); //try writing the (single) measured value to the table try { IFeature feat = (IFeature)rw; //if we are re-calculating all values, there is no need to start editing on each row if (!doReCalcValues) { if (!iwe.IsBeingEdited()) iwe.StartEditing(true); iwe.StartEditOperation(); } feat.set_Value(GetFieldIndex(), value); feat.set_Value(GetFieldUnitIndex(), LinearUnit); feat.Store(); } catch (Exception err) { } finally { if (!doReCalcValues) { iwe.StopEditOperation(); if (iwe.IsBeingEdited()) iwe.StopEditing(true); //there may be more than one row that requires editing doReCalcValues = true; } } } values.Add(value); }