def test_equals_exact_tolerance(): # specifying tolerance p1 = pygeos.points(50, 4) p2 = pygeos.points(50.1, 4.1) actual = pygeos.equals_exact([p1, p2, None], p1, tolerance=0.05) np.testing.assert_allclose(actual, [True, False, False]) assert actual.dtype == np.bool_ actual = pygeos.equals_exact([p1, p2, None], p1, tolerance=0.2) np.testing.assert_allclose(actual, [True, True, False]) assert actual.dtype == np.bool_ # default value for tolerance assert pygeos.equals_exact(p1, p1).item() is True assert pygeos.equals_exact(p1, p2).item() is False
def test_get_parts(geom): expected_num_parts = pygeos.get_num_geometries(geom) expected_parts = pygeos.get_geometry(geom, range(0, expected_num_parts)) parts = pygeos.get_parts(geom) assert len(parts) == expected_num_parts assert np.all(pygeos.equals_exact(parts, expected_parts))
def test_pickle(geom): if pygeos.get_type_id(geom) == 2: # Linearrings get converted to linestrings expected = pygeos.linestrings(pygeos.get_coordinates(geom)) else: expected = geom pickled = pickle.dumps(geom) assert pygeos.equals_exact(pickle.loads(pickled), expected)
def test_line_interpolate_point_geom_array(): actual = pygeos.line_interpolate_point( [line_string, linear_ring, multi_line_string], -1) assert pygeos.equals(actual[0], pygeos.Geometry("POINT (1 0)")) assert pygeos.equals(actual[1], pygeos.Geometry("POINT (0 1)")) assert pygeos.equals_exact(actual[2], pygeos.Geometry("POINT (0.5528 1.1056)"), tolerance=0.001)
def test_get_parts_geometry_collection_multi(): """On the first pass, the individual Multi* geometry objects are returned from the collection. On the second pass, the individual singular geometry objects within those are returned. """ geom = pygeos.geometrycollections([multi_point, multi_line_string, multi_polygon]) expected_num_parts = pygeos.get_num_geometries(geom) expected_parts = pygeos.get_geometry(geom, range(0, expected_num_parts)) parts = pygeos.get_parts(geom) assert len(parts) == expected_num_parts assert np.all(pygeos.equals_exact(parts, expected_parts)) expected_subparts = [] for g in np.asarray(expected_parts): for i in range(0, pygeos.get_num_geometries(g)): expected_subparts.append(pygeos.get_geometry(g, i)) subparts = pygeos.get_parts(parts) assert len(subparts) == len(expected_subparts) assert np.all(pygeos.equals_exact(subparts, expected_subparts))
def test_get_parts_array(): # note: this also verifies that None is handled correctly # in the mix; internally it returns -1 for count of geometries geom = np.array([None, empty_line_string, multi_point, point, multi_polygon]) expected_parts = [] for g in geom: for i in range(0, pygeos.get_num_geometries(g)): expected_parts.append(pygeos.get_geometry(g, i)) parts = pygeos.get_parts(geom) assert len(parts) == len(expected_parts) assert np.all(pygeos.equals_exact(parts, expected_parts))
def test_get_parts_return_index(): geom = np.array([multi_point, point, multi_polygon]) expected_parts = [] expected_index = [] for i, g in enumerate(geom): for j in range(0, pygeos.get_num_geometries(g)): expected_parts.append(pygeos.get_geometry(g, j)) expected_index.append(i) parts, index = pygeos.get_parts(geom, return_index=True) assert len(parts) == len(expected_parts) assert np.all(pygeos.equals_exact(parts, expected_parts)) assert np.array_equal(index, expected_index)
def test_get_rings_return_index(): geom = np.array([polygon, None, empty_polygon, polygon_with_hole]) expected_parts = [] expected_index = [] for i, g in enumerate(geom): if g is None or pygeos.is_empty(g): continue expected_parts.append(pygeos.get_exterior_ring(g)) expected_index.append(i) for j in range(0, pygeos.get_num_interior_rings(g)): expected_parts.append(pygeos.get_interior_ring(g, j)) expected_index.append(i) parts, index = pygeos.get_rings(geom, return_index=True) assert len(parts) == len(expected_parts) assert np.all(pygeos.equals_exact(parts, expected_parts)) assert np.array_equal(index, expected_index)
def test_get_parts_non_multi(geom): """Non-multipart geometries should be returned identical to inputs""" assert np.all(pygeos.equals_exact(np.asarray(geom), pygeos.get_parts(geom)))