def test_from_file_and_then_to_json_with_geometries(shapefile, target_file): graph = Graph.from_file(shapefile) # Even the geometry column is copied to the graph assert all("geometry" in node_data for node_data in graph.nodes.values()) graph.to_json(target_file, include_geometries_as_geojson=True)
def test_from_file_and_then_to_json_does_not_error(shapefile, target_file): graph = Graph.from_file(shapefile) # Even the geometry column is copied to the graph assert all("geometry" in node_data for node_data in graph.nodes.values()) graph.to_json(target_file)
def test_can_ignore_errors_while_making_graph(shapefile): with patch("gerrychain.graph.geo.explain_validity") as explain: explain.return_value = "Invalid geometry" assert Graph.from_file(shapefile, ignore_errors=True)
def test_raises_geometry_error_if_invalid_geometry(shapefile): with patch("gerrychain.graph.geo.explain_validity") as explain: explain.return_value = "Invalid geometry" with pytest.raises(GeometryError): Graph.from_file(shapefile, ignore_errors=False)
def test_from_file_adds_all_data_by_default(shapefile): graph = Graph.from_file(shapefile) assert all("data" in node_data for node_data in graph.nodes.values()) assert all("data2" in node_data for node_data in graph.nodes.values())
def test_make_graph_from_shapefile_has_crs(shapefile): graph = Graph.from_file(shapefile) df = gp.read_file(shapefile) assert CRS.from_json(graph.graph["crs"]).equals(df.crs)
def from_file(cls, filename, assignment, updaters, columns=None): """Create a :class:`GeographicPartition` from an ESRI Shapefile, a GeoPackage, a GeoJSON file, or any other file that the `fiona` library can handle. """ graph = Graph.from_file(filename, columns) cls(graph, assignment, updaters)