diff --git a/nb-configuration.xml b/nb-configuration.xml index d92c62ad88d4894de451ad45eae4c000fefdf620..7103095542c1a062dedf6d7f32faa28c80b6c0de 100755 --- a/nb-configuration.xml +++ b/nb-configuration.xml @@ -14,6 +14,5 @@ That way multiple projects can share the same settings (useful for formatting ru Any value defined here will override the pom.xml file value but is only applicable to the current project. --> <netbeans.hint.license>nibio_open_source_license.ftl</netbeans.hint.license> - <netbeans.hint.jdkPlatform>JDK_1.8_SUN</netbeans.hint.jdkPlatform> </properties> </project-shared-configuration> diff --git a/pom.xml b/pom.xml index 4c7af6c1e08588d64e0ddeac563b8afa5f5b1eb2..ea5b44942a3122db8c7433effc1c4cfe152b846a 100755 --- a/pom.xml +++ b/pom.xml @@ -26,7 +26,7 @@ <dependency> <groupId>com.fasterxml.jackson.core</groupId> <artifactId>jackson-annotations</artifactId> - <version>2.8.10</version> + <version>2.9.8</version> </dependency> <dependency> <groupId>commons-validator</groupId> @@ -37,12 +37,12 @@ <dependency> <groupId>com.fasterxml.jackson.core</groupId> <artifactId>jackson-core</artifactId> - <version>2.8.10</version> + <version>2.9.8</version> </dependency> <dependency> <groupId>com.fasterxml.jackson.core</groupId> <artifactId>jackson-databind</artifactId> - <version>2.8.10</version> + <version>2.9.8</version> </dependency> <dependency> <groupId>org.apache.httpcomponents</groupId> @@ -64,16 +64,22 @@ <version>2.7.0</version> <type>jar</type> </dependency> + <dependency> + <groupId>org.locationtech.jts</groupId> + <artifactId>jts-core</artifactId> + <version>1.16.1</version> + <type>jar</type> + </dependency> <dependency> <groupId>javax</groupId> <artifactId>javaee-api</artifactId> - <version>7.0</version> + <version>8.0</version> <scope>provided</scope> </dependency> <dependency> <groupId>javax</groupId> <artifactId>javaee-web-api</artifactId> - <version>7.0</version> + <version>8.0</version> <scope>provided</scope> </dependency> <dependency> @@ -94,34 +100,42 @@ <dependency> <groupId>org.geotools</groupId> <artifactId>gt-api</artifactId> - <version>17.2</version> + <version>20.3</version> </dependency> <dependency> <groupId>org.geotools</groupId> <artifactId>gt-epsg-hsql</artifactId> - <version>17.2</version> + <version>20.3</version> </dependency> <dependency> <groupId>org.renjin</groupId> <artifactId>renjin-script-engine</artifactId> <version>RELEASE</version> </dependency> - <dependency> - <groupId>com.vividsolutions</groupId> - <artifactId>jts</artifactId> - <version>1.13</version> -</dependency> + <dependency> <groupId>com.bedatadriven</groupId> <artifactId>jackson-datatype-jts</artifactId> <version>2.2</version> </dependency> <dependency> - <groupId>com.github.bjornharrtell</groupId> - <!--groupId>org.wololo</groupId--> + <!--groupId>com.github.bjornharrtell</groupId--> + <groupId>org.wololo</groupId> <artifactId>jts2geojson</artifactId> - <version>0.10.0</version> + <version>0.12.0</version> </dependency> + <!-- https://mvnrepository.com/artifact/org.jscience/jscience --> +<dependency> + <groupId>javax.measure</groupId> + <artifactId>unit-api</artifactId> + <version>1.0</version> +</dependency> +<dependency> + <groupId>tec.units</groupId> + <artifactId>unit-ri</artifactId> + <version>1.0.3</version> +</dependency> + </dependencies> <repositories> <repository> diff --git a/src/main/java/no/nibio/vips/entity/PointWeatherObservationList.java b/src/main/java/no/nibio/vips/entity/PointWeatherObservationList.java index af1f8f37b6b353dee071701b2056489565eda574..4abbdb226a71811321dbbeb9b736a00ecc143c9c 100644 --- a/src/main/java/no/nibio/vips/entity/PointWeatherObservationList.java +++ b/src/main/java/no/nibio/vips/entity/PointWeatherObservationList.java @@ -21,7 +21,8 @@ package no.nibio.vips.entity; import com.fasterxml.jackson.annotation.JsonCreator; import com.fasterxml.jackson.annotation.JsonProperty; -import com.vividsolutions.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; } diff --git a/src/main/java/no/nibio/vips/entity/Result.java b/src/main/java/no/nibio/vips/entity/Result.java index bdb057724bc77107432a55b9ec556c4ef21f55cf..62cd66f270d2cd8eec35f3a3cee96727dbe6b90b 100755 --- a/src/main/java/no/nibio/vips/entity/Result.java +++ b/src/main/java/no/nibio/vips/entity/Result.java @@ -24,14 +24,15 @@ import java.util.Map; import java.util.Set; import com.fasterxml.jackson.databind.annotation.JsonDeserialize; import com.fasterxml.jackson.databind.annotation.JsonSerialize; -import com.vividsolutions.jts.geom.Geometry; +import org.locationtech.jts.geom.Geometry; /** * Represents a result from a model run - * @copyright 2013 {@link http://www.nibio.no NIBIO} - * @author Tor-Einar Skog <tor-einar.skog@hyper.no> + * @copyright 2013-2019 {@link http://www.nibio.no NIBIO} + * @author Tor-Einar Skog <tor-einar.skog@nibio.no> */ +//@JsonbTypeAdapter(value = ResultJsonbAdapter.class) @JsonDeserialize(using=ResultDeserializer.class) @JsonSerialize(using=ResultSerializer.class) public interface Result extends Comparable{ diff --git a/src/main/java/no/nibio/vips/entity/ResultDeserializer.java b/src/main/java/no/nibio/vips/entity/ResultDeserializer.java index 2199b80347d96ab4858db6ddceda7b87d4b51fcb..127e1068fe90da79c05e96d224a310f88a8e66c2 100644 --- a/src/main/java/no/nibio/vips/entity/ResultDeserializer.java +++ b/src/main/java/no/nibio/vips/entity/ResultDeserializer.java @@ -26,10 +26,9 @@ import com.fasterxml.jackson.databind.DeserializationContext; import com.fasterxml.jackson.databind.JsonNode; import com.fasterxml.jackson.databind.ObjectMapper; import com.fasterxml.jackson.databind.deser.std.StdDeserializer; -import com.vividsolutions.jts.geom.Geometry; -import com.vividsolutions.jts.geom.LineString; -import com.vividsolutions.jts.geom.Point; -import com.vividsolutions.jts.geom.Polygon; +import org.locationtech.jts.geom.Geometry; +import org.locationtech.jts.geom.LineString; +import org.locationtech.jts.geom.Polygon; import java.io.IOException; import java.util.Date; import java.util.Map; @@ -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); diff --git a/src/main/java/no/nibio/vips/entity/ResultImpl.java b/src/main/java/no/nibio/vips/entity/ResultImpl.java index 065386444f31924d6bc89e39d6342daac77ca85c..395e37d1ae4426030aae4f7b3503df968cff8214 100755 --- a/src/main/java/no/nibio/vips/entity/ResultImpl.java +++ b/src/main/java/no/nibio/vips/entity/ResultImpl.java @@ -20,7 +20,7 @@ package no.nibio.vips.entity; import com.fasterxml.jackson.databind.annotation.JsonSerialize; -import com.vividsolutions.jts.geom.Geometry; +import org.locationtech.jts.geom.Geometry; import java.text.SimpleDateFormat; import java.util.Date; import java.util.HashMap; diff --git a/src/main/java/no/nibio/vips/entity/ResultJsonbAdapter.java b/src/main/java/no/nibio/vips/entity/ResultJsonbAdapter.java new file mode 100644 index 0000000000000000000000000000000000000000..2038629322c47e15982e5524c512a73d80515650 --- /dev/null +++ b/src/main/java/no/nibio/vips/entity/ResultJsonbAdapter.java @@ -0,0 +1,120 @@ +/* + * 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.entity; + +import com.bedatadriven.jackson.datatype.jts.JtsModule; +import com.fasterxml.jackson.databind.ObjectMapper; +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.math.BigDecimal; +import java.util.Date; +import java.util.Map; +import javax.json.Json; +import javax.json.JsonObject; +import javax.json.JsonObjectBuilder; +import javax.json.JsonValue; +import javax.json.bind.Jsonb; +import javax.json.bind.JsonbBuilder; +import javax.json.bind.adapter.JsonbAdapter; +import no.nibio.vips.gis.GISUtil; + +/** + * @copyright 2019 <a href="http://www.nibio.no/">NIBIO</a> + * @author Tor-Einar Skog <tor-einar.skog@nibio.no> + */ +public class ResultJsonbAdapter implements JsonbAdapter<Result, JsonObject>{ + + @Override + public JsonObject adaptToJson(Result original) throws Exception { + System.out.println("adaptToJson!"); + ObjectMapper objectMapper = new ObjectMapper(); + objectMapper.registerModule(new JtsModule()); + JsonObjectBuilder builder = Json.createObjectBuilder(); + builder.add("validTimeStart", objectMapper.writeValueAsString(original.getValidTimeStart()).replaceAll("\"", "")); + builder.add("validTimeEnd", objectMapper.writeValueAsString(original.getValidTimeStart()).replaceAll("\"", "")); + System.out.println("adaptToJson1"); + String geoJSON = original.getValidGeometry() == null ? "null" + : original.getValidGeometry().getGeometryType().equals("Point") ? objectMapper.writeValueAsString((Point) original.getValidGeometry()) + : original.getValidGeometry().getGeometryType().equals("LineString") ? objectMapper.writeValueAsString((LineString) original.getValidGeometry()) + : original.getValidGeometry().getGeometryType().equals("Polygon") ? objectMapper.writeValueAsString((Polygon) original.getValidGeometry()) + : "null"; + builder.add("validGeometry", geoJSON); + System.out.println("adaptToJson2"); + builder.add("warningStatus", original.getWarningStatus()); + System.out.println("adaptToJson3"); + builder.add("allValues", objectMapper.writeValueAsString(original.getAllValues())); + System.out.println("adaptToJson4"); + builder.add("keys", objectMapper.writeValueAsString(original.getKeys())); + System.out.println("adaptToJson5"); + return builder.build(); + } + + @Override + public Result adaptFromJson(JsonObject adapted) throws Exception { + System.out.println("adaptFromJson!"); + ObjectMapper objectMapper = new ObjectMapper(); + objectMapper.registerModule(new JtsModule()); + Result r = new ResultImpl(); + + + r.setValidTimeStart(objectMapper.convertValue(adapted.getString("validTimeStart"), Date.class)); + r.setValidTimeEnd(objectMapper.convertValue(adapted.getString("validTimeEnd"), Date.class)); + System.out.println("adaptFromJson1"); + if(adapted.get("allValues") != null) + { + r.setAllValues(objectMapper.readValue(adapted.getString("allValues"), Map.class)); + System.out.println("adaptFromJson2"); + } + r.setWarningStatus(adapted.getInt("warningStatus")); + //System.out.println(adapted.getString("validGeometry")); + + + Geometry validGeometry = null; + //System.out.println(geomNode); + if(!adapted.isNull("validGeometry")) + { + JsonObject geomNode = adapted.getValue("validGeometry").asJsonObject(); + switch(geomNode.getString("type")){ + case "Point": + validGeometry = objectMapper.convertValue(adapted.getString("validGeometry"), Point.class); + break; + case "Polygon": + validGeometry = objectMapper.convertValue(adapted.getString("validGeometry"), Polygon.class); + break; + case "LineString": + validGeometry = objectMapper.convertValue(adapted.getString("validGeometry"), LineString.class); + break; + default: + validGeometry = null; + } + if(validGeometry.getSRID() <= 0) + { + validGeometry.setSRID(GISUtil.DEFAULT_SRID); + } + } + + r.setValidGeometry(validGeometry); + //System.out.println(r.getValidGeometry()); + return r; + } + +} diff --git a/src/main/java/no/nibio/vips/entity/ResultSerializer.java b/src/main/java/no/nibio/vips/entity/ResultSerializer.java index 992dbefbe0f7a402e35e91a31f694ab23f4d4102..ae2539a7e66d68cbc2bb026e208e243131dd26f8 100644 --- a/src/main/java/no/nibio/vips/entity/ResultSerializer.java +++ b/src/main/java/no/nibio/vips/entity/ResultSerializer.java @@ -25,11 +25,12 @@ import com.fasterxml.jackson.databind.ObjectMapper; import com.fasterxml.jackson.databind.SerializationFeature; import com.fasterxml.jackson.databind.SerializerProvider; import com.fasterxml.jackson.databind.ser.std.StdSerializer; -import com.vividsolutions.jts.geom.GeometryFactory; -import com.vividsolutions.jts.geom.LineString; -import com.vividsolutions.jts.geom.Point; -import com.vividsolutions.jts.geom.Polygon; +import org.locationtech.jts.geom.GeometryFactory; +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(); } + + } diff --git a/src/main/java/no/nibio/vips/entity/Weather.java b/src/main/java/no/nibio/vips/entity/Weather.java deleted file mode 100755 index 6ab58b5c9c6f0bb8b7087121817fd5e17398be5f..0000000000000000000000000000000000000000 --- a/src/main/java/no/nibio/vips/entity/Weather.java +++ /dev/null @@ -1,82 +0,0 @@ -/* - * Copyright (c) 2014 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.entity; - -import java.util.Date; -import javax.xml.bind.annotation.XmlAccessType; -import javax.xml.bind.annotation.XmlAccessorType; -import javax.xml.bind.annotation.XmlAttribute; -import javax.xml.bind.annotation.XmlElement; -import javax.xml.bind.annotation.XmlRootElement; - -/** - * TEST object - * @author treinar - */ -@XmlRootElement(name="weather") -@XmlAccessorType(XmlAccessType.FIELD) -public class Weather { - - public Weather() - { - - } - - public Weather(Date date, String details){ - this.date=date; - this.details=details; - } - - @XmlAttribute - private Date date; - - @XmlElement - private String details; - - - - /** - * @return the date - */ - public Date getDate() { - return date; - } - - /** - * @param date the date to set - */ - public void setDate(Date date) { - this.date = date; - } - - /** - * @return the details - */ - public String getDetails() { - return details; - } - - /** - * @param details the details to set - */ - public void setDetails(String details) { - this.details = details; - } -} diff --git a/src/main/java/no/nibio/vips/entity/WeatherObservation.java b/src/main/java/no/nibio/vips/entity/WeatherObservation.java index 93761eec3c995988a5ef8295243ebbb4ba3faacf..7b28d57961fc43e2d62a9c8921652214dff6fa98 100755 --- a/src/main/java/no/nibio/vips/entity/WeatherObservation.java +++ b/src/main/java/no/nibio/vips/entity/WeatherObservation.java @@ -19,9 +19,13 @@ package no.nibio.vips.entity; + import com.fasterxml.jackson.annotation.JsonFormat; import com.fasterxml.jackson.annotation.JsonIgnore; import java.util.Date; +import javax.json.bind.annotation.JsonbDateFormat; +import javax.json.bind.annotation.JsonbTransient; + /** * Data object that represents a weather observation. Could be measured (historical @@ -77,6 +81,7 @@ public class WeatherObservation implements Comparable{ public final void setTimeMeasured(Date timeMeasured) { this.timeMeasured = timeMeasured; } @JsonFormat(shape=JsonFormat.Shape.STRING, pattern="yyyy-MM-dd'T'HH:mm:ssXXX", timezone="UTC") // Java >= 7 + @JsonbDateFormat(value = "yyyy-MM-dd'T'HH:mm:ssXXX") public Date getTimeMeasured() { return this.timeMeasured; } public final void setElementMeasurementTypeId(String elementMeasurementTypeId) { @@ -140,6 +145,8 @@ public class WeatherObservation implements Comparable{ this.value = value; } + + //@JsonbTransient @JsonIgnore public long getValiditySignature() { diff --git a/src/main/java/no/nibio/vips/gis/CoordinateProxy.java b/src/main/java/no/nibio/vips/gis/CoordinateProxy.java new file mode 100644 index 0000000000000000000000000000000000000000..2cb53de28e3ec0ab3d256999ed540de63d708739 --- /dev/null +++ b/src/main/java/no/nibio/vips/gis/CoordinateProxy.java @@ -0,0 +1,53 @@ +/* + * 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) + { + + } + +} diff --git a/src/main/java/no/nibio/vips/gis/GISUtil.java b/src/main/java/no/nibio/vips/gis/GISUtil.java index c7c2ca55aa1843a7dd6e0950d449ae1c029da700..41e901cd2f3c07cc83736062f9d8a8a6ecb939df 100644 --- a/src/main/java/no/nibio/vips/gis/GISUtil.java +++ b/src/main/java/no/nibio/vips/gis/GISUtil.java @@ -19,22 +19,17 @@ package no.nibio.vips.gis; -import com.vividsolutions.jts.geom.Coordinate; -import com.vividsolutions.jts.geom.Geometry; -import com.vividsolutions.jts.geom.GeometryFactory; -import com.vividsolutions.jts.geom.Point; -import com.vividsolutions.jts.geom.Polygon; -import com.vividsolutions.jts.geom.PrecisionModel; +import org.locationtech.jts.geom.Coordinate; +import org.locationtech.jts.geom.Geometry; +import org.locationtech.jts.geom.GeometryFactory; +import org.locationtech.jts.geom.Point; +import org.locationtech.jts.geom.Polygon; +import org.locationtech.jts.geom.PrecisionModel; import java.util.ArrayList; import java.util.List; import java.util.Map; -import javax.measure.Measure; -import javax.measure.quantity.Area; -import javax.measure.unit.SI; import org.geotools.geometry.jts.JTS; import org.geotools.referencing.CRS; -import org.geotools.referencing.crs.DefaultGeographicCRS; -import org.opengis.geometry.MismatchedDimensionException; import org.opengis.referencing.FactoryException; import org.opengis.referencing.crs.CoordinateReferenceSystem; import org.opengis.referencing.operation.MathTransform; @@ -214,7 +209,8 @@ public class GISUtil { * * @param p * @return Area in square meters - */ + * Used only by MetnoThreddsDataparser, which is obsolete anyway + * public Measure<Double, Area> calcArea(Polygon p) { Point centroid = p.getCentroid(); try { @@ -230,7 +226,7 @@ public class GISUtil { e.printStackTrace(); } return Measure.valueOf(0.0, SI.SQUARE_METRE); - } + }*/ /** * Create a polygon with the given bounds @@ -279,7 +275,7 @@ public class GISUtil { { Double x = Double.valueOf(xy[0]); Double y = Double.valueOf(xy[1]); - com.vividsolutions.jts.geom.Coordinate jtsCoordinate = new com.vividsolutions.jts.geom.Coordinate(); + org.locationtech.jts.geom.Coordinate jtsCoordinate = new org.locationtech.jts.geom.Coordinate(); jtsCoordinate.x = x; jtsCoordinate.y = y; return createPointWGS84(jtsCoordinate); @@ -289,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; + } } diff --git a/src/test/java/no/nibio/vips/gis/GISUtilTest.java b/src/test/java/no/nibio/vips/gis/GISUtilTest.java index 81559a42cb91d0fab98c92b35b00baffd46a8c83..e6afacf29b2bebeebd3d8d60ff9afad93bcf691f 100644 --- a/src/test/java/no/nibio/vips/gis/GISUtilTest.java +++ b/src/test/java/no/nibio/vips/gis/GISUtilTest.java @@ -18,9 +18,6 @@ */ package no.nibio.vips.gis; -import com.vividsolutions.jts.geom.Coordinate; -import com.vividsolutions.jts.geom.Geometry; -import com.vividsolutions.jts.geom.Point; import java.util.HashMap; import java.util.List; import java.util.Map; @@ -157,7 +154,7 @@ public class GISUtilTest extends TestCase { System.out.println("JSON=" + json); GISUtil instance = new GISUtil(); //List<Geometry> expResult = null; - List<com.vividsolutions.jts.geom.Geometry> geometries = instance.getGeometriesFromGeoJSON(json); + List<org.locationtech.jts.geom.Geometry> geometries = instance.getGeometriesFromGeoJSON(json); Map<String, Object> properties = new HashMap<>(); properties.put("observationId", 12); String result = instance.getGeoJSONFromGeometries(geometries, properties); diff --git a/src/test/java/no/nibio/vips/util/SolarRadiationUtilTest.java b/src/test/java/no/nibio/vips/util/SolarRadiationUtilTest.java index 74023a3609170b32dfdcb609fa150df06d724eca..9ba852b5dade832b4afb9d9749525d1b05ba9779 100755 --- a/src/test/java/no/nibio/vips/util/SolarRadiationUtilTest.java +++ b/src/test/java/no/nibio/vips/util/SolarRadiationUtilTest.java @@ -92,17 +92,17 @@ public class SolarRadiationUtilTest extends TestCase { 0.0, // :04 0.30585446462075766, // :05 0.5320290325650766, // :06 - 0.6674841256201908, // :07 - 0.75255528551197, // :08 - 0.8072260140456831, // :09 + 0.6674841256201905, // :07 + 0.7525552855119699, // :08 + 0.807226014045683, // :09 0.8414344839939248, // :10 0.8603110762175429, // :11 - 0.866352834115879, // :12 + 0.8663528341158789, // :12 0.8603110762175429, // :13 0.8414344839939248, // :14 - 0.8072260140456831, // :15 - 0.75255528551197, // :16 - 0.6674841256201908, // :17 + 0.807226014045683, // :15 + 0.7525552855119699, // :16 + 0.6674841256201905, // :17 0.5320290325650766, // :18 0.30585446462075766, // :19 0.0, // :20