public static List < Coordinate > getCoordinatesAtInterval ( LineString line , double interval , boolean keepExisting , double startFrom , double endAt ) { if ( interval <= 0 ) { throw new IllegalArgumentException ( "Interval needs to be > 0." ) ; } double length = line . getLength ( ) ; if ( startFrom < 0 ) { startFrom = 0.0 ; } if ( endAt < 0 ) { endAt = length ; } List < Coordinate > coordinatesList = new ArrayList < Coordinate > ( ) ; LengthIndexedLine indexedLine = new LengthIndexedLine ( line ) ; Coordinate [ ] existingCoordinates = null ; double [ ] indexOfExisting = null ; if ( keepExisting ) { existingCoordinates = line . getCoordinates ( ) ; indexOfExisting = new double [ existingCoordinates . length ] ; int i = 0 ; for ( Coordinate coordinate : existingCoordinates ) { double indexOf = indexedLine . indexOf ( coordinate ) ; indexOfExisting [ i ] = indexOf ; i ++ ; } } double runningLength = startFrom ; int currentIndexOfexisting = 1 ; // jump first while ( runningLength < endAt ) { if ( keepExisting && currentIndexOfexisting < indexOfExisting . length - 1 && runningLength > indexOfExisting [ currentIndexOfexisting ] ) { // add the existing coordinatesList . add ( existingCoordinates [ currentIndexOfexisting ] ) ; currentIndexOfexisting ++ ; continue ; } Coordinate extractedPoint = indexedLine . extractPoint ( runningLength ) ; coordinatesList . add ( extractedPoint ) ; runningLength = runningLength + interval ; } Coordinate extractedPoint = indexedLine . extractPoint ( endAt ) ; coordinatesList . add ( extractedPoint ) ; return coordinatesList ; }
Returns the coordinates at a given interval along the line .