Skip to content

Commit

Permalink
Fixed handling of XYZM coordinates
Browse files Browse the repository at this point in the history
Signed-off-by: Kai Winter <[email protected]>
  • Loading branch information
kaiwinter committed Sep 14, 2022
1 parent 268b436 commit 15f155a
Show file tree
Hide file tree
Showing 3 changed files with 47 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -514,9 +514,14 @@ private void writeCoordinate(CoordinateSequence seq, int index, OutStream os)
// only write 3rd dim if caller has requested it for this writer
if (outputDimension >= 3) {
// if 3rd dim is requested, only write it if the CoordinateSequence provides it
double ordVal = Coordinate.NULL_ORDINATE;
if (seq.getDimension() >= 3)
ordVal = seq.getOrdinate(index, 2);
double ordVal = seq.getOrdinate(index, 2);
ByteOrderValues.putDouble(ordVal, buf, byteOrder);
os.write(buf, 8);
}
// only write 4th dim if caller has requested it for this writer
if (outputDimension == 4) {
// if 4th dim is requested, only write it if the CoordinateSequence provides it
double ordVal = seq.getOrdinate(index, 3);
ByteOrderValues.putDouble(ordVal, buf, byteOrder);
os.write(buf, 8);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,10 @@
package org.locationtech.jts.io;

import org.locationtech.jts.geom.Coordinate;
import org.locationtech.jts.geom.CoordinateXYZM;
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 junit.textui.TestRunner;
Expand Down Expand Up @@ -125,6 +127,25 @@ public void testGeometryCollection() {
4326,
"0107000020E61000000900000001010000000000000000000000000000000000F03F01010000000000000000000000000000000000F03F01010000000000000000000040000000000000084001020000000200000000000000000000400000000000000840000000000000104000000000000014400102000000020000000000000000000000000000000000F03F000000000000004000000000000008400102000000020000000000000000001040000000000000144000000000000018400000000000001C4001030000000200000005000000000000000000000000000000000000000000000000000000000000000000244000000000000024400000000000002440000000000000244000000000000000000000000000000000000000000000000005000000000000000000F03F000000000000F03F000000000000F03F0000000000002240000000000000224000000000000022400000000000002240000000000000F03F000000000000F03F000000000000F03F01030000000200000005000000000000000000000000000000000000000000000000000000000000000000244000000000000024400000000000002440000000000000244000000000000000000000000000000000000000000000000005000000000000000000F03F000000000000F03F000000000000F03F0000000000002240000000000000224000000000000022400000000000002240000000000000F03F000000000000F03F000000000000F03F0103000000010000000500000000000000000022C0000000000000000000000000000022C00000000000002440000000000000F0BF0000000000002440000000000000F0BF000000000000000000000000000022C00000000000000000");
}

public void testWkbLineStringZM() throws ParseException {
LineString lineZM = new GeometryFactory().createLineString(new Coordinate[]{new CoordinateXYZM(1,2,3,4), new CoordinateXYZM(5,6,7,8)});
byte[] write = new WKBWriter(4).write(lineZM);

LineString deserialisiert = (LineString) new WKBReader().read(write);

assertEquals(lineZM, deserialisiert);

assertEquals(1.0, lineZM.getPointN(0).getCoordinate().getX());
assertEquals(2.0, lineZM.getPointN(0).getCoordinate().getY());
assertEquals(3.0, lineZM.getPointN(0).getCoordinate().getZ());
assertEquals(4.0, lineZM.getPointN(0).getCoordinate().getM());

assertEquals(5.0, lineZM.getPointN(1).getCoordinate().getX());
assertEquals(6.0, lineZM.getPointN(1).getCoordinate().getY());
assertEquals(7.0, lineZM.getPointN(1).getCoordinate().getZ());
assertEquals(8.0, lineZM.getPointN(1).getCoordinate().getM());
}

void checkWKB(String wkt, int dimension, String expectedWKBHex) {
checkWKB(wkt, dimension, ByteOrderValues.LITTLE_ENDIAN, -1, expectedWKBHex);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -181,4 +181,22 @@ public void testWrite3D_withNaN() {
assertEquals("LINESTRING (1 1, 2 2)", wkt);
}

public void testWktLineStringZM() throws ParseException {
LineString lineZM = new GeometryFactory().createLineString(new Coordinate[]{new CoordinateXYZM(1,2,3,4), new CoordinateXYZM(5,6,7,8)});
String write = new WKTWriter(4).write(lineZM);

LineString deserialisiert = (LineString) new WKTReader().read(write);

assertEquals(lineZM, deserialisiert);

assertEquals(1.0, lineZM.getPointN(0).getCoordinate().getX());
assertEquals(2.0, lineZM.getPointN(0).getCoordinate().getY());
assertEquals(3.0, lineZM.getPointN(0).getCoordinate().getZ());
assertEquals(4.0, lineZM.getPointN(0).getCoordinate().getM());

assertEquals(5.0, lineZM.getPointN(1).getCoordinate().getX());
assertEquals(6.0, lineZM.getPointN(1).getCoordinate().getY());
assertEquals(7.0, lineZM.getPointN(1).getCoordinate().getZ());
assertEquals(8.0, lineZM.getPointN(1).getCoordinate().getM());
}
}

0 comments on commit 15f155a

Please sign in to comment.