2022年AE进行编辑 .pdf

上传人:Che****ry 文档编号:27250960 上传时间:2022-07-23 格式:PDF 页数:20 大小:214.21KB
返回 下载 相关 举报
2022年AE进行编辑 .pdf_第1页
第1页 / 共20页
2022年AE进行编辑 .pdf_第2页
第2页 / 共20页
点击查看更多>>
资源描述

《2022年AE进行编辑 .pdf》由会员分享,可在线阅读,更多相关《2022年AE进行编辑 .pdf(20页珍藏版)》请在taowenge.com淘文阁网|工程机械CAD图纸|机械工程制图|CAD装配图下载|SolidWorks_CaTia_CAD_UG_PROE_设计图分享下载上搜索。

1、该文章所在的网址:http:/ ArcMap的 Editor工具,实现要素拖动、编辑。本来根本没有写这个工具的意思,自己一直用的Ae 自带的工具。 虽然可控制力弱了一些,但终究还是凑或能用。一天,问到一个同学,想请教一下,居然以百般理由回绝。算了,秉承毛老人家的口号:自力更生,丰衣足食!好了,闲话少说,各位看官,咱步入正题了。首先,说一下,所有的要素的更新、 插入、删除最好放在编辑的Session 里面,即以一对 StartEditing和 StopEditing包裹。一开始我的疑问在于,为什么我用IWorkspaceEdit的 StartEditing方法后,怎么鼠标不会变成AcrMap里面

2、 Editor的开始编辑那样呢,为什么不能选中要素,为什么不能双击后编辑要素?原来,选中要素和使要素处于编辑状态还是要自己写的(经高人指点,呵呵) 。先介绍一下程序中用到的变量:Code 那我们就按照逻辑顺序来一一展示这个到底是怎么做的。首先是,开始和结束编辑的代码:/开始编辑/ publicvoid StartEditing(bool bWithUndoRedo) if (m_SelectedLayer = null) return; IFeatureLayer featureLayer = m_SelectedLayer as IFeatureLayer; if (featureLayer

3、 = null) return; IFeatureClass featureClass = featureLayer.FeatureClass; if (featureClass = null) return; IDataset dataset = featureClass as IDataset; IWorkspaceEdit workspaceEdit = dataset.Workspace as IWorkspaceEd名师资料总结 - - -精品资料欢迎下载 - - - - - - - - - - - - - - - - - - 名师精心整理 - - - - - - - 第 1 页,共

4、 20 页 - - - - - - - - - it; try workspaceEdit.StartEditing(bWithUndoRedo); m_IsEdited = true; catch return; 当然你可以直接传进来IWorkspace,这个可根据你具体的需求,我这里用当前图层获取工作空间。/结束编辑/ publicvoid StopEditing(bool bSave) if (m_IsEdited) m_IsEdited = false; if (m_SelectedLayer = null) return; IFeatureLayer featureLayer = m

5、_SelectedLayer as IFeatureLayer; if (featureLayer = null) return; IFeatureClass featureClass = featureLayer.FeatureClass; if (featureClass = null) return; 名师资料总结 - - -精品资料欢迎下载 - - - - - - - - - - - - - - - - - - 名师精心整理 - - - - - - - 第 2 页,共 20 页 - - - - - - - - - IDataset dataset = featureClass as I

6、Dataset; IWorkspaceEdit workspaceEdit = dataset.Workspace as IWorkspaceEdit; if (workspaceEdit.IsBeingEdited() try workspaceEdit.StopEditing(bSave); catch workspaceEdit.AbortEditOperation(); return; 开始编辑已经好了,然后就是鼠标点击要素时候,让其处于选中状态,我这里为了方便控制,我分成了两个函数写,给为看官也可以合并成一个:publicvoid GetFeatureOnMouseDown(int

7、x, int y) m_SelectedFeature.Clear(); try if (m_SelectedLayer = null) return; IFeatureLayer featureLayer = m_SelectedLayer as IFeatureLayer; if (featureLayer = null) return; 名师资料总结 - - -精品资料欢迎下载 - - - - - - - - - - - - - - - - - - 名师精心整理 - - - - - - - 第 3 页,共 20 页 - - - - - - - - - IFeatureClass feat

8、ureClass = featureLayer.FeatureClass; if (featureClass = null) return; IPoint point = m_MapControl.ActiveView.ScreenDisplay.DisplayTransformation.ToMapPoint(x, y); IGeometry geometry = point as IGeometry; double length = ConvertPixelsToMapUnits(4); ITopologicalOperator pTopo = geometry as ITopologic

9、alOperator; IGeometry buffer = pTopo.Buffer(length); geometry = buffer.Envelope as IGeometry; ISpatialFilter spatialFilter = new SpatialFilterClass(); spatialFilter.Geometry = geometry; switch (featureClass.ShapeType) case esriGeometryType.esriGeometryPoint: spatialFilter.SpatialRel = esriSpatialRel

10、Enum.esriSpatialRelContains; break; case esriGeometryType.esriGeometryPolygon: spatialFilter.SpatialRel = esriSpatialRelEnum.esriSpatialRelIntersects; break; case esriGeometryType.esriGeometryPolyline: spatialFilter.SpatialRel = esriSpatialRelEnum.esriSpatialRelCrosses; break; spatialFilter.Geometry

11、Field = featureClass.ShapeFieldName; 名师资料总结 - - -精品资料欢迎下载 - - - - - - - - - - - - - - - - - - 名师精心整理 - - - - - - - 第 4 页,共 20 页 - - - - - - - - - IQueryFilter filter = spatialFilter as IQueryFilter; IFeatureCursor cursor = featureClass.Search(filter, false); IFeature pfeature = cursor.NextFeature();

12、 while (pfeature != null) m_SelectedFeature.Add(pfeature); pfeature = cursor.NextFeature(); catch return; /根据鼠标点击位置使击中要素处于高亮显示状态/ publicvoid SelectOnMouseDown() try if (m_SelectedLayer = null) return; m_MapControl.Map.ClearSelection(); m_MapControl.ActiveView.PartialRefresh(esriViewDrawPhase.esriVie

13、wGeoSelection, null, null); foreach (IFeature feature in m_SelectedFeature.ToArray() 名师资料总结 - - -精品资料欢迎下载 - - - - - - - - - - - - - - - - - - 名师精心整理 - - - - - - - 第 5 页,共 20 页 - - - - - - - - - m_MapControl.Map.SelectFeature(m_SelectedLayer, feature); m_MapControl.ActiveView.PartialRefresh(esriViewD

14、rawPhase.esriViewGeoSelection, null, null); catch return; 相信大家对第一个函数并不陌生吧?对的,就是用的空间查询,把点击中的要素放进容器,再用第二个函数进行高亮显示。 这个地方注意, 如果数据量比较多, 强烈推荐用PartialRefresh 而不要用 Refresh,参数的含义请参考帮助。这个只是开始编辑后,可以用鼠标点击选中要素,使其处于高亮状态,然而,ArcMap里面双击要素怎么出现节点用以编辑呢?这个是要自己绘制到MapControl上面去的:/在要素上面绘制一个可拖拽的符号/ publicvoid DrawEditSymbol

15、(IGeometry geometry, IDisplay display) IEngineEditProperties engineProperty = new EngineEditorClass(); ISymbol pointSymbol = engineProperty.SketchVertexSymbol as ISymbol; ISymbol sketchSymbol = engineProperty.SketchSymbol as ISymbol; ITopologicalOperator pTopo = geometry as ITopologicalOperator; 名师资

16、料总结 - - -精品资料欢迎下载 - - - - - - - - - - - - - - - - - - 名师精心整理 - - - - - - - 第 6 页,共 20 页 - - - - - - - - - sketchSymbol.SetupDC(display.hDC, display.DisplayTransformation); sketchSymbol.Draw(pTopo.Boundary); IPointCollection pointCol = geometry as IPointCollection; for ( int i = 0; i pointCol.PointCo

17、unt; i+) IPoint point = pointCol.get_Point(i); pointSymbol.SetupDC(display.hDC, display.DisplayTransformation); pointSymbol.Draw(point); pointSymbol.ResetDC(); ESRI.ArcGIS.ADF.ComReleaser.ReleaseCOMObject(sketchSymbol); ESRI.ArcGIS.ADF.ComReleaser.ReleaseCOMObject(pointSymbol); ESRI.ArcGIS.ADF.ComRe

18、leaser.ReleaseCOMObject(engineProperty); 注意,这个函数是在MapControl的 AfterDraw里面调用的, IDisplay参数,是 AfterDraw事件的参数,我这里就没有画出来,类似ArcMap里面还有一个红色的节点,这里全是绿色的,因为红色对我的用处不大,也就没有必要了,当然各位看官可以自行修改,还有就是绘制符号的时候一定要记得释放内存哦 现在,编辑状态做好了,但是现在只是雏形,因为它还没有响应任何鼠标事件,当鼠标悬停在绿色的节点上时并不会让你可以拖拽,所以我们还要做点工作。那现在就开始如果鼠标悬停在绿色节点上时的代码吧:publicvo

19、id SnapVertex(int x,int y,IGeometry snapContainer,refbool vertexSnaped,refbool contained) 名师资料总结 - - -精品资料欢迎下载 - - - - - - - - - - - - - - - - - - 名师精心整理 - - - - - - - 第 7 页,共 20 页 - - - - - - - - - IPoint point = m_MapControl.ActiveView.ScreenDisplay.DisplayTransformation.ToMapPoint(x, y); IPoint p

20、HitPoint = null; double hitDist = -1, tol = -1; int vertexIndex = -1, partIndex = -1; bool vertex = false; tol = ConvertPixelsToMapUnits(4); IHitTest pHitTest = snapContainer as IHitTest; bool bHit=pHitTest.HitTest(point, tol, esriGeometryHitPartType.esriGeometryPartVertex, pHitPoint, ref hitDist, r

21、ef partIndex, ref vertexIndex, ref vertex); vertexSnaped = false; contained = false; if (bHit) m_MapControl.MousePointer = esriControlsMousePointer.esriPointerCrosshair; vertexSnaped = true; return; else IRelationalOperator pRelOperator=null; ITopologicalOperator pTopo = null; IGeometry buffer = nul

22、l; IPolygon polygon = null; switch (snapContainer.GeometryType) 名师资料总结 - - -精品资料欢迎下载 - - - - - - - - - - - - - - - - - - 名师精心整理 - - - - - - - 第 8 页,共 20 页 - - - - - - - - - case esriGeometryType.esriGeometryPolyline: pTopo = snapContainer as ITopologicalOperator; buffer=pTopo.Buffer(3); polygon = bu

23、ffer as IPolygon; pRelOperator=polygon as IRelationalOperator; break; case esriGeometryType.esriGeometryPolygon: polygon = snapContainer as IPolygon; pRelOperator=polygon as IRelationalOperator; break; case esriGeometryType.esriGeometryPoint: pTopo = snapContainer as ITopologicalOperator; buffer = p

24、Topo.Buffer(3); polygon = buffer as IPolygon; pRelOperator = polygon as IRelationalOperator; break; default: break; if (pRelOperator = null) return; if (pRelOperator.Contains(point) m_MapControl.MousePointer = esriControlsMousePointer.esriPointerSizeAll; contained = true; else m_MapControl.MousePoin

25、ter = esriControlsMousePointer.esriPointerArrow; return; 名师资料总结 - - -精品资料欢迎下载 - - - - - - - - - - - - - - - - - - 名师精心整理 - - - - - - - 第 9 页,共 20 页 - - - - - - - - - 这里就是根据鼠标悬停的位置,来改变鼠标样式,抱歉的很,我没有从AE 里面找到和ArcMap一样的鼠标样式, 只要用一些简单的替代了,当然你可以自己定义,也可以打电话、 发 Email质问 ESRI 客服,如果你知道了,一定要告诉我,否则我诅咒你找不到女朋友!这个函数里

26、面,我需要判断,鼠标是悬停在要素的节点上,还是悬停在要素内部了,这个对于后面处理是拽节点还是移动要素有很大的帮助。这个根据鼠标悬停位置改变鼠标样式,还远远不够滴,当你悬停到绿色节点上时,按下鼠标时,就意味这拖拽开始,当鼠标左键按下并移动时,要出现像橡皮筋一样的连接线,当左键弹起时,就意味着拖拽结束,如果再按下左键,就意味着要素的编辑结束。这个怎么做到呢,请看下面的代码:publicbool EditFeature(int x,int y,IGeometry geometry) GetFeatureOnMouseDown(x, y); SelectOnMouseDown(); if(m_Sele

27、ctedFeature.Count1) returnfalse; if (geometry = null) returnfalse; IPoint pHitPoint=null; double hitDist = 0, tol = 0; int vertexIndex = 0, vertexOffset = 0, numVertices = 0, partIndex = 0; bool vertex=false; IFeature editedFeature = m_SelectedFeature0; point = m_MapControl.ActiveView.ScreenDisplay.

28、DisplayTransformation.ToMapPoint(x, y); tol = ConvertPixelsToMapUnits(4); /IGeometry pGeo = editedFeature.Shape; /m_EditingFeature = editedFeature; 名师资料总结 - - -精品资料欢迎下载 - - - - - - - - - - - - - - - - - - 名师精心整理 - - - - - - - 第 10 页,共 20 页 - - - - - - - - - try switch (geometry.GeometryType) case es

29、riGeometryType.esriGeometryPoint: m_FeedBack = new MovePointFeedbackClass(); m_FeedBack.Display = m_MapControl.ActiveView.ScreenDisplay; IMovePointFeedback pointMove = m_FeedBack as IMovePointFeedback; pointMove.Start(geometry as IPoint, point); break; case esriGeometryType.esriGeometryPolyline: if

30、(TestGeometryHit(tol, point, geometry, ref pHitPoint, ref hitDist, ref partIndex, ref vertexOffset, ref vertexIndex, ref vertex) if(!vertex) IGeometryCollection geometryColl = geometry as IGeometryCollection; IPath path = geometryColl.get_Geometry(partIndex) as IPath; IPointCollection pointColl = pa

31、th as IPointCollection; numVertices = pointColl.PointCount; object missing = Type.Missing; if (vertexIndex = 0) 名师资料总结 - - -精品资料欢迎下载 - - - - - - - - - - - - - - - - - - 名师精心整理 - - - - - - - 第 11 页,共 20 页 - - - - - - - - - object start = 1asobject; pointColl.AddPoint(point, ref start, ref missing); e

32、lse object objVertexIndex=vertexIndex asobject ; pointColl.AddPoint(point, ref missing, ref objVertexIndex); TestGeometryHit(tol, point, geometry, ref pHitPoint, ref hitDist, ref partIndex, ref vertexOffset, ref vertexIndex, ref vertex); m_FeedBack = new LineMovePointFeedbackClass(); m_FeedBack.Disp

33、lay = m_MapControl.ActiveView.ScreenDisplay; ILineMovePointFeedback lineMove = m_FeedBack as ILineMovePointFeedback; lineMove.Start(geometry as IPolyline, vertexIndex, point); elsereturnfalse; break; case esriGeometryType.esriGeometryPolygon: if (TestGeometryHit(tol, point, geometry, ref pHitPoint,

34、ref hitDist, ref partIndex, ref vertexOffset, ref vertexIndex, ref vertex) 名师资料总结 - - -精品资料欢迎下载 - - - - - - - - - - - - - - - - - - 名师精心整理 - - - - - - - 第 12 页,共 20 页 - - - - - - - - - if(!vertex) IGeometryCollection geometryColl = geometry as IGeometryCollection; IPath path = geometryColl.get_Geome

35、try(partIndex) as IPath; IPointCollection pointColl = path as IPointCollection; numVertices = pointColl.PointCount; object missing = Type.Missing; if (vertexIndex = 0) object start = 1asobject; pointColl.AddPoint(point, ref start, ref missing); else object objVertexIndex = vertexIndex asobject; poin

36、tColl.AddPoint(point, ref missing, ref objVertexIndex); TestGeometryHit(tol, point, geometry, ref pHitPoint, ref hitDist, ref partIndex, ref vertexOffset, ref vertexIndex, ref vertex); m_FeedBack = new PolygonMovePointFeedbackClass(); m_FeedBack.Display = m_MapControl.ActiveView.ScreenDisplay; 名师资料总

37、结 - - -精品资料欢迎下载 - - - - - - - - - - - - - - - - - - 名师精心整理 - - - - - - - 第 13 页,共 20 页 - - - - - - - - - IPolygonMovePointFeedback polyMove = m_FeedBack as IPolygonMovePointFeedback; polyMove.Start(geometry as IPolygon, vertexIndex + vertexOffset, point); elsereturnfalse; break; default: break; catc

38、h returnfalse; returntrue; publicvoid FeatureEditMouseMove(int x,int y) if (m_FeedBack = null) return; IPoint point = m_MapControl.ActiveView.ScreenDisplay.DisplayTransformation.ToMapPoint(x, y); m_FeedBack.MoveTo(point); public IGeometry EndFeatureEdit(int x, int y) if (m_FeedBack = null) returnnul

39、l; IGeometry geometry = null; IPoint point = m_MapControl.ActiveView.ScreenDisplay.DisplayTransformation.ToMapPoint(x, y); 名师资料总结 - - -精品资料欢迎下载 - - - - - - - - - - - - - - - - - - 名师精心整理 - - - - - - - 第 14 页,共 20 页 - - - - - - - - - if (m_FeedBack as IMovePointFeedback) != null) IMovePointFeedback p

40、ointMove = m_FeedBack as IMovePointFeedback; geometry = pointMove.Stop() as IGeometry; elseif (m_FeedBack as ILineMovePointFeedback) != null) ILineMovePointFeedback lineMove = m_FeedBack as ILineMovePointFeedback; geometry = lineMove.Stop() as IGeometry; elseif (m_FeedBack as IPolygonMovePointFeedba

41、ck) != null) IPolygonMovePointFeedback polyMove = m_FeedBack as IPolygonMovePointFeedback; geometry = polyMove.Stop() as IGeometry; m_FeedBack = null; m_MapControl.ActiveView.PartialRefresh(esriViewDrawPhase.esriViewGeography, m_SelectedLayer, null); return geometry; 呵,这个排版真的是很累啊,无法自动缩进,害的我只能一行一行的移动

42、。第一个函数,自然是点击下绿色节点时触发,意味着,我们的拖拽就开始了;但是,但按着鼠标左键来回移动时怎么处理啊?呵呵,这就是第二个函数的所具备的功能,所以你要在MapControl 的 MouseMove事件中添加这个函数;但是当你确定你移动的位置是最佳位置的时候,想停下来怎么办呢?这就是第三个函数来帮你了,也就意味着你的拖拽结束, 并返回一个IGeometry,这个 IGeometry就是你编辑过后要素的新的几何形状,并且名师资料总结 - - -精品资料欢迎下载 - - - - - - - - - - - - - - - - - - 名师精心整理 - - - - - - - 第 15 页,共

43、 20 页 - - - - - - - - - 当你移动结束左键弹起的时候,这个新的IGeometry也需要显示出来它的绿色的节点,所以重绘的时候需要这个 IGeometry。好了,我们快大功告成了,stop !好像还少点东西,对了,我们最终是要把最新的几何形状赋给编辑的要素以实现更新,所以我们还需要下面的这个函数:publicbool UpdateEdit(IGeometry newGeom) if (m_SelectedFeature.Count 0) IGeometryCollection pGeoColl = geometry as IGeometryCollecti名师资料总结 -

44、- -精品资料欢迎下载 - - - - - - - - - - - - - - - - - - 名师精心整理 - - - - - - - 第 19 页,共 20 页 - - - - - - - - - on; vertexOffset = 0; for (int i = 0; i partIndex;i=2*i+1) IPointCollection pointColl = pGeoColl.get_Geometry(i) as IPointCollection; vertexOffset = vertexOffset + pointColl.PointCount; return res; /

45、清除要素选择状态,恢复常态/ publicvoid ClearSelection() m_MapControl.Map.ClearSelection(); m_MapControl.ActiveView.PartialRefresh(esriViewDrawPhase.esriViewGeography, m_SelectedLayer, null); 各位看官,由于要素的移动、要素的创建和要素编辑在代码逻辑上差不多,所以我就不做过多阐述了,都是在处理鼠标的事件,需要做判断。其实,可能有看官已经了解,在AE 的帮助里面就有类似的代码,是的,我参考了这部分代码,并对ESRI 的开发和工作人员表示感谢。最后,谢谢AE 开发群一叶知秋老大哥的帮助,总是在繁忙之中耐心的指导,再次表示感谢。希望大家能够有所启发,谢谢大家的支持!示例源码下载地址http:/ - - -精品资料欢迎下载 - - - - - - - - - - - - - - - - - - 名师精心整理 - - - - - - - 第 20 页,共 20 页 - - - - - - - - -

展开阅读全文
相关资源
相关搜索

当前位置:首页 > 教育专区 > 高考资料

本站为文档C TO C交易模式,本站只提供存储空间、用户上传的文档直接被用户下载,本站只是中间服务平台,本站所有文档下载所得的收益归上传人(含作者)所有。本站仅对用户上传内容的表现方式做保护处理,对上载内容本身不做任何修改或编辑。若文档所含内容侵犯了您的版权或隐私,请立即通知淘文阁网,我们立即给予删除!客服QQ:136780468 微信:18945177775 电话:18904686070

工信部备案号:黑ICP备15003705号© 2020-2023 www.taowenge.com 淘文阁