Given an iterable of features
    return a string encoded in waypoint-style used by certain mapbox APIs
    ("lon,lat" pairs separated by ";")

def encode_waypoints(features, min_limit=None, max_limit=None, precision=6):
    """Given an iterable of features
    return a string encoded in waypoint-style used by certain mapbox APIs
    ("lon,lat" pairs separated by ";")
    """
    coords = ['{lon},{lat}'.format(
                  lon=float(round(lon, precision)),
                  lat=float(round(lat, precision)))
              for lon, lat in read_points(features)]

    if min_limit is not None and len(coords) < min_limit:
        raise InvalidFeatureError(
            "Not enough features to encode coordinates, "
            "need at least {0}".format(min_limit))
    if max_limit is not None and len(coords) > max_limit:
        raise InvalidFeatureError(
            "Too many features to encode coordinates, "
            "need at most {0}".format(max_limit))

    return ';'.join(coords)