public static Coordinate [ ] removeRepeatedCoordinates ( Coordinate [ ] coords , double tolerance , boolean duplicateFirstLast ) { ArrayList < Coordinate > finalCoords = new ArrayList < Coordinate > ( ) ; Coordinate prevCoord = coords [ 0 ] ; finalCoords . add ( prevCoord ) ; Coordinate firstCoord = prevCoord ; int nbCoords = coords . length ; for ( int i = 1 ; i < nbCoords ; i ++ ) { Coordinate currentCoord = coords [ i ] ; if ( currentCoord . distance ( prevCoord ) <= tolerance ) { continue ; } finalCoords . add ( currentCoord ) ; prevCoord = currentCoord ; } if ( ! duplicateFirstLast ) { if ( firstCoord . distance ( prevCoord ) <= tolerance ) { finalCoords . remove ( finalCoords . size ( ) - 1 ) ; } } else { finalCoords . add ( firstCoord ) ; } return finalCoords . toArray ( new Coordinate [ 0 ] ) ; }
Remove repeated coordinates according a given tolerance