pyogrio 0.10.0__cp313-cp313-macosx_12_0_x86_64.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/.dylibs/libgdal.35.3.9.1.dylib +0 -0
  2. pyogrio/__init__.py +55 -0
  3. pyogrio/_compat.py +47 -0
  4. pyogrio/_env.py +59 -0
  5. pyogrio/_err.cpython-313-darwin.so +0 -0
  6. pyogrio/_geometry.cpython-313-darwin.so +0 -0
  7. pyogrio/_io.cpython-313-darwin.so +0 -0
  8. pyogrio/_ogr.cpython-313-darwin.so +0 -0
  9. pyogrio/_version.py +21 -0
  10. pyogrio/_vsi.cpython-313-darwin.so +0 -0
  11. pyogrio/core.py +386 -0
  12. pyogrio/errors.py +25 -0
  13. pyogrio/gdal_data/GDAL-targets-release.cmake +19 -0
  14. pyogrio/gdal_data/GDAL-targets.cmake +105 -0
  15. pyogrio/gdal_data/GDALConfig.cmake +24 -0
  16. pyogrio/gdal_data/GDALConfigVersion.cmake +85 -0
  17. pyogrio/gdal_data/GDALLogoBW.svg +138 -0
  18. pyogrio/gdal_data/GDALLogoColor.svg +126 -0
  19. pyogrio/gdal_data/GDALLogoGS.svg +126 -0
  20. pyogrio/gdal_data/LICENSE.TXT +467 -0
  21. pyogrio/gdal_data/MM_m_idofic.csv +321 -0
  22. pyogrio/gdal_data/copyright +467 -0
  23. pyogrio/gdal_data/cubewerx_extra.wkt +48 -0
  24. pyogrio/gdal_data/default.rsc +0 -0
  25. pyogrio/gdal_data/ecw_cs.wkt +1453 -0
  26. pyogrio/gdal_data/eedaconf.json +23 -0
  27. pyogrio/gdal_data/epsg.wkt +1 -0
  28. pyogrio/gdal_data/esri_StatePlane_extra.wkt +631 -0
  29. pyogrio/gdal_data/gdalicon.png +0 -0
  30. pyogrio/gdal_data/gdalinfo_output.schema.json +346 -0
  31. pyogrio/gdal_data/gdalmdiminfo_output.schema.json +321 -0
  32. pyogrio/gdal_data/gdaltileindex.xsd +269 -0
  33. pyogrio/gdal_data/gdalvrt.xsd +880 -0
  34. pyogrio/gdal_data/gfs.xsd +246 -0
  35. pyogrio/gdal_data/gml_registry.xml +117 -0
  36. pyogrio/gdal_data/gml_registry.xsd +66 -0
  37. pyogrio/gdal_data/grib2_center.csv +251 -0
  38. pyogrio/gdal_data/grib2_process.csv +102 -0
  39. pyogrio/gdal_data/grib2_subcenter.csv +63 -0
  40. pyogrio/gdal_data/grib2_table_4_2_0_0.csv +261 -0
  41. pyogrio/gdal_data/grib2_table_4_2_0_1.csv +261 -0
  42. pyogrio/gdal_data/grib2_table_4_2_0_13.csv +261 -0
  43. pyogrio/gdal_data/grib2_table_4_2_0_14.csv +261 -0
  44. pyogrio/gdal_data/grib2_table_4_2_0_15.csv +261 -0
  45. pyogrio/gdal_data/grib2_table_4_2_0_16.csv +261 -0
  46. pyogrio/gdal_data/grib2_table_4_2_0_17.csv +11 -0
  47. pyogrio/gdal_data/grib2_table_4_2_0_18.csv +261 -0
  48. pyogrio/gdal_data/grib2_table_4_2_0_19.csv +261 -0
  49. pyogrio/gdal_data/grib2_table_4_2_0_190.csv +261 -0
  50. pyogrio/gdal_data/grib2_table_4_2_0_191.csv +261 -0
  51. pyogrio/gdal_data/grib2_table_4_2_0_2.csv +261 -0
  52. pyogrio/gdal_data/grib2_table_4_2_0_20.csv +261 -0
  53. pyogrio/gdal_data/grib2_table_4_2_0_21.csv +261 -0
  54. pyogrio/gdal_data/grib2_table_4_2_0_3.csv +261 -0
  55. pyogrio/gdal_data/grib2_table_4_2_0_4.csv +261 -0
  56. pyogrio/gdal_data/grib2_table_4_2_0_5.csv +261 -0
  57. pyogrio/gdal_data/grib2_table_4_2_0_6.csv +261 -0
  58. pyogrio/gdal_data/grib2_table_4_2_0_7.csv +261 -0
  59. pyogrio/gdal_data/grib2_table_4_2_10_0.csv +261 -0
  60. pyogrio/gdal_data/grib2_table_4_2_10_1.csv +261 -0
  61. pyogrio/gdal_data/grib2_table_4_2_10_191.csv +261 -0
  62. pyogrio/gdal_data/grib2_table_4_2_10_2.csv +261 -0
  63. pyogrio/gdal_data/grib2_table_4_2_10_3.csv +261 -0
  64. pyogrio/gdal_data/grib2_table_4_2_10_4.csv +261 -0
  65. pyogrio/gdal_data/grib2_table_4_2_1_0.csv +261 -0
  66. pyogrio/gdal_data/grib2_table_4_2_1_1.csv +261 -0
  67. pyogrio/gdal_data/grib2_table_4_2_1_2.csv +261 -0
  68. pyogrio/gdal_data/grib2_table_4_2_20_0.csv +261 -0
  69. pyogrio/gdal_data/grib2_table_4_2_20_1.csv +261 -0
  70. pyogrio/gdal_data/grib2_table_4_2_20_2.csv +261 -0
  71. pyogrio/gdal_data/grib2_table_4_2_2_0.csv +261 -0
  72. pyogrio/gdal_data/grib2_table_4_2_2_3.csv +261 -0
  73. pyogrio/gdal_data/grib2_table_4_2_2_4.csv +261 -0
  74. pyogrio/gdal_data/grib2_table_4_2_2_5.csv +261 -0
  75. pyogrio/gdal_data/grib2_table_4_2_2_6.csv +261 -0
  76. pyogrio/gdal_data/grib2_table_4_2_3_0.csv +261 -0
  77. pyogrio/gdal_data/grib2_table_4_2_3_1.csv +261 -0
  78. pyogrio/gdal_data/grib2_table_4_2_3_2.csv +28 -0
  79. pyogrio/gdal_data/grib2_table_4_2_3_3.csv +8 -0
  80. pyogrio/gdal_data/grib2_table_4_2_3_4.csv +14 -0
  81. pyogrio/gdal_data/grib2_table_4_2_3_5.csv +11 -0
  82. pyogrio/gdal_data/grib2_table_4_2_3_6.csv +11 -0
  83. pyogrio/gdal_data/grib2_table_4_2_4_0.csv +261 -0
  84. pyogrio/gdal_data/grib2_table_4_2_4_1.csv +261 -0
  85. pyogrio/gdal_data/grib2_table_4_2_4_10.csv +261 -0
  86. pyogrio/gdal_data/grib2_table_4_2_4_2.csv +261 -0
  87. pyogrio/gdal_data/grib2_table_4_2_4_3.csv +261 -0
  88. pyogrio/gdal_data/grib2_table_4_2_4_4.csv +261 -0
  89. pyogrio/gdal_data/grib2_table_4_2_4_5.csv +261 -0
  90. pyogrio/gdal_data/grib2_table_4_2_4_6.csv +261 -0
  91. pyogrio/gdal_data/grib2_table_4_2_4_7.csv +261 -0
  92. pyogrio/gdal_data/grib2_table_4_2_4_8.csv +261 -0
  93. pyogrio/gdal_data/grib2_table_4_2_4_9.csv +261 -0
  94. pyogrio/gdal_data/grib2_table_4_2_local_Canada.csv +5 -0
  95. pyogrio/gdal_data/grib2_table_4_2_local_HPC.csv +2 -0
  96. pyogrio/gdal_data/grib2_table_4_2_local_MRMS.csv +175 -0
  97. pyogrio/gdal_data/grib2_table_4_2_local_NCEP.csv +401 -0
  98. pyogrio/gdal_data/grib2_table_4_2_local_NDFD.csv +38 -0
  99. pyogrio/gdal_data/grib2_table_4_2_local_index.csv +7 -0
  100. pyogrio/gdal_data/grib2_table_4_5.csv +261 -0
  101. pyogrio/gdal_data/grib2_table_versions.csv +3 -0
  102. pyogrio/gdal_data/gt_datum.csv +229 -0
  103. pyogrio/gdal_data/gt_ellips.csv +24 -0
  104. pyogrio/gdal_data/header.dxf +1124 -0
  105. pyogrio/gdal_data/inspire_cp_BasicPropertyUnit.gfs +57 -0
  106. pyogrio/gdal_data/inspire_cp_CadastralBoundary.gfs +60 -0
  107. pyogrio/gdal_data/inspire_cp_CadastralParcel.gfs +81 -0
  108. pyogrio/gdal_data/inspire_cp_CadastralZoning.gfs +161 -0
  109. pyogrio/gdal_data/jpfgdgml_AdmArea.gfs +59 -0
  110. pyogrio/gdal_data/jpfgdgml_AdmBdry.gfs +49 -0
  111. pyogrio/gdal_data/jpfgdgml_AdmPt.gfs +59 -0
  112. pyogrio/gdal_data/jpfgdgml_BldA.gfs +54 -0
  113. pyogrio/gdal_data/jpfgdgml_BldL.gfs +54 -0
  114. pyogrio/gdal_data/jpfgdgml_Cntr.gfs +54 -0
  115. pyogrio/gdal_data/jpfgdgml_CommBdry.gfs +49 -0
  116. pyogrio/gdal_data/jpfgdgml_CommPt.gfs +59 -0
  117. pyogrio/gdal_data/jpfgdgml_Cstline.gfs +54 -0
  118. pyogrio/gdal_data/jpfgdgml_ElevPt.gfs +54 -0
  119. pyogrio/gdal_data/jpfgdgml_GCP.gfs +94 -0
  120. pyogrio/gdal_data/jpfgdgml_LeveeEdge.gfs +49 -0
  121. pyogrio/gdal_data/jpfgdgml_RailCL.gfs +54 -0
  122. pyogrio/gdal_data/jpfgdgml_RdASL.gfs +44 -0
  123. pyogrio/gdal_data/jpfgdgml_RdArea.gfs +54 -0
  124. pyogrio/gdal_data/jpfgdgml_RdCompt.gfs +59 -0
  125. pyogrio/gdal_data/jpfgdgml_RdEdg.gfs +59 -0
  126. pyogrio/gdal_data/jpfgdgml_RdMgtBdry.gfs +49 -0
  127. pyogrio/gdal_data/jpfgdgml_RdSgmtA.gfs +59 -0
  128. pyogrio/gdal_data/jpfgdgml_RvrMgtBdry.gfs +49 -0
  129. pyogrio/gdal_data/jpfgdgml_SBAPt.gfs +49 -0
  130. pyogrio/gdal_data/jpfgdgml_SBArea.gfs +54 -0
  131. pyogrio/gdal_data/jpfgdgml_SBBdry.gfs +44 -0
  132. pyogrio/gdal_data/jpfgdgml_WA.gfs +54 -0
  133. pyogrio/gdal_data/jpfgdgml_WL.gfs +54 -0
  134. pyogrio/gdal_data/jpfgdgml_WStrA.gfs +54 -0
  135. pyogrio/gdal_data/jpfgdgml_WStrL.gfs +54 -0
  136. pyogrio/gdal_data/nitf_spec.xml +3306 -0
  137. pyogrio/gdal_data/nitf_spec.xsd +189 -0
  138. pyogrio/gdal_data/ogrinfo_output.schema.json +528 -0
  139. pyogrio/gdal_data/ogrvrt.xsd +546 -0
  140. pyogrio/gdal_data/osmconf.ini +132 -0
  141. pyogrio/gdal_data/ozi_datum.csv +131 -0
  142. pyogrio/gdal_data/ozi_ellips.csv +35 -0
  143. pyogrio/gdal_data/pci_datum.txt +530 -0
  144. pyogrio/gdal_data/pci_ellips.txt +129 -0
  145. pyogrio/gdal_data/pdfcomposition.xsd +721 -0
  146. pyogrio/gdal_data/pds4_template.xml +65 -0
  147. pyogrio/gdal_data/plscenesconf.json +1985 -0
  148. pyogrio/gdal_data/ruian_vf_ob_v1.gfs +1455 -0
  149. pyogrio/gdal_data/ruian_vf_st_uvoh_v1.gfs +86 -0
  150. pyogrio/gdal_data/ruian_vf_st_v1.gfs +1489 -0
  151. pyogrio/gdal_data/ruian_vf_v1.gfs +2126 -0
  152. pyogrio/gdal_data/s57agencies.csv +249 -0
  153. pyogrio/gdal_data/s57attributes.csv +484 -0
  154. pyogrio/gdal_data/s57expectedinput.csv +1008 -0
  155. pyogrio/gdal_data/s57objectclasses.csv +287 -0
  156. pyogrio/gdal_data/seed_2d.dgn +0 -0
  157. pyogrio/gdal_data/seed_3d.dgn +0 -0
  158. pyogrio/gdal_data/stateplane.csv +259 -0
  159. pyogrio/gdal_data/tms_LINZAntarticaMapTileGrid.json +190 -0
  160. pyogrio/gdal_data/tms_MapML_APSTILE.json +268 -0
  161. pyogrio/gdal_data/tms_MapML_CBMTILE.json +346 -0
  162. pyogrio/gdal_data/tms_NZTM2000.json +243 -0
  163. pyogrio/gdal_data/trailer.dxf +434 -0
  164. pyogrio/gdal_data/usage +4 -0
  165. pyogrio/gdal_data/vcpkg-cmake-wrapper.cmake +23 -0
  166. pyogrio/gdal_data/vcpkg.spdx.json +264 -0
  167. pyogrio/gdal_data/vcpkg_abi_info.txt +41 -0
  168. pyogrio/gdal_data/vdv452.xml +367 -0
  169. pyogrio/gdal_data/vdv452.xsd +63 -0
  170. pyogrio/gdal_data/vicar.json +164 -0
  171. pyogrio/geopandas.py +683 -0
  172. pyogrio/proj_data/CH +22 -0
  173. pyogrio/proj_data/GL27 +23 -0
  174. pyogrio/proj_data/ITRF2000 +24 -0
  175. pyogrio/proj_data/ITRF2008 +94 -0
  176. pyogrio/proj_data/ITRF2014 +55 -0
  177. pyogrio/proj_data/copyright +34 -0
  178. pyogrio/proj_data/deformation_model.schema.json +582 -0
  179. pyogrio/proj_data/nad.lst +142 -0
  180. pyogrio/proj_data/nad27 +810 -0
  181. pyogrio/proj_data/nad83 +745 -0
  182. pyogrio/proj_data/other.extra +53 -0
  183. pyogrio/proj_data/proj-config-version.cmake +44 -0
  184. pyogrio/proj_data/proj-config.cmake +79 -0
  185. pyogrio/proj_data/proj-targets-release.cmake +19 -0
  186. pyogrio/proj_data/proj-targets.cmake +107 -0
  187. pyogrio/proj_data/proj.db +0 -0
  188. pyogrio/proj_data/proj.ini +51 -0
  189. pyogrio/proj_data/proj4-targets-release.cmake +19 -0
  190. pyogrio/proj_data/proj4-targets.cmake +107 -0
  191. pyogrio/proj_data/projjson.schema.json +1174 -0
  192. pyogrio/proj_data/triangulation.schema.json +214 -0
  193. pyogrio/proj_data/usage +4 -0
  194. pyogrio/proj_data/vcpkg.spdx.json +198 -0
  195. pyogrio/proj_data/vcpkg_abi_info.txt +27 -0
  196. pyogrio/proj_data/world +214 -0
  197. pyogrio/raw.py +887 -0
  198. pyogrio/tests/__init__.py +0 -0
  199. pyogrio/tests/conftest.py +398 -0
  200. pyogrio/tests/fixtures/README.md +108 -0
  201. pyogrio/tests/fixtures/curve.gpkg +0 -0
  202. pyogrio/tests/fixtures/curvepolygon.gpkg +0 -0
  203. pyogrio/tests/fixtures/line_zm.gpkg +0 -0
  204. pyogrio/tests/fixtures/multisurface.gpkg +0 -0
  205. pyogrio/tests/fixtures/naturalearth_lowres/naturalearth_lowres.cpg +1 -0
  206. pyogrio/tests/fixtures/naturalearth_lowres/naturalearth_lowres.dbf +0 -0
  207. pyogrio/tests/fixtures/naturalearth_lowres/naturalearth_lowres.prj +1 -0
  208. pyogrio/tests/fixtures/naturalearth_lowres/naturalearth_lowres.shp +0 -0
  209. pyogrio/tests/fixtures/naturalearth_lowres/naturalearth_lowres.shx +0 -0
  210. pyogrio/tests/fixtures/sample.osm.pbf +0 -0
  211. pyogrio/tests/fixtures/test_gpkg_nulls.gpkg +0 -0
  212. pyogrio/tests/test_arrow.py +1195 -0
  213. pyogrio/tests/test_core.py +678 -0
  214. pyogrio/tests/test_geopandas_io.py +2314 -0
  215. pyogrio/tests/test_path.py +364 -0
  216. pyogrio/tests/test_raw_io.py +1515 -0
  217. pyogrio/tests/test_util.py +56 -0
  218. pyogrio/util.py +247 -0
  219. pyogrio-0.10.0.dist-info/LICENSE +21 -0
  220. pyogrio-0.10.0.dist-info/METADATA +129 -0
  221. pyogrio-0.10.0.dist-info/RECORD +223 -0
  222. pyogrio-0.10.0.dist-info/WHEEL +5 -0
  223. pyogrio-0.10.0.dist-info/top_level.txt +1 -0
Binary file
pyogrio/__init__.py ADDED
@@ -0,0 +1,55 @@
1
+ """Vectorized vector I/O using OGR."""
2
+
3
+ try:
4
+ # we try importing shapely, to ensure it is imported (and it can load its
5
+ # own GEOS copy) before we load GDAL and its linked GEOS
6
+ import shapely
7
+ import shapely.geos # noqa: F401
8
+ except Exception:
9
+ pass
10
+
11
+ from pyogrio._version import get_versions
12
+ from pyogrio.core import (
13
+ __gdal_geos_version__,
14
+ __gdal_version__,
15
+ __gdal_version_string__,
16
+ detect_write_driver,
17
+ get_gdal_config_option,
18
+ get_gdal_data_path,
19
+ list_drivers,
20
+ list_layers,
21
+ read_bounds,
22
+ read_info,
23
+ set_gdal_config_options,
24
+ vsi_listtree,
25
+ vsi_rmtree,
26
+ vsi_unlink,
27
+ )
28
+ from pyogrio.geopandas import read_dataframe, write_dataframe
29
+ from pyogrio.raw import open_arrow, read_arrow, write_arrow
30
+
31
+ __version__ = get_versions()["version"]
32
+ del get_versions
33
+
34
+ __all__ = [
35
+ "list_drivers",
36
+ "detect_write_driver",
37
+ "list_layers",
38
+ "read_bounds",
39
+ "read_info",
40
+ "set_gdal_config_options",
41
+ "get_gdal_config_option",
42
+ "get_gdal_data_path",
43
+ "open_arrow",
44
+ "read_arrow",
45
+ "read_dataframe",
46
+ "vsi_listtree",
47
+ "vsi_rmtree",
48
+ "vsi_unlink",
49
+ "write_arrow",
50
+ "write_dataframe",
51
+ "__gdal_version__",
52
+ "__gdal_version_string__",
53
+ "__gdal_geos_version__",
54
+ "__version__",
55
+ ]
pyogrio/_compat.py ADDED
@@ -0,0 +1,47 @@
1
+ from packaging.version import Version
2
+
3
+ from pyogrio.core import __gdal_geos_version__, __gdal_version__
4
+
5
+ # detect optional dependencies
6
+ try:
7
+ import pyarrow
8
+ except ImportError:
9
+ pyarrow = None
10
+
11
+ try:
12
+ import pyproj
13
+ except ImportError:
14
+ pyproj = None
15
+
16
+ try:
17
+ import shapely
18
+ except ImportError:
19
+ shapely = None
20
+
21
+ try:
22
+ import geopandas
23
+ except ImportError:
24
+ geopandas = None
25
+
26
+ try:
27
+ import pandas
28
+ except ImportError:
29
+ pandas = None
30
+
31
+
32
+ HAS_ARROW_API = __gdal_version__ >= (3, 6, 0)
33
+ HAS_ARROW_WRITE_API = __gdal_version__ >= (3, 8, 0)
34
+ HAS_PYARROW = pyarrow is not None
35
+ HAS_PYPROJ = pyproj is not None
36
+
37
+ HAS_GEOPANDAS = geopandas is not None
38
+
39
+ PANDAS_GE_15 = pandas is not None and Version(pandas.__version__) >= Version("1.5.0")
40
+ PANDAS_GE_20 = pandas is not None and Version(pandas.__version__) >= Version("2.0.0")
41
+ PANDAS_GE_22 = pandas is not None and Version(pandas.__version__) >= Version("2.2.0")
42
+
43
+ GDAL_GE_38 = __gdal_version__ >= (3, 8, 0)
44
+
45
+ HAS_GDAL_GEOS = __gdal_geos_version__ is not None
46
+
47
+ HAS_SHAPELY = shapely is not None and Version(shapely.__version__) >= Version("2.0.0")
pyogrio/_env.py ADDED
@@ -0,0 +1,59 @@
1
+ # With Python >= 3.8 on Windows directories in PATH are not automatically
2
+ # searched for DLL dependencies and must be added manually with
3
+ # os.add_dll_directory.
4
+ # adapted from Fiona: https://github.com/Toblerity/Fiona/pull/875
5
+
6
+
7
+ import logging
8
+ import os
9
+ import platform
10
+ from contextlib import contextmanager
11
+ from pathlib import Path
12
+
13
+ log = logging.getLogger(__name__)
14
+ log.addHandler(logging.NullHandler())
15
+
16
+
17
+ try:
18
+ # set GDAL_CURL_CA_BUNDLE / PROJ_CURL_CA_BUNDLE for GDAL >= 3.2
19
+ import certifi
20
+
21
+ ca_bundle = certifi.where()
22
+ os.environ.setdefault("GDAL_CURL_CA_BUNDLE", ca_bundle)
23
+ os.environ.setdefault("PROJ_CURL_CA_BUNDLE", ca_bundle)
24
+ except ImportError:
25
+ pass
26
+
27
+
28
+ gdal_dll_dir = None
29
+
30
+ if platform.system() == "Windows":
31
+ # if loading of extension modules fails, search for gdal dll directory
32
+ try:
33
+ import pyogrio._io # noqa: F401
34
+
35
+ except ImportError:
36
+ for path in os.getenv("PATH", "").split(os.pathsep):
37
+ if list(Path(path).glob("gdal*.dll")):
38
+ log.info(f"Found GDAL at {path}")
39
+ gdal_dll_dir = path
40
+ break
41
+
42
+ if not gdal_dll_dir:
43
+ raise ImportError(
44
+ "GDAL DLL could not be found. It must be on the system PATH."
45
+ )
46
+
47
+
48
+ @contextmanager
49
+ def GDALEnv():
50
+ dll_dir = None
51
+
52
+ if gdal_dll_dir:
53
+ dll_dir = os.add_dll_directory(gdal_dll_dir)
54
+
55
+ try:
56
+ yield None
57
+ finally:
58
+ if dll_dir is not None:
59
+ dll_dir.close()
Binary file
Binary file
Binary file
Binary file
pyogrio/_version.py ADDED
@@ -0,0 +1,21 @@
1
+
2
+ # This file was generated by 'versioneer.py' (0.28) from
3
+ # revision-control system data, or from the parent directory name of an
4
+ # unpacked source archive. Distribution tarballs contain a pre-generated copy
5
+ # of this file.
6
+
7
+ import json
8
+
9
+ version_json = '''
10
+ {
11
+ "date": "2024-09-28T11:22:57-0700",
12
+ "dirty": false,
13
+ "error": null,
14
+ "full-revisionid": "eb8e7889224155ffa0f779360db29f07f370eef1",
15
+ "version": "0.10.0"
16
+ }
17
+ ''' # END VERSION_JSON
18
+
19
+
20
+ def get_versions():
21
+ return json.loads(version_json)
Binary file
pyogrio/core.py ADDED
@@ -0,0 +1,386 @@
1
+ """Core functions to interact with OGR data sources."""
2
+
3
+ from pathlib import Path
4
+ from typing import Optional, Union
5
+
6
+ from pyogrio._env import GDALEnv
7
+ from pyogrio.util import (
8
+ _mask_to_wkb,
9
+ _preprocess_options_key_value,
10
+ get_vsi_path_or_buffer,
11
+ )
12
+
13
+ with GDALEnv():
14
+ from pyogrio._err import _register_error_handler
15
+ from pyogrio._io import ogr_list_layers, ogr_read_bounds, ogr_read_info
16
+ from pyogrio._ogr import (
17
+ _get_drivers_for_path,
18
+ _register_drivers,
19
+ get_gdal_config_option as _get_gdal_config_option,
20
+ get_gdal_data_path as _get_gdal_data_path,
21
+ get_gdal_geos_version,
22
+ get_gdal_version,
23
+ get_gdal_version_string,
24
+ init_gdal_data as _init_gdal_data,
25
+ init_proj_data as _init_proj_data,
26
+ ogr_list_drivers,
27
+ set_gdal_config_options as _set_gdal_config_options,
28
+ )
29
+ from pyogrio._vsi import (
30
+ ogr_vsi_listtree,
31
+ ogr_vsi_rmtree,
32
+ ogr_vsi_unlink,
33
+ )
34
+
35
+ _init_gdal_data()
36
+ _init_proj_data()
37
+ _register_drivers()
38
+ _register_error_handler()
39
+
40
+ __gdal_version__ = get_gdal_version()
41
+ __gdal_version_string__ = get_gdal_version_string()
42
+ __gdal_geos_version__ = get_gdal_geos_version()
43
+
44
+
45
+ def list_drivers(read=False, write=False):
46
+ """List drivers available in GDAL.
47
+
48
+ Parameters
49
+ ----------
50
+ read: bool, optional (default: False)
51
+ If True, will only return drivers that are known to support read capabilities.
52
+ write: bool, optional (default: False)
53
+ If True, will only return drivers that are known to support write capabilities.
54
+
55
+ Returns
56
+ -------
57
+ dict
58
+ Mapping of driver name to file mode capabilities: ``"r"``: read, ``"w"``: write.
59
+ Drivers that are available but with unknown support are marked with ``"?"``
60
+
61
+ """
62
+ drivers = ogr_list_drivers()
63
+
64
+ if read:
65
+ drivers = {k: v for k, v in drivers.items() if v.startswith("r")}
66
+
67
+ if write:
68
+ drivers = {k: v for k, v in drivers.items() if v.endswith("w")}
69
+
70
+ return drivers
71
+
72
+
73
+ def detect_write_driver(path):
74
+ """Attempt to infer the driver for a path by extension or prefix.
75
+
76
+ Only drivers that support write capabilities will be detected.
77
+
78
+ If the path cannot be resolved to a single driver, a ValueError will be
79
+ raised.
80
+
81
+ Parameters
82
+ ----------
83
+ path : str
84
+ data source path
85
+
86
+ Returns
87
+ -------
88
+ str
89
+ name of the driver, if detected
90
+
91
+ """
92
+ # try to infer driver from path
93
+ drivers = _get_drivers_for_path(path)
94
+
95
+ if len(drivers) == 0:
96
+ raise ValueError(
97
+ f"Could not infer driver from path: {path}; please specify driver "
98
+ "explicitly"
99
+ )
100
+
101
+ # if there are multiple drivers detected, user needs to specify the correct
102
+ # one manually
103
+ elif len(drivers) > 1:
104
+ raise ValueError(
105
+ f"Could not infer driver from path: {path}; multiple drivers are "
106
+ f"available for that extension: {', '.join(drivers)}. Please "
107
+ "specify driver explicitly."
108
+ )
109
+
110
+ return drivers[0]
111
+
112
+
113
+ def list_layers(path_or_buffer, /):
114
+ """List layers available in an OGR data source.
115
+
116
+ NOTE: includes both spatial and nonspatial layers.
117
+
118
+ Parameters
119
+ ----------
120
+ path_or_buffer : str, pathlib.Path, bytes, or file-like
121
+ A dataset path or URI, raw buffer, or file-like object with a read method.
122
+
123
+ Returns
124
+ -------
125
+ ndarray shape (2, n)
126
+ array of pairs of [<layer name>, <layer geometry type>]
127
+ Note: geometry is `None` for nonspatial layers.
128
+
129
+ """
130
+ return ogr_list_layers(get_vsi_path_or_buffer(path_or_buffer))
131
+
132
+
133
+ def read_bounds(
134
+ path_or_buffer,
135
+ /,
136
+ layer=None,
137
+ skip_features=0,
138
+ max_features=None,
139
+ where=None,
140
+ bbox=None,
141
+ mask=None,
142
+ ):
143
+ """Read bounds of each feature.
144
+
145
+ This can be used to assist with spatial indexing and partitioning, in
146
+ order to avoid reading all features into memory. It is roughly 2-3x faster
147
+ than reading the full geometry and attributes of a dataset.
148
+
149
+ Parameters
150
+ ----------
151
+ path_or_buffer : str, pathlib.Path, bytes, or file-like
152
+ A dataset path or URI, raw buffer, or file-like object with a read method.
153
+ layer : int or str, optional (default: first layer)
154
+ If an integer is provided, it corresponds to the index of the layer
155
+ with the data source. If a string is provided, it must match the name
156
+ of the layer in the data source. Defaults to first layer in data source.
157
+ skip_features : int, optional (default: 0)
158
+ Number of features to skip from the beginning of the file before returning
159
+ features. Must be less than the total number of features in the file.
160
+ max_features : int, optional (default: None)
161
+ Number of features to read from the file. Must be less than the total
162
+ number of features in the file minus ``skip_features`` (if used).
163
+ where : str, optional (default: None)
164
+ Where clause to filter features in layer by attribute values. Uses a
165
+ restricted form of SQL WHERE clause, defined here:
166
+ http://ogdi.sourceforge.net/prop/6.2.CapabilitiesMetadata.html
167
+ Examples: ``"ISO_A3 = 'CAN'"``, ``"POP_EST > 10000000 AND POP_EST < 100000000"``
168
+ bbox : tuple of (xmin, ymin, xmax, ymax), optional (default: None)
169
+ If present, will be used to filter records whose geometry intersects this
170
+ box. This must be in the same CRS as the dataset. If GEOS is present
171
+ and used by GDAL, only geometries that intersect this bbox will be
172
+ returned; if GEOS is not available or not used by GDAL, all geometries
173
+ with bounding boxes that intersect this bbox will be returned.
174
+ mask : Shapely geometry, optional (default: None)
175
+ If present, will be used to filter records whose geometry intersects
176
+ this geometry. This must be in the same CRS as the dataset. If GEOS is
177
+ present and used by GDAL, only geometries that intersect this geometry
178
+ will be returned; if GEOS is not available or not used by GDAL, all
179
+ geometries with bounding boxes that intersect the bounding box of this
180
+ geometry will be returned. Requires Shapely >= 2.0.
181
+ Cannot be combined with ``bbox`` keyword.
182
+
183
+ Returns
184
+ -------
185
+ tuple of (fids, bounds)
186
+ fids are global IDs read from the FID field of the dataset
187
+ bounds are ndarray of shape(4, n) containing ``xmin``, ``ymin``, ``xmax``,
188
+ ``ymax``
189
+
190
+ """
191
+ return ogr_read_bounds(
192
+ get_vsi_path_or_buffer(path_or_buffer),
193
+ layer=layer,
194
+ skip_features=skip_features,
195
+ max_features=max_features or 0,
196
+ where=where,
197
+ bbox=bbox,
198
+ mask=_mask_to_wkb(mask),
199
+ )
200
+
201
+
202
+ def read_info(
203
+ path_or_buffer,
204
+ /,
205
+ layer=None,
206
+ encoding=None,
207
+ force_feature_count=False,
208
+ force_total_bounds=False,
209
+ **kwargs,
210
+ ):
211
+ """Read information about an OGR data source.
212
+
213
+ ``crs``, ``geometry`` and ``total_bounds`` will be ``None`` and ``features`` will be
214
+ 0 for a nonspatial layer.
215
+
216
+ ``features`` will be -1 if this is an expensive operation for this driver. You can
217
+ force it to be calculated using the ``force_feature_count`` parameter.
218
+
219
+ ``total_bounds`` is the 2-dimensional extent of all features within the dataset:
220
+ (xmin, ymin, xmax, ymax). It will be None if this is an expensive operation for this
221
+ driver or if the data source is nonspatial. You can force it to be calculated using
222
+ the ``force_total_bounds`` parameter.
223
+
224
+ ``fid_column`` is the name of the FID field in the data source, if the FID is
225
+ physically stored (e.g. in GPKG). If the FID is just a sequence, ``fid_column``
226
+ will be "" (e.g. ESRI Shapefile).
227
+
228
+ ``geometry_name`` is the name of the field where the main geometry is stored in the
229
+ data data source, if the field name can by customized (e.g. in GPKG). If no custom
230
+ name is supported, ``geometry_name`` will be "" (e.g. ESRI Shapefile).
231
+
232
+ ``encoding`` will be ``UTF-8`` if either the native encoding is likely to be
233
+ ``UTF-8`` or GDAL can automatically convert from the detected native encoding
234
+ to ``UTF-8``.
235
+
236
+ Parameters
237
+ ----------
238
+ path_or_buffer : str, pathlib.Path, bytes, or file-like
239
+ A dataset path or URI, raw buffer, or file-like object with a read method.
240
+ layer : [type], optional
241
+ Name or index of layer in data source. Reads the first layer by default.
242
+ encoding : [type], optional (default: None)
243
+ If present, will be used as the encoding for reading string values from
244
+ the data source, unless encoding can be inferred directly from the data
245
+ source.
246
+ force_feature_count : bool, optional (default: False)
247
+ True if the feature count should be computed even if it is expensive.
248
+ force_total_bounds : bool, optional (default: False)
249
+ True if the total bounds should be computed even if it is expensive.
250
+ **kwargs
251
+ Additional driver-specific dataset open options passed to OGR. Invalid
252
+ options will trigger a warning.
253
+
254
+ Returns
255
+ -------
256
+ dict
257
+ A dictionary with the following keys::
258
+
259
+ {
260
+ "layer_name": "<layer name>",
261
+ "crs": "<crs>",
262
+ "fields": <ndarray of field names>,
263
+ "dtypes": <ndarray of field dtypes>,
264
+ "encoding": "<encoding>",
265
+ "fid_column": "<fid column name or "">",
266
+ "geometry_name": "<geometry column name or "">",
267
+ "geometry_type": "<geometry type>",
268
+ "features": <feature count or -1>,
269
+ "total_bounds": <tuple with total bounds or None>,
270
+ "driver": "<driver>",
271
+ "capabilities": "<dict of driver capabilities>"
272
+ "dataset_metadata": "<dict of dataset metadata or None>"
273
+ "layer_metadata": "<dict of layer metadata or None>"
274
+ }
275
+
276
+ """
277
+ dataset_kwargs = _preprocess_options_key_value(kwargs) if kwargs else {}
278
+
279
+ return ogr_read_info(
280
+ get_vsi_path_or_buffer(path_or_buffer),
281
+ layer=layer,
282
+ encoding=encoding,
283
+ force_feature_count=force_feature_count,
284
+ force_total_bounds=force_total_bounds,
285
+ dataset_kwargs=dataset_kwargs,
286
+ )
287
+
288
+
289
+ def set_gdal_config_options(options):
290
+ """Set GDAL configuration options.
291
+
292
+ Options are listed here: https://trac.osgeo.org/gdal/wiki/ConfigOptions
293
+
294
+ No error is raised if invalid option names are provided.
295
+
296
+ These options are applied for an entire session rather than for individual
297
+ functions.
298
+
299
+ Parameters
300
+ ----------
301
+ options : dict
302
+ If present, provides a mapping of option name / value pairs for GDAL
303
+ configuration options. ``True`` / ``False`` are normalized to ``'ON'``
304
+ / ``'OFF'``. A value of ``None`` for a config option can be used to clear out a
305
+ previously set value.
306
+
307
+ """
308
+ _set_gdal_config_options(options)
309
+
310
+
311
+ def get_gdal_config_option(name):
312
+ """Get the value for a GDAL configuration option.
313
+
314
+ Parameters
315
+ ----------
316
+ name : str
317
+ name of the option to retrive
318
+
319
+ Returns
320
+ -------
321
+ value of the option or None if not set
322
+ ``'ON'`` / ``'OFF'`` are normalized to ``True`` / ``False``.
323
+
324
+ """
325
+ return _get_gdal_config_option(name)
326
+
327
+
328
+ def get_gdal_data_path():
329
+ """Get the path to the directory GDAL uses to read data files.
330
+
331
+ Returns
332
+ -------
333
+ str, or None if data directory was not found
334
+
335
+ """
336
+ return _get_gdal_data_path()
337
+
338
+
339
+ def vsi_listtree(path: Union[str, Path], pattern: Optional[str] = None):
340
+ """Recursively list the contents of a VSI directory.
341
+
342
+ An fnmatch pattern can be specified to filter the directories/files
343
+ returned.
344
+
345
+ Parameters
346
+ ----------
347
+ path : str or pathlib.Path
348
+ Path to the VSI directory to be listed.
349
+ pattern : str, optional
350
+ Pattern to filter results, in fnmatch format.
351
+
352
+ """
353
+ if isinstance(path, Path):
354
+ path = path.as_posix()
355
+
356
+ return ogr_vsi_listtree(path, pattern=pattern)
357
+
358
+
359
+ def vsi_rmtree(path: Union[str, Path]):
360
+ """Recursively remove VSI directory.
361
+
362
+ Parameters
363
+ ----------
364
+ path : str or pathlib.Path
365
+ path to the VSI directory to be removed.
366
+
367
+ """
368
+ if isinstance(path, Path):
369
+ path = path.as_posix()
370
+
371
+ ogr_vsi_rmtree(path)
372
+
373
+
374
+ def vsi_unlink(path: Union[str, Path]):
375
+ """Remove a VSI file.
376
+
377
+ Parameters
378
+ ----------
379
+ path : str or pathlib.Path
380
+ path to vsimem file to be removed
381
+
382
+ """
383
+ if isinstance(path, Path):
384
+ path = path.as_posix()
385
+
386
+ ogr_vsi_unlink(path)
pyogrio/errors.py ADDED
@@ -0,0 +1,25 @@
1
+ """Custom errors."""
2
+
3
+
4
+ class DataSourceError(RuntimeError):
5
+ """Errors relating to opening or closing an OGRDataSource (with >= 1 layers)."""
6
+
7
+
8
+ class DataLayerError(RuntimeError):
9
+ """Errors relating to working with a single OGRLayer."""
10
+
11
+
12
+ class CRSError(DataLayerError):
13
+ """Errors relating to getting or setting CRS values."""
14
+
15
+
16
+ class FeatureError(DataLayerError):
17
+ """Errors related to reading or writing a feature."""
18
+
19
+
20
+ class GeometryError(DataLayerError):
21
+ """Errors relating to getting or setting a geometry field."""
22
+
23
+
24
+ class FieldError(DataLayerError):
25
+ """Errors relating to getting or setting a non-geometry field."""
@@ -0,0 +1,19 @@
1
+ #----------------------------------------------------------------
2
+ # Generated CMake target import file for configuration "Release".
3
+ #----------------------------------------------------------------
4
+
5
+ # Commands may need to know the format version.
6
+ set(CMAKE_IMPORT_FILE_VERSION 1)
7
+
8
+ # Import target "GDAL::GDAL" for configuration "Release"
9
+ set_property(TARGET GDAL::GDAL APPEND PROPERTY IMPORTED_CONFIGURATIONS RELEASE)
10
+ set_target_properties(GDAL::GDAL PROPERTIES
11
+ IMPORTED_LOCATION_RELEASE "${_IMPORT_PREFIX}/lib/libgdal.35.3.9.1.dylib"
12
+ IMPORTED_SONAME_RELEASE "@rpath/libgdal.35.dylib"
13
+ )
14
+
15
+ list(APPEND _cmake_import_check_targets GDAL::GDAL )
16
+ list(APPEND _cmake_import_check_files_for_GDAL::GDAL "${_IMPORT_PREFIX}/lib/libgdal.35.3.9.1.dylib" )
17
+
18
+ # Commands beyond this point should not need to know the version.
19
+ set(CMAKE_IMPORT_FILE_VERSION)