def set_precision_preserve_topology(preserve_topology): # the preserve_topology kwarg is deprecated (ignored) with pytest.warns(UserWarning): actual = shapely.set_precision( shapely.Geometry("LINESTRING (0 0, 0.1 0.1)"), 1.0, preserve_topology=preserve_topology, ) assert_geometries_equal(shapely.force_2d(actual), shapely.Geometry("LINESTRING EMPTY"))
def set_precision_pointwise_pre_310(): # using 'pointwise' emits a warning with pytest.warns(UserWarning): actual = shapely.set_precision( shapely.Geometry("LINESTRING (0 0, 0.1 0.1)"), 1.0, mode="pointwise", ) assert_geometries_equal(shapely.force_2d(actual), shapely.Geometry("LINESTRING EMPTY"))
def test_set_precision_collapse(geometry, mode, expected): """Lines and polygons collapse to empty geometries if vertices are too close""" actual = shapely.set_precision(geometry, 1, mode=mode) if shapely.geos_version < (3, 9, 0): # pre GEOS 3.9 has difficulty comparing empty geometries exactly # normalize and compare by WKT instead assert shapely.to_wkt(shapely.normalize(actual)) == shapely.to_wkt( shapely.normalize(expected)) else: # force to 2D because GEOS 3.10 yields 3D geometries when they are empty. assert_geometries_equal(shapely.force_2d(actual), expected)
def test_force_2d(geom, expected): actual = shapely.force_2d(geom) assert shapely.get_coordinate_dimension(actual) == 2 assert_geometries_equal(actual, expected)