Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -250,6 +250,10 @@ private void writePolyline(int geometryType, SinglePolylineGeography polyline, O
writeByteOrder(os);
writeGeometryType(geometryType, polyline, os);
List<S2Polyline> s2line = polyline.getPolylines();
if (s2line.isEmpty()) {
writeInt(0, os);
return;
}
for (S2Polyline s2 : s2line) {
List<S2Point> verts = s2.vertices();
writeInt(verts.size(), os);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
import org.locationtech.jts.geom.Coordinate;
import org.locationtech.jts.geom.Geometry;
import org.locationtech.jts.geom.GeometryFactory;
import org.locationtech.jts.geom.LineString;
import org.locationtech.jts.geom.Point;
import org.locationtech.jts.io.ByteOrderValues;
import org.locationtech.jts.io.ParseException;
Expand Down Expand Up @@ -137,6 +138,19 @@ public void fromS2Geography_point() {
assertSame(s2Geog, roundTrip);
}

@Test
public void fromS2Geography_emptyLineString_roundTripsToJTS() {
Geography s2Geog = new SinglePolylineGeography();
s2Geog.setSRID(4326);

WKBGeography geog = WKBGeography.fromS2Geography(s2Geog);
Geometry jts = geog.getJTSGeometry();

assertTrue(jts instanceof LineString);
assertTrue(jts.isEmpty());
assertEquals(4326, jts.getSRID());
}

// ─── Lazy S2 delegation ──────────────────────────────────────────────────

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,18 @@ public void PolylineGeographyToHexTest() throws IOException, ParseException {
}
}

@Test
public void EmptySinglePolylineWritesValidWKB() throws IOException, ParseException {
Geography inputLine = new SinglePolylineGeography();

byte[] wkb = new WKBWriter(2, ByteOrderValues.LITTLE_ENDIAN, false).write(inputLine);

assertEquals("010200000000000000", WKBWriter.toHex(wkb));
Geography outputLine = new WKBReader().read(wkb);
assertTrue(outputLine instanceof SinglePolylineGeography);
assertEquals(0, outputLine.numShapes());
}

@Test
public void MultiPointTest() throws ParseException, IOException {
String wkt = "MULTIPOINT ((10 40), (40 30))";
Expand Down