Skip to content
Snippets Groups Projects
Commit 5eb17a3d authored by Tor-Einar Skog's avatar Tor-Einar Skog
Browse files

Upgrade to new version of JTS, with all kinds of horrible repercussions

parent 4cf11ffb
Branches
Tags
No related merge requests found
......@@ -67,7 +67,7 @@
<dependency>
<groupId>org.locationtech.jts</groupId>
<artifactId>jts-core</artifactId>
<version>1.16.0</version>
<version>1.16.1</version>
<type>jar</type>
</dependency>
<dependency>
......
......@@ -21,7 +21,8 @@ package no.nibio.vips.entity;
import com.fasterxml.jackson.annotation.JsonCreator;
import com.fasterxml.jackson.annotation.JsonProperty;
import org.locationtech.jts.geom.Coordinate;
//import org.locationtech.jts.geom.Coordinate;
import no.nibio.vips.gis.CoordinateProxy;
import java.util.List;
/**
......@@ -29,7 +30,7 @@ import java.util.List;
* @author Tor-Einar Skog <tor-einar.skog@nibio.no>
*/
public class PointWeatherObservationList {
private Coordinate coordinate;
private CoordinateProxy coordinate;
private List<WeatherObservation> observations;
private String timeZone;
......@@ -39,7 +40,7 @@ public class PointWeatherObservationList {
@JsonCreator
public PointWeatherObservationList(
@JsonProperty("coordinate") Coordinate coordinate,
@JsonProperty("coordinate") CoordinateProxy coordinate,
@JsonProperty("observations") List<WeatherObservation> observations,
@JsonProperty("timeZone") String timeZone
)
......@@ -52,14 +53,14 @@ public class PointWeatherObservationList {
/**
* @return the coordinate
*/
public Coordinate getCoordinate() {
public CoordinateProxy getCoordinate() {
return coordinate;
}
/**
* @param coordinate the coordinate to set
*/
public void setCoordinate(Coordinate coordinate) {
public void setCoordinate(CoordinateProxy coordinate) {
this.coordinate = coordinate;
}
......
......@@ -28,7 +28,6 @@ import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.deser.std.StdDeserializer;
import org.locationtech.jts.geom.Geometry;
import org.locationtech.jts.geom.LineString;
import org.locationtech.jts.geom.Point;
import org.locationtech.jts.geom.Polygon;
import java.io.IOException;
import java.util.Date;
......@@ -41,8 +40,10 @@ import no.nibio.vips.gis.GISUtil;
*/
public class ResultDeserializer extends StdDeserializer<Result>{
GISUtil gisUtil;
public ResultDeserializer(){
this(null);
this.gisUtil = new GISUtil();
}
public ResultDeserializer(Class<?>vc){
......@@ -71,7 +72,7 @@ public class ResultDeserializer extends StdDeserializer<Result>{
{
switch(geomNode.get("type").asText()){
case "Point":
validGeometry = objectMapper.convertValue(geomNode, Point.class);
validGeometry = this.gisUtil.getLocationTechPoint(objectMapper.convertValue(geomNode, com.vividsolutions.jts.geom.Point.class));
break;
case "Polygon":
validGeometry = objectMapper.convertValue(geomNode, Polygon.class);
......
......@@ -30,6 +30,7 @@ import org.locationtech.jts.geom.LineString;
import org.locationtech.jts.geom.Point;
import org.locationtech.jts.geom.Polygon;
import java.io.IOException;
import no.nibio.vips.gis.GISUtil;
/**
* Ref http://www.baeldung.com/jackson-custom-serialization
......@@ -39,8 +40,10 @@ import java.io.IOException;
class ResultSerializer extends StdSerializer<ResultImpl>{
ObjectMapper objectMapper;
GeometryFactory gf;
GISUtil gisUtil;
public ResultSerializer() {
this(null);
this.gisUtil = new GISUtil();
}
public ResultSerializer(Class<ResultImpl> t) {
......@@ -52,12 +55,11 @@ class ResultSerializer extends StdSerializer<ResultImpl>{
@Override
public void serialize(ResultImpl t, JsonGenerator jg, SerializerProvider sp) throws IOException {
jg.writeStartObject();
jg.writeStringField("validTimeStart", this.objectMapper.writeValueAsString(t.getValidTimeStart()).replaceAll("\"", ""));
jg.writeStringField("validTimeEnd", this.objectMapper.writeValueAsString(t.getValidTimeEnd()).replaceAll("\"", ""));
String geoJSON = t.getValidGeometry() == null ? "null"
: t.getValidGeometry().getGeometryType().equals("Point") ? objectMapper.writeValueAsString((Point) t.getValidGeometry())
: t.getValidGeometry().getGeometryType().equals("Point") ? objectMapper.writeValueAsString(this.gisUtil.getVividPoint((Point) t.getValidGeometry()))
: t.getValidGeometry().getGeometryType().equals("LineString") ? objectMapper.writeValueAsString((LineString) t.getValidGeometry())
:t.getValidGeometry().getGeometryType().equals("Polygon") ? objectMapper.writeValueAsString((Polygon) t.getValidGeometry())
: "null";
......@@ -71,5 +73,7 @@ class ResultSerializer extends StdSerializer<ResultImpl>{
jg.writeStringField("keys", this.objectMapper.writeValueAsString(t.getKeys()));
jg.writeEndObject();
}
}
/*
* Copyright (c) 2019 NIBIO <http://www.nibio.no/>.
*
* This file is part of VIPSCommon.
* VIPSCommon is free software: you can redistribute it and/or modify
* it under the terms of the NIBIO Open Source License as published by
* NIBIO, either version 1 of the License, or (at your option) any
* later version.
*
* VIPSCommon is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* NIBIO Open Source License for more details.
*
* You should have received a copy of the NIBIO Open Source License
* along with VIPSCommon. If not, see <http://www.nibio.no/licenses/>.
*
*/
package no.nibio.vips.gis;
/**
* @copyright 2019 <a href="http://www.nibio.no/">NIBIO</a>
* @author Tor-Einar Skog <tor-einar.skog@nibio.no>
*/
public class CoordinateProxy extends org.locationtech.jts.geom.Coordinate{
public CoordinateProxy()
{
super();
}
public CoordinateProxy(Double longitude, Double latitude)
{
super(longitude,latitude);
}
public CoordinateProxy(Double longitude, Double latitude, Double altitude)
{
super(longitude,latitude,altitude);
}
/**
* We needed to override this in order to not break deserializing with Jackson. Phew....
* @param m
*/
@Override
public void setM(double m)
{
}
}
......@@ -285,4 +285,26 @@ public class GISUtil {
throw new LonLatStringFormatException(ex.getMessage());
}
}
public com.vividsolutions.jts.geom.Point getVividPoint(org.locationtech.jts.geom.Point locationTechPoint)
{
com.vividsolutions.jts.geom.Coordinate vividCoordinate = new com.vividsolutions.jts.geom.Coordinate(
locationTechPoint.getCoordinate().x,
locationTechPoint.getCoordinate().y,
locationTechPoint.getCoordinate().z
);
com.vividsolutions.jts.geom.Point vividPoint = new com.vividsolutions.jts.geom.GeometryFactory().createPoint(vividCoordinate);
return vividPoint;
}
public org.locationtech.jts.geom.Point getLocationTechPoint(com.vividsolutions.jts.geom.Point vividPoint)
{
org.locationtech.jts.geom.Coordinate locationTechCoordinate = new org.locationtech.jts.geom.Coordinate(
vividPoint.getCoordinate().x,
vividPoint.getCoordinate().y,
vividPoint.getCoordinate().z
);
org.locationtech.jts.geom.Point locationTechPoint = new org.locationtech.jts.geom.GeometryFactory().createPoint(locationTechCoordinate);
return locationTechPoint;
}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment