• 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);
    
    
            }
  • 相关阅读:
    Codeforces Round #578 (Div. 2) 训练总结及题解
    docker
    使用java遍历Map集合的方式
    SpringCloud集成rabbitmq:org.springframework.amqp.AmqpConnectException: java.net.ConnectException的解决办法
    创建新Docker容器时出现“The container name "/xxx" is already in use by container xxxxxxxxxxx...”问题的解决办法
    springBoot 项目中,使用定时任务报错
    java获取当前日期和前一周、前一月、前一年的日期
    用户行为PV&UV
    使用IDEA开发,多模块依赖中,找不到依赖: 程序包xxx.xxx.xxx不存在的问题
    Java获取本地IP地址和主机名
  • 原文地址:https://www.cnblogs.com/gisoracle/p/16047065.html
Copyright © 2020-2023  润新知