def test_get_precision(): geometries = all_types + (point_z, empty_point, empty_line_string, empty_polygon) # default is 0 actual = shapely.get_precision(geometries).tolist() assert actual == [0] * len(geometries) geometry = shapely.set_precision(geometries, 1) actual = shapely.get_precision(geometry).tolist() assert actual == [1] * len(geometries)
def test_set_precision_intersection(): """Operations should use the most precise presision grid size of the inputs""" box1 = shapely.normalize(shapely.box(0, 0, 0.9, 0.9)) box2 = shapely.normalize(shapely.box(0.75, 0, 1.75, 0.75)) assert shapely.get_precision(shapely.intersection(box1, box2)) == 0 # GEOS will use and keep the most precise precision grid size box1 = shapely.set_precision(box1, 0.5) box2 = shapely.set_precision(box2, 1) out = shapely.intersection(box1, box2) assert shapely.get_precision(out) == 0.5 assert_geometries_equal(out, shapely.Geometry("LINESTRING (1 1, 1 0)"))
def test_set_precision(mode): initial_geometry = shapely.Geometry("POINT (0.9 0.9)") assert shapely.get_precision(initial_geometry) == 0 geometry = shapely.set_precision(initial_geometry, 0, mode=mode) assert shapely.get_precision(geometry) == 0 assert_geometries_equal(geometry, initial_geometry) geometry = shapely.set_precision(initial_geometry, 1, mode=mode) assert shapely.get_precision(geometry) == 1 assert_geometries_equal(geometry, shapely.Geometry("POINT (1 1)")) # original should remain unchanged assert_geometries_equal(initial_geometry, shapely.Geometry("POINT (0.9 0.9)"))
def test_set_precision_z(mode): with warnings.catch_warnings(): warnings.simplefilter( "ignore") # GEOS <= 3.9 emits warning for 'pointwise' geometry = shapely.set_precision( shapely.Geometry("POINT Z (0.9 0.9 0.9)"), 1, mode=mode) assert shapely.get_precision(geometry) == 1 assert_geometries_equal(geometry, shapely.Geometry("POINT Z (1 1 0.9)"))
def test_get_precision_none(): assert np.all(np.isnan(shapely.get_precision([None])))