ArcGIS Pro根据线层所有数据生成外接多边形
private Task<bool> ConstructSamplePolygon(FeatureLayer polygonLayer, FeatureLayer lineLayer) { // execute the fine grained API calls on the CIM main thread return QueuedTask.Run(() => { // get the underlying feature class for each layer var polygonFeatureClass = polygonLayer.GetTable() as FeatureClass; var polygonDefinition = polygonFeatureClass.GetDefinition() as FeatureClassDefinition; var lineFeatureClass = lineLayer.GetTable() as FeatureClass; // construct a cursor to retrieve the line features var lineCursor = lineFeatureClass.Search(null, false); // set up the edit operation for the feature creation var createOperation = new EditOperation() { Name = "Create polygons", SelectNewFeatures = false }; PolylineBuilder polylineBuilder = new PolylineBuilder(polygonDefinition.GetSpatialReference()); while (lineCursor.MoveNext()) { // retrieve the first feature using (var lineFeature = lineCursor.Current as Feature) { // add the coordinate collection of the current geometry into our overall list of collections var polylineGeometry = lineFeature.GetShape() as Polyline; polylineBuilder.AddParts(polylineGeometry.Parts); } } // use the ConvexHull method from the GeometryEngine to construct the polygon geometry var newPolygon = GeometryEngine.Instance.ConvexHull(polylineBuilder.ToGeometry()) as Polygon; // queue the polygon creation createOperation.Create(polygonLayer, newPolygon); // execute the edit (polygon create) operation return createOperation.ExecuteAsync(); }); } protected async override void OnClick() { // to work in the context of the active display retrieve the current map Map activeMap = MapView.Active.Map; // retrieve the first line layer in the map var lineFeatureLayer = activeMap.GetLayersAsFlattenedList().OfType<FeatureLayer>().Where( lyr => lyr.ShapeType == ArcGIS.Core.CIM.esriGeometryType.esriGeometryPolyline).FirstOrDefault(); if (lineFeatureLayer == null) return; // retrieve the first polygon feature layer in the map var polygonFeatureLayer = activeMap.GetLayersAsFlattenedList().OfType<FeatureLayer>().Where( lyr => lyr.ShapeType == ArcGIS.Core.CIM.esriGeometryType.esriGeometryPolygon).FirstOrDefault(); if (polygonFeatureLayer == null) return; //construct the polyline based of the convex hull of all polylines await ConstructSamplePolygon(polygonFeatureLayer, lineFeatureLayer); }
分类:
ArcGIS Pro二次开发
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· 全程不用写代码,我用AI程序员写了一个飞机大战
· DeepSeek 开源周回顾「GitHub 热点速览」
· 记一次.NET内存居高不下排查解决与启示
· MongoDB 8.0这个新功能碉堡了,比商业数据库还牛
· .NET10 - 预览版1新功能体验(一)
2020-03-23 ArcGIS Pro 二次开发添加连接,断开连接,导入mxd
2020-03-23 无法将类型“System.Threading.Tasks.Task<string>”隐式转换为“string”
2020-03-23 ArcGIS Pro 读写BLOB字段
2020-03-23 ArcGIS Pro二次开发--增加数据到地图,打开影像
2015-03-23 CAD增强属性块的还原(转)