def test_dedup_super_function(): 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 = Dedup(data).to_dict() assert len(list(topo.keys())) == 12
def test_dedup_merge_continous(): data = [ { "type": "LineString", "coordinates": [(1, 0), (2, 0), (3, 0), (4, 0), (5, 0)] }, { "type": "LineString", "coordinates": [ (5, 0), (4, -1), (4, 0), (4, 1), (3, 1), (3, 0), (2, 1), (2, 0), (1, 0), (1, 1), ], }, ] topo = Dedup(data, options={"prequantize": False}).to_dict() assert len(topo["linestrings"]) == 6 assert len(topo["junctions"]) == 5
def test_dedup_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 = Dedup(data).to_dict() assert len(topo["linestrings"]) == 9 assert len(topo["junctions"]) == 7
def test_no_shared_paths_in_geoms(self): data = geopandas.read_file( geopandas.datasets.get_path("naturalearth_lowres")) data = data[(data.name == "Togo") | (data.name == "Liberia")] topo = Dedup(data).to_dict() self.assertEqual(len(topo["bookkeeping_shared_arcs"]), 0) self.assertEqual(len(topo["bookkeeping_duplicates"]), 0)
def test_dedup_topology_false(): data = geopandas.read_file( geopandas.datasets.get_path("naturalearth_lowres")) topo = Dedup(data, options={"topology": False}).to_dict() assert len(topo["linestrings"]) == 288 assert len(topo["junctions"]) == 0
def test_dedup_merge_continous_shared_path(): data = geojson.loads( '{"type": "FeatureCollection", "features": [{"id": "0", "type": "Feature", "properties": {"certainty": 4}, "geometry": {"type": "Polygon", "coordinates": [[[380565.0, -3576915.0], [380595.0, -3576915.0], [380595.0, -3576945.0], [380625.0, -3576945.0], [380625.0, -3576975.0], [380595.0, -3576975.0], [380595.0, -3577005.0], [380565.0, -3577005.0], [380565.0, -3577035.0], [380595.0, -3577035.0], [380595.0, -3577065.0], [380625.0, -3577065.0], [380625.0, -3577095.0], [380655.0, -3577095.0], [380655.0, -3577065.0], [380685.0, -3577065.0], [380685.0, -3577035.0], [380745.0, -3577035.0], [380745.0, -3577065.0], [380775.0, -3577065.0], [380775.0, -3577095.0], [380895.0, -3577095.0], [380895.0, -3577125.0], [380865.0, -3577125.0], [380865.0, -3577215.0], [380835.0, -3577215.0], [380835.0, -3577245.0], [380805.0, -3577245.0], [380805.0, -3577215.0], [380745.0, -3577215.0], [380745.0, -3577245.0], [380685.0, -3577245.0], [380685.0, -3577215.0], [380625.0, -3577215.0], [380625.0, -3577245.0], [380595.0, -3577245.0], [380595.0, -3577185.0], [380565.0, -3577185.0], [380565.0, -3577125.0], [380535.0, -3577125.0], [380535.0, -3577005.0], [380505.0, -3577005.0], [380505.0, -3576945.0], [380535.0, -3576945.0], [380565.0, -3576945.0], [380565.0, -3576915.0]]]}}, {"id": "1", "type": "Feature", "properties": {"certainty": 4}, "geometry": {"type": "Polygon", "coordinates": [[[380685.0, -3577335.0], [380715.0, -3577335.0], [380715.0, -3577365.0], [380745.0, -3577365.0], [380745.0, -3577395.0], [380715.0, -3577395.0], [380715.0, -3577425.0], [380685.0, -3577425.0], [380685.0, -3577395.0], [380655.0, -3577395.0], [380655.0, -3577365.0], [380685.0, -3577365.0], [380685.0, -3577335.0]]]}}, {"id": "2", "type": "Feature", "properties": {"certainty": 4}, "geometry": {"type": "Polygon", "coordinates": [[[380865.0, -3577395.0], [380895.0, -3577395.0], [380895.0, -3577425.0], [380925.0, -3577425.0], [380925.0, -3577455.0], [380895.0, -3577455.0], [380895.0, -3577485.0], [380835.0, -3577485.0], [380835.0, -3577425.0], [380865.0, -3577425.0], [380865.0, -3577395.0]]]}}, {"id": "3", "type": "Feature", "properties": {"certainty": 4}, "geometry": {"type": "Polygon", "coordinates": [[[381075.0, -3577965.0], [381195.0, -3577965.0], [381195.0, -3578025.0], [381165.0, -3578025.0], [381165.0, -3578055.0], [381135.0, -3578055.0], [381105.0, -3578055.0], [381105.0, -3578085.0], [381075.0, -3578085.0], [381075.0, -3578115.0], [381045.0, -3578115.0], [381045.0, -3578145.0], [381015.0, -3578145.0], [381015.0, -3578115.0], [380985.0, -3578115.0], [380985.0, -3578145.0], [380955.0, -3578145.0], [380955.0, -3578115.0], [380925.0, -3578115.0], [380925.0, -3578145.0], [380865.0, -3578145.0], [380865.0, -3578115.0], [380835.0, -3578115.0], [380835.0, -3578085.0], [380805.0, -3578085.0], [380805.0, -3577995.0], [380835.0, -3577995.0], [380835.0, -3578025.0], [380865.0, -3578025.0], [380865.0, -3578055.0], [380895.0, -3578055.0], [380895.0, -3578085.0], [380985.0, -3578085.0], [380985.0, -3578055.0], [381015.0, -3578055.0], [381015.0, -3578025.0], [381045.0, -3578025.0], [381045.0, -3577995.0], [381075.0, -3577995.0], [381075.0, -3577965.0]]]}}, {"id": "4", "type": "Feature", "properties": {"certainty": 4}, "geometry": {"type": "Polygon", "coordinates": [[[381255.0, -3578085.0], [381315.0, -3578085.0], [381315.0, -3578115.0], [381345.0, -3578115.0], [381345.0, -3578145.0], [381315.0, -3578145.0], [381285.0, -3578145.0], [381285.0, -3578175.0], [381255.0, -3578175.0], [381255.0, -3578145.0], [381225.0, -3578145.0], [381225.0, -3578115.0], [381255.0, -3578115.0], [381255.0, -3578085.0]]]}}, {"id": "5", "type": "Feature", "properties": {"certainty": 0}, "geometry": {"type": "Polygon", "coordinates": [[[381500.0, -3578500.0], [380400.0, -3578500.0], [380400.0, -3576500.0], [381500.0, -3576500.0], [381500.0, -3578500.0]], [[381285.0, -3578145.0], [381315.0, -3578145.0], [381345.0, -3578145.0], [381345.0, -3578115.0], [381315.0, -3578115.0], [381315.0, -3578085.0], [381255.0, -3578085.0], [381255.0, -3578115.0], [381225.0, -3578115.0], [381225.0, -3578145.0], [381255.0, -3578145.0], [381255.0, -3578175.0], [381285.0, -3578175.0], [381285.0, -3578145.0]], [[380805.0, -3577995.0], [380805.0, -3578085.0], [380835.0, -3578085.0], [380835.0, -3578115.0], [380865.0, -3578115.0], [380865.0, -3578145.0], [380925.0, -3578145.0], [380925.0, -3578115.0], [380955.0, -3578115.0], [380955.0, -3578145.0], [380985.0, -3578145.0], [380985.0, -3578115.0], [381015.0, -3578115.0], [381015.0, -3578145.0], [381045.0, -3578145.0], [381045.0, -3578115.0], [381075.0, -3578115.0], [381075.0, -3578085.0], [381105.0, -3578085.0], [381105.0, -3578055.0], [381135.0, -3578055.0], [381165.0, -3578055.0], [381165.0, -3578025.0], [381195.0, -3578025.0], [381195.0, -3577965.0], [381075.0, -3577965.0], [381075.0, -3577995.0], [381045.0, -3577995.0], [381045.0, -3578025.0], [381015.0, -3578025.0], [381015.0, -3578055.0], [380985.0, -3578055.0], [380985.0, -3578085.0], [380895.0, -3578085.0], [380895.0, -3578055.0], [380865.0, -3578055.0], [380865.0, -3578025.0], [380835.0, -3578025.0], [380835.0, -3577995.0], [380805.0, -3577995.0]], [[380895.0, -3577455.0], [380925.0, -3577455.0], [380925.0, -3577425.0], [380895.0, -3577425.0], [380895.0, -3577395.0], [380865.0, -3577395.0], [380865.0, -3577425.0], [380835.0, -3577425.0], [380835.0, -3577485.0], [380895.0, -3577485.0], [380895.0, -3577455.0]], [[380565.0, -3576915.0], [380565.0, -3576945.0], [380535.0, -3576945.0], [380505.0, -3576945.0], [380505.0, -3577005.0], [380535.0, -3577005.0], [380535.0, -3577125.0], [380565.0, -3577125.0], [380565.0, -3577185.0], [380595.0, -3577185.0], [380595.0, -3577245.0], [380625.0, -3577245.0], [380625.0, -3577215.0], [380685.0, -3577215.0], [380685.0, -3577245.0], [380745.0, -3577245.0], [380745.0, -3577215.0], [380805.0, -3577215.0], [380805.0, -3577245.0], [380835.0, -3577245.0], [380835.0, -3577215.0], [380865.0, -3577215.0], [380865.0, -3577125.0], [380895.0, -3577125.0], [380895.0, -3577095.0], [380775.0, -3577095.0], [380775.0, -3577065.0], [380745.0, -3577065.0], [380745.0, -3577035.0], [380685.0, -3577035.0], [380685.0, -3577065.0], [380655.0, -3577065.0], [380655.0, -3577095.0], [380625.0, -3577095.0], [380625.0, -3577065.0], [380595.0, -3577065.0], [380595.0, -3577035.0], [380565.0, -3577035.0], [380565.0, -3577005.0], [380595.0, -3577005.0], [380595.0, -3576975.0], [380625.0, -3576975.0], [380625.0, -3576945.0], [380595.0, -3576945.0], [380595.0, -3576915.0], [380565.0, -3576915.0]], [[380655.0, -3577365.0], [380655.0, -3577395.0], [380685.0, -3577395.0], [380685.0, -3577425.0], [380715.0, -3577425.0], [380715.0, -3577395.0], [380745.0, -3577395.0], [380745.0, -3577365.0], [380715.0, -3577365.0], [380715.0, -3577335.0], [380685.0, -3577335.0], [380685.0, -3577365.0], [380655.0, -3577365.0]]]}}]}' ) topo = Dedup(data, options={"shared_coords": False}).to_dict() assert len(topo["linestrings"]) == 10 assert len(topo["junctions"]) == 0
def test_s2_geometries(self): data = [ wkt.loads( "MULTILINESTRING ((-51.17176115208171 -30.05269620283153, -51.18859500873385 -29.99305326146263, -51.1541142383379 -29.95234110496228, -51.13731737261026 -30.01193511071039, -51.17176115208171 -30.05269620283153), (-51.13731737261026 -30.01193511071039, -51.1541142383379 -29.95234110496228, -51.11963364027719 -29.91170657721793, -51.10287369862932 -29.97125162042611, -51.13731737261026 -30.01193511071039), (-51.13799328025614 -30.17188406207867, -51.17176115208171 -30.05269620283153, -51.10287369862932 -29.97125162042611, -51.06925390117097 -30.09024489967364, -51.13799328025614 -30.17188406207867), (-51.06925390117097 -30.09024489967364, -51.0860804353923 -30.03076444145886, -51.05167386668366 -29.99010960397871, -51.03488427131447 -30.04954147652281, -51.06925390117097 -30.09024489967364), (-51.0860804353923 -30.03076444145886, -51.10287369862932 -29.97125162042611, -51.0684302317277 -29.9306455702365, -51.05167386668366 -29.99010960397871, -51.0860804353923 -30.03076444145886))" ) ] topo = Dedup(data).to_dict() self.assertEqual(len(topo["junctions"]), 6) self.assertEqual(len(topo["bookkeeping_duplicates"]), 0)
def test_dedup_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 = Dedup(data).to_dict() assert len(topo["bookkeeping_shared_arcs"]) == 3 assert len(topo["bookkeeping_duplicates"]) == 0
def test_arc_not_shared_arcs_got_deleted(self): data = geopandas.read_file( geopandas.datasets.get_path("naturalearth_lowres")) data = data[(data.name == "Botswana") | (data.name == "South Africa") | (data.name == "Zimbabwe") | (data.name == "Mozambique") | (data.name == "Zambia")] topo = Dedup(data).to_dict() self.assertEqual(len(topo["bookkeeping_shared_arcs"]), 9) self.assertEqual(len(topo["bookkeeping_duplicates"]), 0)
def test_super_function_dedup(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 = Dedup(data).to_dict() self.assertEqual( list(topo.keys()), [ "type", "linestrings", "bookkeeping_geoms", "objects", "options", "bbox", "junctions", "bookkeeping_duplicates", "bookkeeping_arcs", "bookkeeping_shared_arcs", ], )
def test_array_bk_sarcs_reference(self): data = { "foo": { "type": "LineString", "coordinates": [[4, 0], [2, 2], [0, 0]] }, "bar": { "type": "LineString", "coordinates": [[0, 2], [1, 1], [2, 2], [3, 1], [4, 2]], }, } topo = Dedup(data).to_dict() self.assertEqual(len(topo["bookkeeping_shared_arcs"]), 1) self.assertEqual(len(topo["junctions"]), 4)
def test_two_polygon_reversed_shared_arc(self): data = { "abcda": { "type": "Polygon", "coordinates": [[[0, 0], [1, 0], [1, 1], [0, 1], [0, 0]]], }, # rotated to BCDAB, cut BC-CDAB "befcb": { "type": "Polygon", "coordinates": [[[1, 0], [2, 0], [2, 1], [1, 1], [1, 0]]], }, } topo = Dedup(data).to_dict() self.assertEqual(len(topo["bookkeeping_duplicates"]), 0) self.assertEqual(topo["bookkeeping_shared_arcs"], [2]) self.assertEqual(topo["bookkeeping_arcs"], [[2, 0], [1, 2]])
def test_dedup_shared_paths_array_bk_sarcs_reference(): data = { "foo": { "type": "LineString", "coordinates": [[4, 0], [2, 2], [0, 0]] }, "bar": { "type": "LineString", "coordinates": [[0, 2], [1, 1], [2, 2], [3, 1], [4, 2]], }, } topo = Dedup(data, options={"shared_coords": False}).to_dict() assert len(topo["bookkeeping_shared_arcs"]) == 1 assert len(topo["junctions"]) == 4
def test_dedup_shared_line_ABCDBE_and_FBCG(): data = { "abcdbe": { "type": "LineString", "coordinates": [[0, 0], [1, 0], [2, 0], [3, 0], [1, 0], [4, 0]], }, "fbcg": { "type": "LineString", "coordinates": [[0, 1], [1, 0], [2, 0], [3, 1]] }, } topo = Dedup(data).to_dict() assert len(topo["bookkeeping_duplicates"]) == 0 assert topo["bookkeeping_shared_arcs"] == [4] assert topo["bookkeeping_arcs"] == [[0, 4, 1, 2], [3, 4, 5]]
def test_dedup_two_polygon_reversed_shared_arc(): data = { "abcda": { "type": "Polygon", "coordinates": [[[0, 0], [1, 0], [1, 1], [0, 1], [0, 0]]], }, # rotated to BCDAB, cut BC-CDAB "befcb": { "type": "Polygon", "coordinates": [[[1, 0], [2, 0], [2, 1], [1, 1], [1, 0]]], }, } topo = Dedup(data).to_dict() assert len(topo["bookkeeping_duplicates"]) == 0 assert topo["bookkeeping_shared_arcs"] == [2] assert topo["bookkeeping_arcs"] == [[2, 0], [1, 2]]
def test_duplicate_polygon_no_junctions(self): 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 = Dedup(data).to_dict() self.assertEqual(len(topo["bookkeeping_duplicates"]), 0) self.assertEqual(topo["bookkeeping_shared_arcs"], [0]) self.assertEqual(topo["bookkeeping_arcs"], [[0], [0]]) self.assertEqual(topo["bookkeeping_geoms"], [[0], [1]])
def test_shared_line_ABCDBE_and_FBCG(self): data = { "abcdbe": { "type": "LineString", "coordinates": [[0, 0], [1, 0], [2, 0], [3, 0], [1, 0], [4, 0]], }, "fbcg": { "type": "LineString", "coordinates": [[0, 1], [1, 0], [2, 0], [3, 1]], }, } topo = Dedup(data).to_dict() self.assertEqual(len(topo["bookkeeping_duplicates"]), 0) self.assertEqual(topo["bookkeeping_shared_arcs"], [4]) self.assertEqual(topo["bookkeeping_arcs"], [[0, 4, 1, 2], [3, 4, 5]])
def test_dedup_duplicate_polygon_no_junctions(): 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 = Dedup(data).to_dict() assert len(topo["bookkeeping_duplicates"]) == 0 assert topo["bookkeeping_shared_arcs"] == [0] assert topo["bookkeeping_arcs"] == [[0], [0]] assert topo["bookkeeping_geoms"] == [[0], [1]]
def test_duplicate_rotated_hole_interior(self): data = { "foo": { "type": "MultiPolygon", "coordinates": [ [ [[0, 0], [20, 0], [10, 20], [0, 0]], # CCW [[3, 2], [10, 16], [17, 2], [3, 2]], # CW ], [[[6, 4], [14, 4], [10, 12], [6, 4]]], # CCW ], }, "bar": { "type": "Polygon", "coordinates": [[[17, 2], [3, 2], [10, 16], [17, 2]]], }, } topo = Dedup(data).to_dict() # print(topo) self.assertEqual(len(topo["bookkeeping_duplicates"]), 0) self.assertEqual(topo["bookkeeping_geoms"], [[0, 1], [2], [3]])
def test_dedup_duplicate_rotated_hole_interior(): data = { "foo": { "type": "MultiPolygon", "coordinates": [ [ [[0, 0], [20, 0], [10, 20], [0, 0]], # CCW [[3, 2], [10, 16], [17, 2], [3, 2]], # CW ], [[[6, 4], [14, 4], [10, 12], [6, 4]]], # CCW ], }, "bar": { "type": "Polygon", "coordinates": [[[17, 2], [3, 2], [10, 16], [17, 2]]], }, } topo = Dedup(data).to_dict() assert len(topo["bookkeeping_duplicates"]) == 0 assert topo["bookkeeping_geoms"] == [[0, 1], [2], [3]]