|
18 | 18 | import io |
19 | 19 | import tempfile |
20 | 20 | import warnings |
| 21 | +import zipfile |
21 | 22 | from pathlib import Path |
22 | 23 |
|
23 | 24 | import geoarrow.pyarrow as ga |
@@ -131,6 +132,43 @@ def test_read_ogr_filter(con): |
131 | 132 | ) |
132 | 133 |
|
133 | 134 |
|
| 135 | +def test_read_ogr_layer_selection(con): |
| 136 | + series = geopandas.GeoSeries.from_xy([0, 1], [1, 2], crs="EPSG:3857") |
| 137 | + gdf = geopandas.GeoDataFrame({"val": ["a", "b"], "geom": series}) |
| 138 | + gdf = gdf.set_geometry(gdf["geom"]) |
| 139 | + |
| 140 | + with tempfile.TemporaryDirectory() as td: |
| 141 | + gpkg_path = f"{td}/test.gpkg" |
| 142 | + gdf.to_file(gpkg_path, layer="my_layer") |
| 143 | + |
| 144 | + # Reading with the correct layer name should work |
| 145 | + geopandas.testing.assert_geodataframe_equal( |
| 146 | + con.read_pyogrio(gpkg_path, options={"layer": "my_layer"}).to_pandas(), |
| 147 | + gdf, |
| 148 | + ) |
| 149 | + |
| 150 | + |
| 151 | +def test_read_ogr_path_suffix(con): |
| 152 | + series = geopandas.GeoSeries.from_xy([0, 1], [1, 2], crs="EPSG:3857") |
| 153 | + gdf = geopandas.GeoDataFrame({"val": ["a", "b"], "geom": series}) |
| 154 | + gdf = gdf.set_geometry(gdf["geom"]) |
| 155 | + |
| 156 | + with tempfile.TemporaryDirectory() as td: |
| 157 | + gpkg_path = f"{td}/data.gpkg" |
| 158 | + gdf.to_file(gpkg_path) |
| 159 | + |
| 160 | + zip_path = f"{td}/archive.zip" |
| 161 | + with zipfile.ZipFile(zip_path, "w") as zf: |
| 162 | + zf.write(gpkg_path, "nested/data.gpkg") |
| 163 | + |
| 164 | + geopandas.testing.assert_geodataframe_equal( |
| 165 | + con.read_pyogrio( |
| 166 | + zip_path, options={"path_suffix": "nested/data.gpkg"} |
| 167 | + ).to_pandas(), |
| 168 | + gdf, |
| 169 | + ) |
| 170 | + |
| 171 | + |
134 | 172 | def test_read_ogr_file_not_found(con): |
135 | 173 | with pytest.raises( |
136 | 174 | sedonadb._lib.SedonaError, match="Can't infer schema for zero objects" |
|
0 commit comments