def test_set_coords_0dim(): # a geometry input returns a geometry actual = set_coordinates(point, [[1, 1]]) assert isinstance(actual, shapely.Geometry) # a 0-dim array input returns a 0-dim array actual = set_coordinates(np.asarray(point), [[1, 1]]) assert isinstance(actual, np.ndarray) assert actual.ndim == 0
def test_set_coords(geoms, count, has_ring, include_z): arr_geoms = np.array(geoms, np.object_) n = 3 if include_z else 2 coords = get_coordinates(arr_geoms, include_z=include_z) + np.random.random((1, n)) new_geoms = set_coordinates(arr_geoms, coords) assert_equal(coords, get_coordinates(new_geoms, include_z=include_z))
def test_set_coords_mixed_dimension(include_z): geoms = np.array([point, point_z], dtype=object) coords = get_coordinates(geoms, include_z=include_z) new_geoms = set_coordinates(geoms, coords * 2) if include_z: # preserve original dimensionality assert not shapely.has_z(new_geoms[0]) assert shapely.has_z(new_geoms[1]) else: # all 2D assert not shapely.has_z(new_geoms).any()
def test_set_coords_breaks_ring(): with pytest.raises(shapely.GEOSException): set_coordinates(linear_ring, np.random.random((5, 2)))
def test_set_coords_nan(): geoms = np.array([point]) coords = np.array([[np.nan, np.inf]]) new_geoms = set_coordinates(geoms, coords) assert_equal(coords, get_coordinates(new_geoms))