pyogrio 0.9.0__cp312-cp312-win_amd64.whl → 0.11.0__cp312-cp312-win_amd64.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Potentially problematic release.
This version of pyogrio might be problematic. Click here for more details.
- pyogrio/__init__.py +35 -28
- pyogrio/_compat.py +15 -1
- pyogrio/_env.py +4 -6
- pyogrio/_err.c +8941 -3106
- pyogrio/_err.cp312-win_amd64.pyd +0 -0
- pyogrio/_geometry.c +1008 -807
- pyogrio/_geometry.cp312-win_amd64.pyd +0 -0
- pyogrio/_io.c +10678 -9440
- pyogrio/_io.cp312-win_amd64.pyd +0 -0
- pyogrio/_ogr.c +1950 -1873
- pyogrio/_ogr.cp312-win_amd64.pyd +0 -0
- pyogrio/_version.py +3 -3
- pyogrio/_vsi.c +7558 -2509
- pyogrio/_vsi.cp312-win_amd64.pyd +0 -0
- pyogrio/core.py +86 -20
- pyogrio/errors.py +9 -16
- pyogrio/gdal_data/GDAL-targets.cmake +2 -2
- pyogrio/gdal_data/GDALConfig.cmake +0 -1
- pyogrio/gdal_data/GDALConfigVersion.cmake +3 -3
- pyogrio/gdal_data/MM_m_idofic.csv +321 -0
- pyogrio/gdal_data/gdalinfo_output.schema.json +3 -3
- pyogrio/gdal_data/gdaltileindex.xsd +253 -0
- pyogrio/gdal_data/gdalvrt.xsd +178 -63
- pyogrio/gdal_data/nitf_spec.xml +1 -17
- pyogrio/gdal_data/nitf_spec.xsd +1 -17
- pyogrio/gdal_data/ogrinfo_output.schema.json +23 -0
- pyogrio/gdal_data/ogrvrt.xsd +4 -17
- pyogrio/gdal_data/osmconf.ini +3 -1
- pyogrio/gdal_data/pci_datum.txt +222 -155
- pyogrio/gdal_data/pci_ellips.txt +90 -38
- pyogrio/gdal_data/pdfcomposition.xsd +1 -17
- pyogrio/gdal_data/vcpkg.spdx.json +29 -24
- pyogrio/gdal_data/vcpkg_abi_info.txt +32 -31
- pyogrio/gdal_data/vdv452.xml +1 -17
- pyogrio/gdal_data/vdv452.xsd +1 -17
- pyogrio/geopandas.py +122 -66
- pyogrio/proj_data/ITRF2014 +1 -1
- pyogrio/proj_data/ITRF2020 +91 -0
- pyogrio/proj_data/proj-config-version.cmake +2 -2
- pyogrio/proj_data/proj-config.cmake +1 -1
- pyogrio/proj_data/proj-targets-release.cmake +3 -2
- pyogrio/proj_data/proj-targets.cmake +2 -2
- pyogrio/proj_data/proj.db +0 -0
- pyogrio/proj_data/proj.ini +11 -3
- pyogrio/proj_data/proj4-targets-release.cmake +3 -2
- pyogrio/proj_data/proj4-targets.cmake +2 -2
- pyogrio/proj_data/projjson.schema.json +1 -1
- pyogrio/proj_data/usage +7 -2
- pyogrio/proj_data/vcpkg.spdx.json +26 -21
- pyogrio/proj_data/vcpkg_abi_info.txt +19 -18
- pyogrio/raw.py +46 -30
- pyogrio/tests/conftest.py +214 -12
- pyogrio/tests/fixtures/README.md +32 -13
- pyogrio/tests/fixtures/curve.gpkg +0 -0
- pyogrio/tests/fixtures/{test_multisurface.gpkg → curvepolygon.gpkg} +0 -0
- pyogrio/tests/fixtures/line_zm.gpkg +0 -0
- pyogrio/tests/fixtures/multisurface.gpkg +0 -0
- pyogrio/tests/test_arrow.py +181 -24
- pyogrio/tests/test_core.py +170 -76
- pyogrio/tests/test_geopandas_io.py +483 -135
- pyogrio/tests/test_path.py +39 -17
- pyogrio/tests/test_raw_io.py +170 -55
- pyogrio/tests/test_util.py +56 -0
- pyogrio/util.py +69 -32
- pyogrio-0.11.0.dist-info/DELVEWHEEL +2 -0
- pyogrio-0.11.0.dist-info/METADATA +124 -0
- {pyogrio-0.9.0.dist-info → pyogrio-0.11.0.dist-info}/RECORD +90 -102
- {pyogrio-0.9.0.dist-info → pyogrio-0.11.0.dist-info}/WHEEL +1 -1
- {pyogrio-0.9.0.dist-info → pyogrio-0.11.0.dist-info/licenses}/LICENSE +1 -1
- pyogrio.libs/{Lerc-5e4d8cbeeabca06f95e2270792304dc3.dll → Lerc-0a4c85fb364eca6153da109568898e6c.dll} +0 -0
- pyogrio.libs/{gdal-b434963605a006e01c486c0df6dea4e0.dll → gdal-34e3e080255b205ef706390e097fa4dc.dll} +0 -0
- pyogrio.libs/geos-d8f20037634583c2efcd6ea1f4153169.dll +0 -0
- pyogrio.libs/geos_c-046e8885887192fced9516bda554471d.dll +0 -0
- pyogrio.libs/geotiff-1f2f76a5d30685a8e0497d9dbf8a79cf.dll +0 -0
- pyogrio.libs/{iconv-2-8fcc23ddc6f096c45871011b6e008b44.dll → iconv-2-4b71ebbdf6834234e0c64cb2439b77cf.dll} +0 -0
- pyogrio.libs/{jpeg62-2f9b7af22d78338e8f0be0058503dc35.dll → jpeg62-bf2a75b1f2695748cd86238ddb19c65b.dll} +0 -0
- pyogrio.libs/json-c-4bc6781090e73c9b22d8dc057618a277.dll +0 -0
- pyogrio.libs/libcrypto-3-x64-c8f1692ed45cf55faecce2c448056b2e.dll +0 -0
- pyogrio.libs/libcurl-f3604410cd467a44d927794ebdce81b8.dll +0 -0
- pyogrio.libs/libexpat-385074fd54deb4b640baafa42cbb3146.dll +0 -0
- pyogrio.libs/liblzma-8968f0bfd463b7fe612b20d07adc3c1e.dll +0 -0
- pyogrio.libs/libpng16-44105208fe941d03e9f0c17bdbb952f7.dll +0 -0
- pyogrio.libs/libssl-3-x64-58c364315f431ab1f0e48b311b8cf105.dll +0 -0
- pyogrio.libs/msvcp140-99aa35e2033bb8d388bc35c8a68b77e3.dll +0 -0
- pyogrio.libs/proj_9-ee59474f99643c112eb02aa34a910237.dll +0 -0
- pyogrio.libs/{qhull_r-c45abde5d0c92faf723cc2942138af77.dll → qhull_r-eaac2f11a3d8241f082e54447c7504d7.dll} +0 -0
- pyogrio.libs/sqlite3-dc748e3452944fd41001abacdd783569.dll +0 -0
- pyogrio.libs/tiff-c409ddbe87b39639b83fee50d4aea318.dll +0 -0
- pyogrio.libs/{zlib1-e1272810861a13dd8d6cff3beac47f17.dll → zlib1-094085b7b78666197dcc8e1fce2d835d.dll} +0 -0
- pyogrio/_err.pxd +0 -4
- pyogrio/_err.pyx +0 -250
- pyogrio/_geometry.pxd +0 -4
- pyogrio/_geometry.pyx +0 -129
- pyogrio/_io.pxd +0 -0
- pyogrio/_io.pyx +0 -2742
- pyogrio/_ogr.pxd +0 -444
- pyogrio/_ogr.pyx +0 -346
- pyogrio/_vsi.pxd +0 -4
- pyogrio/_vsi.pyx +0 -140
- pyogrio/arrow_bridge.h +0 -115
- pyogrio/gdal_data/bag_template.xml +0 -201
- pyogrio/gdal_data/gmlasconf.xml +0 -169
- pyogrio/gdal_data/gmlasconf.xsd +0 -1066
- pyogrio/gdal_data/netcdf_config.xsd +0 -143
- pyogrio/tests/fixtures/poly_not_enough_points.shp.zip +0 -0
- pyogrio/tests/fixtures/test_datetime.geojson +0 -7
- pyogrio/tests/fixtures/test_datetime_tz.geojson +0 -8
- pyogrio/tests/fixtures/test_fgdb.gdb.zip +0 -0
- pyogrio/tests/fixtures/test_nested.geojson +0 -18
- pyogrio/tests/fixtures/test_ogr_types_list.geojson +0 -12
- pyogrio-0.9.0.dist-info/DELVEWHEEL +0 -2
- pyogrio-0.9.0.dist-info/METADATA +0 -100
- pyogrio.libs/geos-f0622d0794b81c937a851b2e6fa9b712.dll +0 -0
- pyogrio.libs/geos_c-0e16bf70612fc3301d077b9d863a3fdb.dll +0 -0
- pyogrio.libs/geotiff-772e7c705fb15ddf91b432adb4eb1f6c.dll +0 -0
- pyogrio.libs/json-c-e52a077545e4057de42beb4948289b41.dll +0 -0
- pyogrio.libs/libcurl-bc81cd8afe15b10c0821b181b6af8bd0.dll +0 -0
- pyogrio.libs/libexpat-fbe03ca8917dfda776562d4338b289b8.dll +0 -0
- pyogrio.libs/liblzma-6b36f24d54d3dd45f274a2aebef81085.dll +0 -0
- pyogrio.libs/libpng16-13928571ad910705eae8d7dd8eef8b11.dll +0 -0
- pyogrio.libs/msvcp140-46db46e967c8db2cb7a20fc75872a57e.dll +0 -0
- pyogrio.libs/proj-8a30239ef2dfc3b9dd2bb48e8abb330f.dll +0 -0
- pyogrio.libs/sqlite3-df30c3cf230727e23c43c40126a530f7.dll +0 -0
- pyogrio.libs/tiff-43630f30487a9015213475ae86ed3fa3.dll +0 -0
- {pyogrio-0.9.0.dist-info → pyogrio-0.11.0.dist-info}/top_level.txt +0 -0
pyogrio/tests/test_core.py
CHANGED
|
@@ -1,29 +1,35 @@
|
|
|
1
|
+
from pathlib import Path
|
|
2
|
+
|
|
1
3
|
import numpy as np
|
|
2
|
-
from numpy import
|
|
3
|
-
import pytest
|
|
4
|
+
from numpy import allclose, array_equal
|
|
4
5
|
|
|
5
6
|
from pyogrio import (
|
|
6
|
-
__gdal_version__,
|
|
7
7
|
__gdal_geos_version__,
|
|
8
|
+
__gdal_version__,
|
|
9
|
+
detect_write_driver,
|
|
10
|
+
get_gdal_config_option,
|
|
11
|
+
get_gdal_data_path,
|
|
8
12
|
list_drivers,
|
|
9
13
|
list_layers,
|
|
10
14
|
read_bounds,
|
|
11
15
|
read_info,
|
|
12
16
|
set_gdal_config_options,
|
|
13
|
-
|
|
14
|
-
|
|
17
|
+
vsi_listtree,
|
|
18
|
+
vsi_rmtree,
|
|
19
|
+
vsi_unlink,
|
|
15
20
|
)
|
|
16
|
-
from pyogrio.core import detect_write_driver
|
|
17
21
|
from pyogrio._compat import GDAL_GE_38
|
|
18
|
-
from pyogrio.errors import DataSourceError, DataLayerError
|
|
19
|
-
from pyogrio.tests.conftest import HAS_SHAPELY, prepare_testfile
|
|
20
|
-
|
|
21
22
|
from pyogrio._env import GDALEnv
|
|
23
|
+
from pyogrio.errors import DataLayerError, DataSourceError
|
|
24
|
+
from pyogrio.raw import read, write
|
|
25
|
+
from pyogrio.tests.conftest import START_FID, prepare_testfile, requires_shapely
|
|
26
|
+
|
|
27
|
+
import pytest
|
|
22
28
|
|
|
23
29
|
with GDALEnv():
|
|
24
30
|
# NOTE: this must be AFTER above imports, which init the GDAL and PROJ data
|
|
25
31
|
# search paths
|
|
26
|
-
from pyogrio._ogr import
|
|
32
|
+
from pyogrio._ogr import has_gdal_data, has_proj_data, ogr_driver_supports_write
|
|
27
33
|
|
|
28
34
|
|
|
29
35
|
try:
|
|
@@ -100,9 +106,9 @@ def test_detect_write_driver_unsupported(path):
|
|
|
100
106
|
detect_write_driver(path)
|
|
101
107
|
|
|
102
108
|
|
|
103
|
-
@pytest.mark.parametrize("path", ["test.xml"
|
|
109
|
+
@pytest.mark.parametrize("path", ["test.xml"])
|
|
104
110
|
def test_detect_write_driver_multiple_unsupported(path):
|
|
105
|
-
with pytest.raises(ValueError, match="multiple drivers are available"):
|
|
111
|
+
with pytest.raises(ValueError, match="multiple drivers are available "):
|
|
106
112
|
detect_write_driver(path)
|
|
107
113
|
|
|
108
114
|
|
|
@@ -151,7 +157,16 @@ def test_list_drivers():
|
|
|
151
157
|
assert len(drivers) == len(expected)
|
|
152
158
|
|
|
153
159
|
|
|
154
|
-
def test_list_layers(
|
|
160
|
+
def test_list_layers(
|
|
161
|
+
naturalearth_lowres,
|
|
162
|
+
naturalearth_lowres_vsi,
|
|
163
|
+
naturalearth_lowres_vsimem,
|
|
164
|
+
line_zm_file,
|
|
165
|
+
curve_file,
|
|
166
|
+
curve_polygon_file,
|
|
167
|
+
multisurface_file,
|
|
168
|
+
no_geometry_file,
|
|
169
|
+
):
|
|
155
170
|
assert array_equal(
|
|
156
171
|
list_layers(naturalearth_lowres), [["naturalearth_lowres", "Polygon"]]
|
|
157
172
|
)
|
|
@@ -160,21 +175,27 @@ def test_list_layers(naturalearth_lowres, naturalearth_lowres_vsi, test_fgdb_vsi
|
|
|
160
175
|
list_layers(naturalearth_lowres_vsi[1]), [["naturalearth_lowres", "Polygon"]]
|
|
161
176
|
)
|
|
162
177
|
|
|
178
|
+
assert array_equal(
|
|
179
|
+
list_layers(naturalearth_lowres_vsimem),
|
|
180
|
+
[["naturalearth_lowres", "MultiPolygon"]],
|
|
181
|
+
)
|
|
182
|
+
|
|
163
183
|
# Measured 3D is downgraded to plain 3D during read
|
|
164
184
|
# Make sure this warning is raised
|
|
165
185
|
with pytest.warns(
|
|
166
186
|
UserWarning, match=r"Measured \(M\) geometry types are not supported"
|
|
167
187
|
):
|
|
168
|
-
|
|
169
|
-
# GDAL >= 3.4.0 includes 'another_relationship' layer
|
|
170
|
-
assert len(fgdb_layers) >= 7
|
|
188
|
+
assert array_equal(list_layers(line_zm_file), [["line_zm", "LineString Z"]])
|
|
171
189
|
|
|
172
|
-
|
|
173
|
-
|
|
190
|
+
# Curve / surface types are downgraded to plain types
|
|
191
|
+
assert array_equal(list_layers(curve_file), [["curve", "LineString"]])
|
|
192
|
+
assert array_equal(list_layers(curve_polygon_file), [["curvepolygon", "Polygon"]])
|
|
193
|
+
assert array_equal(
|
|
194
|
+
list_layers(multisurface_file), [["multisurface", "MultiPolygon"]]
|
|
195
|
+
)
|
|
174
196
|
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
assert array_equal(fgdb_layers[6], ["test_areas", "MultiPolygon Z"])
|
|
197
|
+
# Make sure that nonspatial layer has None for geometry
|
|
198
|
+
assert array_equal(list_layers(no_geometry_file), [["no_geometry", None]])
|
|
178
199
|
|
|
179
200
|
|
|
180
201
|
def test_list_layers_bytes(geojson_bytes):
|
|
@@ -184,6 +205,13 @@ def test_list_layers_bytes(geojson_bytes):
|
|
|
184
205
|
assert layers[0, 0] == "test"
|
|
185
206
|
|
|
186
207
|
|
|
208
|
+
def test_list_layers_nonseekable_bytes(nonseekable_bytes):
|
|
209
|
+
layers = list_layers(nonseekable_bytes)
|
|
210
|
+
|
|
211
|
+
assert layers.shape == (1, 2)
|
|
212
|
+
assert layers[0, 1] == "Point"
|
|
213
|
+
|
|
214
|
+
|
|
187
215
|
def test_list_layers_filelike(geojson_filelike):
|
|
188
216
|
layers = list_layers(geojson_filelike)
|
|
189
217
|
|
|
@@ -191,22 +219,18 @@ def test_list_layers_filelike(geojson_filelike):
|
|
|
191
219
|
assert layers[0, 0] == "test"
|
|
192
220
|
|
|
193
221
|
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
assert allclose(bounds[:, 0], [-180.0, -18.28799, 180.0, -16.02088])
|
|
202
|
-
|
|
222
|
+
@pytest.mark.parametrize(
|
|
223
|
+
"testfile",
|
|
224
|
+
["naturalearth_lowres", "naturalearth_lowres_vsimem", "naturalearth_lowres_vsi"],
|
|
225
|
+
)
|
|
226
|
+
def test_read_bounds(testfile, request):
|
|
227
|
+
path = request.getfixturevalue(testfile)
|
|
228
|
+
path = path if not isinstance(path, tuple) else path[1]
|
|
203
229
|
|
|
204
|
-
|
|
205
|
-
fids, bounds = read_bounds(naturalearth_lowres_vsi[1])
|
|
230
|
+
fids, bounds = read_bounds(path)
|
|
206
231
|
assert fids.shape == (177,)
|
|
207
232
|
assert bounds.shape == (4, 177)
|
|
208
|
-
|
|
209
|
-
assert fids[0] == 0
|
|
233
|
+
assert fids[0] == START_FID[Path(path).suffix]
|
|
210
234
|
# Fiji; wraps antimeridian
|
|
211
235
|
assert allclose(bounds[:, 0], [-180.0, -18.28799, 180.0, -16.02088])
|
|
212
236
|
|
|
@@ -218,6 +242,13 @@ def test_read_bounds_bytes(geojson_bytes):
|
|
|
218
242
|
assert allclose(bounds[:, 0], [-180.0, -18.28799, 180.0, -16.02088])
|
|
219
243
|
|
|
220
244
|
|
|
245
|
+
def test_read_bounds_nonseekable_bytes(nonseekable_bytes):
|
|
246
|
+
fids, bounds = read_bounds(nonseekable_bytes)
|
|
247
|
+
assert fids.shape == (1,)
|
|
248
|
+
assert bounds.shape == (4, 1)
|
|
249
|
+
assert allclose(bounds[:, 0], [1, 1, 1, 1])
|
|
250
|
+
|
|
251
|
+
|
|
221
252
|
def test_read_bounds_filelike(geojson_filelike):
|
|
222
253
|
fids, bounds = read_bounds(geojson_filelike)
|
|
223
254
|
assert fids.shape == (3,)
|
|
@@ -255,8 +286,12 @@ def test_read_bounds_negative_skip_features(naturalearth_lowres):
|
|
|
255
286
|
|
|
256
287
|
|
|
257
288
|
def test_read_bounds_where_invalid(naturalearth_lowres_all_ext):
|
|
258
|
-
|
|
259
|
-
|
|
289
|
+
if naturalearth_lowres_all_ext.suffix == ".gpkg" and __gdal_version__ >= (3, 11, 0):
|
|
290
|
+
with pytest.raises(DataLayerError, match="no such column"):
|
|
291
|
+
read_bounds(naturalearth_lowres_all_ext, where="invalid")
|
|
292
|
+
else:
|
|
293
|
+
with pytest.raises(ValueError, match="Invalid SQL"):
|
|
294
|
+
read_bounds(naturalearth_lowres_all_ext, where="invalid")
|
|
260
295
|
|
|
261
296
|
|
|
262
297
|
def test_read_bounds_where(naturalearth_lowres):
|
|
@@ -285,12 +320,9 @@ def test_read_bounds_bbox(naturalearth_lowres_all_ext):
|
|
|
285
320
|
fids, bounds = read_bounds(naturalearth_lowres_all_ext, bbox=(-85, 8, -80, 10))
|
|
286
321
|
|
|
287
322
|
assert fids.shape == (2,)
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
else:
|
|
292
|
-
# fid in other formats is 0-based
|
|
293
|
-
assert array_equal(fids, [33, 34]) # PAN, CRI
|
|
323
|
+
fids_expected = np.array([33, 34]) # PAN, CRI
|
|
324
|
+
fids_expected += START_FID[naturalearth_lowres_all_ext.suffix]
|
|
325
|
+
assert array_equal(fids, fids_expected)
|
|
294
326
|
|
|
295
327
|
assert bounds.shape == (4, 2)
|
|
296
328
|
assert allclose(
|
|
@@ -302,9 +334,7 @@ def test_read_bounds_bbox(naturalearth_lowres_all_ext):
|
|
|
302
334
|
)
|
|
303
335
|
|
|
304
336
|
|
|
305
|
-
@
|
|
306
|
-
not HAS_SHAPELY, reason="Shapely is required for mask functionality"
|
|
307
|
-
)
|
|
337
|
+
@requires_shapely
|
|
308
338
|
@pytest.mark.parametrize(
|
|
309
339
|
"mask",
|
|
310
340
|
[
|
|
@@ -318,9 +348,7 @@ def test_read_bounds_mask_invalid(naturalearth_lowres, mask):
|
|
|
318
348
|
read_bounds(naturalearth_lowres, mask=mask)
|
|
319
349
|
|
|
320
350
|
|
|
321
|
-
@
|
|
322
|
-
not HAS_SHAPELY, reason="Shapely is required for mask functionality"
|
|
323
|
-
)
|
|
351
|
+
@requires_shapely
|
|
324
352
|
def test_read_bounds_bbox_mask_invalid(naturalearth_lowres):
|
|
325
353
|
with pytest.raises(ValueError, match="cannot set both 'bbox' and 'mask'"):
|
|
326
354
|
read_bounds(
|
|
@@ -328,9 +356,7 @@ def test_read_bounds_bbox_mask_invalid(naturalearth_lowres):
|
|
|
328
356
|
)
|
|
329
357
|
|
|
330
358
|
|
|
331
|
-
@
|
|
332
|
-
not HAS_SHAPELY, reason="Shapely is required for mask functionality"
|
|
333
|
-
)
|
|
359
|
+
@requires_shapely
|
|
334
360
|
@pytest.mark.parametrize(
|
|
335
361
|
"mask,expected",
|
|
336
362
|
[
|
|
@@ -361,12 +387,8 @@ def test_read_bounds_mask(naturalearth_lowres_all_ext, mask, expected):
|
|
|
361
387
|
|
|
362
388
|
fids = read_bounds(naturalearth_lowres_all_ext, mask=mask)[0]
|
|
363
389
|
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
assert array_equal(fids, np.array(expected) + 1)
|
|
367
|
-
else:
|
|
368
|
-
# fid in other formats is 0-based
|
|
369
|
-
assert array_equal(fids, expected)
|
|
390
|
+
fids_expected = np.array(expected) + START_FID[naturalearth_lowres_all_ext.suffix]
|
|
391
|
+
assert array_equal(fids, fids_expected)
|
|
370
392
|
|
|
371
393
|
|
|
372
394
|
@pytest.mark.skipif(
|
|
@@ -382,21 +404,15 @@ def test_read_bounds_bbox_intersects_vs_envelope_overlaps(naturalearth_lowres_al
|
|
|
382
404
|
if __gdal_geos_version__ is None:
|
|
383
405
|
# bboxes for CAN, RUS overlap but do not intersect geometries
|
|
384
406
|
assert fids.shape == (4,)
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
else:
|
|
389
|
-
# fid in other formats is 0-based
|
|
390
|
-
assert array_equal(fids, [3, 4, 18, 27]) # CAN, USA, RUS, MEX
|
|
407
|
+
fids_expected = np.array([3, 4, 18, 27]) # CAN, USA, RUS, MEX
|
|
408
|
+
fids_expected += START_FID[naturalearth_lowres_all_ext.suffix]
|
|
409
|
+
assert array_equal(fids, fids_expected)
|
|
391
410
|
|
|
392
411
|
else:
|
|
393
412
|
assert fids.shape == (2,)
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
else:
|
|
398
|
-
# fid in other formats is 0-based
|
|
399
|
-
assert array_equal(fids, [4, 27]) # USA, MEX
|
|
413
|
+
fids_expected = np.array([4, 27]) # USA, MEX
|
|
414
|
+
fids_expected += START_FID[naturalearth_lowres_all_ext.suffix]
|
|
415
|
+
assert array_equal(fids, fids_expected)
|
|
400
416
|
|
|
401
417
|
|
|
402
418
|
@pytest.mark.parametrize("naturalearth_lowres", [".shp", ".gpkg"], indirect=True)
|
|
@@ -426,7 +442,8 @@ def test_read_info(naturalearth_lowres):
|
|
|
426
442
|
elif naturalearth_lowres.suffix == ".shp":
|
|
427
443
|
# fid_column == "" for formats where fid is not physically stored
|
|
428
444
|
assert meta["fid_column"] == ""
|
|
429
|
-
# geometry_name == "" for formats where geometry column name cannot be
|
|
445
|
+
# geometry_name == "" for formats where geometry column name cannot be
|
|
446
|
+
# customized
|
|
430
447
|
assert meta["geometry_name"] == ""
|
|
431
448
|
assert meta["geometry_type"] == "Polygon"
|
|
432
449
|
assert meta["driver"] == "ESRI Shapefile"
|
|
@@ -435,8 +452,14 @@ def test_read_info(naturalearth_lowres):
|
|
|
435
452
|
raise ValueError(f"test not implemented for ext {naturalearth_lowres.suffix}")
|
|
436
453
|
|
|
437
454
|
|
|
438
|
-
|
|
439
|
-
|
|
455
|
+
@pytest.mark.parametrize(
|
|
456
|
+
"testfile", ["naturalearth_lowres_vsimem", "naturalearth_lowres_vsi"]
|
|
457
|
+
)
|
|
458
|
+
def test_read_info_vsi(testfile, request):
|
|
459
|
+
path = request.getfixturevalue(testfile)
|
|
460
|
+
path = path if not isinstance(path, tuple) else path[1]
|
|
461
|
+
|
|
462
|
+
meta = read_info(path)
|
|
440
463
|
|
|
441
464
|
assert meta["fields"].shape == (5,)
|
|
442
465
|
assert meta["features"] == 177
|
|
@@ -449,6 +472,13 @@ def test_read_info_bytes(geojson_bytes):
|
|
|
449
472
|
assert meta["features"] == 3
|
|
450
473
|
|
|
451
474
|
|
|
475
|
+
def test_read_info_nonseekable_bytes(nonseekable_bytes):
|
|
476
|
+
meta = read_info(nonseekable_bytes)
|
|
477
|
+
|
|
478
|
+
assert meta["fields"].shape == (0,)
|
|
479
|
+
assert meta["features"] == 1
|
|
480
|
+
|
|
481
|
+
|
|
452
482
|
def test_read_info_filelike(geojson_filelike):
|
|
453
483
|
meta = read_info(geojson_filelike)
|
|
454
484
|
|
|
@@ -483,8 +513,8 @@ def test_read_info_filelike(geojson_filelike):
|
|
|
483
513
|
),
|
|
484
514
|
],
|
|
485
515
|
)
|
|
486
|
-
def test_read_info_dataset_kwargs(
|
|
487
|
-
meta = read_info(
|
|
516
|
+
def test_read_info_dataset_kwargs(nested_geojson_file, dataset_kwargs, fields):
|
|
517
|
+
meta = read_info(nested_geojson_file, **dataset_kwargs)
|
|
488
518
|
assert meta["fields"].tolist() == fields
|
|
489
519
|
|
|
490
520
|
|
|
@@ -543,8 +573,8 @@ def test_read_info_unspecified_layer_warning(data_dir):
|
|
|
543
573
|
read_info(data_dir / "sample.osm.pbf")
|
|
544
574
|
|
|
545
575
|
|
|
546
|
-
def test_read_info_without_geometry(
|
|
547
|
-
assert read_info(
|
|
576
|
+
def test_read_info_without_geometry(no_geometry_file):
|
|
577
|
+
assert read_info(no_geometry_file)["total_bounds"] is None
|
|
548
578
|
|
|
549
579
|
|
|
550
580
|
@pytest.mark.parametrize(
|
|
@@ -586,3 +616,67 @@ def test_error_handling_warning(capfd, naturalearth_lowres):
|
|
|
586
616
|
read_info(naturalearth_lowres, INVALID="YES")
|
|
587
617
|
|
|
588
618
|
assert capfd.readouterr().err == ""
|
|
619
|
+
|
|
620
|
+
|
|
621
|
+
def test_vsimem_listtree_rmtree_unlink(naturalearth_lowres):
|
|
622
|
+
"""Test all basic functionalities of file handling in /vsimem/."""
|
|
623
|
+
# Prepare test data in /vsimem
|
|
624
|
+
meta, _, geometry, field_data = read(naturalearth_lowres)
|
|
625
|
+
meta["spatial_index"] = False
|
|
626
|
+
meta["geometry_type"] = "MultiPolygon"
|
|
627
|
+
test_file_path = Path("/vsimem/pyogrio_test_naturalearth_lowres.gpkg")
|
|
628
|
+
test_dir_path = Path(f"/vsimem/pyogrio_dir_test/{naturalearth_lowres.stem}.gpkg")
|
|
629
|
+
|
|
630
|
+
write(test_file_path, geometry, field_data, **meta)
|
|
631
|
+
write(test_dir_path, geometry, field_data, **meta)
|
|
632
|
+
|
|
633
|
+
# Check if everything was created properly with listtree
|
|
634
|
+
files = vsi_listtree("/vsimem/")
|
|
635
|
+
assert test_file_path.as_posix() in files
|
|
636
|
+
assert test_dir_path.as_posix() in files
|
|
637
|
+
|
|
638
|
+
# Check listtree with pattern
|
|
639
|
+
files = vsi_listtree("/vsimem/", pattern="pyogrio_dir_test*.gpkg")
|
|
640
|
+
assert test_file_path.as_posix() not in files
|
|
641
|
+
assert test_dir_path.as_posix() in files
|
|
642
|
+
|
|
643
|
+
files = vsi_listtree("/vsimem/", pattern="pyogrio_test*.gpkg")
|
|
644
|
+
assert test_file_path.as_posix() in files
|
|
645
|
+
assert test_dir_path.as_posix() not in files
|
|
646
|
+
|
|
647
|
+
# Remove test_dir and its contents
|
|
648
|
+
vsi_rmtree(test_dir_path.parent)
|
|
649
|
+
files = vsi_listtree("/vsimem/")
|
|
650
|
+
assert test_file_path.as_posix() in files
|
|
651
|
+
assert test_dir_path.as_posix() not in files
|
|
652
|
+
|
|
653
|
+
# Remove test_file
|
|
654
|
+
vsi_unlink(test_file_path)
|
|
655
|
+
|
|
656
|
+
|
|
657
|
+
def test_vsimem_rmtree_error(naturalearth_lowres_vsimem):
|
|
658
|
+
with pytest.raises(NotADirectoryError, match="Path is not a directory"):
|
|
659
|
+
vsi_rmtree(naturalearth_lowres_vsimem)
|
|
660
|
+
|
|
661
|
+
with pytest.raises(FileNotFoundError, match="Path does not exist"):
|
|
662
|
+
vsi_rmtree("/vsimem/non-existent")
|
|
663
|
+
|
|
664
|
+
with pytest.raises(
|
|
665
|
+
OSError, match="path to in-memory file or directory is required"
|
|
666
|
+
):
|
|
667
|
+
vsi_rmtree("/vsimem")
|
|
668
|
+
with pytest.raises(
|
|
669
|
+
OSError, match="path to in-memory file or directory is required"
|
|
670
|
+
):
|
|
671
|
+
vsi_rmtree("/vsimem/")
|
|
672
|
+
|
|
673
|
+
# Verify that naturalearth_lowres_vsimem still exists.
|
|
674
|
+
assert naturalearth_lowres_vsimem.as_posix() in vsi_listtree("/vsimem")
|
|
675
|
+
|
|
676
|
+
|
|
677
|
+
def test_vsimem_unlink_error(naturalearth_lowres_vsimem):
|
|
678
|
+
with pytest.raises(IsADirectoryError, match="Path is a directory"):
|
|
679
|
+
vsi_unlink(naturalearth_lowres_vsimem.parent)
|
|
680
|
+
|
|
681
|
+
with pytest.raises(FileNotFoundError, match="Path does not exist"):
|
|
682
|
+
vsi_unlink("/vsimem/non-existent.gpkg")
|