Esempio n. 1
0
    def maybe(cls, x):
        if isinstance(x, Rectangle):
            return x

        if com.is_listlike_2elem(x):
            x = com._flatten_list_of_listlike(x)
        if com.is_listlike(x) and len(x) == 4:
            return Rectangle.fromDegrees(*x)
        return x
Esempio n. 2
0
    def fromDegreesArray(cls, x):
        # convert shaply.Polygon to coordinateslist
        x = shapefile._maybe_shapely_polygon(x)
        x = shapefile._maybe_shapely_line(x)
        x = geocode._maybe_geocode(x, height=0)

        if com.is_listlike_2elem(x):
            x = com._flatten_list_of_listlike(x)
        elif com.is_listlike_3elem(x):
            raise NotImplementedError

        return Cartesian3Array(x)
Esempio n. 3
0
def _maybe_cartesian2_list(x, key):
    """
    Convert list or tuple to list of Cartesian2 instances. Used by PolylineVolume
    """
    if com.is_listlike(x):
        if all(isinstance(e, Cartesian2) for e in x):
            return x
        elif all(isinstance(e, _Cartesian) for e in x):
            # for better error message
            msg = '{key} must be a listlike of Cartesian2: {x}'
            raise ValueError(msg.format(key=key, x=x))

        if com.is_listlike_2elem(x):
            x = com._flatten_list_of_listlike(x)

    x = com.validate_listlike_even(x, key=key)
    x = [Cartesian2(i, j) for (i, j) in zip(x[::2], x[1::2])]
    return x