def test_multipoint(self): # From coordinate tuples geom = MultiPoint(((1.0, 2.0), (3.0, 4.0))) assert len(geom.geoms) == 2 assert dump_coords(geom) == [[(1.0, 2.0)], [(3.0, 4.0)]] # From points geom = MultiPoint((Point(1.0, 2.0), Point(3.0, 4.0))) assert len(geom.geoms) == 2 assert dump_coords(geom) == [[(1.0, 2.0)], [(3.0, 4.0)]] # From another multi-point geom2 = MultiPoint(geom) assert len(geom2.geoms) == 2 assert dump_coords(geom2) == [[(1.0, 2.0)], [(3.0, 4.0)]] # Sub-geometry Access assert isinstance(geom.geoms[0], Point) assert geom.geoms[0].x == 1.0 assert geom.geoms[0].y == 2.0 with pytest.raises(IndexError): # index out of range geom.geoms[2] # Geo interface assert geom.__geo_interface__ == { "type": "MultiPoint", "coordinates": ((1.0, 2.0), (3.0, 4.0)), }
def test_multipoint_array_coercion(): geom = MultiPoint(((1.0, 2.0), (3.0, 4.0))) arr = np.array(geom) assert arr.ndim == 0 assert arr.size == 1 assert arr.dtype == np.dtype("object") assert arr.item() == geom
def test_multipoint(): g = MultiPoint([(1, 2), (3, 4)]) assert hash(g) == hash(MultiPoint([(1, 2), (3, 4)])) assert hash(g) != hash(MultiPoint([(1, 2), (3, 3)]))
def test_len_raises(): geom = MultiPoint([[5.0, 6.0], [7.0, 8.0]]) with pytest.raises(TypeError): len(geom)
def test_numpy_object_array(): geom = MultiPoint(((1.0, 2.0), (3.0, 4.0))) ar = np.empty(1, object) ar[:] = [geom] assert ar[0] == geom
def test_create_multi_with_empty_component(self): msg = "Can't create MultiPoint with empty component" with pytest.raises(EmptyPartError, match=msg): MultiPoint([Point(0, 0), Point()]).wkt
def test_multipoint_from_numpy(self): # Construct from a numpy array geom = MultiPoint(np.array([[0.0, 0.0], [1.0, 2.0]])) assert isinstance(geom, MultiPoint) assert len(geom.geoms) == 2 assert dump_coords(geom) == [[(0.0, 0.0)], [(1.0, 2.0)]]
def test_empty_multipoint(self): assert MultiPoint().is_empty
def test_numpy_object_array(): geoms = [Point(), GeometryCollection()] arr = np.empty(2, object) arr[:] = geoms def test_shape_empty(): empty_mp = MultiPolygon() empty_json = mapping(empty_mp) empty_shape = shape(empty_json) assert empty_shape.is_empty @pytest.mark.parametrize( "geom", [ Point(), LineString(), Polygon(), MultiPoint(), MultiLineString(), MultiPolygon(), GeometryCollection(), LinearRing(), ], ) def test_empty_geometry_bounds(geom): """The bounds of an empty geometry is a tuple of NaNs""" assert len(geom.bounds) == 4 assert all(math.isnan(v) for v in geom.bounds)
def test_point(): assert bool(Point()) is False def test_geometry_collection(): assert bool(GeometryCollection()) is False geometries_all_types = [ Point(1, 1), LinearRing([(0, 0), (1, 1), (0, 1), (0, 0)]), LineString([(0, 0), (1, 1), (0, 1), (0, 0)]), Polygon([(0, 0), (1, 1), (0, 1), (0, 0)]), MultiPoint([(1, 1)]), MultiLineString([[(0, 0), (1, 1), (0, 1), (0, 0)]]), MultiPolygon([Polygon([(0, 0), (1, 1), (0, 1), (0, 0)])]), GeometryCollection([Point(1, 1)]), ] @pytest.mark.parametrize("geom", geometries_all_types) def test_setattr_disallowed(geom): with pytest.raises(AttributeError): geom.name = "test" @pytest.mark.parametrize("geom", geometries_all_types) def test_comparison_notimplemented(geom): # comparing to a non-geometry class should return NotImplemented in __eq__