def test_hashmap_geomcol_multipolygon_polygon(self): 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 = topojson.hashmap( topojson.dedup(topojson.cut(topojson.join(topojson.extract(data)))) ) # print(topo) self.assertEqual( topo["objects"]["data"]["geometries"][0]["arcs"], [[[4, 0]], [[1]], [[2]]] )
def test_shared_junctions_in_shared_paths(self): data = geopandas.read_file( geopandas.datasets.get_path('naturalearth_lowres')) data = data[(data.name == 'Togo') | (data.name == 'Benin') | (data.name == 'Burkina Faso')] topo = topojson.join(topojson.extract(data)) self.assertEqual(len(topo["junctions"]), 6)
def test_albania_greece(self): data = geopandas.read_file(geopandas.datasets.get_path("naturalearth_lowres")) data = data[(data.name == "Albania") | (data.name == "Greece")] topo = topojson.hashmap( topojson.dedup(topojson.cut(topojson.join(topojson.extract(data)))) ) self.assertEqual(len(topo["arcs"]), 3)
def test_nybb_fast_split(self): nybb_path = geopandas.datasets.get_path("nybb") data = geopandas.read_file(nybb_path) data.set_index("BoroCode", inplace=True) topo = topojson.cut(topojson.join(topojson.extract(data))) self.assertEqual(topo["bookkeeping_linestrings"].size, 5618)
def test_shared_segment_partly_start_partly_end_segment(self): data = geopandas.read_file( geopandas.datasets.get_path("naturalearth_lowres")) data = data[(data.name == "Eritrea") | (data.name == "Ethiopia") | (data.name == "Sudan")] topo = topojson.join(topojson.extract(data)) self.assertEqual(len(topo['junctions']), 11)
def test_ring_ABCA_is_closed(self): data = { "abca": { "type": "Polygon", "coordinates": [[[0, 0], [1, 0], [0, 1], [0, 0]]], } } topo = topojson.join(topojson.extract(data)) self.assertListEqual(topo["junctions"], [])
def test_single_ring_ABCA(self): data = { "abca": { "type": "LineString", "coordinates": [[0, 0], [1, 0], [1, 1], [0, 0]], } } topo = topojson.join(topojson.extract(data)) 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 = topojson.join(topojson.extract(data)) self.assertListEqual(topo["junctions"], [])
def test_benin_surrounding_countries(self): data = geopandas.read_file(geopandas.datasets.get_path("naturalearth_lowres")) data = data[ (data.name == "Togo") | (data.name == "Benin") | (data.name == "Burkina Faso") ] topo = topojson.hashmap( topojson.dedup(topojson.cut(topojson.join(topojson.extract(data)))) ) self.assertEqual(len(topo["arcs"]), 6)
def test_line_ABDE_skips_point_reversed_line_EDCBA(self): data = { "edcba": { "type": "LineString", "coordinates": [[4, 0], [3, 0], [2, 0], [1, 0], [0, 0]], }, "abde": { "type": "LineString", "coordinates": [[0, 0], [1, 0], [3, 0], [4, 0]], }, } topo = topojson.join(topojson.extract(data)) self.assertListEqual(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 = topojson.join(topojson.extract(data)) self.assertListEqual(topo["junctions"], [])
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 = topojson.join(topojson.extract(data)) self.assertListEqual(topo["junctions"], [])
def test_rotated_ring_and_line_no_junctions(self): data = { "abcaLine": { "type": "LineString", "coordinates": [[0, 0], [1, 1], [2, 0], [0, 0]], }, "bcabPolygon": { "type": "Polygon", "coordinates": [[[1, 1], [2, 0], [0, 0], [1, 1]]], }, } topo = topojson.join(topojson.extract(data)) self.assertListEqual(topo["junctions"], [])
def test_rotated_duplicate_rings(self): 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 = topojson.join(topojson.extract(data)) self.assertListEqual(topo["junctions"], [])
def test_shared_arcs_ordering_issues(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 = topojson.hashmap( topojson.dedup(topojson.cut(topojson.join(topojson.extract(data)))) ) self.assertEqual(len(topo["arcs"]), 18)
def test_geom_surrounding_many_geometries(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 == "Namibia") | (data.name == "Zambia") ] topo = topojson.hashmap( topojson.dedup(topojson.cut(topojson.join(topojson.extract(data)))) ) self.assertEqual(len(topo["arcs"]), 14)
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 = topojson.join(topojson.extract(data)) self.assertListEqual(topo["junctions"], [])
def test_coincident_rings_ABCA_BACB_share_BCAB(self): 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 = topojson.join(topojson.extract(data)) self.assertListEqual(topo["junctions"], [])
def test_exact_duplicate_rings_ABCA_ACBA_share_ABCA(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 = topojson.join(topojson.extract(data)) self.assertListEqual(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 = topojson.join(topojson.extract(data)) self.assertListEqual(topo["junctions"], [])
def test_duplicate_lines_junction_endpoints(self): data = { "abc1": { "type": "LineString", "coordinates": [[0, 0], [1, 0], [2, 0]] }, "abc2": { "type": "LineString", "coordinates": [[0, 0], [1, 0], [2, 0]] }, } topo = topojson.join(topojson.extract(data)) # print(topo) self.assertListEqual(topo["junctions"], [])
def test_forward_backward_lines(self): data = { "foo": { "type": "LineString", "coordinates": [(0, 0), (10, 0), (10, 5), (20, 5)], }, "bar": { "type": "LineString", "coordinates": [(5, 0), (30, 0), (30, 5), (0, 5)], }, } topo = topojson.join(topojson.extract(data)) # print(topo) self.assertTrue(len(topo["junctions"]), 4)
def test_exact_duplicate_rings(self): data = { "abca1": { "type": "Polygon", "coordinates": [[[0, 0], [1, 1], [2, 0], [0, 0]]], }, "abca2": { "type": "Polygon", "coordinates": [[[0, 0], [1, 1], [2, 0], [0, 0]]], }, } topo = topojson.join(topojson.extract(data)) # print(topo) self.assertListEqual(topo["junctions"], [])
def test_reversed_line_CBA_extends_new_line_AB(self): data = { "cba": { "type": "LineString", "coordinates": [[2, 0], [1, 0], [0, 0]] }, "ab": { "type": "LineString", "coordinates": [[0, 0], [1, 0]] }, } topo = topojson.join(topojson.extract(data)) self.assertTrue( geometry.Point(1.0, 0.0).within(geometry.MultiPoint(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 = topojson.join(topojson.extract(data)) # print(topo) self.assertFalse( geometry.Point(1.0, 0.0) in geometry.MultiPoint(topo["junctions"]))
def test_line_ABC_extends_line_BC(self): data = { "abc": { "type": "LineString", "coordinates": [[0, 0], [1, 0], [2, 0]] }, "bc": { "type": "LineString", "coordinates": [[1, 0], [2, 0]] }, } topo = topojson.join(topojson.extract(data)) self.assertTrue( geometry.MultiPoint(topo["junctions"]).equals( geometry.MultiPoint([(1.0, 0.0), (0.0, 0.0), (2.0, 0.0)])))
def test_line_ABD_deviates_line_CBA(self): data = { "cba": { "type": "LineString", "coordinates": [[2, 0], [1, 0], [0, 0]] }, "abd": { "type": "LineString", "coordinates": [[0, 0], [1, 0], [3, 0]] }, } topo = topojson.join(topojson.extract(data)) self.assertTrue( geometry.MultiPoint(topo["junctions"]).equals( geometry.MultiPoint([(2.0, 0.0), (0.0, 0.0)])))
def test_line_DBC_merge_reversed_line_CBA(self): data = { "cba": { "type": "LineString", "coordinates": [[2, 0], [1, 0], [0, 0]] }, "dbc": { "type": "LineString", "coordinates": [[3, 0], [1, 0], [2, 0]] }, } topo = topojson.join(topojson.extract(data)) self.assertTrue( geometry.MultiPoint(topo["junctions"]).equals( geometry.MultiPoint([(2.0, 0.0), (1.0, 0.0), (3.0, 0.0)])))
def test_hashmap_backward_polygon(self): data = { "abc": { "type": "Polygon", "coordinates": [[[0, 0], [1, 0], [1, 1], [0, 1], [0, 0]]], }, "def": { "type": "Polygon", "coordinates": [[[1, 0], [2, 0], [2, 1], [1, 1], [1, 0]]], }, } topo = topojson.hashmap( topojson.dedup(topojson.cut(topojson.join(topojson.extract(data)))) ) self.assertEqual(topo["objects"]["data"]["geometries"][0]["arcs"], [[-3, 0]]) self.assertEqual(topo["objects"]["data"]["geometries"][1]["arcs"], [[1, 2]])
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 = topojson.join(topojson.extract(data)) self.assertTrue( geometry.MultiPoint([ (0.0, 0.0), (1.0, 0.0), (2.0, 0.0) ]).equals(geometry.MultiPoint(topo["junctions"])))