Ejemplo n.º 1
0
        private static Polyline CreateWkbMultiLineString(BinaryReader reader, WkbByteOrder byteOrder)
        {
            // Get the number of linestrings in this multilinestring.
            var numLineStrings = (int)ReadUInt32(reader, byteOrder);

            if (numLineStrings < 1)
            {
                throw new Exception("Could not create linestring");
            }

            // Read linestring header
            reader.ReadByte();
            ReadUInt32(reader, byteOrder);

            var mline = new PolylineBuilder(CreateWkbLineString(reader, byteOrder));

            // Loop on the number of linestrings.
            for (var i = 1; i < numLineStrings; i++)
            {
                // Read linestring header
                reader.ReadByte();
                ReadUInt32(reader, byteOrder);

                mline.AddParts(CreateWkbLineString(reader, byteOrder).Parts);
            }

            // Create and return the MultiLineString.
            return(mline.ToGeometry());
        }
        /// <summary>
        /// Create sample polygon feature using the point geometries from the multi-point feature using the
        /// ConvexHull method provided by the GeometryEngine.
        /// </summary>
        /// <param name="polygonLayer">Polygon geometry feature layer used to add the new feature.</param>
        /// <param name="lineLayer">The polyline feature layer containing the features used to construct the polygon.</param>
        /// <returns></returns>
        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();
            }));
        }
Ejemplo n.º 3
0
        private void AddLineLayer(List <IGeoInfo> lineList, Layer layer)
        {
            foreach (LineGeoInfo line in lineList)
            {
                if (line.Polylines.Values.Count == 0)
                {
                    continue;
                }

                PolylineBuilder builder = new PolylineBuilder(SpatialReferences.Wgs84);
                line.Polylines.Values.ToList().ForEach(p => builder.AddParts(p.Parts));

                Polyline polyline = builder.ToGeometry();
                layer.GraphicsLayer.Graphics.Add(new Graphic(polyline, line.AttrList, MapLineLayer.GetSymbol(GeoMarkerType.Line, GeoStatus.Normal)));
                _shapeList.Add(polyline.Extent);

                //_otherGraphic.Graphics.Add(new Graphic(polyline.Extent.GetCenter(), line.AttrList, MapLineLayer.GetSymbol(GeoType.Point, GeoStatus.Normal)));
            }
        }
Ejemplo n.º 4
0
        /// <summary>
        /// Create sample polygon feature using the point geometries from the multi-point feature using the 
        /// ConvexHull method provided by the GeometryEngine.
        /// </summary>
        /// <param name="polygonLayer">Polygon geometry feature layer used to add the new feature.</param>
        /// <param name="lineLayer">The polyline feature layer containing the features used to construct the polygon.</param>
        /// <returns></returns>
        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
                    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.ConvexHull(polylineBuilder.ToGeometry()) as Polygon;

                // queue the polygon creation
                createOperation.Create(polygonLayer, newPolygon);

                // execute the edit (polygon create) operation
                return createOperation.ExecuteAsync();
            });
        }
        private static async Task PolygonsForContours(List <CandidateDam> candidates, List <Contour> contours, PolylineBuilder polylineBuilder)
        {
            foreach (var contour in contours)
            {
                var contourGeometry = contour.Polyline;
                int counter         = 0;
                int contourHeight   = 0;
                foreach (var candidate in candidates.Where(c => c.ContourID == contour.ObjectID).ToList())
                {
                    try
                    {
                        while (polylineBuilder.CountParts > 0)
                        {
                            polylineBuilder.RemovePart(0);
                        }

                        //add the full contour
                        polylineBuilder.AddParts(contourGeometry.Parts);
                        //split at the endpoint
                        polylineBuilder.SplitAtDistance(candidate.EndPointDistance, false, true);

                        if (candidate.DamSpansContourStart)
                        {
                            //remove the part of the contour after the endpoint
                            //split at the startpoint
                            if (candidate.StartPointDistance != 0)
                            {
                                polylineBuilder.SplitAtDistance(candidate.StartPointDistance, false, true);
                                //remove the part of the polyline before the startpoint
                                polylineBuilder.RemovePart(1);
                            }
                            //Handle the situation, when the startpoint is on the very beginning of the contour line
                            else
                            {
                                polylineBuilder.RemovePart(0);
                            }
                        }
                        else
                        {
                            //remove the part of the contour after the endpoint
                            polylineBuilder.RemovePart(1);
                            //split at the startpoint
                            if (candidate.StartPointDistance != 0)
                            {
                                polylineBuilder.SplitAtDistance(candidate.StartPointDistance, false, true);
                                //remove the part of the polyline before the startpoint
                                polylineBuilder.RemovePart(0);
                            }
                        }
                        var newPolygon3D = PolygonBuilder.CreatePolygon(polylineBuilder.ToGeometry().Copy3DCoordinatesToList(), SpatialReference);

                        ReservoirSurface surface = new ReservoirSurface();
                        surface.Polygon       = GeometryEngine.Instance.Move(newPolygon3D, 0, 0, candidate.ContourHeight) as Polygon;
                        surface.DamID         = (long)candidate.ObjectID;
                        surface.ContourHeight = (short)candidate.ContourHeight;
                        surfaces.Add(surface);

                        counter++;
                        contourHeight = candidate.ContourHeight;
                    }
                    catch (Exception ex)
                    {
                        SharedFunctions.Log("Error for DamID " + candidate.ObjectID + " for ContourHeight " + candidate.ContourHeight + ": (" + ex.Message + ")");
                    }
                }

                SharedFunctions.Log("Created " + surfaces.Count.ToString("N0") + " Polygons ... " + counter.ToString("N0") + " for Contour " + contour.ObjectID + " (" + contour.Height + " m)");
            }
        }