Пример #1
0
    def __new__(self, points=None):
        if points is None:
            # allow creation of empty multipoints, to support unpickling
            # TODO better empty constructor
            return shapely.from_wkt("MULTIPOINT EMPTY")
        elif isinstance(points, MultiPoint):
            return points

        m = len(points)
        subs = []
        for i in range(m):
            p = point.Point(points[i])
            if p.is_empty:
                raise EmptyPartError(
                    "Can't create MultiPoint with empty component")
            subs.append(p)

        if len(points) == 0:
            return shapely.from_wkt("MULTIPOINT EMPTY")

        return shapely.multipoints(subs)
Пример #2
0
    def __new__(self, points=None):
        """
        Parameters
        ----------
        points : sequence
            A sequence of (x, y [,z]) numeric coordinate pairs or triples or a
            sequence of objects that implement the numpy array interface,
            including instances of Point.

        Example
        -------
        Construct a 2 point collection

          >>> from shapely.geometry import Point
          >>> ob = MultiPoint([[0.0, 0.0], [1.0, 2.0]])
          >>> len(ob.geoms)
          2
          >>> type(ob.geoms[0]) == Point
          True
        """
        if points is None:
            # allow creation of empty multipoints, to support unpickling
            # TODO better empty constructor
            return shapely.from_wkt("MULTIPOINT EMPTY")
        elif isinstance(points, MultiPoint):
            return points

        m = len(points)
        subs = []
        for i in range(m):
            p = point.Point(points[i])
            if p.is_empty:
                raise EmptyPartError(
                    "Can't create MultiPoint with empty component")
            subs.append(p)

        if len(points) == 0:
            return shapely.from_wkt("MULTIPOINT EMPTY")

        return shapely.multipoints(subs)
Пример #3
0
def test_repr_multipoint_with_point_empty():
    # Test if segfault is prevented
    geom = shapely.multipoints([point, empty_point])
    assert repr(geom) == "<shapely.MultiPoint Exception in WKT writer>"
Пример #4
0
def test_to_wkt_multipoint_with_point_empty_errors():
    # test if segfault is prevented
    geom = shapely.multipoints([empty_point, point])
    with pytest.raises(ValueError):
        shapely.to_wkt(geom)
Пример #5
0
def test_to_wkt_multipoint_with_point_empty():
    geom = shapely.multipoints([empty_point, point])
    assert shapely.to_wkt(geom) == "MULTIPOINT (EMPTY, 2 3)"
Пример #6
0
    assert shapely.to_wkb(actual, hex=True, byte_order=1) == wkb
    assert shapely.to_wkb(actual, hex=True, include_srid=True,
                          byte_order=1) == ewkb

    point = shapely.points(1, 1)
    point_with_srid = shapely.set_srid(point, np.int32(4326))
    result = shapely.to_wkb(point_with_srid, include_srid=True, byte_order=1)
    assert np.frombuffer(result[5:9], "<u4").item() == 4326


@pytest.mark.parametrize(
    "geom,expected",
    [
        (empty_point, POINT_NAN_WKB),
        (empty_point_z, POINT_NAN_WKB),
        (shapely.multipoints([empty_point]), MULTIPOINT_NAN_WKB),
        (shapely.multipoints([empty_point_z]), MULTIPOINT_NAN_WKB),
        (shapely.geometrycollections([empty_point
                                      ]), GEOMETRYCOLLECTION_NAN_WKB),
        (shapely.geometrycollections([empty_point_z
                                      ]), GEOMETRYCOLLECTION_NAN_WKB),
        (
            shapely.geometrycollections([shapely.multipoints([empty_point])]),
            NESTED_COLLECTION_NAN_WKB,
        ),
        (
            shapely.geometrycollections([shapely.multipoints([empty_point_z])
                                         ]),
            NESTED_COLLECTION_NAN_WKB,
        ),
    ],
Пример #7
0
import shapely

shapely20_todo = pytest.mark.xfail(
    strict=False, reason="Not yet implemented for Shapely 2.0"
)

point_polygon_testdata = (
    shapely.points(np.arange(6), np.arange(6)),
    shapely.box(2, 2, 4, 4),
)
point = shapely.points(2, 3)
line_string = shapely.linestrings([(0, 0), (1, 0), (1, 1)])
linear_ring = shapely.linearrings([(0, 0), (1, 0), (1, 1), (0, 1), (0, 0)])
polygon = shapely.polygons([(0, 0), (2, 0), (2, 2), (0, 2), (0, 0)])
multi_point = shapely.multipoints([(0, 0), (1, 2)])
multi_line_string = shapely.multilinestrings([[(0, 0), (1, 2)]])
multi_polygon = shapely.multipolygons(
    [
        [(0, 0), (1, 0), (1, 1), (0, 1), (0, 0)],
        [(2.1, 2.1), (2.2, 2.1), (2.2, 2.2), (2.1, 2.2), (2.1, 2.1)],
    ]
)
geometry_collection = shapely.geometrycollections(
    [shapely.points(51, -1), shapely.linestrings([(52, -1), (49, 2)])]
)
point_z = shapely.points(2, 3, 4)
line_string_z = shapely.linestrings([(0, 0, 4), (1, 0, 4), (1, 1, 4)])
polygon_z = shapely.polygons([(0, 0, 4), (2, 0, 4), (2, 2, 4), (0, 2, 4), (0, 0, 4)])
geometry_collection_z = shapely.geometrycollections([point_z, line_string_z])
polygon_with_hole = shapely.Geometry(
Пример #8
0
def test_multipoints():
    actual = shapely.multipoints(np.array([point], dtype=object),
                                 indices=np.zeros(1, dtype=np.intp))
    assert_geometries_equal(actual, shapely.multipoints([point]))