Skip to content

Commit

Permalink
Fix for issue #132
Browse files Browse the repository at this point in the history
  • Loading branch information
maesenka committed May 20, 2021
1 parent a243711 commit d38a00e
Show file tree
Hide file tree
Showing 9 changed files with 69 additions and 8 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
![Build Status](https://github.com/GeoLatte/geolatte-geom/workflows/Java%20CI/badge.svg)
[![Language grade: Java](https://img.shields.io/lgtm/grade/java/g/GeoLatte/geolatte-geom.svg?logo=lgtm&logoWidth=18)](https://lgtm.com/projects/g/GeoLatte/geolatte-geom/context:java)

# Geolatte-geom

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@
*/
abstract class AbstractPositionSequence<P extends Position> implements PositionSequence<P>, CoordinateSequence, Serializable {

private static final long serialVersionUID = 6884205871950410216L;

private final PositionFactory<P> factory;

public AbstractPositionSequence(PositionFactory<P> factory) {
Expand Down
2 changes: 1 addition & 1 deletion geom/src/main/java/org/geolatte/geom/Positions.java
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@ public static <Q extends Position, P extends Position> PositionSequence<P> copy(
final Class<P> targetPosClass) {
return copy(source, targetPosClass, Double.NaN);
}

//Factories
public static class CanMakeP2D implements PositionFactory<C2D> {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@

import org.geolatte.geom.Position;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
Expand All @@ -37,7 +38,9 @@
* @author Karel Maesen, Geovise BVBA
* creation-date: 4/29/11
*/
abstract public class CoordinateSystem<P extends Position> {
abstract public class CoordinateSystem<P extends Position> implements Serializable {

private static final long serialVersionUID = 6884205871950410216L;

private final CoordinateSystemAxis[] axes;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,18 @@

package org.geolatte.geom.crs;

import java.io.Serializable;
import java.util.Objects;

/**
* An axis of a <code>CoordinateSystem.</code>
*
* @author Karel Maesen, Geovise BVBA
* creation-date: 4/29/11
*/
abstract public class CoordinateSystemAxis {
abstract public class CoordinateSystemAxis implements Serializable {

private static final long serialVersionUID = 6884205871950410216L;

private final String axisName;
private final CoordinateSystemAxisDirection coordinateSystemAxisDirection;
Expand Down Expand Up @@ -87,7 +92,7 @@ public static StraightLineAxis mkZAxis() {
/**
* Returns the name of this axis.
*
* @return
* @return the Axis name
*/
public String getAxisName() {
return axisName;
Expand Down Expand Up @@ -119,10 +124,10 @@ public boolean equals(Object o) {

CoordinateSystemAxis that = (CoordinateSystemAxis) o;

if (axisName != null ? !axisName.equals(that.axisName) : that.axisName != null) return false;
if (!Objects.equals(axisName, that.axisName)) return false;
if (coordinateSystemAxisDirection != that.coordinateSystemAxisDirection) return false;
if (normalOrder != that.normalOrder) return false;
return !(unit != null ? !unit.equals(that.unit) : that.unit != null);
return Objects.equals(unit, that.unit);
}

@Override
Expand Down
6 changes: 5 additions & 1 deletion geom/src/main/java/org/geolatte/geom/crs/CrsId.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package org.geolatte.geom.crs;

import java.io.Serializable;

/**
* An identifier for a <code>CoordinateReferenceSystem</code> or other object referenced in a
* <code>CoordinateReferenceSystem</code> definition.
Expand All @@ -14,7 +16,9 @@
*
* @author Karel Maesen, Geovise BVBA, 2011
*/
public class CrsId {
public class CrsId implements Serializable {

private static final long serialVersionUID = 6884205871950410216L;

final static public String DEFAULT_AUTHORITY = "EPSG";

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@

package org.geolatte.geom.crs;

import java.io.Serializable;

/**
* Abstract base class for classes the are identified by a <code>CrsId</code> (e.g. by EPSG-code).
*
Expand All @@ -32,7 +34,9 @@
* @author Karel Maesen, Geovise BVBA
* creation-date: 11/21/11
*/
abstract public class CrsIdentifiable {
abstract public class CrsIdentifiable implements Serializable {

private static final long serialVersionUID = 6884205871950410216L;

private final CrsId crsId;
private final String name;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,8 @@
*/
class PointSequenceCoordinateSequenceFactory implements CoordinateSequenceFactory, Serializable {

private static final long serialVersionUID = 6884205871950410216L;

@Override
public CoordinateSequence create(Coordinate[] coordinates) {
CoordinateReferenceSystem<?> crs = determineCRS(coordinates);
Expand Down
40 changes: 40 additions & 0 deletions geom/src/test/java/org/geolatte/geom/crs/SerializableTest.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
package org.geolatte.geom.crs;

import org.geolatte.geom.G3D;
import org.geolatte.geom.G3DM;
import org.junit.Test;

import java.io.*;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;

import static org.junit.Assert.assertEquals;

public class SerializableTest {

@Test
public void testCastToSerializable() throws IOException, ClassNotFoundException {
CoordinateReferenceSystem<G3DM> crs = CoordinateReferenceSystems.WGS84
.addVerticalSystem(LinearUnit.METER,G3D.class)
.addLinearSystem(LinearUnit.METER, G3DM.class);

Serializable ser = (Serializable) crs;
Path tmpDir = Paths.get("/tmp");
File tempFile = Files.createTempFile(tmpDir, "", ".ser").toFile();
tempFile.deleteOnExit();
try (ObjectOutputStream out = new ObjectOutputStream(new FileOutputStream(tempFile))){
out.writeObject(crs);
};

CoordinateReferenceSystem<G3DM> deser;
try (ObjectInputStream ins = new ObjectInputStream(new FileInputStream(tempFile))) {
deser = (CoordinateReferenceSystem<G3DM>) ins.readObject();
}

assertEquals(crs, deser);

}


}

0 comments on commit d38a00e

Please sign in to comment.