Skip to content

Commit 9d75547

Browse files
GisMarschdsmiley
authored andcommitted
Update JTS to 18.1 (#205)
Introduces an incompatibility with earlier JTS versions.
1 parent 6e4bf7a commit 9d75547

File tree

4 files changed

+16
-14
lines changed

4 files changed

+16
-14
lines changed

CHANGES.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
## VERSION X.X
22

3-
(TBD)
3+
* \#206: Upgraded to JTS 1.18.1. This JTS release had an incompatible [API change](https://github.com/locationtech/jts/blob/master/doc/JTS_Version_History.md#api-changes) and it requires Java 1.8.
4+
Only Spatial4j's `JtsBinaryCodec` was impacted, and thus only use of this will require a JTS upgrade.
5+
(Christian Marsch)
46

57
## VERSION 0.8
68

pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,7 @@
120120
<dependency>
121121
<groupId>org.locationtech.jts</groupId>
122122
<artifactId>jts-core</artifactId>
123-
<version>1.17.0</version>
123+
<version>1.18.1</version>
124124
<optional>true</optional>
125125
</dependency>
126126

src/main/java/org/locationtech/spatial4j/io/jts/JtsBinaryCodec.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,15 +85,17 @@ public Shape readJtsGeom(final DataInput dataInput) throws IOException {
8585
InStream inStream = new InStream() {//a strange JTS abstraction
8686
boolean first = true;
8787
@Override
88-
public void read(byte[] buf) throws IOException {
88+
public int read(byte[] buf) throws IOException {
8989
if (first) {//we don't write JTS's leading BOM so synthesize reading it
9090
if (buf.length != 1)
9191
throw new IllegalStateException("Expected initial read of one byte, not: " + buf.length);
9292
buf[0] = WKBConstants.wkbXDR;//0
9393
first = false;
94+
return 1;
9495
} else {
9596
//TODO for performance, specialize for common array lengths: 1, 4, 8
9697
dataInput.readFully(buf);
98+
return buf.length;
9799
}
98100
}
99101
};

src/test/java/org/locationtech/spatial4j/io/JtsBinaryCodecTest.java

Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -8,19 +8,16 @@
88

99
package org.locationtech.spatial4j.io;
1010

11-
import com.carrotsearch.randomizedtesting.annotations.ParametersFactory;
12-
import org.locationtech.spatial4j.context.SpatialContext;
13-
import org.locationtech.spatial4j.context.jts.JtsSpatialContext;
14-
import org.locationtech.spatial4j.context.jts.JtsSpatialContextFactory;
15-
import org.locationtech.spatial4j.shape.Shape;
11+
import org.junit.Test;
1612
import org.locationtech.jts.geom.Coordinate;
1713
import org.locationtech.jts.geom.Geometry;
1814
import org.locationtech.jts.geom.PrecisionModel;
1915
import org.locationtech.jts.util.GeometricShapeFactory;
20-
21-
import org.junit.Test;
22-
23-
import java.util.Arrays;
16+
import org.locationtech.spatial4j.context.SpatialContext;
17+
import org.locationtech.spatial4j.context.jts.JtsSpatialContext;
18+
import org.locationtech.spatial4j.context.jts.JtsSpatialContextFactory;
19+
import org.locationtech.spatial4j.shape.Shape;
20+
import org.locationtech.spatial4j.shape.jts.JtsGeometry;
2421

2522
public class JtsBinaryCodecTest extends BinaryCodecTest {
2623

@@ -32,9 +29,10 @@ public SpatialContext initContext() {
3229
}
3330

3431
@Test
35-
public void testPoly() {
32+
public void testPoly() throws Exception {
3633
JtsSpatialContext ctx = (JtsSpatialContext)super.ctx;
37-
ctx.makeShape(randomGeometry(randomIntBetween(3, 20)), false, false);
34+
final JtsGeometry shape = ctx.makeShape(randomGeometry(randomIntBetween(3, 20)), false, false);
35+
assertRoundTrip(shape);
3836
}
3937

4038
@Override

0 commit comments

Comments
 (0)