Skip to content

Commit 6dfe7b3

Browse files
committed
Change CoverageGapFinder to return polygons for gaps
1 parent 6def33a commit 6dfe7b3

File tree

1 file changed

+7
-6
lines changed

1 file changed

+7
-6
lines changed

modules/core/src/main/java/org/locationtech/jts/coverage/CoverageGapFinder.java

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616

1717
import org.locationtech.jts.algorithm.construct.MaximumInscribedCircle;
1818
import org.locationtech.jts.geom.Coordinate;
19+
import org.locationtech.jts.geom.CoordinateArrays;
1920
import org.locationtech.jts.geom.Geometry;
2021
import org.locationtech.jts.geom.LineString;
2122
import org.locationtech.jts.geom.LinearRing;
@@ -45,7 +46,7 @@ public class CoverageGapFinder {
4546
*
4647
* @param coverage a set of polygons forming a polygonal coverage
4748
* @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
4950
*/
5051
public static Geometry findGaps(Geometry[] coverage, double gapWidth) {
5152
CoverageGapFinder finder = new CoverageGapFinder(coverage);
@@ -74,21 +75,21 @@ public Geometry findGaps(double gapWidth) {
7475
Geometry union = CoverageUnion.union(coverage);
7576
List<Polygon> polygons = PolygonExtracter.getPolygons(union);
7677

77-
List<LineString> gapLines = new ArrayList<LineString>();
78+
List<Polygon> gapLines = new ArrayList<Polygon>();
7879
for (Polygon poly : polygons) {
7980
for (int i = 0; i < poly.getNumInteriorRing(); i++) {
8081
LinearRing hole = poly.getInteriorRingN(i);
8182
if (isGap(hole, gapWidth)) {
82-
gapLines.add(copyLine(hole));
83+
gapLines.add(toPolygon(hole));
8384
}
8485
}
8586
}
8687
return union.getFactory().buildGeometry(gapLines);
8788
}
8889

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);
9293
}
9394

9495
private boolean isGap(LinearRing hole, double maxGapWidth) {

0 commit comments

Comments
 (0)