Skip to content
Snippets Groups Projects
Commit df069c60 authored by Lene Wasskog's avatar Lene Wasskog
Browse files

feat: Parse coordinates to double

parent 8d598373
Branches
No related tags found
1 merge request!191Add map module and Open-Meteo support
...@@ -44,6 +44,7 @@ import no.nibio.vips.util.ParseRESTParamUtil; ...@@ -44,6 +44,7 @@ import no.nibio.vips.util.ParseRESTParamUtil;
import no.nibio.vips.util.WeatherElements; import no.nibio.vips.util.WeatherElements;
import no.nibio.vips.util.weather.WeatherDataSourceException; import no.nibio.vips.util.weather.WeatherDataSourceException;
import no.nibio.vips.util.weather.WeatherDataSourceUtil; import no.nibio.vips.util.weather.WeatherDataSourceUtil;
import org.slf4j.LoggerFactory;
/** /**
* @copyright 2015 <a href="http://www.nibio.no/">NIBIO</a> * @copyright 2015 <a href="http://www.nibio.no/">NIBIO</a>
...@@ -52,6 +53,8 @@ import no.nibio.vips.util.weather.WeatherDataSourceUtil; ...@@ -52,6 +53,8 @@ import no.nibio.vips.util.weather.WeatherDataSourceUtil;
@Path("rest/barleynetblotchmodel") @Path("rest/barleynetblotchmodel")
@Facet("restricted") @Facet("restricted")
public class BarleyNetBlotchModelService { public class BarleyNetBlotchModelService {
private static final org.slf4j.Logger LOGGER = LoggerFactory.getLogger(BarleyNetBlotchModelService.class);
private final static String VIPSCOREMANAGER_URL = System.getProperty("no.nibio.vips.logic.VIPSCOREMANAGER_URL"); private final static String VIPSCOREMANAGER_URL = System.getProperty("no.nibio.vips.logic.VIPSCOREMANAGER_URL");
@PersistenceContext(unitName="VIPSLogic-PU") @PersistenceContext(unitName="VIPSLogic-PU")
...@@ -135,8 +138,8 @@ public class BarleyNetBlotchModelService { ...@@ -135,8 +138,8 @@ public class BarleyNetBlotchModelService {
@PathParam("organizationId") Integer organizationId, @PathParam("organizationId") Integer organizationId,
@QueryParam("timeZone") String timeZoneStr, @QueryParam("timeZone") String timeZoneStr,
@QueryParam("weatherdataType") String weatherdataType, @QueryParam("weatherdataType") String weatherdataType,
@QueryParam("latitude") Double latitude, @QueryParam("latitude") String latitude,
@QueryParam("longitude") Double longitude, @QueryParam("longitude") String longitude,
@QueryParam("weatherStationId") Integer weatherStationId, @QueryParam("weatherStationId") Integer weatherStationId,
@QueryParam("sowingDate") String sowingDateStr, @QueryParam("sowingDate") String sowingDateStr,
@QueryParam("cropId") Integer cropOrganismId, @QueryParam("cropId") Integer cropOrganismId,
...@@ -165,6 +168,8 @@ public class BarleyNetBlotchModelService { ...@@ -165,6 +168,8 @@ public class BarleyNetBlotchModelService {
Date sprayingDate = parseUtil.parseISODate(sprayingDateStr, timeZone); Date sprayingDate = parseUtil.parseISODate(sprayingDateStr, timeZone);
Integer preparationId = parseUtil.parseInteger(preparationIdStr); Integer preparationId = parseUtil.parseInteger(preparationIdStr);
Double preparationDose = parseUtil.parseDouble(preparationDoseStr); Double preparationDose = parseUtil.parseDouble(preparationDoseStr);
Double latitudeDouble = parseUtil.parseDouble(latitude);
Double longitudeDouble = parseUtil.parseDouble(longitude);
// Build model configuration // Build model configuration
ModelConfiguration config = new ModelConfiguration(); ModelConfiguration config = new ModelConfiguration();
...@@ -175,9 +180,11 @@ public class BarleyNetBlotchModelService { ...@@ -175,9 +180,11 @@ public class BarleyNetBlotchModelService {
Date endDateForWeatherData = calculateEndDateForWeatherData(timeZone, sowingDate); Date endDateForWeatherData = calculateEndDateForWeatherData(timeZone, sowingDate);
List<WeatherObservation> observations; List<WeatherObservation> observations;
if("weatherstation".equals(weatherdataType)) {
if (weatherdataType != null && "weatherstation".equals(weatherdataType.trim())) {
PointOfInterestWeatherStation weatherStation = PointOfInterestWeatherStation weatherStation =
em.find(PointOfInterestWeatherStation.class, weatherStationId); em.find(PointOfInterestWeatherStation.class, weatherStationId);
LOGGER.info("Run model with weatherdata from weatherstation {}", weatherStation.getName());
try { try {
observations = wsdUtil.getWeatherObservations( observations = wsdUtil.getWeatherObservations(
weatherStation, weatherStation,
...@@ -198,8 +205,9 @@ public class BarleyNetBlotchModelService { ...@@ -198,8 +205,9 @@ public class BarleyNetBlotchModelService {
} }
} else { } else {
PointOfInterest coordinates = new PointOfInterest(); PointOfInterest coordinates = new PointOfInterest();
coordinates.setLatitude(latitude); coordinates.setLatitude(latitudeDouble);
coordinates.setLongitude(longitude); coordinates.setLongitude(longitudeDouble);
LOGGER.info("Run model with weatherdata for latitude={} and longitude={}", latitude, longitude);
try { try {
observations = wsdUtil.getWeatherObservations( observations = wsdUtil.getWeatherObservations(
"https://weather.vips.nibio.no/rest/grid/openmeteo/" + coordinates.getLongitude() + "_" + coordinates.getLatitude(), "https://weather.vips.nibio.no/rest/grid/openmeteo/" + coordinates.getLongitude() + "_" + coordinates.getLatitude(),
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment