public static double getLength ( Geometry geometry ) { double length = 0 ; if ( geometry . getGeometries ( ) != null ) { for ( Geometry child : geometry . getGeometries ( ) ) { length += getLength ( child ) ; } } if ( geometry . getCoordinates ( ) != null && ( Geometry . LINE_STRING . equals ( geometry . getGeometryType ( ) ) || Geometry . LINEAR_RING . equals ( geometry . getGeometryType ( ) ) ) ) { for ( int i = 0 ; i < geometry . getCoordinates ( ) . length - 1 ; i ++ ) { double deltaX = geometry . getCoordinates ( ) [ i + 1 ] . getX ( ) - geometry . getCoordinates ( ) [ i ] . getX ( ) ; double deltaY = geometry . getCoordinates ( ) [ i + 1 ] . getY ( ) - geometry . getCoordinates ( ) [ i ] . getY ( ) ; length += Math . sqrt ( deltaX * deltaX + deltaY * deltaY ) ; } } return length ; }
Return the length of the geometry . This adds up the length of all edges within the geometry .