예제 #1
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);
        }
예제 #2
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);

            var 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);
        }
예제 #3
0
 /// <summary>
 /// Completes the building of the input subgraphs by depth-labelling them,
 /// and adds them to the PolygonBuilder.
 /// </summary>
 /// <remarks>
 /// The subgraph list must be sorted in rightmost-coordinate order.
 /// </remarks>
 /// <param name="subgraphList"> the subgraphs to build</param>
 /// <param name="polyBuilder"> the PolygonBuilder which will build the final polygons</param>
 private static void BuildSubgraphs(IEnumerable<BufferSubgraph> subgraphList, PolygonBuilder polyBuilder)
 {
     var processedGraphs = new List<BufferSubgraph>();
     foreach (var subgraph in subgraphList)
     {
         Coordinate p = subgraph.RightMostCoordinate;
         //      int outsideDepth = 0;
         //      if (polyBuilder.containsPoint(p))
         //        outsideDepth = 1;
         var locater = new SubgraphDepthLocater(processedGraphs);
         int outsideDepth = locater.GetDepth(p);
         //      try {
         subgraph.ComputeDepth(outsideDepth);
         //      }
         //      catch (RuntimeException ex) {
         //        // debugging only
         //        //subgraph.saveDirEdges();
         //        throw ex;
         //      }
         subgraph.FindResultEdges();
         processedGraphs.Add(subgraph);
         polyBuilder.Add(new List<EdgeEnd>(
             Utilities.Caster.Upcast<DirectedEdge, EdgeEnd>(subgraph.DirectedEdges)), subgraph.Nodes);
     }
 }
예제 #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();
            }

            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
        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;
        }