|
16 | 16 |
|
17 | 17 | import org.locationtech.jts.algorithm.construct.MaximumInscribedCircle; |
18 | 18 | import org.locationtech.jts.geom.Coordinate; |
| 19 | +import org.locationtech.jts.geom.CoordinateArrays; |
19 | 20 | import org.locationtech.jts.geom.Geometry; |
20 | 21 | import org.locationtech.jts.geom.LineString; |
21 | 22 | import org.locationtech.jts.geom.LinearRing; |
@@ -45,7 +46,7 @@ public class CoverageGapFinder { |
45 | 46 | * |
46 | 47 | * @param coverage a set of polygons forming a polygonal coverage |
47 | 48 | * @param gapWidth the maximum width of gap to detect |
48 | | - * @return a geometry indicating the locations of gaps (which is empty if no gaps were found), or null if the coverage was empty |
| 49 | + * @return a MultiPolygon indicating the locations of gaps (empty if no gaps were found), or null if the coverage was empty |
49 | 50 | */ |
50 | 51 | public static Geometry findGaps(Geometry[] coverage, double gapWidth) { |
51 | 52 | CoverageGapFinder finder = new CoverageGapFinder(coverage); |
@@ -74,21 +75,21 @@ public Geometry findGaps(double gapWidth) { |
74 | 75 | Geometry union = CoverageUnion.union(coverage); |
75 | 76 | List<Polygon> polygons = PolygonExtracter.getPolygons(union); |
76 | 77 |
|
77 | | - List<LineString> gapLines = new ArrayList<LineString>(); |
| 78 | + List<Polygon> gapLines = new ArrayList<Polygon>(); |
78 | 79 | for (Polygon poly : polygons) { |
79 | 80 | for (int i = 0; i < poly.getNumInteriorRing(); i++) { |
80 | 81 | LinearRing hole = poly.getInteriorRingN(i); |
81 | 82 | if (isGap(hole, gapWidth)) { |
82 | | - gapLines.add(copyLine(hole)); |
| 83 | + gapLines.add(toPolygon(hole)); |
83 | 84 | } |
84 | 85 | } |
85 | 86 | } |
86 | 87 | return union.getFactory().buildGeometry(gapLines); |
87 | 88 | } |
88 | 89 |
|
89 | | - private LineString copyLine(LinearRing hole) { |
90 | | - Coordinate[] pts = hole.getCoordinates(); |
91 | | - return hole.getFactory().createLineString(pts); |
| 90 | + private Polygon toPolygon(LinearRing hole) { |
| 91 | + Coordinate[] pts = CoordinateArrays.copyDeep(hole.getCoordinates()); |
| 92 | + return hole.getFactory().createPolygon(pts); |
92 | 93 | } |
93 | 94 |
|
94 | 95 | private boolean isGap(LinearRing hole, double maxGapWidth) { |
|
0 commit comments