diff --git a/pom.xml b/pom.xml index 9cbfee396949026204ba72f8bffe6e053b2b1c55..3e07131b1bbc9315176f76716baf4267e48fdf13 100755 --- a/pom.xml +++ b/pom.xml @@ -96,6 +96,11 @@ <artifactId>renjin-script-engine</artifactId> <version>RELEASE</version> </dependency> + <dependency> + <groupId>com.vividsolutions</groupId> + <artifactId>jts</artifactId> + <version>1.13</version> +</dependency> </dependencies> <repositories> <repository> diff --git a/src/main/java/no/nibio/vips/entity/MultiPointWeatherObservationList.java b/src/main/java/no/nibio/vips/entity/MultiPointWeatherObservationList.java new file mode 100644 index 0000000000000000000000000000000000000000..8b7f1bd84e74af2599317a942cf4a9b64c778b7c --- /dev/null +++ b/src/main/java/no/nibio/vips/entity/MultiPointWeatherObservationList.java @@ -0,0 +1,73 @@ +/* + * Copyright (c) 2017 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.fasterxml.jackson.annotation.JsonCreator; +import com.fasterxml.jackson.annotation.JsonProperty; +import java.util.List; +import no.nibio.vips.gis.SimpleWGS84Coordinate; + +/** + * @copyright 2017 <a href="http://www.nibio.no/">NIBIO</a> + * @author Tor-Einar Skog <tor-einar.skog@nibio.no> + */ +public class MultiPointWeatherObservationList { + private SimpleWGS84Coordinate coordinate; + private List<WeatherObservation> observations; + + @JsonCreator + public MultiPointWeatherObservationList( + @JsonProperty("coordinate") SimpleWGS84Coordinate coordinate, + @JsonProperty("observations") List<WeatherObservation> observations + ) + { + this.coordinate = coordinate; + this.observations = observations; + } + + /** + * @return the coordinate + */ + public SimpleWGS84Coordinate getCoordinate() { + return coordinate; + } + + /** + * @param coordinate the coordinate to set + */ + public void setCoordinate(SimpleWGS84Coordinate coordinate) { + this.coordinate = coordinate; + } + + /** + * @return the observations + */ + public List<WeatherObservation> getObservations() { + return observations; + } + + /** + * @param observations the observations to set + */ + public void setObservations(List<WeatherObservation> observations) { + this.observations = observations; + } + +} diff --git a/src/main/java/no/nibio/vips/entity/Result.java b/src/main/java/no/nibio/vips/entity/Result.java index 4e18ec6ac2da5230a89354682fdb1553d7185856..cd1cff0eec546b284279461f1d1a10f234779327 100755 --- a/src/main/java/no/nibio/vips/entity/Result.java +++ b/src/main/java/no/nibio/vips/entity/Result.java @@ -23,6 +23,7 @@ import java.util.Date; import java.util.Map; import java.util.Set; import com.fasterxml.jackson.databind.annotation.JsonDeserialize; +import com.vividsolutions.jts.geom.Geometry; /** @@ -40,11 +41,16 @@ public interface Result extends Comparable{ public final static Integer WARNING_STATUS_HIGH_RISK = 4; /* Time for which these results are valid */ - public void setResultValidTime(Date time); - public Date getResultValidTime(); + public void setValidTimeStart(Date time); + public Date getValidTimeStart(); + public void setValidTimeEnd(Date time); + public Date getValidTimeEnd(); + + // Spatial validity + public void setValidGeometry(Geometry geometry); + public Geometry getValidGeometry(); /* The result parameters in this Result object */ - public void setKeys(Set<String> keys); public Set<String> getKeys(); /* Setting and getting values */ diff --git a/src/main/java/no/nibio/vips/entity/ResultImpl.java b/src/main/java/no/nibio/vips/entity/ResultImpl.java index f8da1f68b64c5afb24eaebf28c67ee13f87163f3..e65b7c75cd752bcf2f1d237d4358a58e74511bb4 100755 --- a/src/main/java/no/nibio/vips/entity/ResultImpl.java +++ b/src/main/java/no/nibio/vips/entity/ResultImpl.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2015 NIBIO <http://www.nibio.no/>. + * Copyright (c) 2017 NIBIO <http://www.nibio.no/>. * * This file is part of VIPSCommon. * VIPSCommon is free software: you can redistribute it and/or modify @@ -19,6 +19,7 @@ package no.nibio.vips.entity; +import com.vividsolutions.jts.geom.Geometry; import java.text.SimpleDateFormat; import java.util.Date; import java.util.HashMap; @@ -29,33 +30,28 @@ import java.util.TimeZone; /** * Represents a result - * @copyright 2013 <a href="http://www.nibio.no">NIBIO</a> + * @copyright 2013-2017 <a href="http://www.nibio.no">NIBIO</a> * @author Tor-Einar Skog <tor-einar.skog@nibio.no> */ public class ResultImpl implements Result{ - private Date resultValidTime; - private Set<String> keys; + private Date validTimeStart, validTimeEnd; + private Geometry validGeometry; private Map<String, String> values; private Integer warningStatus; @Override - public void setResultValidTime(Date time) { - this.resultValidTime = time; + public void setValidTimeStart(Date time) { + this.validTimeStart = time; } @Override - public Date getResultValidTime() { - return this.resultValidTime; - } - - @Override - public void setKeys(Set<String> keys) { - this.keys = keys; + public Date getValidTimeStart() { + return this.validTimeStart; } @Override public Set<String> getKeys() { - return this.values != null ? this.values.keySet() : new HashSet<String>(); + return this.values != null ? this.values.keySet() : new HashSet<>(); } @Override @@ -73,7 +69,7 @@ public class ResultImpl implements Result{ @Override public Map<String, String> getAllValues() { - return this.values != null ? this.values : new HashMap<String,String>(); + return this.values != null ? this.values : new HashMap<>(); } @Override @@ -88,7 +84,7 @@ public class ResultImpl implements Result{ */ @Override public int compareTo(Object t) { - return this.getResultValidTime().compareTo(((Result) t).getResultValidTime()); + return this.getValidTimeStart().compareTo(((Result) t).getValidTimeStart()); } @Override @@ -105,7 +101,7 @@ public class ResultImpl implements Result{ public String toString(){ SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ssXXX"); format.setTimeZone(TimeZone.getTimeZone("UTC")); - String retVal = "[" + format.format(resultValidTime) + "], WARNING_STATUS=" + this.getWarningStatus() + ", "; + String retVal = "[" + format.format(validTimeStart) + "], WARNING_STATUS=" + this.getWarningStatus() + ", "; if(this.getKeys() != null) { for(String key: this.getKeys()) @@ -119,4 +115,36 @@ public class ResultImpl implements Result{ } return retVal; } + + /** + * @return the validTimeEnd + */ + @Override + public Date getValidTimeEnd() { + return validTimeEnd != null ? this.validTimeEnd : this.validTimeStart; + } + + /** + * @param validTimeEnd the validTimeEnd to set + */ + @Override + public void setValidTimeEnd(Date validTimeEnd) { + this.validTimeEnd = validTimeEnd; + } + + /** + * @return the validGeometry + */ + @Override + public Geometry getValidGeometry() { + return validGeometry; + } + + /** + * @param validGeometry the validGeometry to set + */ + @Override + public void setValidGeometry(Geometry validGeometry) { + this.validGeometry = validGeometry; + } } diff --git a/src/main/java/no/nibio/vips/gis/SimpleWGS84Coordinate.java b/src/main/java/no/nibio/vips/gis/SimpleWGS84Coordinate.java new file mode 100644 index 0000000000000000000000000000000000000000..73dd6461c7c26667e469cae4cb2de5a3b43d7269 --- /dev/null +++ b/src/main/java/no/nibio/vips/gis/SimpleWGS84Coordinate.java @@ -0,0 +1,99 @@ +/* + * Copyright (c) 2017 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; + +import com.fasterxml.jackson.annotation.JsonCreator; +import com.fasterxml.jackson.annotation.JsonProperty; + +/** + * This is for multi point data serialization purposes + * @copyright 2017 <a href="http://www.nibio.no/">NIBIO</a> + * @author Tor-Einar Skog <tor-einar.skog@nibio.no> + */ + +public class SimpleWGS84Coordinate { + + private Double latitude, longitude, altitude; + @JsonCreator + public SimpleWGS84Coordinate( + @JsonProperty("latitude") Double latitude, + @JsonProperty("longitude") Double longitude, + @JsonProperty("altitude") Double altitude + ) + { + this.latitude = latitude; + this.longitude = longitude; + this.altitude = altitude; + } + + public SimpleWGS84Coordinate(Double latitude, Double longitude) + { + this(latitude, longitude, null); + } + + /** + * @return the latitude + */ + public Double getLatitude() { + return latitude; + } + + /** + * @param latitude the latitude to set + */ + public void setLatitude(Double latitude) { + this.latitude = latitude; + } + + /** + * @return the longitude + */ + public Double getLongitude() { + return longitude; + } + + /** + * @param longitude the longitude to set + */ + public void setLongitude(Double longitude) { + this.longitude = longitude; + } + + /** + * @return the altitude + */ + public Double getAltitude() { + return altitude; + } + + /** + * @param altitude the altitude to set + */ + public void setAltitude(Double altitude) { + this.altitude = altitude; + } + + @Override + public String toString() + { + return this.getClass().getName() + " lat=" + this.getLatitude() + ", lon=" + this.getLongitude() + ", alt=" + this.getAltitude(); + } + +} diff --git a/src/main/java/no/nibio/vips/model/Model.java b/src/main/java/no/nibio/vips/model/Model.java index c7da13680994c5d0c990759f8987a69165fad6f3..05de57c7b3bee6c14221619ea5979257f5dbebca 100755 --- a/src/main/java/no/nibio/vips/model/Model.java +++ b/src/main/java/no/nibio/vips/model/Model.java @@ -19,9 +19,9 @@ package no.nibio.vips.model; -import no.nibio.vips.entity.Result; import java.util.List; import no.nibio.vips.entity.ModelConfiguration; +import no.nibio.vips.entity.Result; /** * All models must implement this interface diff --git a/src/main/java/no/nibio/vips/util/test/WeatherDataFileReader.java b/src/main/java/no/nibio/vips/util/test/WeatherDataFileReader.java index 8f6917ab09dcc31cfebd7cd3d0ac84c3419386fb..2628ffa3cc8303d74efd05f131d78cf76d162cbc 100644 --- a/src/main/java/no/nibio/vips/util/test/WeatherDataFileReader.java +++ b/src/main/java/no/nibio/vips/util/test/WeatherDataFileReader.java @@ -27,11 +27,11 @@ import com.fasterxml.jackson.databind.MappingJsonFactory; import com.fasterxml.jackson.databind.ObjectMapper; import java.io.BufferedInputStream; import java.io.IOException; -import java.io.InputStream; import java.util.ArrayList; import java.util.Date; import java.util.List; import no.nibio.vips.entity.ModelConfiguration; +import no.nibio.vips.entity.MultiPointWeatherObservationList; import no.nibio.vips.entity.WeatherObservation; import no.nibio.vips.model.ConfigValidationException; @@ -98,4 +98,34 @@ public class WeatherDataFileReader { throw new ConfigValidationException(ex.getMessage()); } } + + /** + * + * + * @param weatherDataFileName filename and path on classpath + * @param modelId 10 chars ID of model + * @return A Model Configuration with weather data. Can be filled with other configuration data + * @throws ConfigValidationException + */ + public ModelConfiguration getModelConfigurationWithMultiPointWeatherObservationList(String weatherDataFileName, String modelId) throws ConfigValidationException + { + try { + ModelConfiguration config = new ModelConfiguration(); + config.setModelId(modelId); + BufferedInputStream inputStream = new BufferedInputStream(this.getClass().getResourceAsStream(weatherDataFileName)); + JsonFactory f = new MappingJsonFactory(); + JsonParser jp = f.createParser(inputStream); + JsonNode all = jp.readValueAsTree(); + List<WeatherObservation> observations = new ArrayList<>(); + ObjectMapper mapper = new ObjectMapper(); + List<MultiPointWeatherObservationList> theList = mapper.convertValue(all, new TypeReference<List<MultiPointWeatherObservationList>>(){}); + config.setConfigParameter("multiPointWeatherObservations", theList); + + return config; + } catch (IOException ex) { + ex.printStackTrace(); + throw new ConfigValidationException(ex.getMessage()); + } + + } }