diff --git a/modules/app/src/main/java/org/locationtech/jtstest/function/CoverageFunctions.java b/modules/app/src/main/java/org/locationtech/jtstest/function/CoverageFunctions.java index 7dcc957ef3..74f52f6a1b 100644 --- a/modules/app/src/main/java/org/locationtech/jtstest/function/CoverageFunctions.java +++ b/modules/app/src/main/java/org/locationtech/jtstest/function/CoverageFunctions.java @@ -34,16 +34,16 @@ public static Geometry validatePolygonWithGaps(Geometry geom, Geometry adjacentP return CoveragePolygonValidator.validate(geom, toGeometryArray(adjacentPolys), gapWidth); } - public static Geometry validateCoverage(Geometry geom) { + public static Geometry validate(Geometry geom) { Geometry[] invalid = CoverageValidator.validate(toGeometryArray(geom)); - return FunctionsUtil.buildGeometry(invalid); + return FunctionsUtil.buildGeometryCollection(invalid, geom.getFactory().createLineString()); } - public static Geometry validateCoverageWithGaps(Geometry geom, + public static Geometry validateWithGaps(Geometry geom, @Metadata(title="Gap width") double gapWidth) { Geometry[] invalid = CoverageValidator.validate(toGeometryArray(geom), gapWidth); - return FunctionsUtil.buildGeometry(invalid); + return FunctionsUtil.buildGeometryCollection(invalid, geom.getFactory().createLineString()); } public static Geometry findGaps(Geometry geom, @@ -53,7 +53,7 @@ public static Geometry findGaps(Geometry geom, } @Metadata(description="Fast Union of a coverage") - public static Geometry unionCoverage(Geometry coverage) { + public static Geometry union(Geometry coverage) { Geometry[] cov = toGeometryArray(coverage); return CoverageUnion.union(cov); } diff --git a/modules/app/src/main/java/org/locationtech/jtstest/function/FunctionsUtil.java b/modules/app/src/main/java/org/locationtech/jtstest/function/FunctionsUtil.java index f4ee726b45..3c331308e7 100644 --- a/modules/app/src/main/java/org/locationtech/jtstest/function/FunctionsUtil.java +++ b/modules/app/src/main/java/org/locationtech/jtstest/function/FunctionsUtil.java @@ -79,10 +79,7 @@ public static Geometry buildGeometry(List geoms, Geometry parentGeom) public static Geometry buildGeometry(Geometry[] geoms) { - GeometryFactory gf = JTSTestBuilder.getGeometryFactory(); - if (geoms.length > 0) { - gf = getFactoryOrDefault(geoms[0]); - } + GeometryFactory gf = getFactory(geoms); List geomList = new ArrayList(); for (Geometry geom : geoms) { @@ -95,6 +92,28 @@ public static Geometry buildGeometry(Geometry[] geoms) return gf.buildGeometry(geomList); } + public static Geometry buildGeometryCollection(Geometry[] geoms, Geometry nullGeom) + { + GeometryFactory gf = getFactory(geoms); + + Geometry[] geomArray = new Geometry[geoms.length]; + for (int i = 0; i < geoms.length; i++) { + Geometry srcGeom = geoms[i] == null ? nullGeom : geoms[i]; + if (srcGeom != null) { + geomArray[i] = srcGeom.copy(); + } + } + return gf.createGeometryCollection(geomArray); + } + + private static GeometryFactory getFactory(Geometry[] geoms) { + GeometryFactory gf = JTSTestBuilder.getGeometryFactory(); + if (geoms.length > 0) { + gf = getFactoryOrDefault(geoms[0]); + } + return gf; + } + public static Geometry buildGeometry(Geometry a, Geometry b) { Geometry[] geoms = toGeometryArray(a, b); return getFactoryOrDefault(a, b).createGeometryCollection(geoms); }