예제 #1
0
        /// <summary>
        ///
        /// </summary>
        /// <returns></returns>
        public virtual bool IsInteriorsConnected()
        {
            // node the edges, in case holes touch the shell
            IList splitEdges = new ArrayList();

            geomGraph.ComputeSplitEdges(splitEdges);

            // form the edges into rings
            PlanarGraph graph = new PlanarGraph(new OverlayNodeFactory());

            graph.AddEdges(splitEdges);
            SetInteriorEdgesInResult(graph);
            graph.LinkResultDirectedEdges();
            IList edgeRings = BuildEdgeRings(graph.EdgeEnds);

            /*
             * Mark all the edges for the edgeRings corresponding to the shells
             * of the input polygons.  Note only ONE ring gets marked for each shell.
             */
            VisitShellInteriors(geomGraph.Geometry, graph);

            /*
             * If there are any unvisited shell edges
             * (i.e. a ring which is not a hole and which has the interior
             * of the parent area on the RHS)
             * this means that one or more holes must have split the interior of the
             * polygon into at least two pieces.  The polygon is thus invalid.
             */
            return(!HasUnvisitedShellEdge(edgeRings));
        }
예제 #2
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="g"></param>
        /// <param name="distance"></param>
        /// <returns></returns>
        public IGeometry Buffer(IGeometry g, double distance)
        {
            PrecisionModel precisionModel = _workingPrecisionModel ?? new PrecisionModel(g.PrecisionModel);

            // factory must be the same as the one used by the input
            _geomFact = g.Factory;

            OffsetCurveBuilder curveBuilder = new OffsetCurveBuilder(precisionModel, _quadrantSegments);

            curveBuilder.EndCapStyle = _endCapStyle;
            OffsetCurveSetBuilder curveSetBuilder = new OffsetCurveSetBuilder(g, distance, curveBuilder);

            IList bufferSegStrList = curveSetBuilder.GetCurves();

            // short-circuit test
            if (bufferSegStrList.Count <= 0)
            {
                IGeometry emptyGeom = _geomFact.CreateGeometryCollection(new Geometry[0]);
                return(emptyGeom);
            }

            ComputeNodedEdges(bufferSegStrList, precisionModel);
            _graph = new PlanarGraph(new OverlayNodeFactory());
            _graph.AddEdges(_edgeList.Edges);

            IList          subgraphList = CreateSubgraphs(_graph);
            PolygonBuilder polyBuilder  = new PolygonBuilder(_geomFact);

            BuildSubgraphs(subgraphList, polyBuilder);
            IList resultPolyList = polyBuilder.Polygons;

            IGeometry resultGeom = _geomFact.BuildGeometry(resultPolyList);

            return(resultGeom);
        }
예제 #3
0
        private void ComputeOverlay(SpatialFunction opCode)
        {
            // copy points from input Geometries.
            // This ensures that any Point geometries
            // in the input are considered for inclusion in the result set
            CopyPoints(0);
            CopyPoints(1);

            // node the input Geometries
            arg[0].ComputeSelfNodes(lineIntersector, false);
            arg[1].ComputeSelfNodes(lineIntersector, false);

            // compute intersections between edges of the two input geometries
            arg[0].ComputeEdgeIntersections(arg[1], lineIntersector, true);

            IList baseSplitEdges = new ArrayList();

            arg[0].ComputeSplitEdges(baseSplitEdges);
            arg[1].ComputeSplitEdges(baseSplitEdges);
            // add the noded edges to this result graph
            InsertUniqueEdges(baseSplitEdges);

            ComputeLabelsFromDepths();
            ReplaceCollapsedEdges();

            if (!NodingValidatorDisabled)
            {
                var nv = new EdgeNodingValidator(edgeList.Edges);
                nv.checkValid();
            }

            graph.AddEdges(edgeList.Edges);
            ComputeLabelling();
            LabelIncompleteNodes();

            /*
             * The ordering of building the result Geometries is important.
             * Areas must be built before lines, which must be built before points.
             * This is so that lines which are covered by areas are not included
             * explicitly, and similarly for points.
             */
            FindResultAreaEdges(opCode);
            CancelDuplicateResultEdges();
            var polyBuilder = new PolygonBuilder(geomFact);

            polyBuilder.Add(graph);
            resultPolyList = polyBuilder.Polygons;

            var lineBuilder = new LineBuilder(this, geomFact, ptLocator);

            resultLineList = lineBuilder.Build(opCode);

            var pointBuilder = new PointBuilder(this, geomFact, ptLocator);

            resultPointList = pointBuilder.Build(opCode);

            // gather the results from all calculations into a single Geometry for the result set
            resultGeom = ComputeGeometry(resultPointList, resultLineList, resultPolyList);
        }
예제 #4
0
        public IGeometry Buffer(IGeometry g, double distance)
        {
            IPrecisionModel precisionModel = _workingPrecisionModel;

            if (precisionModel == null)
            {
                precisionModel = g.PrecisionModel;
            }

            // factory must be the same as the one used by the input
            _geomFact = g.Factory;

            OffsetCurveBuilder curveBuilder = new OffsetCurveBuilder(precisionModel, _bufParams);

            OffsetCurveSetBuilder curveSetBuilder = new OffsetCurveSetBuilder(g, distance, curveBuilder);

            var bufferSegStrList = curveSetBuilder.GetCurves();

            // short-circuit test
            if (bufferSegStrList.Count <= 0)
            {
                return(CreateEmptyResultGeometry());
            }

            //BufferDebug.runCount++;
            //String filename = "run" + BufferDebug.runCount + "_curves";
            //System.out.println("saving " + filename);
            //BufferDebug.saveEdges(bufferEdgeList, filename);
            // DEBUGGING ONLY
            //WKTWriter wktWriter = new WKTWriter();
            //Debug.println("Rings: " + wktWriter.write(convertSegStrings(bufferSegStrList.iterator())));
            //wktWriter.setMaxCoordinatesPerLine(10);
            //System.out.println(wktWriter.writeFormatted(convertSegStrings(bufferSegStrList.iterator())));

            ComputeNodedEdges(bufferSegStrList, precisionModel);
            _graph = new PlanarGraph(new OverlayNodeFactory());
            _graph.AddEdges(_edgeList.Edges);

            IEnumerable <BufferSubgraph> subgraphList = CreateSubgraphs(_graph);
            PolygonBuilder polyBuilder = new PolygonBuilder(_geomFact);

            BuildSubgraphs(subgraphList, polyBuilder);
            var resultPolyList = polyBuilder.Polygons;

            // just in case...
            if (resultPolyList.Count <= 0)
            {
                return(CreateEmptyResultGeometry());
            }

            IGeometry resultGeom = _geomFact.BuildGeometry(resultPolyList);

            return(resultGeom);
        }
예제 #5
0
        private void ComputeBuffer(double distance, int quadrantSegments)
        {
            if (_makePrecise)
            {
                double scale = GetArgGeometry(0).PrecisionModel.Scale;
                distance *= scale;
            }
            BufferEdgeBuilder bufEdgeBuilder = new BufferEdgeBuilder(_cga, _li, distance, _makePrecise, quadrantSegments);
            ArrayList         bufferEdgeList = bufEdgeBuilder.GetEdges(GetArgGeometry(0));

            // DEBUGGING ONLY
            //WKTWriter wktWriter = new WKTWriter();
            //Debug.println("Rings: " + wktWriter.write(toLineStrings(bufferEdgeList.iterator())));

            ArrayList nodedEdges = this.NodeEdges(bufferEdgeList);

            //TESTING - node again to ensure edges are noded completely

            /*
             * List nodedEdges2 = nodeEdges(nodedEdges);
             * List nodedEdges3 = nodeEdges(nodedEdges2);
             * List nodedEdges4 = nodeEdges(nodedEdges3);
             * List nodedEdges5 = nodeEdges(nodedEdges4);
             * List nodedEdges6 = nodeEdges(nodedEdges5);
             */
            //for (Iterator i = nodedEdges.iterator(); i.hasNext(); )
            foreach (object obj in nodedEdges)
            {
                Edge e = (Edge)obj;
                InsertEdge(e);
            }
            ReplaceCollapsedEdges();

            // DEBUGGING ONLY
            //Debug.println("Noded: " + wktWriter.write(toLineStrings(edgeList.iterator())));

            _graph.AddEdges(_edgeList);

            ArrayList      subgraphList = CreateSubgraphs();
            PolygonBuilder polyBuilder  = new PolygonBuilder(_geomFact, _cga);

            BuildSubgraphs(subgraphList, polyBuilder);
            ArrayList resultPolyList = polyBuilder.GetPolygons();

            _resultGeom = ComputeGeometry(resultPolyList);
            //computeBufferLine(graph);
        }
예제 #6
0
        public IGeometry Buffer(IGeometry g, double distance)
        {
            IPrecisionModel precisionModel = _workingPrecisionModel;

            if (precisionModel == null)
            {
                precisionModel = g.PrecisionModel;
            }

            // factory must be the same as the one used by the input
            _geomFact = g.Factory;

            OffsetCurveBuilder curveBuilder = new OffsetCurveBuilder(precisionModel, _bufParams);

            OffsetCurveSetBuilder curveSetBuilder = new OffsetCurveSetBuilder(g, distance, curveBuilder);

            var bufferSegStrList = curveSetBuilder.GetCurves();

            // short-circuit test
            if (bufferSegStrList.Count <= 0)
            {
                return(CreateEmptyResultGeometry());
            }

            ComputeNodedEdges(bufferSegStrList, precisionModel);
            _graph = new PlanarGraph(new OverlayNodeFactory());
            _graph.AddEdges(_edgeList.Edges);

            IEnumerable <BufferSubgraph> subgraphList = CreateSubgraphs(_graph);
            PolygonBuilder polyBuilder = new PolygonBuilder(_geomFact);

            BuildSubgraphs(subgraphList, polyBuilder);
            var resultPolyList = polyBuilder.Polygons;

            // just in case...
            if (resultPolyList.Count <= 0)
            {
                return(CreateEmptyResultGeometry());
            }

            IGeometry resultGeom = _geomFact.BuildGeometry(resultPolyList);

            return(resultGeom);
        }
예제 #7
0
		public virtual Geometry Buffer(Geometry g, double distance)
		{
			PrecisionModel precisionModel = workingPrecisionModel;
			if (precisionModel == null)
				precisionModel = g.PrecisionModel;
			
			// factory must be the same as the one used by the input
			geomFact = g.Factory;
			
			OffsetCurveBuilder curveBuilder = 
                new OffsetCurveBuilder(precisionModel, quadrantSegments);
			curveBuilder.EndCapStyle = endCapStyle;

			OffsetCurveSetBuilder curveSetBuilder = 
                new OffsetCurveSetBuilder(g, distance, curveBuilder);
			
			ArrayList bufferSegStrList = curveSetBuilder.Curves;
			
			// short-circuit test
			if (bufferSegStrList.Count <= 0)
			{
				Geometry emptyGeom = 
                    geomFact.CreateGeometryCollection(new Geometry[0]);

				return emptyGeom;
			}
			
			ComputeNodedEdges(bufferSegStrList, precisionModel);
			graph = new PlanarGraph(new OverlayNodeFactory());
			graph.AddEdges(edgeList.Edges);
			
			IList subgraphList         = CreateSubgraphs(graph);
			PolygonBuilder polyBuilder = new PolygonBuilder(geomFact);
			
            BuildSubgraphs(subgraphList, polyBuilder);

			GeometryList resultPolyList = polyBuilder.Build();
			
			Geometry resultGeom = geomFact.BuildGeometry(resultPolyList);

			return resultGeom;
		}
예제 #8
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="g"></param>
        /// <param name="distance"></param>
        /// <returns></returns>
        public IGeometry Buffer(IGeometry g, double distance)
        {
            var precisionModel = workingPrecisionModel ?? g.PrecisionModel;

            // factory must be the same as the one used by the input
            geomFact = g.Factory;

            var curveBuilder = new OffsetCurveBuilder(precisionModel, quadrantSegments)
            {
                EndCapStyle = endCapStyle
            };
            var curveSetBuilder = new OffsetCurveSetBuilder(g, distance, curveBuilder);

            var bufferSegStrList = curveSetBuilder.GetCurves();

            // short-circuit test
            if (bufferSegStrList.Count <= 0)
            {
                IGeometry emptyGeom = geomFact.CreateGeometryCollection(new IGeometry[0]);
                return(emptyGeom);
            }

            ComputeNodedEdges(bufferSegStrList, precisionModel);
            graph = new PlanarGraph(new OverlayNodeFactory());
            graph.AddEdges(edgeList.Edges);

            var subgraphList = CreateSubgraphs(graph);
            var polyBuilder  = new PolygonBuilder(geomFact);

            BuildSubgraphs(subgraphList, polyBuilder);
            var resultPolyList = polyBuilder.Polygons;

            var resultGeom = geomFact.BuildGeometry(resultPolyList);

            return(resultGeom);
        }
예제 #9
0
        public void Generate(int pointCount)
        {
            //Generate random points
            HashSet <Coordinate> hashSet = new HashSet <Coordinate>();
            {
                Random rand = new Random(seed);
                while (hashSet.Count < pointCount)
                {
                    double x = rand.NextDouble() * 2 - 1;
                    double y = rand.NextDouble() * 2 - 1;
                    if (x < -0.99 || y < -0.99 || x > 0.99 || y > 0.99)
                    {
                        continue;
                    }
                    hashSet.Add(new Coordinate(x, y));
                }
            }
            //Optimize points
            {
                Coordinate[] points = hashSet.ToArray();
                for (int i = 0; i < 2; i++)
                {
                    VoronoiDiagramBuilder builder = new VoronoiDiagramBuilder();
                    builder.SetSites(points);
                    VoronoiDiagram = builder.GetDiagram(new GeometryFactory());
                    for (int j = 0; j < points.Length; j++)
                    {
                        Polygon poly = VoronoiDiagram[j] as Polygon;
                        points[j] = new Coordinate(poly.Centroid.X, poly.Centroid.Y);
                    }
                }
            }
            //Build graph
            PlanarGraph graph;
            {
                VoronoiDiagram = ClipGeometryCollection(VoronoiDiagram, new Envelope(-1, 1, -1, 1));
                graph          = new PlanarGraph(new OverlayNodeFactory());
                List <Edge> edges = new List <Edge>();
                for (int i = 0; i < VoronoiDiagram.Count; i++)
                {
                    Polygon      poly   = VoronoiDiagram[i] as Polygon;
                    Coordinate[] coords = poly.Coordinates;
                    for (int j = 1; j < coords.Length; j++)
                    {
                        edges.Add(new Edge(new[] { coords[j - 1], coords[j] }, new Label(Location.Boundary)));
                    }
                }
                graph.AddEdges(edges);
            }
            //Convert graph
            Dictionary <Node, MapNode> nodeDict;

            {
                Dictionary <MapPolygon, HashSet <MapPolygon> > polys = new Dictionary <MapPolygon, HashSet <MapPolygon> >();
                nodeDict = new Dictionary <Node, MapNode>();
                Dictionary <MapNode, Tuple <HashSet <MapPolygon>, HashSet <MapEdge> > > dats =
                    new Dictionary <MapNode, Tuple <HashSet <MapPolygon>, HashSet <MapEdge> > >();
                for (int i = 0; i < VoronoiDiagram.Count; i++)
                {
                    List <MapNode> nodes = new List <MapNode>();
                    MapPolygon     poly  = new MapPolygon
                    {
                        CentroidX = VoronoiDiagram[i].Centroid.X,
                        CentroidY = VoronoiDiagram[i].Centroid.Y,
                        Polygon   = VoronoiDiagram[i] as Polygon
                    };
                    foreach (Coordinate j in VoronoiDiagram[i].Coordinates.Skip(1))
                    {
                        Node    n = graph.Find(j);
                        MapNode mapNode;
                        if (!nodeDict.TryGetValue(n, out mapNode))
                        {
                            mapNode = new MapNode {
                                X = j.X, Y = j.Y
                            };
                            dats[mapNode] =
                                new Tuple <HashSet <MapPolygon>, HashSet <MapEdge> >(new HashSet <MapPolygon> {
                                poly
                            },
                                                                                     new HashSet <MapEdge>());
                        }
                        else
                        {
                            dats[mapNode].Item1.Add(poly);
                        }
                        nodes.Add(nodeDict[n] = mapNode);
                    }
                    poly.Nodes = nodes.ToArray();
                    polys.Add(poly, new HashSet <MapPolygon>());
                }
                foreach (KeyValuePair <Node, MapNode> i in nodeDict)
                {
                    foreach (MapPolygon j in dats[i.Value].Item1)
                    {
                        foreach (MapPolygon k in dats[i.Value].Item1)
                        {
                            if (j != k)
                            {
                                polys[j].Add(k);
                                polys[k].Add(j);
                            }
                        }
                    }
                    foreach (EdgeEnd j in i.Key.Edges)
                    {
                        MapNode from = nodeDict[graph.Find(j.Coordinate)];
                        MapNode to   = nodeDict[graph.Find(j.DirectedCoordinate)];
                        dats[from].Item2.Add(new MapEdge {
                            From = from, To = to
                        });
                    }
                }
                int ftrh = dats.Count(_ => _.Value.Item2.Count == 0);
                foreach (KeyValuePair <MapNode, Tuple <HashSet <MapPolygon>, HashSet <MapEdge> > > i in dats)
                {
                    i.Key.Edges = i.Value.Item2.ToArray();
                }
                KeyValuePair <MapPolygon, HashSet <MapPolygon> >[] x = polys.ToArray();
                for (int i = 0; i < x.Length; i++)
                {
                    x[i].Key.Neighbour = x[i].Value.ToArray();
                    x[i].Key.Id        = i;
                }
                Polygons = x.Select(_ => _.Key).ToArray();
            }
            //Generate map
            DetermineLandmass();
            FindOceans();
            ComputeDistances();
            RedistributeElevation(nodeDict.Values);
            FindLakesAndCoasts();
        }
예제 #10
0
        private void ComputeOverlay(SpatialFunction opCode)
        {
            // copy points from input Geometries.
            // This ensures that any Point geometries
            // in the input are considered for inclusion in the result set
            CopyPoints(0);
            CopyPoints(1);

            // node the input Geometries
            arg[0].ComputeSelfNodes(lineIntersector, false);
            arg[1].ComputeSelfNodes(lineIntersector, false);

            // compute intersections between edges of the two input geometries
            arg[0].ComputeEdgeIntersections(arg[1], lineIntersector, true);

            IList <Edge> baseSplitEdges = new List <Edge>();

            arg[0].ComputeSplitEdges(baseSplitEdges);
            arg[1].ComputeSplitEdges(baseSplitEdges);
            // add the noded edges to this result graph
            InsertUniqueEdges(baseSplitEdges);

            ComputeLabelsFromDepths();
            ReplaceCollapsedEdges();

            if (!NodingValidatorDisabled)
            {
                /*
                 * Check that the noding completed correctly.
                 *
                 * This test is slow, but necessary in order to catch robustness failure
                 * situations.
                 * If an exception is thrown because of a noding failure,
                 * then snapping will be performed, which will hopefully avoid the problem.
                 * In the future hopefully a faster check can be developed.
                 *
                 */
                var nv = new EdgeNodingValidator(_edgeList.Edges);
                nv.CheckValid();
            }

            _graph.AddEdges(_edgeList.Edges);
            ComputeLabelling();
            LabelIncompleteNodes();

            /*
             * The ordering of building the result Geometries is important.
             * Areas must be built before lines, which must be built before points.
             * This is so that lines which are covered by areas are not included
             * explicitly, and similarly for points.
             */
            FindResultAreaEdges(opCode);
            CancelDuplicateResultEdges();
            var polyBuilder = new PolygonBuilder(_geomFact);

            polyBuilder.Add(_graph);
            _resultPolyList = polyBuilder.Polygons;

            var lineBuilder = new LineBuilder(this, _geomFact, _ptLocator);

            _resultLineList = lineBuilder.Build(opCode);

            var pointBuilder = new PointBuilder(this, _geomFact);//, _ptLocator);

            _resultPointList = pointBuilder.Build(opCode);

            // gather the results from all calculations into a single Geometry for the result set
            _resultGeom = ComputeGeometry(_resultPointList, _resultLineList, _resultPolyList, opCode);
        }
예제 #11
0
        }         // public Geometry GetResultGeometry( int funcCode )

        private void ComputeOverlay(int opCode)
        {
            // copy points from input Geometries.
            // This ensures that any Point geometries
            // in the input are considered for inclusion in the result set
            CopyPoints(0);
            CopyPoints(1);

            // node the input Geometries
            _arg[0].ComputeSelfNodes(_li);
            _arg[1].ComputeSelfNodes(_li);

            // compute intersections between edges of the two input geometries
            _arg[0].ComputeEdgeIntersections(_arg[1], _li, true);

            ArrayList baseSplitEdges = new ArrayList();

            _arg[0].ComputeSplitEdges(baseSplitEdges);
            _arg[1].ComputeSplitEdges(baseSplitEdges);
            ArrayList splitEdges = new ArrayList(baseSplitEdges);


            /* NO LONGER USED
             * // if we are working in fixed precision, we must renode to ensure noding is complete
             * if (makePrecise) {
             * List splitEdges1 = completeEdgeNoding(baseSplitEdges);
             * splitEdges = completeEdgeNoding(splitEdges1);
             * } */

            // add the noded edges to this result graph
            InsertUniqueEdges(baseSplitEdges);

            ComputeLabelsFromDepths();
            ReplaceCollapsedEdges();

            //Trace.WriteLine( edgeList.ToString());

            _graph.AddEdges(_edgeList);
            ComputeLabelling();
            LabelIncompleteNodes();

            // The ordering of building the result Geometries is important.
            // Areas must be built before lines, which must be built before points.
            // This is so that lines which are covered by areas are not included
            // explicitly, and similarly for points.

            FindResultAreaEdges(opCode);
            CancelDuplicateResultEdges();
            PolygonBuilder polyBuilder = new PolygonBuilder(_geomFact, _cga);

            polyBuilder.Add(_graph);
            _resultPolyList = polyBuilder.GetPolygons();

            LineBuilder lineBuilder = new LineBuilder(this, _geomFact, _ptLocator);

            _resultLineList = lineBuilder.Build(opCode);

            PointBuilder pointBuilder = new PointBuilder(this, _geomFact, _ptLocator);

            _resultPointList = pointBuilder.Build(opCode);

            // gather the results from all calculations into a single Geometry for the result set
            _resultGeom = ComputeGeometry(_resultPointList, _resultLineList, _resultPolyList);
        }         //private void ComputeOverlay( int opCode )