public LineString extractPart ( double startDistance , double endDistance ) { LineString result = new LineString ( ) ; for ( int i = 0 ; i < this . segments . size ( ) ; startDistance -= this . segments . get ( i ) . length ( ) , endDistance -= this . segments . get ( i ) . length ( ) , i ++ ) { LineSegment segment = this . segments . get ( i ) ; // Skip first segments that we don't need double length = segment . length ( ) ; if ( length < startDistance ) { continue ; } Point startPoint = null , endPoint = null ; if ( startDistance >= 0 ) { // This will be our starting point startPoint = segment . pointAlongLineSegment ( startDistance ) ; } if ( endDistance < length ) { // this will be our ending point endPoint = segment . pointAlongLineSegment ( endDistance ) ; } if ( startPoint != null && endPoint == null ) { // This ist the starting segment, end will come in a later segment result . segments . add ( new LineSegment ( startPoint , segment . end ) ) ; } else if ( startPoint == null && endPoint == null ) { // Center segment between start and end segment, add completely result . segments . add ( segment ) ; } else if ( startPoint == null && endPoint != null ) { // End segment, start was in earlier segment result . segments . add ( new LineSegment ( segment . start , endPoint ) ) ; } else if ( startPoint != null && endPoint != null ) { // Start and end on same segment result . segments . add ( new LineSegment ( startPoint , endPoint ) ) ; } if ( endPoint != null ) break ; } return result ; }
Creates a new LineString that consists of only the part between startDistance and endDistance .