Skip to content

Commit

Permalink
Unit test for locationtech#733
Browse files Browse the repository at this point in the history
M coordinate is read as Z coordinate after writing/reading.
  • Loading branch information
kaiwinter committed Aug 23, 2024
1 parent e98dcac commit 783a059
Showing 1 changed file with 26 additions and 0 deletions.
26 changes: 26 additions & 0 deletions modules/core/src/test/java/org/locationtech/jts/io/WKBTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
package org.locationtech.jts.io;

import java.io.IOException;
import java.util.Arrays;

import org.locationtech.jts.geom.Coordinate;
import org.locationtech.jts.geom.CoordinateFilter;
Expand Down Expand Up @@ -151,6 +152,31 @@ public void testGeometryCollectionEmpty()
{
runWKBTest("GEOMETRYCOLLECTION EMPTY");
}

public void testWriteAndRead() throws ParseException {
String wkt = "MULTILINESTRING M((1 1 1, 2 2 2))";
WKTReader wktReader = new WKTReader();
Geometry geometryBefore = wktReader.read(wkt);

WKBWriter wkbWriter = new WKBWriter(3);
byte[] write = wkbWriter.write(geometryBefore);

WKBReader wkbReader = new WKBReader();
Geometry geometryAfter = wkbReader.read(write);

System.out.println(Arrays.asList(geometryBefore.getCoordinates()));
System.out.println(Arrays.asList(geometryAfter.getCoordinates()));

assertEquals(geometryBefore.getCoordinates()[0].getX(), geometryAfter.getCoordinates()[0].getX());
assertEquals(geometryBefore.getCoordinates()[0].getY(), geometryAfter.getCoordinates()[0].getY());
assertEquals(geometryBefore.getCoordinates()[0].getZ(), geometryAfter.getCoordinates()[0].getZ());
assertEquals(geometryBefore.getCoordinates()[0].getM(), geometryAfter.getCoordinates()[0].getM());

assertEquals(geometryBefore.getCoordinates()[1].getX(), geometryAfter.getCoordinates()[1].getX());
assertEquals(geometryBefore.getCoordinates()[1].getY(), geometryAfter.getCoordinates()[1].getY());
assertEquals(geometryBefore.getCoordinates()[1].getZ(), geometryAfter.getCoordinates()[1].getZ());
assertEquals(geometryBefore.getCoordinates()[1].getM(), geometryAfter.getCoordinates()[1].getM());
}

private void runWKBTest(String wkt) throws IOException, ParseException
{
Expand Down

0 comments on commit 783a059

Please sign in to comment.