import java.util.List;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
public class Coordinates {
static class LatLon {
double lat;
double lon;
public LatLon( double lat, double lon ) {
this.lat = lat;
this.lon = lon;
}
@Override public String toString(){ return lat + ", " + lon; }
}
public static void main( String[] args ){
String info =
"LINESTRING (" +
"-79.0578544444577 43.0929133770364, " +
"-79.0559554404751 43.0929995585932, " +
"-79.0540564364926 43.09308574015, " +
"-79.0504086322323 43.0931797561892, " +
"-79.0503228015438 43.0911427096913)";
Pattern p = Pattern.compile( "[^\\(]+\\(([^\\)]+).*" );
Matcher m = p.matcher( info );
if( m.matches()) {
List< LatLon > coordinates = new java.util.LinkedList<>();
String[] coords = m.group( 1 ).split( "," );
for( int i = 0; i < coords.length; ++i ) {
String[] latLon = coords[i].trim().split( " " );
coordinates.add(
new LatLon(
Double.parseDouble( latLon[0] ),
Double.parseDouble( latLon[1] )));
}
System.out.println( coordinates );
}
}
}
输出:
[-79.0578544444577, 43.0929133770364, -79.0559554404751, 43.0929995585932, -79.0540564364926, 43.09308574015, -79.0504086322323, 43.0931797561892, -79.0503228015438, 43.0911427096913]