diff --git a/src/main/java/no/nibio/vips/gis/GISUtil.java b/src/main/java/no/nibio/vips/gis/GISUtil.java index a009737be501ef04ea8fe917062855dcfe523456..c7c2ca55aa1843a7dd6e0950d449ae1c029da700 100644 --- a/src/main/java/no/nibio/vips/gis/GISUtil.java +++ b/src/main/java/no/nibio/vips/gis/GISUtil.java @@ -267,4 +267,26 @@ public class GISUtil { return null; } } + + public Point getJtsPointFromString(String lonlatCoordinate) throws LonLatStringFormatException + { + String[] xy = lonlatCoordinate.split(","); + if(xy.length != 2) + { + throw new LonLatStringFormatException("Coordinate string must contain [lon,lat], which is not the case here: " + lonlatCoordinate); + } + try + { + Double x = Double.valueOf(xy[0]); + Double y = Double.valueOf(xy[1]); + com.vividsolutions.jts.geom.Coordinate jtsCoordinate = new com.vividsolutions.jts.geom.Coordinate(); + jtsCoordinate.x = x; + jtsCoordinate.y = y; + return createPointWGS84(jtsCoordinate); + } + catch(NumberFormatException ex) + { + throw new LonLatStringFormatException(ex.getMessage()); + } + } } diff --git a/src/main/java/no/nibio/vips/gis/LonLatStringFormatException.java b/src/main/java/no/nibio/vips/gis/LonLatStringFormatException.java new file mode 100644 index 0000000000000000000000000000000000000000..5a4c0782856c6f4ac79452b63716e88c56c9afb8 --- /dev/null +++ b/src/main/java/no/nibio/vips/gis/LonLatStringFormatException.java @@ -0,0 +1,31 @@ +/* + * Copyright (c) 2019 NIBIO <http://www.nibio.no/>. + * + * This file is part of VIPSLogic. + * VIPSLogic 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. + * + * VIPSLogic 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 VIPSLogic. 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 LonLatStringFormatException extends Exception { + public LonLatStringFormatException(String msg) + { + super(msg); + } +}