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

Final adaptations to GIS aware result object

parent b5637d7d
No related branches found
No related tags found
No related merge requests found
...@@ -33,6 +33,7 @@ import com.vividsolutions.jts.geom.Polygon; ...@@ -33,6 +33,7 @@ import com.vividsolutions.jts.geom.Polygon;
import java.io.IOException; import java.io.IOException;
import java.util.Date; import java.util.Date;
import java.util.Map; import java.util.Map;
import no.nibio.vips.gis.GISUtil;
/** /**
* @copyright 2018 <a href="http://www.nibio.no/">NIBIO</a> * @copyright 2018 <a href="http://www.nibio.no/">NIBIO</a>
...@@ -53,7 +54,9 @@ public class ResultDeserializer extends StdDeserializer<Result>{ ...@@ -53,7 +54,9 @@ public class ResultDeserializer extends StdDeserializer<Result>{
ObjectMapper objectMapper = new ObjectMapper(); ObjectMapper objectMapper = new ObjectMapper();
objectMapper.registerModule(new JtsModule()); objectMapper.registerModule(new JtsModule());
Result r = new ResultImpl(); Result r = new ResultImpl();
//System.out.println(jp.getText());
JsonNode node = jp.getCodec().readTree(jp); JsonNode node = jp.getCodec().readTree(jp);
//System.out.println(node);
r.setValidTimeStart(objectMapper.convertValue(node.get("validTimeStart"), Date.class)); r.setValidTimeStart(objectMapper.convertValue(node.get("validTimeStart"), Date.class));
r.setValidTimeEnd(objectMapper.convertValue(node.get("validTimeEnd"), Date.class)); r.setValidTimeEnd(objectMapper.convertValue(node.get("validTimeEnd"), Date.class));
if(node.get("allValues") != null) if(node.get("allValues") != null)
...@@ -63,6 +66,7 @@ public class ResultDeserializer extends StdDeserializer<Result>{ ...@@ -63,6 +66,7 @@ public class ResultDeserializer extends StdDeserializer<Result>{
r.setWarningStatus(node.get("warningStatus").asInt()); r.setWarningStatus(node.get("warningStatus").asInt());
JsonNode geomNode = node.get("validGeometry"); JsonNode geomNode = node.get("validGeometry");
Geometry validGeometry = null; Geometry validGeometry = null;
//System.out.println(geomNode);
if(geomNode != null && geomNode.get("type") != null) if(geomNode != null && geomNode.get("type") != null)
{ {
switch(geomNode.get("type").asText()){ switch(geomNode.get("type").asText()){
...@@ -78,8 +82,14 @@ public class ResultDeserializer extends StdDeserializer<Result>{ ...@@ -78,8 +82,14 @@ public class ResultDeserializer extends StdDeserializer<Result>{
default: default:
validGeometry = null; validGeometry = null;
} }
if(validGeometry.getSRID() <= 0)
{
validGeometry.setSRID(GISUtil.DEFAULT_SRID);
}
} }
r.setValidGeometry(validGeometry); r.setValidGeometry(validGeometry);
//System.out.println(r.getValidGeometry());
return r; return r;
} }
......
...@@ -61,7 +61,11 @@ class ResultSerializer extends StdSerializer<ResultImpl>{ ...@@ -61,7 +61,11 @@ class ResultSerializer extends StdSerializer<ResultImpl>{
: t.getValidGeometry().getGeometryType().equals("LineString") ? objectMapper.writeValueAsString((LineString) t.getValidGeometry()) : t.getValidGeometry().getGeometryType().equals("LineString") ? objectMapper.writeValueAsString((LineString) t.getValidGeometry())
:t.getValidGeometry().getGeometryType().equals("Polygon") ? objectMapper.writeValueAsString((Polygon) t.getValidGeometry()) :t.getValidGeometry().getGeometryType().equals("Polygon") ? objectMapper.writeValueAsString((Polygon) t.getValidGeometry())
: "null"; : "null";
jg.writeStringField("validGeometry", geoJSON);
//jg.writeObjectField("validGeometry", t.getValidGeometry());
//System.out.println(geoJSON);
jg.writeRaw(",\"validGeometry\":" + geoJSON);
//
jg.writeNumberField("warningStatus", t.getWarningStatus()); jg.writeNumberField("warningStatus", t.getWarningStatus());
jg.writeStringField("allValues", this.objectMapper.writeValueAsString(t.getAllValues())); jg.writeStringField("allValues", this.objectMapper.writeValueAsString(t.getAllValues()));
jg.writeStringField("keys", this.objectMapper.writeValueAsString(t.getKeys())); jg.writeStringField("keys", this.objectMapper.writeValueAsString(t.getKeys()));
......
...@@ -52,6 +52,8 @@ import org.wololo.jts2geojson.GeoJSONWriter; ...@@ -52,6 +52,8 @@ import org.wololo.jts2geojson.GeoJSONWriter;
*/ */
public class GISUtil { public class GISUtil {
public static Integer DEFAULT_SRID = 4326;
/** /**
* Calculates the coordinates of a nearby destination * Calculates the coordinates of a nearby destination
* @param origin WGS84 where to start from * @param origin WGS84 where to start from
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment