Class MaximalEdgeRing

 1  
 2  
 3 /*
 4  * Copyright (c) 2016 Vivid Solutions.
 5  *
 6  * All rights reserved. This program and the accompanying materials
 7  * are made available under the terms of the Eclipse Public License 2.0
 8  * and Eclipse Distribution License v. 1.0 which accompanies this distribution.
 9  * The Eclipse Public License is available at http://www.eclipse.org/legal/epl-v20.html
10  * and the Eclipse Distribution License is available at
11  *
12  * http://www.eclipse.org/org/documents/edl-v10.php.
13  */
14 package org.locationtech.jts.operation.overlay;
15  
16 import java.util.ArrayList;
17 import java.util.List;
18  
19 import org.locationtech.jts.geom.GeometryFactory;
20 import org.locationtech.jts.geomgraph.DirectedEdge;
21 import org.locationtech.jts.geomgraph.DirectedEdgeStar;
22 import org.locationtech.jts.geomgraph.EdgeRing;
23 import org.locationtech.jts.geomgraph.Node;
24  
25 /**
26  * A ring of {@link DirectedEdge}s which may contain nodes of degree > 2.
27  * A <tt>MaximalEdgeRing</tt> may represent two different spatial entities:
28  * <ul>
29  * <li>a single polygon possibly containing inversions (if the ring is oriented CW)
30  * <li>a single hole possibly containing exversions (if the ring is oriented CCW)
31  * </ul>
32  * If the MaximalEdgeRing represents a polygon,
33  * the interior of the polygon is strongly connected.
34  * <p>
35  * These are the form of rings used to define polygons under some spatial data models.
36  * However, under the OGC SFS model, {@link MinimalEdgeRing}s are required.
37  * A MaximalEdgeRing can be converted to a list of MinimalEdgeRings using the
38  * {@link #buildMinimalRings() } method.
39  *
40  * @version 1.7
41  * @see org.locationtech.jts.operation.overlay.MinimalEdgeRing
42  */
43 public class MaximalEdgeRing
44   extends EdgeRing
45 {
46  
47   public MaximalEdgeRing(DirectedEdge start, GeometryFactory geometryFactory) {
48     super(start, geometryFactory);
49   }
50  
51   public DirectedEdge getNext(DirectedEdge de)
52   {
53     return de.getNext();
54   }
55   public void setEdgeRing(DirectedEdge de, EdgeRing er)
56   {
57     de.setEdgeRing(er);
58   }
59  
60   /**
61    * For all nodes in this EdgeRing,
62    * link the DirectedEdges at the node to form minimalEdgeRings
63    */
64   public void linkDirectedEdgesForMinimalEdgeRings()
65   {
66     DirectedEdge de = startDe;
67     do {
68       Node node = de.getNode();
69       ((DirectedEdgeStar) node.getEdges()).linkMinimalDirectedEdges(this);
70       de = de.getNext();
71     } while (de != startDe);
72   }
73  
74   public List buildMinimalRings()
75   {
76     List minEdgeRings = new ArrayList();
77     DirectedEdge de = startDe;
78     do {
79       if (de.getMinEdgeRing() == null) {
80         EdgeRing minEr = new MinimalEdgeRing(de, geometryFactory);
81         minEdgeRings.add(minEr);
82       }
83       de = de.getNext();
84     } while (de != startDe);
85     return minEdgeRings;
86   }
87  
88 }
89