pyogrio 0.10.0__cp313-cp313-manylinux_2_28_aarch64.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.

Files changed (223) hide show
  1. pyogrio/__init__.py +55 -0
  2. pyogrio/_compat.py +47 -0
  3. pyogrio/_env.py +59 -0
  4. pyogrio/_err.cpython-313-aarch64-linux-gnu.so +0 -0
  5. pyogrio/_geometry.cpython-313-aarch64-linux-gnu.so +0 -0
  6. pyogrio/_io.cpython-313-aarch64-linux-gnu.so +0 -0
  7. pyogrio/_ogr.cpython-313-aarch64-linux-gnu.so +0 -0
  8. pyogrio/_version.py +21 -0
  9. pyogrio/_vsi.cpython-313-aarch64-linux-gnu.so +0 -0
  10. pyogrio/core.py +386 -0
  11. pyogrio/errors.py +25 -0
  12. pyogrio/gdal_data/GDAL-targets-release.cmake +19 -0
  13. pyogrio/gdal_data/GDAL-targets.cmake +105 -0
  14. pyogrio/gdal_data/GDALConfig.cmake +24 -0
  15. pyogrio/gdal_data/GDALConfigVersion.cmake +85 -0
  16. pyogrio/gdal_data/GDALLogoBW.svg +138 -0
  17. pyogrio/gdal_data/GDALLogoColor.svg +126 -0
  18. pyogrio/gdal_data/GDALLogoGS.svg +126 -0
  19. pyogrio/gdal_data/LICENSE.TXT +467 -0
  20. pyogrio/gdal_data/MM_m_idofic.csv +321 -0
  21. pyogrio/gdal_data/copyright +467 -0
  22. pyogrio/gdal_data/cubewerx_extra.wkt +48 -0
  23. pyogrio/gdal_data/default.rsc +0 -0
  24. pyogrio/gdal_data/ecw_cs.wkt +1453 -0
  25. pyogrio/gdal_data/eedaconf.json +23 -0
  26. pyogrio/gdal_data/epsg.wkt +1 -0
  27. pyogrio/gdal_data/esri_StatePlane_extra.wkt +631 -0
  28. pyogrio/gdal_data/gdalicon.png +0 -0
  29. pyogrio/gdal_data/gdalinfo_output.schema.json +346 -0
  30. pyogrio/gdal_data/gdalmdiminfo_output.schema.json +321 -0
  31. pyogrio/gdal_data/gdaltileindex.xsd +269 -0
  32. pyogrio/gdal_data/gdalvrt.xsd +880 -0
  33. pyogrio/gdal_data/gfs.xsd +246 -0
  34. pyogrio/gdal_data/gml_registry.xml +117 -0
  35. pyogrio/gdal_data/gml_registry.xsd +66 -0
  36. pyogrio/gdal_data/grib2_center.csv +251 -0
  37. pyogrio/gdal_data/grib2_process.csv +102 -0
  38. pyogrio/gdal_data/grib2_subcenter.csv +63 -0
  39. pyogrio/gdal_data/grib2_table_4_2_0_0.csv +261 -0
  40. pyogrio/gdal_data/grib2_table_4_2_0_1.csv +261 -0
  41. pyogrio/gdal_data/grib2_table_4_2_0_13.csv +261 -0
  42. pyogrio/gdal_data/grib2_table_4_2_0_14.csv +261 -0
  43. pyogrio/gdal_data/grib2_table_4_2_0_15.csv +261 -0
  44. pyogrio/gdal_data/grib2_table_4_2_0_16.csv +261 -0
  45. pyogrio/gdal_data/grib2_table_4_2_0_17.csv +11 -0
  46. pyogrio/gdal_data/grib2_table_4_2_0_18.csv +261 -0
  47. pyogrio/gdal_data/grib2_table_4_2_0_19.csv +261 -0
  48. pyogrio/gdal_data/grib2_table_4_2_0_190.csv +261 -0
  49. pyogrio/gdal_data/grib2_table_4_2_0_191.csv +261 -0
  50. pyogrio/gdal_data/grib2_table_4_2_0_2.csv +261 -0
  51. pyogrio/gdal_data/grib2_table_4_2_0_20.csv +261 -0
  52. pyogrio/gdal_data/grib2_table_4_2_0_21.csv +261 -0
  53. pyogrio/gdal_data/grib2_table_4_2_0_3.csv +261 -0
  54. pyogrio/gdal_data/grib2_table_4_2_0_4.csv +261 -0
  55. pyogrio/gdal_data/grib2_table_4_2_0_5.csv +261 -0
  56. pyogrio/gdal_data/grib2_table_4_2_0_6.csv +261 -0
  57. pyogrio/gdal_data/grib2_table_4_2_0_7.csv +261 -0
  58. pyogrio/gdal_data/grib2_table_4_2_10_0.csv +261 -0
  59. pyogrio/gdal_data/grib2_table_4_2_10_1.csv +261 -0
  60. pyogrio/gdal_data/grib2_table_4_2_10_191.csv +261 -0
  61. pyogrio/gdal_data/grib2_table_4_2_10_2.csv +261 -0
  62. pyogrio/gdal_data/grib2_table_4_2_10_3.csv +261 -0
  63. pyogrio/gdal_data/grib2_table_4_2_10_4.csv +261 -0
  64. pyogrio/gdal_data/grib2_table_4_2_1_0.csv +261 -0
  65. pyogrio/gdal_data/grib2_table_4_2_1_1.csv +261 -0
  66. pyogrio/gdal_data/grib2_table_4_2_1_2.csv +261 -0
  67. pyogrio/gdal_data/grib2_table_4_2_20_0.csv +261 -0
  68. pyogrio/gdal_data/grib2_table_4_2_20_1.csv +261 -0
  69. pyogrio/gdal_data/grib2_table_4_2_20_2.csv +261 -0
  70. pyogrio/gdal_data/grib2_table_4_2_2_0.csv +261 -0
  71. pyogrio/gdal_data/grib2_table_4_2_2_3.csv +261 -0
  72. pyogrio/gdal_data/grib2_table_4_2_2_4.csv +261 -0
  73. pyogrio/gdal_data/grib2_table_4_2_2_5.csv +261 -0
  74. pyogrio/gdal_data/grib2_table_4_2_2_6.csv +261 -0
  75. pyogrio/gdal_data/grib2_table_4_2_3_0.csv +261 -0
  76. pyogrio/gdal_data/grib2_table_4_2_3_1.csv +261 -0
  77. pyogrio/gdal_data/grib2_table_4_2_3_2.csv +28 -0
  78. pyogrio/gdal_data/grib2_table_4_2_3_3.csv +8 -0
  79. pyogrio/gdal_data/grib2_table_4_2_3_4.csv +14 -0
  80. pyogrio/gdal_data/grib2_table_4_2_3_5.csv +11 -0
  81. pyogrio/gdal_data/grib2_table_4_2_3_6.csv +11 -0
  82. pyogrio/gdal_data/grib2_table_4_2_4_0.csv +261 -0
  83. pyogrio/gdal_data/grib2_table_4_2_4_1.csv +261 -0
  84. pyogrio/gdal_data/grib2_table_4_2_4_10.csv +261 -0
  85. pyogrio/gdal_data/grib2_table_4_2_4_2.csv +261 -0
  86. pyogrio/gdal_data/grib2_table_4_2_4_3.csv +261 -0
  87. pyogrio/gdal_data/grib2_table_4_2_4_4.csv +261 -0
  88. pyogrio/gdal_data/grib2_table_4_2_4_5.csv +261 -0
  89. pyogrio/gdal_data/grib2_table_4_2_4_6.csv +261 -0
  90. pyogrio/gdal_data/grib2_table_4_2_4_7.csv +261 -0
  91. pyogrio/gdal_data/grib2_table_4_2_4_8.csv +261 -0
  92. pyogrio/gdal_data/grib2_table_4_2_4_9.csv +261 -0
  93. pyogrio/gdal_data/grib2_table_4_2_local_Canada.csv +5 -0
  94. pyogrio/gdal_data/grib2_table_4_2_local_HPC.csv +2 -0
  95. pyogrio/gdal_data/grib2_table_4_2_local_MRMS.csv +175 -0
  96. pyogrio/gdal_data/grib2_table_4_2_local_NCEP.csv +401 -0
  97. pyogrio/gdal_data/grib2_table_4_2_local_NDFD.csv +38 -0
  98. pyogrio/gdal_data/grib2_table_4_2_local_index.csv +7 -0
  99. pyogrio/gdal_data/grib2_table_4_5.csv +261 -0
  100. pyogrio/gdal_data/grib2_table_versions.csv +3 -0
  101. pyogrio/gdal_data/gt_datum.csv +229 -0
  102. pyogrio/gdal_data/gt_ellips.csv +24 -0
  103. pyogrio/gdal_data/header.dxf +1124 -0
  104. pyogrio/gdal_data/inspire_cp_BasicPropertyUnit.gfs +57 -0
  105. pyogrio/gdal_data/inspire_cp_CadastralBoundary.gfs +60 -0
  106. pyogrio/gdal_data/inspire_cp_CadastralParcel.gfs +81 -0
  107. pyogrio/gdal_data/inspire_cp_CadastralZoning.gfs +161 -0
  108. pyogrio/gdal_data/jpfgdgml_AdmArea.gfs +59 -0
  109. pyogrio/gdal_data/jpfgdgml_AdmBdry.gfs +49 -0
  110. pyogrio/gdal_data/jpfgdgml_AdmPt.gfs +59 -0
  111. pyogrio/gdal_data/jpfgdgml_BldA.gfs +54 -0
  112. pyogrio/gdal_data/jpfgdgml_BldL.gfs +54 -0
  113. pyogrio/gdal_data/jpfgdgml_Cntr.gfs +54 -0
  114. pyogrio/gdal_data/jpfgdgml_CommBdry.gfs +49 -0
  115. pyogrio/gdal_data/jpfgdgml_CommPt.gfs +59 -0
  116. pyogrio/gdal_data/jpfgdgml_Cstline.gfs +54 -0
  117. pyogrio/gdal_data/jpfgdgml_ElevPt.gfs +54 -0
  118. pyogrio/gdal_data/jpfgdgml_GCP.gfs +94 -0
  119. pyogrio/gdal_data/jpfgdgml_LeveeEdge.gfs +49 -0
  120. pyogrio/gdal_data/jpfgdgml_RailCL.gfs +54 -0
  121. pyogrio/gdal_data/jpfgdgml_RdASL.gfs +44 -0
  122. pyogrio/gdal_data/jpfgdgml_RdArea.gfs +54 -0
  123. pyogrio/gdal_data/jpfgdgml_RdCompt.gfs +59 -0
  124. pyogrio/gdal_data/jpfgdgml_RdEdg.gfs +59 -0
  125. pyogrio/gdal_data/jpfgdgml_RdMgtBdry.gfs +49 -0
  126. pyogrio/gdal_data/jpfgdgml_RdSgmtA.gfs +59 -0
  127. pyogrio/gdal_data/jpfgdgml_RvrMgtBdry.gfs +49 -0
  128. pyogrio/gdal_data/jpfgdgml_SBAPt.gfs +49 -0
  129. pyogrio/gdal_data/jpfgdgml_SBArea.gfs +54 -0
  130. pyogrio/gdal_data/jpfgdgml_SBBdry.gfs +44 -0
  131. pyogrio/gdal_data/jpfgdgml_WA.gfs +54 -0
  132. pyogrio/gdal_data/jpfgdgml_WL.gfs +54 -0
  133. pyogrio/gdal_data/jpfgdgml_WStrA.gfs +54 -0
  134. pyogrio/gdal_data/jpfgdgml_WStrL.gfs +54 -0
  135. pyogrio/gdal_data/nitf_spec.xml +3306 -0
  136. pyogrio/gdal_data/nitf_spec.xsd +189 -0
  137. pyogrio/gdal_data/ogrinfo_output.schema.json +528 -0
  138. pyogrio/gdal_data/ogrvrt.xsd +546 -0
  139. pyogrio/gdal_data/osmconf.ini +132 -0
  140. pyogrio/gdal_data/ozi_datum.csv +131 -0
  141. pyogrio/gdal_data/ozi_ellips.csv +35 -0
  142. pyogrio/gdal_data/pci_datum.txt +530 -0
  143. pyogrio/gdal_data/pci_ellips.txt +129 -0
  144. pyogrio/gdal_data/pdfcomposition.xsd +721 -0
  145. pyogrio/gdal_data/pds4_template.xml +65 -0
  146. pyogrio/gdal_data/plscenesconf.json +1985 -0
  147. pyogrio/gdal_data/ruian_vf_ob_v1.gfs +1455 -0
  148. pyogrio/gdal_data/ruian_vf_st_uvoh_v1.gfs +86 -0
  149. pyogrio/gdal_data/ruian_vf_st_v1.gfs +1489 -0
  150. pyogrio/gdal_data/ruian_vf_v1.gfs +2126 -0
  151. pyogrio/gdal_data/s57agencies.csv +249 -0
  152. pyogrio/gdal_data/s57attributes.csv +484 -0
  153. pyogrio/gdal_data/s57expectedinput.csv +1008 -0
  154. pyogrio/gdal_data/s57objectclasses.csv +287 -0
  155. pyogrio/gdal_data/seed_2d.dgn +0 -0
  156. pyogrio/gdal_data/seed_3d.dgn +0 -0
  157. pyogrio/gdal_data/stateplane.csv +259 -0
  158. pyogrio/gdal_data/tms_LINZAntarticaMapTileGrid.json +190 -0
  159. pyogrio/gdal_data/tms_MapML_APSTILE.json +268 -0
  160. pyogrio/gdal_data/tms_MapML_CBMTILE.json +346 -0
  161. pyogrio/gdal_data/tms_NZTM2000.json +243 -0
  162. pyogrio/gdal_data/trailer.dxf +434 -0
  163. pyogrio/gdal_data/usage +4 -0
  164. pyogrio/gdal_data/vcpkg-cmake-wrapper.cmake +23 -0
  165. pyogrio/gdal_data/vcpkg.spdx.json +264 -0
  166. pyogrio/gdal_data/vcpkg_abi_info.txt +41 -0
  167. pyogrio/gdal_data/vdv452.xml +367 -0
  168. pyogrio/gdal_data/vdv452.xsd +63 -0
  169. pyogrio/gdal_data/vicar.json +164 -0
  170. pyogrio/geopandas.py +683 -0
  171. pyogrio/proj_data/CH +22 -0
  172. pyogrio/proj_data/GL27 +23 -0
  173. pyogrio/proj_data/ITRF2000 +24 -0
  174. pyogrio/proj_data/ITRF2008 +94 -0
  175. pyogrio/proj_data/ITRF2014 +55 -0
  176. pyogrio/proj_data/copyright +34 -0
  177. pyogrio/proj_data/deformation_model.schema.json +582 -0
  178. pyogrio/proj_data/nad.lst +142 -0
  179. pyogrio/proj_data/nad27 +810 -0
  180. pyogrio/proj_data/nad83 +745 -0
  181. pyogrio/proj_data/other.extra +53 -0
  182. pyogrio/proj_data/proj-config-version.cmake +44 -0
  183. pyogrio/proj_data/proj-config.cmake +79 -0
  184. pyogrio/proj_data/proj-targets-release.cmake +19 -0
  185. pyogrio/proj_data/proj-targets.cmake +107 -0
  186. pyogrio/proj_data/proj.db +0 -0
  187. pyogrio/proj_data/proj.ini +51 -0
  188. pyogrio/proj_data/proj4-targets-release.cmake +19 -0
  189. pyogrio/proj_data/proj4-targets.cmake +107 -0
  190. pyogrio/proj_data/projjson.schema.json +1174 -0
  191. pyogrio/proj_data/triangulation.schema.json +214 -0
  192. pyogrio/proj_data/usage +4 -0
  193. pyogrio/proj_data/vcpkg.spdx.json +198 -0
  194. pyogrio/proj_data/vcpkg_abi_info.txt +27 -0
  195. pyogrio/proj_data/world +214 -0
  196. pyogrio/raw.py +887 -0
  197. pyogrio/tests/__init__.py +0 -0
  198. pyogrio/tests/conftest.py +398 -0
  199. pyogrio/tests/fixtures/README.md +108 -0
  200. pyogrio/tests/fixtures/curve.gpkg +0 -0
  201. pyogrio/tests/fixtures/curvepolygon.gpkg +0 -0
  202. pyogrio/tests/fixtures/line_zm.gpkg +0 -0
  203. pyogrio/tests/fixtures/multisurface.gpkg +0 -0
  204. pyogrio/tests/fixtures/naturalearth_lowres/naturalearth_lowres.cpg +1 -0
  205. pyogrio/tests/fixtures/naturalearth_lowres/naturalearth_lowres.dbf +0 -0
  206. pyogrio/tests/fixtures/naturalearth_lowres/naturalearth_lowres.prj +1 -0
  207. pyogrio/tests/fixtures/naturalearth_lowres/naturalearth_lowres.shp +0 -0
  208. pyogrio/tests/fixtures/naturalearth_lowres/naturalearth_lowres.shx +0 -0
  209. pyogrio/tests/fixtures/sample.osm.pbf +0 -0
  210. pyogrio/tests/fixtures/test_gpkg_nulls.gpkg +0 -0
  211. pyogrio/tests/test_arrow.py +1195 -0
  212. pyogrio/tests/test_core.py +678 -0
  213. pyogrio/tests/test_geopandas_io.py +2314 -0
  214. pyogrio/tests/test_path.py +364 -0
  215. pyogrio/tests/test_raw_io.py +1515 -0
  216. pyogrio/tests/test_util.py +56 -0
  217. pyogrio/util.py +247 -0
  218. pyogrio-0.10.0.dist-info/LICENSE +21 -0
  219. pyogrio-0.10.0.dist-info/METADATA +129 -0
  220. pyogrio-0.10.0.dist-info/RECORD +223 -0
  221. pyogrio-0.10.0.dist-info/WHEEL +5 -0
  222. pyogrio-0.10.0.dist-info/top_level.txt +1 -0
  223. pyogrio.libs/libgdal-b0847c7b.so.35.3.9.1 +0 -0
@@ -0,0 +1,678 @@
1
+ from pathlib import Path
2
+
3
+ import numpy as np
4
+ from numpy import allclose, array_equal
5
+
6
+ from pyogrio import (
7
+ __gdal_geos_version__,
8
+ __gdal_version__,
9
+ detect_write_driver,
10
+ get_gdal_config_option,
11
+ get_gdal_data_path,
12
+ list_drivers,
13
+ list_layers,
14
+ read_bounds,
15
+ read_info,
16
+ set_gdal_config_options,
17
+ vsi_listtree,
18
+ vsi_rmtree,
19
+ vsi_unlink,
20
+ )
21
+ from pyogrio._compat import GDAL_GE_38
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
28
+
29
+ with GDALEnv():
30
+ # NOTE: this must be AFTER above imports, which init the GDAL and PROJ data
31
+ # search paths
32
+ from pyogrio._ogr import has_gdal_data, has_proj_data, ogr_driver_supports_write
33
+
34
+
35
+ try:
36
+ import shapely
37
+ except ImportError:
38
+ pass
39
+
40
+
41
+ def test_gdal_data():
42
+ # test will fail if GDAL data files cannot be found, indicating an
43
+ # installation error
44
+ assert has_gdal_data()
45
+
46
+
47
+ def test_proj_data():
48
+ # test will fail if PROJ data files cannot be found, indicating an
49
+ # installation error
50
+ assert has_proj_data()
51
+
52
+
53
+ def test_get_gdal_data_path():
54
+ # test will fail if the function returns None, which means that GDAL
55
+ # cannot find data files, indicating an installation error
56
+ assert isinstance(get_gdal_data_path(), str)
57
+
58
+
59
+ def test_gdal_geos_version():
60
+ assert __gdal_geos_version__ is None or isinstance(__gdal_geos_version__, tuple)
61
+
62
+
63
+ @pytest.mark.parametrize(
64
+ "path,expected",
65
+ [
66
+ ("test.shp", "ESRI Shapefile"),
67
+ ("test.shp.zip", "ESRI Shapefile"),
68
+ ("test.geojson", "GeoJSON"),
69
+ ("test.geojsonl", "GeoJSONSeq"),
70
+ ("test.gpkg", "GPKG"),
71
+ pytest.param(
72
+ "test.gpkg.zip",
73
+ "GPKG",
74
+ marks=pytest.mark.skipif(
75
+ __gdal_version__ < (3, 7, 0),
76
+ reason="writing *.gpkg.zip requires GDAL >= 3.7.0",
77
+ ),
78
+ ),
79
+ # postgres can be detected by prefix instead of extension
80
+ pytest.param(
81
+ "PG:dbname=test",
82
+ "PostgreSQL",
83
+ marks=pytest.mark.skipif(
84
+ "PostgreSQL" not in list_drivers(),
85
+ reason="PostgreSQL path test requires PostgreSQL driver",
86
+ ),
87
+ ),
88
+ ],
89
+ )
90
+ def test_detect_write_driver(path, expected):
91
+ assert detect_write_driver(path) == expected
92
+
93
+
94
+ @pytest.mark.parametrize(
95
+ "path",
96
+ [
97
+ "test.svg", # only supports read
98
+ "test.", # not a valid extension
99
+ "test", # no extension or prefix
100
+ "test.foo", # not a valid extension
101
+ "FOO:test", # not a valid prefix
102
+ ],
103
+ )
104
+ def test_detect_write_driver_unsupported(path):
105
+ with pytest.raises(ValueError, match="Could not infer driver from path"):
106
+ detect_write_driver(path)
107
+
108
+
109
+ @pytest.mark.parametrize("path", ["test.xml", "test.txt"])
110
+ def test_detect_write_driver_multiple_unsupported(path):
111
+ with pytest.raises(ValueError, match="multiple drivers are available"):
112
+ detect_write_driver(path)
113
+
114
+
115
+ @pytest.mark.parametrize(
116
+ "driver,expected",
117
+ [
118
+ # drivers known to be well-supported by pyogrio
119
+ ("ESRI Shapefile", True),
120
+ ("GeoJSON", True),
121
+ ("GeoJSONSeq", True),
122
+ ("GPKG", True),
123
+ # drivers not supported for write by GDAL
124
+ ("HTTP", False),
125
+ ("OAPIF", False),
126
+ ],
127
+ )
128
+ def test_ogr_driver_supports_write(driver, expected):
129
+ assert ogr_driver_supports_write(driver) == expected
130
+
131
+
132
+ def test_list_drivers():
133
+ all_drivers = list_drivers()
134
+
135
+ # verify that the core drivers are present
136
+ for name in ("ESRI Shapefile", "GeoJSON", "GeoJSONSeq", "GPKG", "OpenFileGDB"):
137
+ assert name in all_drivers
138
+
139
+ expected_capability = "rw"
140
+ if name == "OpenFileGDB" and __gdal_version__ < (3, 6, 0):
141
+ expected_capability = "r"
142
+
143
+ assert all_drivers[name] == expected_capability
144
+
145
+ drivers = list_drivers(read=True)
146
+ expected = {k: v for k, v in all_drivers.items() if v.startswith("r")}
147
+ assert len(drivers) == len(expected)
148
+
149
+ drivers = list_drivers(write=True)
150
+ expected = {k: v for k, v in all_drivers.items() if v.endswith("w")}
151
+ assert len(drivers) == len(expected)
152
+
153
+ drivers = list_drivers(read=True, write=True)
154
+ expected = {
155
+ k: v for k, v in all_drivers.items() if v.startswith("r") and v.endswith("w")
156
+ }
157
+ assert len(drivers) == len(expected)
158
+
159
+
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
+ ):
170
+ assert array_equal(
171
+ list_layers(naturalearth_lowres), [["naturalearth_lowres", "Polygon"]]
172
+ )
173
+
174
+ assert array_equal(
175
+ list_layers(naturalearth_lowres_vsi[1]), [["naturalearth_lowres", "Polygon"]]
176
+ )
177
+
178
+ assert array_equal(
179
+ list_layers(naturalearth_lowres_vsimem),
180
+ [["naturalearth_lowres", "MultiPolygon"]],
181
+ )
182
+
183
+ # Measured 3D is downgraded to plain 3D during read
184
+ # Make sure this warning is raised
185
+ with pytest.warns(
186
+ UserWarning, match=r"Measured \(M\) geometry types are not supported"
187
+ ):
188
+ assert array_equal(list_layers(line_zm_file), [["line_zm", "LineString Z"]])
189
+
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
+ )
196
+
197
+ # Make sure that nonspatial layer has None for geometry
198
+ assert array_equal(list_layers(no_geometry_file), [["no_geometry", None]])
199
+
200
+
201
+ def test_list_layers_bytes(geojson_bytes):
202
+ layers = list_layers(geojson_bytes)
203
+
204
+ assert layers.shape == (1, 2)
205
+ assert layers[0, 0] == "test"
206
+
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
+
215
+ def test_list_layers_filelike(geojson_filelike):
216
+ layers = list_layers(geojson_filelike)
217
+
218
+ assert layers.shape == (1, 2)
219
+ assert layers[0, 0] == "test"
220
+
221
+
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]
229
+
230
+ fids, bounds = read_bounds(path)
231
+ assert fids.shape == (177,)
232
+ assert bounds.shape == (4, 177)
233
+ assert fids[0] == START_FID[Path(path).suffix]
234
+ # Fiji; wraps antimeridian
235
+ assert allclose(bounds[:, 0], [-180.0, -18.28799, 180.0, -16.02088])
236
+
237
+
238
+ def test_read_bounds_bytes(geojson_bytes):
239
+ fids, bounds = read_bounds(geojson_bytes)
240
+ assert fids.shape == (3,)
241
+ assert bounds.shape == (4, 3)
242
+ assert allclose(bounds[:, 0], [-180.0, -18.28799, 180.0, -16.02088])
243
+
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
+
252
+ def test_read_bounds_filelike(geojson_filelike):
253
+ fids, bounds = read_bounds(geojson_filelike)
254
+ assert fids.shape == (3,)
255
+ assert bounds.shape == (4, 3)
256
+ assert allclose(bounds[:, 0], [-180.0, -18.28799, 180.0, -16.02088])
257
+
258
+
259
+ def test_read_bounds_max_features(naturalearth_lowres):
260
+ bounds = read_bounds(naturalearth_lowres, max_features=2)[1]
261
+ assert bounds.shape == (4, 2)
262
+
263
+
264
+ def test_read_bounds_unspecified_layer_warning(data_dir):
265
+ """Reading a multi-layer file without specifying a layer gives a warning."""
266
+ with pytest.warns(UserWarning, match="More than one layer found "):
267
+ read_bounds(data_dir / "sample.osm.pbf")
268
+
269
+
270
+ def test_read_bounds_negative_max_features(naturalearth_lowres):
271
+ with pytest.raises(ValueError, match="'max_features' must be >= 0"):
272
+ read_bounds(naturalearth_lowres, max_features=-1)
273
+
274
+
275
+ def test_read_bounds_skip_features(naturalearth_lowres):
276
+ expected_bounds = read_bounds(naturalearth_lowres, max_features=11)[1][:, 10]
277
+ fids, bounds = read_bounds(naturalearth_lowres, skip_features=10)
278
+ assert bounds.shape == (4, 167)
279
+ assert allclose(bounds[:, 0], expected_bounds)
280
+ assert fids[0] == 10
281
+
282
+
283
+ def test_read_bounds_negative_skip_features(naturalearth_lowres):
284
+ with pytest.raises(ValueError, match="'skip_features' must be >= 0"):
285
+ read_bounds(naturalearth_lowres, skip_features=-1)
286
+
287
+
288
+ def test_read_bounds_where_invalid(naturalearth_lowres_all_ext):
289
+ with pytest.raises(ValueError, match="Invalid SQL"):
290
+ read_bounds(naturalearth_lowres_all_ext, where="invalid")
291
+
292
+
293
+ def test_read_bounds_where(naturalearth_lowres):
294
+ fids, bounds = read_bounds(naturalearth_lowres, where="iso_a3 = 'CAN'")
295
+ assert fids.shape == (1,)
296
+ assert bounds.shape == (4, 1)
297
+ assert fids[0] == 3
298
+ assert allclose(bounds[:, 0], [-140.99778, 41.675105, -52.648099, 83.23324])
299
+
300
+
301
+ @pytest.mark.parametrize("bbox", [(1,), (1, 2), (1, 2, 3)])
302
+ def test_read_bounds_bbox_invalid(naturalearth_lowres, bbox):
303
+ with pytest.raises(ValueError, match="Invalid bbox"):
304
+ read_bounds(naturalearth_lowres, bbox=bbox)
305
+
306
+
307
+ def test_read_bounds_bbox(naturalearth_lowres_all_ext):
308
+ # should return no features
309
+ fids, bounds = read_bounds(
310
+ naturalearth_lowres_all_ext, bbox=(0, 0, 0.00001, 0.00001)
311
+ )
312
+
313
+ assert fids.shape == (0,)
314
+ assert bounds.shape == (4, 0)
315
+
316
+ fids, bounds = read_bounds(naturalearth_lowres_all_ext, bbox=(-85, 8, -80, 10))
317
+
318
+ assert fids.shape == (2,)
319
+ fids_expected = np.array([33, 34]) # PAN, CRI
320
+ fids_expected += START_FID[naturalearth_lowres_all_ext.suffix]
321
+ assert array_equal(fids, fids_expected)
322
+
323
+ assert bounds.shape == (4, 2)
324
+ assert allclose(
325
+ bounds.T,
326
+ [
327
+ [-82.96578305, 7.22054149, -77.24256649, 9.61161001],
328
+ [-85.94172543, 8.22502798, -82.54619626, 11.21711925],
329
+ ],
330
+ )
331
+
332
+
333
+ @requires_shapely
334
+ @pytest.mark.parametrize(
335
+ "mask",
336
+ [
337
+ {"type": "Point", "coordinates": [0, 0]},
338
+ '{"type": "Point", "coordinates": [0, 0]}',
339
+ "invalid",
340
+ ],
341
+ )
342
+ def test_read_bounds_mask_invalid(naturalearth_lowres, mask):
343
+ with pytest.raises(ValueError, match="'mask' parameter must be a Shapely geometry"):
344
+ read_bounds(naturalearth_lowres, mask=mask)
345
+
346
+
347
+ @requires_shapely
348
+ def test_read_bounds_bbox_mask_invalid(naturalearth_lowres):
349
+ with pytest.raises(ValueError, match="cannot set both 'bbox' and 'mask'"):
350
+ read_bounds(
351
+ naturalearth_lowres, bbox=(-85, 8, -80, 10), mask=shapely.Point(-105, 55)
352
+ )
353
+
354
+
355
+ @requires_shapely
356
+ @pytest.mark.parametrize(
357
+ "mask,expected",
358
+ [
359
+ ("POINT (-105 55)", [3]),
360
+ ("POLYGON ((-80 8, -80 10, -85 10, -85 8, -80 8))", [33, 34]),
361
+ (
362
+ """POLYGON ((
363
+ 6.101929 50.97085,
364
+ 5.773002 50.906611,
365
+ 5.593156 50.642649,
366
+ 6.059271 50.686052,
367
+ 6.374064 50.851481,
368
+ 6.101929 50.97085
369
+ ))""",
370
+ [121, 129, 130],
371
+ ),
372
+ (
373
+ """GEOMETRYCOLLECTION (
374
+ POINT (-7.7 53),
375
+ POLYGON ((-80 8, -80 10, -85 10, -85 8, -80 8))
376
+ )""",
377
+ [33, 34, 133],
378
+ ),
379
+ ],
380
+ )
381
+ def test_read_bounds_mask(naturalearth_lowres_all_ext, mask, expected):
382
+ mask = shapely.from_wkt(mask)
383
+
384
+ fids = read_bounds(naturalearth_lowres_all_ext, mask=mask)[0]
385
+
386
+ fids_expected = np.array(expected) + START_FID[naturalearth_lowres_all_ext.suffix]
387
+ assert array_equal(fids, fids_expected)
388
+
389
+
390
+ @pytest.mark.skipif(
391
+ __gdal_version__ < (3, 4, 0),
392
+ reason="Cannot determine if GEOS is present or absent for GDAL < 3.4",
393
+ )
394
+ def test_read_bounds_bbox_intersects_vs_envelope_overlaps(naturalearth_lowres_all_ext):
395
+ # If GEOS is present and used by GDAL, bbox filter will be based on intersection
396
+ # of bbox and actual geometries; if GEOS is absent or not used by GDAL, it
397
+ # will be based on overlap of bounding boxes instead
398
+ fids, _ = read_bounds(naturalearth_lowres_all_ext, bbox=(-140, 20, -100, 45))
399
+
400
+ if __gdal_geos_version__ is None:
401
+ # bboxes for CAN, RUS overlap but do not intersect geometries
402
+ assert fids.shape == (4,)
403
+ fids_expected = np.array([3, 4, 18, 27]) # CAN, USA, RUS, MEX
404
+ fids_expected += START_FID[naturalearth_lowres_all_ext.suffix]
405
+ assert array_equal(fids, fids_expected)
406
+
407
+ else:
408
+ assert fids.shape == (2,)
409
+ fids_expected = np.array([4, 27]) # USA, MEX
410
+ fids_expected += START_FID[naturalearth_lowres_all_ext.suffix]
411
+ assert array_equal(fids, fids_expected)
412
+
413
+
414
+ @pytest.mark.parametrize("naturalearth_lowres", [".shp", ".gpkg"], indirect=True)
415
+ def test_read_info(naturalearth_lowres):
416
+ meta = read_info(naturalearth_lowres)
417
+
418
+ assert meta["layer_name"] == "naturalearth_lowres"
419
+ assert meta["crs"] == "EPSG:4326"
420
+ assert meta["encoding"] == "UTF-8"
421
+ assert meta["fields"].shape == (5,)
422
+ assert meta["dtypes"].tolist() == ["int64", "object", "object", "object", "float64"]
423
+ assert meta["features"] == 177
424
+ assert allclose(meta["total_bounds"], (-180, -90, 180, 83.64513))
425
+ assert meta["capabilities"]["random_read"] is True
426
+ assert meta["capabilities"]["fast_spatial_filter"] is False
427
+ assert meta["capabilities"]["fast_feature_count"] is True
428
+ assert meta["capabilities"]["fast_total_bounds"] is True
429
+
430
+ if naturalearth_lowres.suffix == ".gpkg":
431
+ assert meta["fid_column"] == "fid"
432
+ assert meta["geometry_name"] == "geom"
433
+ assert meta["geometry_type"] == "MultiPolygon"
434
+ assert meta["driver"] == "GPKG"
435
+ if GDAL_GE_38:
436
+ # this capability is only True for GPKG if GDAL >= 3.8
437
+ assert meta["capabilities"]["fast_set_next_by_index"] is True
438
+ elif naturalearth_lowres.suffix == ".shp":
439
+ # fid_column == "" for formats where fid is not physically stored
440
+ assert meta["fid_column"] == ""
441
+ # geometry_name == "" for formats where geometry column name cannot be
442
+ # customized
443
+ assert meta["geometry_name"] == ""
444
+ assert meta["geometry_type"] == "Polygon"
445
+ assert meta["driver"] == "ESRI Shapefile"
446
+ assert meta["capabilities"]["fast_set_next_by_index"] is True
447
+ else:
448
+ raise ValueError(f"test not implemented for ext {naturalearth_lowres.suffix}")
449
+
450
+
451
+ @pytest.mark.parametrize(
452
+ "testfile", ["naturalearth_lowres_vsimem", "naturalearth_lowres_vsi"]
453
+ )
454
+ def test_read_info_vsi(testfile, request):
455
+ path = request.getfixturevalue(testfile)
456
+ path = path if not isinstance(path, tuple) else path[1]
457
+
458
+ meta = read_info(path)
459
+
460
+ assert meta["fields"].shape == (5,)
461
+ assert meta["features"] == 177
462
+
463
+
464
+ def test_read_info_bytes(geojson_bytes):
465
+ meta = read_info(geojson_bytes)
466
+
467
+ assert meta["fields"].shape == (5,)
468
+ assert meta["features"] == 3
469
+
470
+
471
+ def test_read_info_nonseekable_bytes(nonseekable_bytes):
472
+ meta = read_info(nonseekable_bytes)
473
+
474
+ assert meta["fields"].shape == (0,)
475
+ assert meta["features"] == 1
476
+
477
+
478
+ def test_read_info_filelike(geojson_filelike):
479
+ meta = read_info(geojson_filelike)
480
+
481
+ assert meta["fields"].shape == (5,)
482
+ assert meta["features"] == 3
483
+
484
+
485
+ @pytest.mark.parametrize(
486
+ "dataset_kwargs,fields",
487
+ [
488
+ ({}, ["top_level", "intermediate_level"]),
489
+ (
490
+ {"FLATTEN_NESTED_ATTRIBUTES": "YES"},
491
+ [
492
+ "top_level",
493
+ "intermediate_level_bottom_level",
494
+ ],
495
+ ),
496
+ (
497
+ {"flatten_nested_attributes": "yes"},
498
+ [
499
+ "top_level",
500
+ "intermediate_level_bottom_level",
501
+ ],
502
+ ),
503
+ (
504
+ {"flatten_nested_attributes": True},
505
+ [
506
+ "top_level",
507
+ "intermediate_level_bottom_level",
508
+ ],
509
+ ),
510
+ ],
511
+ )
512
+ def test_read_info_dataset_kwargs(nested_geojson_file, dataset_kwargs, fields):
513
+ meta = read_info(nested_geojson_file, **dataset_kwargs)
514
+ assert meta["fields"].tolist() == fields
515
+
516
+
517
+ def test_read_info_invalid_dataset_kwargs(naturalearth_lowres):
518
+ with pytest.warns(RuntimeWarning, match="does not support open option INVALID"):
519
+ read_info(naturalearth_lowres, INVALID="YES")
520
+
521
+
522
+ def test_read_info_force_feature_count_exception(data_dir):
523
+ with pytest.raises(DataLayerError, match="Could not iterate over features"):
524
+ read_info(data_dir / "sample.osm.pbf", layer="lines", force_feature_count=True)
525
+
526
+
527
+ @pytest.mark.parametrize(
528
+ "layer, force, expected",
529
+ [
530
+ ("points", False, -1),
531
+ ("points", True, 8),
532
+ ("lines", False, -1),
533
+ ("lines", True, 36),
534
+ ],
535
+ )
536
+ def test_read_info_force_feature_count(data_dir, layer, force, expected):
537
+ # the sample OSM file has non-increasing node IDs which causes the default
538
+ # custom indexing to raise an exception iterating over features
539
+ meta = read_info(
540
+ data_dir / "sample.osm.pbf",
541
+ layer=layer,
542
+ force_feature_count=force,
543
+ USE_CUSTOM_INDEXING=False,
544
+ )
545
+ assert meta["features"] == expected
546
+
547
+
548
+ @pytest.mark.parametrize(
549
+ "force_total_bounds, expected_total_bounds",
550
+ [(True, (-180.0, -90.0, 180.0, 83.64513)), (False, None)],
551
+ )
552
+ def test_read_info_force_total_bounds(
553
+ tmp_path, naturalearth_lowres, force_total_bounds, expected_total_bounds
554
+ ):
555
+ geojson_path = prepare_testfile(
556
+ naturalearth_lowres, dst_dir=tmp_path, ext=".geojsonl"
557
+ )
558
+
559
+ info = read_info(geojson_path, force_total_bounds=force_total_bounds)
560
+ if expected_total_bounds is not None:
561
+ assert allclose(info["total_bounds"], expected_total_bounds)
562
+ else:
563
+ assert info["total_bounds"] is None
564
+
565
+
566
+ def test_read_info_unspecified_layer_warning(data_dir):
567
+ """Reading a multi-layer file without specifying a layer gives a warning."""
568
+ with pytest.warns(UserWarning, match="More than one layer found "):
569
+ read_info(data_dir / "sample.osm.pbf")
570
+
571
+
572
+ def test_read_info_without_geometry(no_geometry_file):
573
+ assert read_info(no_geometry_file)["total_bounds"] is None
574
+
575
+
576
+ @pytest.mark.parametrize(
577
+ "name,value,expected",
578
+ [
579
+ ("CPL_DEBUG", "ON", True),
580
+ ("CPL_DEBUG", True, True),
581
+ ("CPL_DEBUG", "OFF", False),
582
+ ("CPL_DEBUG", False, False),
583
+ ],
584
+ )
585
+ def test_set_config_options(name, value, expected):
586
+ set_gdal_config_options({name: value})
587
+ actual = get_gdal_config_option(name)
588
+ assert actual == expected
589
+
590
+
591
+ def test_reset_config_options():
592
+ set_gdal_config_options({"foo": "bar"})
593
+ assert get_gdal_config_option("foo") == "bar"
594
+
595
+ set_gdal_config_options({"foo": None})
596
+ assert get_gdal_config_option("foo") is None
597
+
598
+
599
+ def test_error_handling(capfd):
600
+ # an operation that triggers a GDAL Failure
601
+ # -> error translated into Python exception + not printed to stderr
602
+ with pytest.raises(DataSourceError, match="No such file or directory"):
603
+ read_info("non-existent.shp")
604
+
605
+ assert capfd.readouterr().err == ""
606
+
607
+
608
+ def test_error_handling_warning(capfd, naturalearth_lowres):
609
+ # an operation that triggers a GDAL Warning
610
+ # -> translated into a Python warning + not printed to stderr
611
+ with pytest.warns(RuntimeWarning, match="does not support open option INVALID"):
612
+ read_info(naturalearth_lowres, INVALID="YES")
613
+
614
+ assert capfd.readouterr().err == ""
615
+
616
+
617
+ def test_vsimem_listtree_rmtree_unlink(naturalearth_lowres):
618
+ """Test all basic functionalities of file handling in /vsimem/."""
619
+ # Prepare test data in /vsimem
620
+ meta, _, geometry, field_data = read(naturalearth_lowres)
621
+ meta["spatial_index"] = False
622
+ meta["geometry_type"] = "MultiPolygon"
623
+ test_file_path = Path("/vsimem/pyogrio_test_naturalearth_lowres.gpkg")
624
+ test_dir_path = Path(f"/vsimem/pyogrio_dir_test/{naturalearth_lowres.stem}.gpkg")
625
+
626
+ write(test_file_path, geometry, field_data, **meta)
627
+ write(test_dir_path, geometry, field_data, **meta)
628
+
629
+ # Check if everything was created properly with listtree
630
+ files = vsi_listtree("/vsimem/")
631
+ assert test_file_path.as_posix() in files
632
+ assert test_dir_path.as_posix() in files
633
+
634
+ # Check listtree with pattern
635
+ files = vsi_listtree("/vsimem/", pattern="pyogrio_dir_test*.gpkg")
636
+ assert test_file_path.as_posix() not in files
637
+ assert test_dir_path.as_posix() in files
638
+
639
+ files = vsi_listtree("/vsimem/", pattern="pyogrio_test*.gpkg")
640
+ assert test_file_path.as_posix() in files
641
+ assert test_dir_path.as_posix() not in files
642
+
643
+ # Remove test_dir and its contents
644
+ vsi_rmtree(test_dir_path.parent)
645
+ files = vsi_listtree("/vsimem/")
646
+ assert test_file_path.as_posix() in files
647
+ assert test_dir_path.as_posix() not in files
648
+
649
+ # Remove test_file
650
+ vsi_unlink(test_file_path)
651
+
652
+
653
+ def test_vsimem_rmtree_error(naturalearth_lowres_vsimem):
654
+ with pytest.raises(NotADirectoryError, match="Path is not a directory"):
655
+ vsi_rmtree(naturalearth_lowres_vsimem)
656
+
657
+ with pytest.raises(FileNotFoundError, match="Path does not exist"):
658
+ vsi_rmtree("/vsimem/non-existent")
659
+
660
+ with pytest.raises(
661
+ OSError, match="path to in-memory file or directory is required"
662
+ ):
663
+ vsi_rmtree("/vsimem")
664
+ with pytest.raises(
665
+ OSError, match="path to in-memory file or directory is required"
666
+ ):
667
+ vsi_rmtree("/vsimem/")
668
+
669
+ # Verify that naturalearth_lowres_vsimem still exists.
670
+ assert naturalearth_lowres_vsimem.as_posix() in vsi_listtree("/vsimem")
671
+
672
+
673
+ def test_vsimem_unlink_error(naturalearth_lowres_vsimem):
674
+ with pytest.raises(IsADirectoryError, match="Path is a directory"):
675
+ vsi_unlink(naturalearth_lowres_vsimem.parent)
676
+
677
+ with pytest.raises(FileNotFoundError, match="Path does not exist"):
678
+ vsi_unlink("/vsimem/non-existent.gpkg")