Beispiel #1
0
def test_cut_super_function_cut():
    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 = Cut(data).to_dict()

    assert len(list(topo.keys())) == 11
Beispiel #2
0
def test_cut_nybb_fast_split():
    nybb_path = geopandas.datasets.get_path("nybb")
    data = geopandas.read_file(nybb_path)
    data.set_index("BoroCode", inplace=True)
    topo = Cut(data).to_dict()

    assert topo["bookkeeping_linestrings"].size == 5618
Beispiel #3
0
def test_cut_border_egypt_sudan():
    data = geopandas.read_file(
        geopandas.datasets.get_path("naturalearth_lowres"))
    data = data[(data.name == "Egypt") | (data.name == "Sudan")]
    topo = Cut(data).to_dict()

    assert len(topo["bookkeeping_duplicates"].tolist()) == 1
Beispiel #4
0
def test_cut_geomcol_multipolygon_polygon():
    data = {
        "foo": {
            "type":
            "GeometryCollection",
            "geometries": [
                {
                    "type":
                    "MultiPolygon",
                    "coordinates": [
                        [
                            [[10, 20], [20, 0], [0, 0], [10, 20]],
                            [[3, 2], [10, 16], [17, 2], [3, 2]],
                        ],
                        [[[6, 4], [14, 4], [10, 12], [6, 4]]],
                    ],
                },
                {
                    "type": "Polygon",
                    "coordinates": [[[20, 0], [35, 5], [10, 20], [20, 0]]],
                },
            ],
        }
    }
    topo = Cut(data).to_dict()

    assert topo["bookkeeping_linestrings"].size == 8
Beispiel #5
0
 def test_many_junctions(self):
     data = geopandas.read_file("tests/files_geojson/mesh2d.geojson",
                                driver="GeoJSON")
     # previous test ran in 8.798s (best of 3)
     # current test ran in 8.182s (best of 3)
     topo = Cut(data).to_dict()
     self.assertEqual(topo["bookkeeping_linestrings"].size, 11010)
Beispiel #6
0
def test_cut_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 = Cut(data).to_dict()

    assert len(topo["linestrings"]) == 12
    assert len(topo["junctions"]) == 7
Beispiel #7
0
def test_cut_low_prequantize():
    import topojson as tp

    data = tp.utils.example_data_africa()
    topo = Cut(data, options={"prequantize": 75}).to_dict()

    assert len(topo["bookkeeping_duplicates"]) == 153
Beispiel #8
0
def test_cut_shared_paths_rotated_duplicates_rings_BCAB_ABCA_no_cuts():
    data = {
        "abca": {"type": "Polygon", "coordinates": [[[0, 0], [1, 0], [2, 1], [0, 0]]]},
        "bcab": {"type": "Polygon", "coordinates": [[[1, 0], [2, 1], [0, 0], [1, 0]]]},
    }
    topo = Cut(data, options={"shared_coords": False}).to_dict()

    assert len(topo["junctions"]) == 0
    assert len(topo["bookkeeping_duplicates"]) == 0
Beispiel #9
0
def test_cut_exact_duplicate_lines_ABC_ABC_no_cuts():
    data = {
        "abc": {"type": "LineString", "coordinates": [[0, 0], [1, 0], [2, 0]]},
        "abc2": {"type": "LineString", "coordinates": [[0, 0], [1, 0], [2, 0]]},
    }
    topo = Cut(data).to_dict()

    assert len(topo["junctions"]) == 0
    assert topo["bookkeeping_duplicates"].tolist() == [[1, 0]]
Beispiel #10
0
def test_cut_reversed_rings_ABCA_ACBA_no_cuts():
    data = {
        "abca": {"type": "Polygon", "coordinates": [[[0, 0], [1, 0], [2, 1], [0, 0]]]},
        "acba": {"type": "Polygon", "coordinates": [[[0, 0], [2, 1], [1, 0], [0, 0]]]},
    }
    topo = Cut(data).to_dict()

    assert len(topo["junctions"]) == 1
    assert topo["bookkeeping_duplicates"].tolist() == [[1, 0]]
Beispiel #11
0
 def test_super_function_cut(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 = Cut(data).to_dict()
     self.assertEqual(
         list(topo.keys()),
         [
             "type",
             "linestrings",
             "bookkeeping_geoms",
             "objects",
             "options",
             "bbox",
             "junctions",
             "bookkeeping_duplicates",
             "bookkeeping_linestrings",
         ],
     )
Beispiel #12
0
def test_cut_overlapping_rings_are_cut():
    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 = Cut(data).to_dict()

    assert topo["bookkeeping_linestrings"].size == 6
    assert topo["bookkeeping_duplicates"].tolist() == [[4, 1]]
Beispiel #13
0
def test_cut_ring_ABCA_line_ABCA_no_cuts():
    data = {
        "abcaLine": {
            "type": "Linestring",
            "coordinates": [[0, 0], [1, 0], [2, 1], [0, 0]],
        },
        "abcaPolygon": {
            "type": "Polygon",
            "coordinates": [[[0, 0], [1, 0], [2, 1], [0, 0]]],
        },
    }
    topo = Cut(data).to_dict()

    assert len(topo["junctions"]) == 0
    assert topo["bookkeeping_duplicates"].tolist() == [[1, 0]]
Beispiel #14
0
 def test_ring_ABCA_line_ABCA_no_cuts(self):
     data = {
         "abcaLine": {
             "type": "Linestring",
             "coordinates": [[0, 0], [1, 0], [2, 1], [0, 0]],
         },
         "abcaPolygon": {
             "type": "Polygon",
             "coordinates": [[[0, 0], [1, 0], [2, 1], [0, 0]]],
         },
     }
     topo = Cut(data).to_dict()
     # print(topo)
     self.assertEqual(len(topo["junctions"]), 0)
     self.assertSequenceEqual(topo["bookkeeping_duplicates"].tolist(),
                              [[1, 0]])
Beispiel #15
0
 def test_overlapping_rings_are_cut(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 = Cut(data).to_dict()
     # print(topo)
     self.assertEqual(topo["bookkeeping_linestrings"].size, 6)
     self.assertSequenceEqual(topo["bookkeeping_duplicates"].tolist(),
                              [[4, 1]])
Beispiel #16
0
 def test_exact_duplicate_lines_ABC_ABC_no_cuts(self):
     data = {
         "abc": {
             "type": "LineString",
             "coordinates": [[0, 0], [1, 0], [2, 0]]
         },
         "abc2": {
             "type": "LineString",
             "coordinates": [[0, 0], [1, 0], [2, 0]]
         },
     }
     topo = Cut(data).to_dict()
     # print(topo)
     self.assertEqual(len(topo["junctions"]), 0)
     self.assertSequenceEqual(topo["bookkeeping_duplicates"].tolist(),
                              [[1, 0]])
Beispiel #17
0
def test_cut_junctions_coords():
    data = geopandas.read_file(
        "tests/files_geojson/naturalearth_alb_grc.geojson")
    topo = Cut(data, options={"shared_paths": "coords"}).to_dict()

    assert len(topo["linestrings"]) == 3