def test_nested_geometrycollection(self): data = { "foo": { "type": "GeometryCollection", "geometries": [ { "type": "GeometryCollection", "geometries": [{ "type": "LineString", "coordinates": [[0.1, 0.2], [0.3, 0.4]], }], }, { "type": "Polygon", "coordinates": [[[0.5, 0.6], [0.7, 0.8], [0.9, 1.0]]], }, ], } } topo = topojson.extract(data) self.assertEqual( len(topo["objects"]["foo"]["geometries"][0]["geometries"][0] ["arcs"]), 1)
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_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_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_geojson_feature_geom_col(self): with open("tests/files_geojson/feature.geojson") as f: data = geojson.load(f) topo = topojson.extract(data) self.assertEqual(len(topo["objects"]), 1) self.assertEqual(len(topo["bookkeeping_geoms"]), 3) self.assertEqual(len(topo["linestrings"]), 3)
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_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_geopandas_geoseries(self): data = geopandas.GeoSeries([ geometry.Polygon([(0, 0), (1, 0), (1, 1)]), geometry.Polygon([(0, 0), (1, 0), (1, 1), (0, 1)]), geometry.Polygon([(2, 0), (3, 0), (3, 1), (2, 1)]), ]) topo = topojson.extract(data) print(topo)
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_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_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_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_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_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_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_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_linestring(self): data = { "foo": { "type": "LineString", "coordinates": [[0, 0], [1, 0], [2, 0]] }, "bar": { "type": "LineString", "coordinates": [[0, 0], [1, 0], [2, 0]] }, } topo = topojson.extract(data) self.assertEqual(len(topo["linestrings"]), 2)
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_invalid_polygon(self): data = { "wrong": { "type": "Polygon", "coordinates": [[[0, 0], [1, 0], [2, 0], [0, 0]]], }, "valid": { "type": "Polygon", "coordinates": [[[0, 0], [2, 0], [1, 1], [0, 0]]], }, } topo = topojson.extract(data) self.assertEqual(len(topo["linestrings"]), 1)
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_multilinestring(self): data = { "foo": { "type": "MultiLineString", "coordinates": [ [[0.0, 0.0], [1, 1], [3, 3]], [[1, 1], [0, 1]], [[3, 3], [4, 4], [0, 1]], ], } } topo = topojson.extract(data) self.assertEqual(len(topo["linestrings"]), 3)
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_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_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_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_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)])))