public static double[] fromNationalGrid(String ng){
  String trimmed=ng.trim();
  String ref=trimmed.substring(0,2);
  GridSquare gridSquare=GRID_SQUARES.get(ref);
  if (gridSquare == null) {
    throw new IllegalArgumentException("Invalid NG: " + trimmed);
  }
  List<String> list=WHITESPACE_SPLITTER.splitToList(trimmed.substring(2));
  Double n=null;
  Double e=null;
  if (list.size() >= 2) {
    e=parseDoubleWithCoordPrecision(list.get(0));
    n=parseDoubleWithCoordPrecision(list.get(1));
  }
 else   if (list.size() == 1) {
    String[] ret=splitConsolidated(list.get(0));
    e=parseDoubleWithCoordPrecision(ret[0]);
    n=parseDoubleWithCoordPrecision(ret[1]);
  }
 else {
    throw new IllegalArgumentException("Invalid NG coords " + ng);
  }
  if (n == null || e == null) {
    throw new IllegalArgumentException("Unable to extract NE from " + ng);
  }
  return gridSquare.toEastingNorthing(e,n);
}

public static double [ ] fromNationalGrid ( String ng ) { String trimmed = ng . trim ( ) ; String ref = trimmed . substring ( 0 , 2 ) ; GridSquare gridSquare = GRID_SQUARES . get ( ref ) ; if ( gridSquare == null ) { throw new IllegalArgumentException ( "Invalid NG: " + trimmed ) ; } List < String > list = WHITESPACE_SPLITTER . splitToList ( trimmed . substring ( 2 ) ) ; Double n = null ; Double e = null ; if ( list . size ( ) >= 2 ) { e = parseDoubleWithCoordPrecision ( list . get ( 0 ) ) ; n = parseDoubleWithCoordPrecision ( list . get ( 1 ) ) ; } else if ( list . size ( ) == 1 ) { String [ ] ret = splitConsolidated ( list . get ( 0 ) ) ; e = parseDoubleWithCoordPrecision ( ret [ 0 ] ) ; n = parseDoubleWithCoordPrecision ( ret [ 1 ] ) ; } else { throw new IllegalArgumentException ( "Invalid NG coords " + ng ) ; } if ( n == null || e == null ) { throw new IllegalArgumentException ( "Unable to extract NE from " + ng ) ; } return gridSquare . toEastingNorthing ( e , n ) ; }
convert from a string to northing and easting
