Skip to content

Commit

Permalink
Fix TestBuilder Coverage.validate result to be GC
Browse files Browse the repository at this point in the history
  • Loading branch information
dr-jts committed Jul 4, 2023
1 parent dcb4edf commit 69ba32b
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<Geometry> geomList = new ArrayList<Geometry>();
for (Geometry geom : geoms) {
Expand All @@ -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); }
Expand Down

0 comments on commit 69ba32b

Please sign in to comment.