Skip to content
Original file line number Diff line number Diff line change
Expand Up @@ -1362,6 +1362,10 @@ public static Geometry intersection(Geometry leftGeometry, Geometry rightGeometr
return leftGeometry.intersection(rightGeometry);
}

public static Geometry sharedPaths(Geometry leftGeometry, Geometry rightGeometry) {
return SharedPaths.compute(leftGeometry, rightGeometry);
}

public static Geometry makeValid(Geometry geometry, boolean keepCollapsed) {
GeometryFixer fixer = new GeometryFixer(geometry);
fixer.setKeepCollapsed(keepCollapsed);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -175,14 +175,23 @@ public static String getEWKT(Geometry geometry) {
if (srid != 0) {
sridString = "SRID=" + String.valueOf(srid) + ";";
}
return sridString + new WKTWriter(4).write(geometry);
return sridString + writeWKT(geometry);
}

public static String getWKT(Geometry geometry) {
if (geometry == null) {
return null;
}
return new WKTWriter(4).write(geometry);
return writeWKT(geometry);
}

private static String writeWKT(Geometry geometry) {
// JTS 1.20 omits the separator between a dimensional marker and EMPTY for nested empty
// geometries (for example, "MULTILINESTRING ZEMPTY"), which its own WKTReader rejects.
String wkt = new WKTWriter(4).write(geometry);
return wkt.replace("ZMEMPTY", "ZM EMPTY")
.replace("ZEMPTY", "Z EMPTY")
.replace("MEMPTY", "M EMPTY");
}

public static String getHexEWKB(Geometry geometry, int endian) {
Expand Down
764 changes: 764 additions & 0 deletions common/src/main/java/org/apache/sedona/common/utils/SharedPaths.java

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,10 @@
import java.util.List;
import java.util.Objects;
import org.apache.sedona.common.utils.GeomUtils;
import org.junit.Assert;
import org.junit.Test;
import org.locationtech.jts.geom.*;
import org.locationtech.jts.io.WKTReader;

public class GeometryUtilTest {
public static final GeometryFactory GEOMETRY_FACTORY = new GeometryFactory();
Expand Down Expand Up @@ -54,4 +56,23 @@ public void extractGeometryCollection() {
GEOMETRY_FACTORY.createGeometryCollection(geoms.toArray(new Geometry[geoms.size()]))),
"GEOMETRYCOLLECTION (POLYGON ((0 1, 3 0, 4 3, 0 4, 0 1)), POLYGON ((3 4, 6 3, 5 5, 3 4)), POINT (5 8), POLYGON ((0 1, 3 0, 4 3, 0 4, 0 1)), POLYGON ((3 4, 6 3, 5 5, 3 4)))"));
}

@Test
public void dimensionalNestedEmptyWKTRoundTrips() throws Exception {
WKTReader reader = new WKTReader();
for (String wkt :
new String[] {
"GEOMETRYCOLLECTION Z (LINESTRING Z (0 0 1, 1 1 2), MULTILINESTRING Z EMPTY)",
"GEOMETRYCOLLECTION M (LINESTRING M (0 0 1, 1 1 2), MULTILINESTRING M EMPTY)",
"GEOMETRYCOLLECTION ZM (LINESTRING ZM (0 0 1 2, 1 1 3 4), " + "MULTILINESTRING ZM EMPTY)"
}) {
Geometry geometry = reader.read(wkt);
String serialized = GeomUtils.getWKT(geometry);

Assert.assertFalse(serialized.contains("ZEMPTY"));
Assert.assertFalse(serialized.contains("MEMPTY"));
Assert.assertFalse(serialized.contains("ZMEMPTY"));
Assert.assertTrue(geometry.equalsExact(reader.read(serialized)));
}
}
}
Loading
Loading