public static double getDistanceBetween ( IHMConnection connection , Coordinate p1 , Coordinate p2 , int srid ) throws Exception { if ( srid < 0 ) { srid = 4326 ; } GeometryFactory gf = new GeometryFactory ( ) ; LineString lineString = gf . createLineString ( new Coordinate [ ] { p1 , p2 } ) ; String sql = "select GeodesicLength(LineFromText(\"" + lineString . toText ( ) + "\"," + srid + "));" ; try ( IHMStatement stmt = connection . createStatement ( ) ; IHMResultSet rs = stmt . executeQuery ( sql ) ; ) { if ( rs . next ( ) ) { double length = rs . getDouble ( 1 ) ; return length ; } throw new RuntimeException ( "Could not calculate distance." ) ; } }
Calculates the GeodesicLength between to points .