def sample_line_from_center(polyline, length_to_sample):
    """Takes a polyline and samples it a target length using the segmentAlongLine method."""
    line_length = float(polyline.length)
    half_way_point = float(polyline.length) / 2
    start_point = half_way_point - length_to_sample / 2
    end_point = half_way_point + length_to_sample / 2
    if line_length <= length_to_sample / 2:
        start_point = 0
        end_point = line_length
    segment_returned = polyline.segmentAlongLine(start_point, end_point)
    return segment_returned