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

Added lonlat string conversion utility method

parent 3fed32b9
No related branches found
No related tags found
No related merge requests found
......@@ -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());
}
}
}
/*
* 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);
}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment