• 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);
    
    
            }
  • 相关阅读:
    14.6 将运算分组为事务
    Android 取得 ListView中每个Item项目的值
    【编程题目】n 个骰子的点数
    【编程题目】扑克牌的顺子
    【编程题目】颠倒栈☆
    【编程题目】输出 1 到最大的 N 位数
    【编程题目】寻找丑数
    【编程题目】在字符串中删除特定的字符
    【编程题目】复杂链表的复制☆
    【编程题目】找出数组中两个只出现一次的数字 ★★(自己没做出来)
  • 原文地址:https://www.cnblogs.com/gisoracle/p/16047065.html
Copyright © 2020-2023  润新知