pyogrio 0.10.0__cp313-cp313-manylinux_2_28_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/__init__.py +55 -0
  2. pyogrio/_compat.py +47 -0
  3. pyogrio/_env.py +59 -0
  4. pyogrio/_err.cpython-313-x86_64-linux-gnu.so +0 -0
  5. pyogrio/_geometry.cpython-313-x86_64-linux-gnu.so +0 -0
  6. pyogrio/_io.cpython-313-x86_64-linux-gnu.so +0 -0
  7. pyogrio/_ogr.cpython-313-x86_64-linux-gnu.so +0 -0
  8. pyogrio/_version.py +21 -0
  9. pyogrio/_vsi.cpython-313-x86_64-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-44263852.so.35.3.9.1 +0 -0
pyogrio/raw.py ADDED
@@ -0,0 +1,887 @@
1
+ """Low level functions to read and write OGR data sources."""
2
+
3
+ import warnings
4
+ from io import BytesIO
5
+ from pathlib import Path
6
+
7
+ from pyogrio._compat import HAS_ARROW_API, HAS_ARROW_WRITE_API, HAS_PYARROW
8
+ from pyogrio._env import GDALEnv
9
+ from pyogrio.core import detect_write_driver
10
+ from pyogrio.errors import DataSourceError
11
+ from pyogrio.util import (
12
+ _mask_to_wkb,
13
+ _preprocess_options_key_value,
14
+ get_vsi_path_or_buffer,
15
+ vsi_path,
16
+ )
17
+
18
+ with GDALEnv():
19
+ from pyogrio._io import ogr_open_arrow, ogr_read, ogr_write, ogr_write_arrow
20
+ from pyogrio._ogr import (
21
+ _get_driver_metadata_item,
22
+ get_gdal_version,
23
+ get_gdal_version_string,
24
+ ogr_driver_supports_vsi,
25
+ ogr_driver_supports_write,
26
+ )
27
+
28
+
29
+ DRIVERS_NO_MIXED_SINGLE_MULTI = {
30
+ "FlatGeobuf",
31
+ "GPKG",
32
+ }
33
+
34
+ DRIVERS_NO_MIXED_DIMENSIONS = {
35
+ "FlatGeobuf",
36
+ }
37
+
38
+
39
+ def read(
40
+ path_or_buffer,
41
+ /,
42
+ layer=None,
43
+ encoding=None,
44
+ columns=None,
45
+ read_geometry=True,
46
+ force_2d=False,
47
+ skip_features=0,
48
+ max_features=None,
49
+ where=None,
50
+ bbox=None,
51
+ mask=None,
52
+ fids=None,
53
+ sql=None,
54
+ sql_dialect=None,
55
+ return_fids=False,
56
+ datetime_as_string=False,
57
+ **kwargs,
58
+ ):
59
+ """Read OGR data source into numpy arrays.
60
+
61
+ IMPORTANT: non-linear geometry types (e.g., MultiSurface) are converted
62
+ to their linear approximations.
63
+
64
+ Parameters
65
+ ----------
66
+ path_or_buffer : pathlib.Path or str, or bytes buffer
67
+ A dataset path or URI, raw buffer, or file-like object with a read method.
68
+ layer : int or str, optional (default: first layer)
69
+ If an integer is provided, it corresponds to the index of the layer
70
+ with the data source. If a string is provided, it must match the name
71
+ of the layer in the data source. Defaults to first layer in data source.
72
+ encoding : str, optional (default: None)
73
+ If present, will be used as the encoding for reading string values from
74
+ the data source. By default will automatically try to detect the native
75
+ encoding and decode to ``UTF-8``.
76
+ columns : list-like, optional (default: all columns)
77
+ List of column names to import from the data source. Column names must
78
+ exactly match the names in the data source, and will be returned in
79
+ the order they occur in the data source. To avoid reading any columns,
80
+ pass an empty list-like. If combined with ``where`` parameter, must
81
+ include columns referenced in the ``where`` expression or the data may
82
+ not be correctly read; the data source may return empty results or
83
+ raise an exception (behavior varies by driver).
84
+ read_geometry : bool, optional (default: True)
85
+ If True, will read geometry into WKB. If False, geometry will be None.
86
+ force_2d : bool, optional (default: False)
87
+ If the geometry has Z values, setting this to True will cause those to
88
+ be ignored and 2D geometries to be returned
89
+ skip_features : int, optional (default: 0)
90
+ Number of features to skip from the beginning of the file before
91
+ returning features. If greater than available number of features, an
92
+ empty DataFrame will be returned. Using this parameter may incur
93
+ significant overhead if the driver does not support the capability to
94
+ randomly seek to a specific feature, because it will need to iterate
95
+ over all prior features.
96
+ max_features : int, optional (default: None)
97
+ Number of features to read from the file.
98
+ where : str, optional (default: None)
99
+ Where clause to filter features in layer by attribute values. If the data source
100
+ natively supports SQL, its specific SQL dialect should be used (eg. SQLite and
101
+ GeoPackage: `SQLITE`_, PostgreSQL). If it doesn't, the `OGRSQL WHERE`_ syntax
102
+ should be used. Note that it is not possible to overrule the SQL dialect, this
103
+ is only possible when you use the SQL parameter.
104
+ Examples: ``"ISO_A3 = 'CAN'"``, ``"POP_EST > 10000000 AND POP_EST < 100000000"``
105
+ bbox : tuple of (xmin, ymin, xmax, ymax), optional (default: None)
106
+ If present, will be used to filter records whose geometry intersects this
107
+ box. This must be in the same CRS as the dataset. If GEOS is present
108
+ and used by GDAL, only geometries that intersect this bbox will be
109
+ returned; if GEOS is not available or not used by GDAL, all geometries
110
+ with bounding boxes that intersect this bbox will be returned.
111
+ Cannot be combined with ``mask`` keyword.
112
+ mask : Shapely geometry, optional (default: None)
113
+ If present, will be used to filter records whose geometry intersects
114
+ this geometry. This must be in the same CRS as the dataset. If GEOS is
115
+ present and used by GDAL, only geometries that intersect this geometry
116
+ will be returned; if GEOS is not available or not used by GDAL, all
117
+ geometries with bounding boxes that intersect the bounding box of this
118
+ geometry will be returned. Requires Shapely >= 2.0.
119
+ Cannot be combined with ``bbox`` keyword.
120
+ fids : array-like, optional (default: None)
121
+ Array of integer feature id (FID) values to select. Cannot be combined
122
+ with other keywords to select a subset (``skip_features``,
123
+ ``max_features``, ``where``, ``bbox``, or ``mask``). Note that the
124
+ starting index is driver and file specific (e.g. typically 0 for
125
+ Shapefile and 1 for GeoPackage, but can still depend on the specific
126
+ file). The performance of reading a large number of features usings FIDs
127
+ is also driver specific.
128
+ sql : str, optional (default: None)
129
+ The SQL statement to execute. Look at the sql_dialect parameter for more
130
+ information on the syntax to use for the query. When combined with other
131
+ keywords like ``columns``, ``skip_features``, ``max_features``,
132
+ ``where``, ``bbox``, or ``mask``, those are applied after the SQL query.
133
+ Be aware that this can have an impact on performance, (e.g. filtering
134
+ with the ``bbox`` or ``mask`` keywords may not use spatial indexes).
135
+ Cannot be combined with the ``layer`` or ``fids`` keywords.
136
+ sql_dialect : str, optional (default: None)
137
+ The SQL dialect the ``sql`` statement is written in. Possible values:
138
+
139
+ - **None**: if the data source natively supports SQL, its specific SQL dialect
140
+ will be used by default (eg. SQLite and Geopackage: `SQLITE`_, PostgreSQL).
141
+ If the data source doesn't natively support SQL, the `OGRSQL`_ dialect is
142
+ the default.
143
+ - '`OGRSQL`_': can be used on any data source. Performance can suffer
144
+ when used on data sources with native support for SQL.
145
+ - '`SQLITE`_': can be used on any data source. All spatialite_
146
+ functions can be used. Performance can suffer on data sources with
147
+ native support for SQL, except for Geopackage and SQLite as this is
148
+ their native SQL dialect.
149
+
150
+ return_fids : bool, optional (default: False)
151
+ If True, will return the FIDs of the feature that were read.
152
+ datetime_as_string : bool, optional (default: False)
153
+ If True, will return datetime dtypes as detected by GDAL as a string
154
+ array (which can be used to extract timezone info), instead of
155
+ a datetime64 array.
156
+
157
+ **kwargs
158
+ Additional driver-specific dataset open options passed to OGR. Invalid
159
+ options will trigger a warning.
160
+
161
+ Returns
162
+ -------
163
+ (dict, fids, geometry, data fields)
164
+ Returns a tuple of meta information about the data source in a dict,
165
+ an ndarray of FIDs corresponding to the features that were read or None
166
+ (if return_fids is False),
167
+ an ndarray of geometry objects or None (if data source does not include
168
+ geometry or read_geometry is False), a tuple of ndarrays for each field
169
+ in the data layer.
170
+
171
+ Meta is: {
172
+ "crs": "<crs>",
173
+ "fields": <ndarray of field names>,
174
+ "dtypes": <ndarray of numpy dtypes corresponding to fields>
175
+ "encoding": "<encoding>",
176
+ "geometry_type": "<geometry type>"
177
+ }
178
+
179
+ .. _OGRSQL:
180
+
181
+ https://gdal.org/user/ogr_sql_dialect.html#ogr-sql-dialect
182
+
183
+ .. _OGRSQL WHERE:
184
+
185
+ https://gdal.org/user/ogr_sql_dialect.html#where
186
+
187
+ .. _SQLITE:
188
+
189
+ https://gdal.org/user/sql_sqlite_dialect.html#sql-sqlite-dialect
190
+
191
+ .. _spatialite:
192
+
193
+ https://www.gaia-gis.it/gaia-sins/spatialite-sql-latest.html
194
+
195
+ """
196
+ dataset_kwargs = _preprocess_options_key_value(kwargs) if kwargs else {}
197
+
198
+ return ogr_read(
199
+ get_vsi_path_or_buffer(path_or_buffer),
200
+ layer=layer,
201
+ encoding=encoding,
202
+ columns=columns,
203
+ read_geometry=read_geometry,
204
+ force_2d=force_2d,
205
+ skip_features=skip_features,
206
+ max_features=max_features or 0,
207
+ where=where,
208
+ bbox=bbox,
209
+ mask=_mask_to_wkb(mask),
210
+ fids=fids,
211
+ sql=sql,
212
+ sql_dialect=sql_dialect,
213
+ return_fids=return_fids,
214
+ dataset_kwargs=dataset_kwargs,
215
+ datetime_as_string=datetime_as_string,
216
+ )
217
+
218
+
219
+ def read_arrow(
220
+ path_or_buffer,
221
+ /,
222
+ layer=None,
223
+ encoding=None,
224
+ columns=None,
225
+ read_geometry=True,
226
+ force_2d=False,
227
+ skip_features=0,
228
+ max_features=None,
229
+ where=None,
230
+ bbox=None,
231
+ mask=None,
232
+ fids=None,
233
+ sql=None,
234
+ sql_dialect=None,
235
+ return_fids=False,
236
+ **kwargs,
237
+ ):
238
+ """Read OGR data source into a pyarrow Table.
239
+
240
+ See docstring of `read` for parameters.
241
+
242
+ Returns
243
+ -------
244
+ (dict, pyarrow.Table)
245
+
246
+ Returns a tuple of meta information about the data source in a dict,
247
+ and a pyarrow Table with data.
248
+
249
+ Meta is: {
250
+ "crs": "<crs>",
251
+ "fields": <ndarray of field names>,
252
+ "encoding": "<encoding>",
253
+ "geometry_type": "<geometry_type>",
254
+ "geometry_name": "<name of geometry column in arrow table>",
255
+ }
256
+
257
+ """
258
+ if not HAS_PYARROW:
259
+ raise RuntimeError(
260
+ "pyarrow required to read using 'read_arrow'. You can use 'open_arrow' "
261
+ "to read data with an alternative Arrow implementation"
262
+ )
263
+
264
+ from pyarrow import Table
265
+
266
+ gdal_version = get_gdal_version()
267
+
268
+ if skip_features < 0:
269
+ raise ValueError("'skip_features' must be >= 0")
270
+
271
+ if max_features is not None and max_features < 0:
272
+ raise ValueError("'max_features' must be >= 0")
273
+
274
+ # limit batch size to max_features if set
275
+ if "batch_size" in kwargs:
276
+ batch_size = kwargs.pop("batch_size")
277
+ else:
278
+ batch_size = 65_536
279
+
280
+ if max_features is not None and max_features < batch_size:
281
+ batch_size = max_features
282
+
283
+ # handle skip_features internally within open_arrow if GDAL >= 3.8.0
284
+ gdal_skip_features = 0
285
+ if gdal_version >= (3, 8, 0):
286
+ gdal_skip_features = skip_features
287
+ skip_features = 0
288
+
289
+ with open_arrow(
290
+ path_or_buffer,
291
+ layer=layer,
292
+ encoding=encoding,
293
+ columns=columns,
294
+ read_geometry=read_geometry,
295
+ force_2d=force_2d,
296
+ where=where,
297
+ bbox=bbox,
298
+ mask=mask,
299
+ fids=fids,
300
+ sql=sql,
301
+ sql_dialect=sql_dialect,
302
+ return_fids=return_fids,
303
+ skip_features=gdal_skip_features,
304
+ batch_size=batch_size,
305
+ use_pyarrow=True,
306
+ **kwargs,
307
+ ) as source:
308
+ meta, reader = source
309
+
310
+ if max_features is not None:
311
+ batches = []
312
+ count = 0
313
+ while True:
314
+ try:
315
+ batch = reader.read_next_batch()
316
+ batches.append(batch)
317
+
318
+ count += len(batch)
319
+ if count >= (skip_features + max_features):
320
+ break
321
+
322
+ except StopIteration:
323
+ break
324
+
325
+ # use combine_chunks to release the original memory that included
326
+ # too many features
327
+ table = (
328
+ Table.from_batches(batches, schema=reader.schema)
329
+ .slice(skip_features, max_features)
330
+ .combine_chunks()
331
+ )
332
+
333
+ elif skip_features > 0:
334
+ table = reader.read_all().slice(skip_features).combine_chunks()
335
+
336
+ else:
337
+ table = reader.read_all()
338
+
339
+ return meta, table
340
+
341
+
342
+ def open_arrow(
343
+ path_or_buffer,
344
+ /,
345
+ layer=None,
346
+ encoding=None,
347
+ columns=None,
348
+ read_geometry=True,
349
+ force_2d=False,
350
+ skip_features=0,
351
+ max_features=None,
352
+ where=None,
353
+ bbox=None,
354
+ mask=None,
355
+ fids=None,
356
+ sql=None,
357
+ sql_dialect=None,
358
+ return_fids=False,
359
+ batch_size=65_536,
360
+ use_pyarrow=False,
361
+ **kwargs,
362
+ ):
363
+ """Open OGR data source as a stream of Arrow record batches.
364
+
365
+ See docstring of `read` for parameters.
366
+
367
+ The returned object is reading from a stream provided by OGR and must not be
368
+ accessed after the OGR dataset has been closed, i.e. after the context manager has
369
+ been closed.
370
+
371
+ By default this functions returns a generic stream object implementing
372
+ the `Arrow PyCapsule Protocol`_ (i.e. having an ``__arrow_c_stream__``
373
+ method). This object can then be consumed by your Arrow implementation
374
+ of choice that supports this protocol.
375
+ Optionally, you can specify ``use_pyarrow=True`` to directly get the
376
+ stream as a `pyarrow.RecordBatchReader`.
377
+
378
+ .. _Arrow PyCapsule Protocol: https://arrow.apache.org/docs/format/CDataInterface/PyCapsuleInterface.html
379
+
380
+ Other Parameters
381
+ ----------------
382
+ batch_size : int (default: 65_536)
383
+ Maximum number of features to retrieve in a batch.
384
+ use_pyarrow : bool (default: False)
385
+ If True, return a pyarrow RecordBatchReader instead of a generic
386
+ ArrowStream object. In the default case, this stream object needs
387
+ to be passed to another library supporting the Arrow PyCapsule
388
+ Protocol to consume the stream of data.
389
+
390
+ Examples
391
+ --------
392
+ >>> from pyogrio.raw import open_arrow
393
+ >>> import pyarrow as pa
394
+ >>> import shapely
395
+ >>>
396
+ >>> with open_arrow(path) as source:
397
+ >>> meta, stream = source
398
+ >>> # wrap the arrow stream object in a pyarrow RecordBatchReader
399
+ >>> reader = pa.RecordBatchReader.from_stream(stream)
400
+ >>> geom_col = meta["geometry_name"] or "wkb_geometry"
401
+ >>> for batch in reader:
402
+ >>> geometries = shapely.from_wkb(batch[geom_col])
403
+
404
+ The returned `stream` object needs to be consumed by a library implementing
405
+ the Arrow PyCapsule Protocol. In the above example, pyarrow is used through
406
+ its RecordBatchReader. For this case, you can also specify ``use_pyarrow=True``
407
+ to directly get this result as a short-cut:
408
+
409
+ >>> with open_arrow(path, use_pyarrow=True) as source:
410
+ >>> meta, reader = source
411
+ >>> geom_col = meta["geometry_name"] or "wkb_geometry"
412
+ >>> for batch in reader:
413
+ >>> geometries = shapely.from_wkb(batch[geom_col])
414
+
415
+ Returns
416
+ -------
417
+ (dict, pyarrow.RecordBatchReader or ArrowStream)
418
+
419
+ Returns a tuple of meta information about the data source in a dict,
420
+ and a data stream object (a generic ArrowStream object, or a pyarrow
421
+ RecordBatchReader if `use_pyarrow` is set to True).
422
+
423
+ Meta is: {
424
+ "crs": "<crs>",
425
+ "fields": <ndarray of field names>,
426
+ "encoding": "<encoding>",
427
+ "geometry_type": "<geometry_type>",
428
+ "geometry_name": "<name of geometry column in arrow table>",
429
+ }
430
+
431
+ """
432
+ if not HAS_ARROW_API:
433
+ raise RuntimeError("GDAL>= 3.6 required to read using arrow")
434
+
435
+ dataset_kwargs = _preprocess_options_key_value(kwargs) if kwargs else {}
436
+
437
+ return ogr_open_arrow(
438
+ get_vsi_path_or_buffer(path_or_buffer),
439
+ layer=layer,
440
+ encoding=encoding,
441
+ columns=columns,
442
+ read_geometry=read_geometry,
443
+ force_2d=force_2d,
444
+ skip_features=skip_features,
445
+ max_features=max_features or 0,
446
+ where=where,
447
+ bbox=bbox,
448
+ mask=_mask_to_wkb(mask),
449
+ fids=fids,
450
+ sql=sql,
451
+ sql_dialect=sql_dialect,
452
+ return_fids=return_fids,
453
+ dataset_kwargs=dataset_kwargs,
454
+ batch_size=batch_size,
455
+ use_pyarrow=use_pyarrow,
456
+ )
457
+
458
+
459
+ def _parse_options_names(xml):
460
+ """Convert metadata xml to list of names."""
461
+ # Based on Fiona's meta.py
462
+ # (https://github.com/Toblerity/Fiona/blob/91c13ad8424641557a4e5f038f255f9b657b1bc5/fiona/meta.py)
463
+ import xml.etree.ElementTree as ET
464
+
465
+ options = []
466
+ if xml:
467
+ root = ET.fromstring(xml)
468
+ for option in root.iter("Option"):
469
+ # some options explicitly have scope='raster'
470
+ if option.attrib.get("scope", "vector") != "raster":
471
+ options.append(option.attrib["name"])
472
+
473
+ return options
474
+
475
+
476
+ def _validate_metadata(dataset_metadata, layer_metadata, metadata):
477
+ """Validate the metadata."""
478
+ if metadata is not None:
479
+ if layer_metadata is not None:
480
+ raise ValueError("Cannot pass both metadata and layer_metadata")
481
+ layer_metadata = metadata
482
+
483
+ # validate metadata types
484
+ for meta in [dataset_metadata, layer_metadata]:
485
+ if meta is not None:
486
+ for k, v in meta.items():
487
+ if not isinstance(k, str):
488
+ raise ValueError(f"metadata key {k} must be a string")
489
+
490
+ if not isinstance(v, str):
491
+ raise ValueError(f"metadata value {v} must be a string")
492
+
493
+ return dataset_metadata, layer_metadata
494
+
495
+
496
+ def _preprocess_options_kwargs(driver, dataset_options, layer_options, kwargs):
497
+ """Preprocess kwargs and split in dataset and layer creation options."""
498
+ dataset_kwargs = _preprocess_options_key_value(dataset_options or {})
499
+ layer_kwargs = _preprocess_options_key_value(layer_options or {})
500
+ if kwargs:
501
+ kwargs = _preprocess_options_key_value(kwargs)
502
+ dataset_option_names = _parse_options_names(
503
+ _get_driver_metadata_item(driver, "DMD_CREATIONOPTIONLIST")
504
+ )
505
+ layer_option_names = _parse_options_names(
506
+ _get_driver_metadata_item(driver, "DS_LAYER_CREATIONOPTIONLIST")
507
+ )
508
+ for k, v in kwargs.items():
509
+ if k in dataset_option_names:
510
+ dataset_kwargs[k] = v
511
+ elif k in layer_option_names:
512
+ layer_kwargs[k] = v
513
+ else:
514
+ raise ValueError(f"unrecognized option '{k}' for driver '{driver}'")
515
+
516
+ return dataset_kwargs, layer_kwargs
517
+
518
+
519
+ def _get_write_path_driver(path, driver, append=False):
520
+ """Validate and return path and driver.
521
+
522
+ Parameters
523
+ ----------
524
+ path : str or io.BytesIO
525
+ path to output file on writeable file system or an io.BytesIO object to
526
+ allow writing to memory. Will raise NotImplementedError if an open file
527
+ handle is passed.
528
+ driver : str, optional (default: None)
529
+ The OGR format driver used to write the vector file. By default attempts
530
+ to infer driver from path. Must be provided to write to a file-like
531
+ object.
532
+ append : bool, optional (default: False)
533
+ True if path and driver is being tested for append support
534
+
535
+ Returns
536
+ -------
537
+ (path, driver)
538
+
539
+ """
540
+ if isinstance(path, BytesIO):
541
+ if driver is None:
542
+ raise ValueError("driver must be provided to write to in-memory file")
543
+
544
+ # blacklist certain drivers known not to work in current memory implementation
545
+ # because they create multiple files
546
+ if driver in {"ESRI Shapefile", "OpenFileGDB"}:
547
+ raise ValueError(f"writing to in-memory file is not supported for {driver}")
548
+
549
+ # verify that driver supports VSI methods
550
+ if not ogr_driver_supports_vsi(driver):
551
+ raise DataSourceError(
552
+ f"{driver} does not support ability to write in-memory in GDAL "
553
+ f"{get_gdal_version_string()}"
554
+ )
555
+
556
+ if append:
557
+ raise NotImplementedError("append is not supported for in-memory files")
558
+
559
+ elif hasattr(path, "write") and not isinstance(path, Path):
560
+ raise NotImplementedError(
561
+ "writing to an open file handle is not yet supported; instead, write to a "
562
+ "BytesIO instance and then read bytes from that to write to the file handle"
563
+ )
564
+
565
+ else:
566
+ path = vsi_path(path)
567
+
568
+ if driver is None:
569
+ driver = detect_write_driver(path)
570
+
571
+ # verify that driver supports writing
572
+ if not ogr_driver_supports_write(driver):
573
+ raise DataSourceError(
574
+ f"{driver} does not support write functionality in GDAL "
575
+ f"{get_gdal_version_string()}"
576
+ )
577
+
578
+ # prevent segfault from: https://github.com/OSGeo/gdal/issues/5739
579
+ if append and driver == "FlatGeobuf" and get_gdal_version() <= (3, 5, 0):
580
+ raise RuntimeError(
581
+ "append to FlatGeobuf is not supported for GDAL <= 3.5.0 due to segfault"
582
+ )
583
+
584
+ return path, driver
585
+
586
+
587
+ def write(
588
+ path,
589
+ geometry,
590
+ field_data,
591
+ fields,
592
+ field_mask=None,
593
+ layer=None,
594
+ driver=None,
595
+ # derived from meta if roundtrip
596
+ geometry_type=None,
597
+ crs=None,
598
+ encoding=None,
599
+ promote_to_multi=None,
600
+ nan_as_null=True,
601
+ append=False,
602
+ dataset_metadata=None,
603
+ layer_metadata=None,
604
+ metadata=None,
605
+ dataset_options=None,
606
+ layer_options=None,
607
+ gdal_tz_offsets=None,
608
+ **kwargs,
609
+ ):
610
+ """Write geometry and field data to an OGR file format.
611
+
612
+ Parameters
613
+ ----------
614
+ path : str or io.BytesIO
615
+ path to output file on writeable file system or an io.BytesIO object to
616
+ allow writing to memory. Will raise NotImplementedError if an open file
617
+ handle is passed; use BytesIO instead.
618
+ NOTE: support for writing to memory is limited to specific drivers.
619
+ geometry : ndarray of WKB encoded geometries or None
620
+ If None, geometries will not be written to output file
621
+ field_data : list-like of shape (num_fields, num_records)
622
+ contains one record per field to be written in same order as fields
623
+ fields : list-like
624
+ contains field names
625
+ field_mask : list-like of ndarrays or None, optional (default: None)
626
+ contains mask arrays indicating null values of the field at the same
627
+ position in the outer list, or None to indicate field does not have
628
+ a mask array
629
+ layer : str, optional (default: None)
630
+ layer name to create. If writing to memory and layer name is not
631
+ provided, it layer name will be set to a UUID4 value.
632
+ driver : string, optional (default: None)
633
+ The OGR format driver used to write the vector file. By default attempts
634
+ to infer driver from path. Must be provided to write to memory.
635
+ geometry_type : str, optional (default: None)
636
+ Possible values are: "Unknown", "Point", "LineString", "Polygon",
637
+ "MultiPoint", "MultiLineString", "MultiPolygon" or "GeometryCollection".
638
+
639
+ This parameter does not modify the geometry, but it will try to force
640
+ the layer type of the output file to this value. Use this parameter with
641
+ caution because using a wrong layer geometry type may result in errors
642
+ when writing the file, may be ignored by the driver, or may result in
643
+ invalid files.
644
+ crs : str, optional (default: None)
645
+ WKT-encoded CRS of the geometries to be written.
646
+ encoding : str, optional (default: None)
647
+ If present, will be used as the encoding for writing string values to
648
+ the file. Use with caution, only certain drivers support encodings
649
+ other than UTF-8.
650
+ promote_to_multi : bool, optional (default: None)
651
+ If True, will convert singular geometry types in the data to their
652
+ corresponding multi geometry type for writing. By default, will convert
653
+ mixed singular and multi geometry types to multi geometry types for
654
+ drivers that do not support mixed singular and multi geometry types. If
655
+ False, geometry types will not be promoted, which may result in errors
656
+ or invalid files when attempting to write mixed singular and multi
657
+ geometry types to drivers that do not support such combinations.
658
+ nan_as_null : bool, default True
659
+ For floating point columns (float32 / float64), whether NaN values are
660
+ written as "null" (missing value). Defaults to True because in pandas
661
+ NaNs are typically used as missing value. Note that when set to False,
662
+ behaviour is format specific: some formats don't support NaNs by
663
+ default (e.g. GeoJSON will skip this property) or might treat them as
664
+ null anyway (e.g. GeoPackage).
665
+ append : bool, optional (default: False)
666
+ If True, the data source specified by path already exists, and the
667
+ driver supports appending to an existing data source, will cause the
668
+ data to be appended to the existing records in the data source. Not
669
+ supported for writing to in-memory files.
670
+ NOTE: append support is limited to specific drivers and GDAL versions.
671
+ dataset_metadata : dict, optional (default: None)
672
+ Metadata to be stored at the dataset level in the output file; limited
673
+ to drivers that support writing metadata, such as GPKG, and silently
674
+ ignored otherwise. Keys and values must be strings.
675
+ layer_metadata : dict, optional (default: None)
676
+ Metadata to be stored at the layer level in the output file; limited to
677
+ drivers that support writing metadata, such as GPKG, and silently
678
+ ignored otherwise. Keys and values must be strings.
679
+ metadata : dict, optional (default: None)
680
+ alias of layer_metadata
681
+ dataset_options : dict, optional
682
+ Dataset creation options (format specific) passed to OGR. Specify as
683
+ a key-value dictionary.
684
+ layer_options : dict, optional
685
+ Layer creation options (format specific) passed to OGR. Specify as
686
+ a key-value dictionary.
687
+ gdal_tz_offsets : dict, optional (default: None)
688
+ Used to handle GDAL timezone offsets for each field contained in dict.
689
+ **kwargs
690
+ Additional driver-specific dataset creation options passed to OGR. Invalid
691
+ options will trigger a warning.
692
+
693
+ """
694
+ # if dtypes is given, remove it from kwargs (dtypes is included in meta returned by
695
+ # read, and it is convenient to pass meta directly into write for round trip tests)
696
+ kwargs.pop("dtypes", None)
697
+
698
+ path, driver = _get_write_path_driver(path, driver, append=append)
699
+
700
+ dataset_metadata, layer_metadata = _validate_metadata(
701
+ dataset_metadata, layer_metadata, metadata
702
+ )
703
+
704
+ if geometry is not None and promote_to_multi is None:
705
+ promote_to_multi = (
706
+ geometry_type.startswith("Multi")
707
+ and driver in DRIVERS_NO_MIXED_SINGLE_MULTI
708
+ )
709
+
710
+ if geometry is not None and crs is None:
711
+ warnings.warn(
712
+ "'crs' was not provided. The output dataset will not have "
713
+ "projection information defined and may not be usable in other "
714
+ "systems.",
715
+ stacklevel=2,
716
+ )
717
+
718
+ # preprocess kwargs and split in dataset and layer creation options
719
+ dataset_kwargs, layer_kwargs = _preprocess_options_kwargs(
720
+ driver, dataset_options, layer_options, kwargs
721
+ )
722
+
723
+ ogr_write(
724
+ path,
725
+ layer=layer,
726
+ driver=driver,
727
+ geometry=geometry,
728
+ geometry_type=geometry_type,
729
+ field_data=field_data,
730
+ field_mask=field_mask,
731
+ fields=fields,
732
+ crs=crs,
733
+ encoding=encoding,
734
+ promote_to_multi=promote_to_multi,
735
+ nan_as_null=nan_as_null,
736
+ append=append,
737
+ dataset_metadata=dataset_metadata,
738
+ layer_metadata=layer_metadata,
739
+ dataset_kwargs=dataset_kwargs,
740
+ layer_kwargs=layer_kwargs,
741
+ gdal_tz_offsets=gdal_tz_offsets,
742
+ )
743
+
744
+
745
+ def write_arrow(
746
+ arrow_obj,
747
+ path,
748
+ layer=None,
749
+ driver=None,
750
+ geometry_name=None,
751
+ geometry_type=None,
752
+ crs=None,
753
+ encoding=None,
754
+ append=False,
755
+ dataset_metadata=None,
756
+ layer_metadata=None,
757
+ metadata=None,
758
+ dataset_options=None,
759
+ layer_options=None,
760
+ **kwargs,
761
+ ):
762
+ """Write an Arrow-compatible data source to an OGR file format.
763
+
764
+ .. _Arrow PyCapsule Protocol: https://arrow.apache.org/docs/format/CDataInterface/PyCapsuleInterface.html
765
+
766
+ Parameters
767
+ ----------
768
+ arrow_obj
769
+ The Arrow data to write. This can be any Arrow-compatible tabular data
770
+ object that implements the `Arrow PyCapsule Protocol`_ (i.e. has an
771
+ ``__arrow_c_stream__`` method), for example a pyarrow Table or
772
+ RecordBatchReader.
773
+ path : str or io.BytesIO
774
+ path to output file on writeable file system or an io.BytesIO object to
775
+ allow writing to memory
776
+ NOTE: support for writing to memory is limited to specific drivers.
777
+ layer : str, optional (default: None)
778
+ layer name to create. If writing to memory and layer name is not
779
+ provided, it layer name will be set to a UUID4 value.
780
+ driver : string, optional (default: None)
781
+ The OGR format driver used to write the vector file. By default attempts
782
+ to infer driver from path. Must be provided to write to memory.
783
+ geometry_name : str, optional (default: None)
784
+ The name of the column in the input data that will be written as the
785
+ geometry field. Will be inferred from the input data if the geometry
786
+ column is annotated as an "geoarrow.wkb" or "ogc.wkb" extension type.
787
+ Otherwise needs to be specified explicitly.
788
+ geometry_type : str
789
+ The geometry type of the written layer. Currently, this needs to be
790
+ specified explicitly when creating a new layer with geometries.
791
+ Possible values are: "Unknown", "Point", "LineString", "Polygon",
792
+ "MultiPoint", "MultiLineString", "MultiPolygon" or "GeometryCollection".
793
+
794
+ This parameter does not modify the geometry, but it will try to force the layer
795
+ type of the output file to this value. Use this parameter with caution because
796
+ using a wrong layer geometry type may result in errors when writing the
797
+ file, may be ignored by the driver, or may result in invalid files.
798
+ crs : str, optional (default: None)
799
+ WKT-encoded CRS of the geometries to be written.
800
+ encoding : str, optional (default: None)
801
+ Only used for the .dbf file of ESRI Shapefiles. If not specified,
802
+ uses the default locale.
803
+ append : bool, optional (default: False)
804
+ If True, the data source specified by path already exists, and the
805
+ driver supports appending to an existing data source, will cause the
806
+ data to be appended to the existing records in the data source. Not
807
+ supported for writing to in-memory files.
808
+ NOTE: append support is limited to specific drivers and GDAL versions.
809
+ dataset_metadata : dict, optional (default: None)
810
+ Metadata to be stored at the dataset level in the output file; limited
811
+ to drivers that support writing metadata, such as GPKG, and silently
812
+ ignored otherwise. Keys and values must be strings.
813
+ layer_metadata : dict, optional (default: None)
814
+ Metadata to be stored at the layer level in the output file; limited to
815
+ drivers that support writing metadata, such as GPKG, and silently
816
+ ignored otherwise. Keys and values must be strings.
817
+ metadata : dict, optional (default: None)
818
+ alias of layer_metadata
819
+ dataset_options : dict, optional
820
+ Dataset creation options (format specific) passed to OGR. Specify as
821
+ a key-value dictionary.
822
+ layer_options : dict, optional
823
+ Layer creation options (format specific) passed to OGR. Specify as
824
+ a key-value dictionary.
825
+ **kwargs
826
+ Additional driver-specific dataset or layer creation options passed
827
+ to OGR. pyogrio will attempt to automatically pass those keywords
828
+ either as dataset or as layer creation option based on the known
829
+ options for the specific driver. Alternatively, you can use the
830
+ explicit `dataset_options` or `layer_options` keywords to manually
831
+ do this (for example if an option exists as both dataset and layer
832
+ option).
833
+
834
+ """
835
+ if not HAS_ARROW_WRITE_API:
836
+ raise RuntimeError("GDAL>=3.8 required to write using arrow")
837
+
838
+ if not hasattr(arrow_obj, "__arrow_c_stream__"):
839
+ raise ValueError(
840
+ "The provided data is not recognized as Arrow data. The object "
841
+ "should implement the Arrow PyCapsule Protocol (i.e. have a "
842
+ "'__arrow_c_stream__' method)."
843
+ )
844
+
845
+ path, driver = _get_write_path_driver(path, driver, append=append)
846
+
847
+ if "promote_to_multi" in kwargs:
848
+ raise ValueError(
849
+ "The 'promote_to_multi' option is not supported when writing using Arrow"
850
+ )
851
+
852
+ if geometry_name is not None:
853
+ if geometry_type is None:
854
+ raise ValueError("'geometry_type' keyword is required")
855
+ if crs is None:
856
+ # TODO: does GDAL infer CRS automatically from geometry metadata?
857
+ warnings.warn(
858
+ "'crs' was not provided. The output dataset will not have "
859
+ "projection information defined and may not be usable in other "
860
+ "systems.",
861
+ stacklevel=2,
862
+ )
863
+
864
+ dataset_metadata, layer_metadata = _validate_metadata(
865
+ dataset_metadata, layer_metadata, metadata
866
+ )
867
+
868
+ # preprocess kwargs and split in dataset and layer creation options
869
+ dataset_kwargs, layer_kwargs = _preprocess_options_kwargs(
870
+ driver, dataset_options, layer_options, kwargs
871
+ )
872
+
873
+ ogr_write_arrow(
874
+ path,
875
+ layer=layer,
876
+ driver=driver,
877
+ arrow_obj=arrow_obj,
878
+ geometry_type=geometry_type,
879
+ geometry_name=geometry_name,
880
+ crs=crs,
881
+ encoding=encoding,
882
+ append=append,
883
+ dataset_metadata=dataset_metadata,
884
+ layer_metadata=layer_metadata,
885
+ dataset_kwargs=dataset_kwargs,
886
+ layer_kwargs=layer_kwargs,
887
+ )