Example #1
0
        /// <summary>
        /// The Voronoi Graph calculation creates a delaunay tesselation where 
        /// each point is effectively converted into triangles.
        /// </summary>
        /// <param name="points">The points to use for creating the tesselation</param>
        /// <returns></returns>
        public static IFeatureSet DelaunayLines(IFeatureSet points)
        {
            double[] vertices = points.Vertex;
            VoronoiGraph gp = Fortune.ComputeVoronoiGraph(vertices);
          
            FeatureSet result = new FeatureSet();
            foreach (VoronoiEdge edge in gp.Edges)
            {
                Coordinate c1 = edge.RightData.ToCoordinate();
                Coordinate c2 = edge.LeftData.ToCoordinate();
                LineString ls = new LineString(new List<Coordinate>{c1, c2});
                Feature f = new Feature(ls);
                result.AddFeature(f);
            }
            return result;

        }
Example #2
0
        /// <summary>
        /// The Voronoi Graph calculation creates the lines that form a voronoi diagram
        /// </summary>
        /// <param name="points">The points to use for creating the tesselation</param>
        /// <returns></returns>
        public static IFeatureSet VoronoiLines(IFeatureSet points)
        {
            double[] vertices = points.Vertex;
            VoronoiGraph gp = Fortune.ComputeVoronoiGraph(vertices);

            HandleBoundaries(gp, points.Envelope);

            FeatureSet result = new FeatureSet();
            foreach (VoronoiEdge edge in gp.Edges)
            {
                Coordinate c1 = edge.VVertexA.ToCoordinate();
                Coordinate c2 = edge.VVertexB.ToCoordinate();
                LineString ls = new LineString(new List<Coordinate> { c1, c2 });
                Feature f = new Feature(ls);
                result.AddFeature(f);
            }
            return result;

        }
        /// <summary>
        /// Executes the ClipPolygonWithLine Operation tool programaticaly.
        /// Ping deleted static for external testing 01/2010
        /// </summary>
        /// <param name="input1">The input Polygon FeatureSet.</param>
        /// <param name="input2">The input Polyline FeatureSet.</param>
        /// <param name="output">The output Polygon FeatureSet.</param>
        /// <param name="cancelProgressHandler">The progress handler.</param>
        /// <returns></returns>
        public bool Execute(IFeatureSet input1, IFeatureSet input2, IFeatureSet output, ICancelProgressHandler cancelProgressHandler)
        {
            //Validates the input and output data
            if (input1 == null || input2 == null || output == null)
            {
                return false;
            }
            if (cancelProgressHandler.Cancel)
                return false;
            IFeature polygon = input1.Features[0];
            IFeature line = input2.Features[0];
            IFeatureSet resultFS = new FeatureSet(FeatureTypes.Polygon);
            int previous = 0;
            if (DoClipPolygonWithLine(ref polygon, ref line, ref output) == false)
            {
                throw new SystemException(TextStrings.Exceptioninclipin);
            }
            int intFeature = output.Features.Count;
            for (int i = 0; i < intFeature; i++)
            {
                Polygon poly = new Polygon(output.Features[i].Coordinates);
                resultFS.AddFeature(poly);

                int current = Convert.ToInt32(Math.Round(i * 100D / intFeature));
                //only update when increment in percentage
                if (current > previous)
                    cancelProgressHandler.Progress("", current, current + TextStrings.progresscompleted);
                previous = current;
            }
            cancelProgressHandler.Progress("", 100, 100 + TextStrings.progresscompleted);
            resultFS.SaveAs(output.Filename, true);
            return true;
        }