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