Skip to content

Commit 99fc5d6

Browse files
billtianmaesenka
authored andcommitted
change CrsParameter, Extension, Projection to Serializable and fix bug when cache ProjectedCoordinateReferenceSystem
(cherry picked from commit 263e0f0)
1 parent eabf159 commit 99fc5d6

File tree

4 files changed

+33
-5
lines changed

4 files changed

+33
-5
lines changed

geom/src/main/java/org/geolatte/geom/crs/CrsParameter.java

+4-1
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121

2222
package org.geolatte.geom.crs;
2323

24+
import java.io.Serializable;
2425
import java.util.HashMap;
2526
import java.util.List;
2627
import java.util.Map;
@@ -31,7 +32,9 @@
3132
* @author Karel Maesen, Geovise BVBA
3233
* creation-date: 8/2/11
3334
*/
34-
public class CrsParameter {
35+
public class CrsParameter implements Serializable {
36+
37+
private static final long serialVersionUID = 6884205871950410216L;
3538

3639
private final String name;
3740
private final double value;

geom/src/main/java/org/geolatte/geom/crs/Extension.java

+5-1
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,13 @@
11
package org.geolatte.geom.crs;
22

3+
import java.io.Serializable;
4+
35
/**
46
* Created by Karel Maesen, Geovise BVBA on 23/04/16.
57
*/
6-
public class Extension {
8+
public class Extension implements Serializable {
9+
10+
private static final long serialVersionUID = 6884205871950410216L;
711

812
private final String name;
913
private final String value;

geom/src/main/java/org/geolatte/geom/crs/Projection.java

+5-1
Original file line numberDiff line numberDiff line change
@@ -21,13 +21,17 @@
2121

2222
package org.geolatte.geom.crs;
2323

24+
import java.io.Serializable;
25+
2426
/**
2527
* A projection from geographic coordinates to projected coordinates in a Cartesian plan.
2628
*
2729
* @author Karel Maesen, Geovise BVBA
2830
* creation-date: 8/2/11
2931
*/
30-
public class Projection {
32+
public class Projection implements Serializable {
33+
34+
private static final long serialVersionUID = 6884205871950410216L;
3135

3236
public final static Projection UNKNOWN = new Projection(CrsId.UNDEFINED, "unknown");
3337

geom/src/test/java/org/geolatte/geom/crs/SerializableTest.java

+19-2
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,6 @@
66

77
import java.io.*;
88
import java.nio.file.Files;
9-
import java.nio.file.Path;
10-
import java.nio.file.Paths;
119

1210
import static org.junit.Assert.assertEquals;
1311

@@ -35,5 +33,24 @@ public void testCastToSerializable() throws IOException, ClassNotFoundException
3533

3634
}
3735

36+
@Test
37+
public void testProjectedCrsCastToSerializable() throws IOException, ClassNotFoundException {
38+
ProjectedCoordinateReferenceSystem crs = CoordinateReferenceSystems.WEB_MERCATOR;
39+
40+
Serializable ser = (Serializable) crs;
41+
File tempFile = Files.createTempFile("pcrs", ".ser").toFile();
42+
tempFile.deleteOnExit();
43+
try (ObjectOutputStream out = new ObjectOutputStream(new FileOutputStream(tempFile))){
44+
out.writeObject(crs);
45+
};
46+
47+
ProjectedCoordinateReferenceSystem deser;
48+
try (ObjectInputStream ins = new ObjectInputStream(new FileInputStream(tempFile))) {
49+
deser = (ProjectedCoordinateReferenceSystem) ins.readObject();
50+
}
51+
52+
assertEquals(crs, deser);
53+
54+
}
3855

3956
}

0 commit comments

Comments
 (0)