def test_super_function_extract(self): data = geometry.GeometryCollection([ geometry.Polygon([[0, 0], [1, 0], [1, 1], [0, 1], [0, 0]]), geometry.Polygon([[1, 0], [2, 0], [2, 1], [1, 1], [1, 0]]) ]) topo = Join(data).to_dict() self.assertEqual(list(topo.keys()), ["type", "linestrings", "bookkeeping_geoms", "objects", "options","bbox", "junctions"])
def test_join_super_function_extract(): data = geometry.GeometryCollection([ geometry.Polygon([[0, 0], [1, 0], [1, 1], [0, 1], [0, 0]]), geometry.Polygon([[1, 0], [2, 0], [2, 1], [1, 1], [1, 0]]), ]) topo = Join(data).to_dict() assert len(list(topo.keys())) == 9
def test_join_line_DBE_share_singe_midpoint_line_ABC(): data = { "abc": {"type": "LineString", "coordinates": [[0, 0], [1, 0], [2, 0]]}, "dbe": {"type": "LineString", "coordinates": [[0, 1], [1, 0], [2, 1]]}, } topo = Join(data).to_dict() assert topo["junctions"] == []
def test_join_single_ring_ABCA(): data = { "abca": {"type": "LineString", "coordinates": [[0, 0], [1, 0], [1, 1], [0, 0]]} } topo = Join(data).to_dict() assert topo["junctions"] == []
def test_join_ring_ABCA_is_closed(): data = { "abca": {"type": "Polygon", "coordinates": [[[0, 0], [1, 0], [0, 1], [0, 0]]]} } topo = Join(data).to_dict() assert topo["junctions"] == []
def test_line_DBE_share_singe_midpoint_line_ABC(self): data = { "abc": {"type": "LineString", "coordinates": [[0, 0], [1, 0], [2, 0]]}, "dbe": {"type": "LineString", "coordinates": [[0, 1], [1, 0], [2, 1]]}, } topo = Join(data).to_dict() self.assertListEqual(topo["junctions"], [])
def test_join_rotated_duplicate_rings(): data = { "abca": {"type": "Polygon", "coordinates": [[[0, 0], [1, 1], [2, 0], [0, 0]]]}, "bcab": {"type": "Polygon", "coordinates": [[[1, 1], [2, 0], [0, 0], [1, 1]]]}, } topo = Join(data).to_dict() assert topo["junctions"] == []
def test_join_linemerge_multilinestring(): data = [ {"type": "LineString", "coordinates": [(0, 0), (10, 0), (10, 5), (20, 5)]}, { "type": "LineString", "coordinates": [ (5, 0), (25, 0), (25, 5), (16, 5), (16, 10), (14, 10), (14, 5), (0, 5), ], }, ] topo = Join(data).to_dict() assert len(topo["linestrings"]) == 2 assert len(topo["junctions"]) == 7 # test the shared_paths_approach using dicts def test_join_shared_paths_dict(): data = { "cba": {"type": "LineString", "coordinates": [[2, 0], [1, 0], [0, 0]]}, "ab": {"type": "LineString", "coordinates": [[0, 0], [1, 0]]}, } topo = Join(data, options={"shared_paths": "dict"}).to_dict() assert geometry.MultiPoint(topo["junctions"]).equals( geometry.MultiPoint([(0.0, 0.0), (1.0, 0.0)]) )
def test_line_ADE_share_starts_with_ABC(self): data = { "ade": {"type": "LineString", "coordinates": [[0, 0], [1, 0], [2, 0]]}, "abc": {"type": "LineString", "coordinates": [[0, 0], [1, 1], [2, 1]]}, } topo = Join(data).to_dict() self.assertListEqual(topo["junctions"], [])
def test_join_coincident_ring_ABCA_and_line_DBE_share_B(): data = { "abca": {"type": "Polygon", "coordinates": [[[0, 0], [1, 0], [0, 1], [0, 0]]]}, "dbe": {"type": "LineString", "coordinates": [[2, 1], [1, 0], [2, 2]]}, } topo = Join(data).to_dict() assert topo["junctions"] == []
def test_join_shared_segment_partly_start_partly_end_segment(): data = geopandas.read_file( geopandas.datasets.get_path("naturalearth_lowres")) data = data[(data.name == "Eritrea") | (data.name == "Ethiopia") | (data.name == "Sudan")] topo = Join(data).to_dict() assert len(topo["junctions"]) == 6
def test_join_reversed_line_CBA_extends_new_line_AB(): data = { "cba": {"type": "LineString", "coordinates": [[2, 0], [1, 0], [0, 0]]}, "ab": {"type": "LineString", "coordinates": [[0, 0], [1, 0]]}, } topo = Join(data).to_dict() assert geometry.Point(1.0, 0.0) in geometry.MultiPoint(topo["junctions"])
def test_join_line_ADE_share_starts_with_ABC(): data = { "ade": {"type": "LineString", "coordinates": [[0, 0], [1, 0], [2, 0]]}, "abc": {"type": "LineString", "coordinates": [[0, 0], [1, 1], [2, 1]]}, } topo = Join(data).to_dict() assert topo["junctions"] == []
def test_join_reversed_duplicate_lines_junction_endpoints(): data = { "abc": {"type": "LineString", "coordinates": [[0, 0], [1, 0], [2, 0]]}, "cba": {"type": "LineString", "coordinates": [[2, 0], [1, 0], [0, 0]]}, } topo = Join(data).to_dict() assert topo["junctions"] == []
def test_join_undefined_for_non_junction_points(): data = { "cba": {"type": "LineString", "coordinates": [[2, 0], [1, 0], [0, 0]]}, "ab": {"type": "LineString", "coordinates": [[0, 0], [2, 0]]}, } topo = Join(data).to_dict() assert geometry.Point(1.0, 0.0) not in geometry.MultiPoint(topo["junctions"])
def test_join_shared_junctions_in_shared_paths(): data = geopandas.read_file( geopandas.datasets.get_path("naturalearth_lowres")) data = data[(data.name == "Togo") | (data.name == "Benin") | (data.name == "Burkina Faso")] topo = Join(data).to_dict() assert len(topo["junctions"]) == 6
def test_join_coincident_rings_ABCA_BACB_share_BCAB(): data = { "abca": {"type": "Polygon", "coordinates": [[[0, 0], [1, 0], [0, 1], [0, 0]]]}, "bacb": {"type": "Polygon", "coordinates": [[[1, 0], [0, 0], [0, 1], [1, 0]]]}, } topo = Join(data).to_dict() assert topo["junctions"] == []
def test_join_exact_duplicate_rings_ABCA_ACBA_share_ABCA(): data = { "abca": {"type": "Polygon", "coordinates": [[[0, 0], [1, 0], [0, 1], [0, 0]]]}, "acba": {"type": "Polygon", "coordinates": [[[0, 0], [0, 1], [1, 0], [0, 0]]]}, } topo = Join(data).to_dict() assert topo["junctions"] == []
def test_reversed_duplicate_lines_junction_endpoints(self): data = { "abc": {"type": "LineString", "coordinates": [[0, 0], [1, 0], [2, 0]]}, "cba": {"type": "LineString", "coordinates": [[2, 0], [1, 0], [0, 0]]}, } topo = Join(data).to_dict() # print(topo) self.assertListEqual(topo["junctions"], [])
def test_join_prequantize_points(): data = [ {"type": "Polygon", "coordinates": [[[0, 0], [1, 0], [1, 1], [0, 1], [0, 0]]]}, {"type": "Point", "coordinates": [-0.5, 1.5]}, ] topo = Join(data, options={"prequantize": True}).to_dict() assert topo["bbox"] == (-0.5, 0.0, 1.0, 1.5)
def test_join_linemerge_multilinestring(): data = [ { "type": "LineString", "coordinates": [(0, 0), (10, 0), (10, 5), (20, 5)] }, { "type": "LineString", "coordinates": [ (5, 0), (25, 0), (25, 5), (16, 5), (16, 10), (14, 10), (14, 5), (0, 5), ], }, ] topo = Join(data).to_dict() assert len(topo["linestrings"]) == 2 assert len(topo["junctions"]) == 7 # test the shared_paths_approach using dicts def test_join_shared_paths_dict(): data = { "cba": { "type": "LineString", "coordinates": [[2, 0], [1, 0], [0, 0]] }, "ab": { "type": "LineString", "coordinates": [[0, 0], [1, 0]] }, } topo = Join(data, options={"shared_coords": True}).to_dict() assert geometry.MultiPoint(topo["junctions"]).equals( geometry.MultiPoint([(0.0, 0.0), (1.0, 0.0)])) # test a list of two invalid geometric objects with prequantize True def test_join_invalid_prequantize(): data = [ { "type": "MultiPolygon", "coordinates": [[[0, 0], [1, 0], [1, 1], [0, 1], [0, 0]]], }, { "type": "MultiPolygon", "coordinates": [[[0, 0], [1, 0], [1, 1], [0, 1], [0, 0]]], }, ] topo = Join(data, options={"prequantize": True}).to_dict() assert len(topo["junctions"]) == 0
def test_single_ring_ABCA(self): data = { "abca": { "type": "LineString", "coordinates": [[0, 0], [1, 0], [1, 1], [0, 0]], } } topo = Join(data).to_dict() self.assertListEqual(topo["junctions"], [])
def test_line_ABCDBD_self_intersects_with_end(self): data = { "abcdbd": { "type": "LineString", "coordinates": [[0, 0], [1, 0], [4, 0], [3, 0], [4, 0]], } } topo = Join(data).to_dict() self.assertListEqual(topo["junctions"], [])
def test_line_ABC_extends_line_BA(self): data = { "ba": {"type": "LineString", "coordinates": [[1, 0], [0, 0]]}, "abc": {"type": "LineString", "coordinates": [[0, 0], [1, 0], [2, 0]]}, } topo = Join(data).to_dict() self.assertTrue( geometry.MultiPoint(topo["junctions"]).equals( geometry.MultiPoint([(1.0, 0.0), (0.0, 0.0)])))
def test_true_for_junction_points(self): data = { "cba": {"type": "LineString", "coordinates": [[2, 0], [1, 0], [0, 0]]}, "ab": {"type": "LineString", "coordinates": [[0, 0], [1, 0]]}, } topo = Join(data).to_dict() self.assertTrue(geometry.MultiPoint([ (0.0, 0.0),(1.0, 0.0),(2.0, 0.0) ]).equals(geometry.MultiPoint(topo["junctions"])))
def test_ring_ABCA_is_closed(self): data = { "abca": { "type": "Polygon", "coordinates": [[[0, 0], [1, 0], [0, 1], [0, 0]]], } } topo = Join(data).to_dict() self.assertListEqual(topo["junctions"], [])
def test_undefined_for_non_junction_points(self): data = { "cba": {"type": "LineString", "coordinates": [[2, 0], [1, 0], [0, 0]]}, "ab": {"type": "LineString", "coordinates": [[0, 0], [2, 0]]}, } topo = Join(data).to_dict() # print(topo) self.assertFalse( geometry.Point(1.0, 0.0) in geometry.MultiPoint(topo["junctions"]) )
def test_join_line_ABCDBD_self_intersects_with_end(): data = { "abcdbd": { "type": "LineString", "coordinates": [[0, 0], [1, 0], [4, 0], [3, 0], [4, 0]], } } topo = Join(data).to_dict() assert topo["junctions"] == []
def test_line_ABCDB_self_intersects(self): data = { "abcdbe": { "type": "LineString", "coordinates": [[0, 0], [1, 0], [2, 0], [3, 0], [1, 0], [4, 0]], }, "fbg": {"type": "LineString", "coordinates": [[0, 1], [1, 0], [2, 1]]}, } topo = Join(data).to_dict() self.assertListEqual(topo["junctions"], [])
def test_coincident_ring_ABCA_and_line_DBE_share_B(self): data = { "abca": { "type": "Polygon", "coordinates": [[[0, 0], [1, 0], [0, 1], [0, 0]]], }, "dbe": {"type": "LineString", "coordinates": [[2, 1], [1, 0], [2, 2]]}, } topo = Join(data).to_dict() self.assertListEqual(topo["junctions"], [])