1
+ """Core functions to interact with OGR data sources."""
2
+
1
3
from pyogrio ._env import GDALEnv
2
4
from pyogrio .util import (
3
- get_vsi_path_or_buffer ,
4
- _preprocess_options_key_value ,
5
5
_mask_to_wkb ,
6
+ _preprocess_options_key_value ,
7
+ get_vsi_path_or_buffer ,
6
8
)
7
9
8
-
9
10
with GDALEnv ():
11
+ from pyogrio ._err import _register_error_handler
12
+ from pyogrio ._io import ogr_list_layers , ogr_read_bounds , ogr_read_info
10
13
from pyogrio ._ogr import (
11
- get_gdal_version ,
12
- get_gdal_version_string ,
13
- get_gdal_geos_version ,
14
- ogr_list_drivers ,
15
- set_gdal_config_options as _set_gdal_config_options ,
14
+ _get_drivers_for_path ,
15
+ _register_drivers ,
16
16
get_gdal_config_option as _get_gdal_config_option ,
17
17
get_gdal_data_path as _get_gdal_data_path ,
18
+ get_gdal_geos_version ,
19
+ get_gdal_version ,
20
+ get_gdal_version_string ,
18
21
init_gdal_data as _init_gdal_data ,
19
22
init_proj_data as _init_proj_data ,
20
- _register_drivers ,
21
- _get_drivers_for_path ,
23
+ ogr_list_drivers ,
24
+ set_gdal_config_options as _set_gdal_config_options ,
22
25
)
23
- from pyogrio ._err import _register_error_handler
24
- from pyogrio ._io import ogr_list_layers , ogr_read_bounds , ogr_read_info
25
26
26
27
_init_gdal_data ()
27
28
_init_proj_data ()
@@ -48,8 +49,8 @@ def list_drivers(read=False, write=False):
48
49
dict
49
50
Mapping of driver name to file mode capabilities: ``"r"``: read, ``"w"``: write.
50
51
Drivers that are available but with unknown support are marked with ``"?"``
51
- """
52
52
53
+ """
53
54
drivers = ogr_list_drivers ()
54
55
55
56
if read :
@@ -62,20 +63,23 @@ def list_drivers(read=False, write=False):
62
63
63
64
64
65
def detect_write_driver (path ):
65
- """Attempt to infer the driver for a path by extension or prefix. Only
66
- drivers that support write capabilities will be detected.
66
+ """Attempt to infer the driver for a path by extension or prefix.
67
+
68
+ Only drivers that support write capabilities will be detected.
67
69
68
70
If the path cannot be resolved to a single driver, a ValueError will be
69
71
raised.
70
72
71
73
Parameters
72
74
----------
73
75
path : str
76
+ data source path
74
77
75
78
Returns
76
79
-------
77
80
str
78
81
name of the driver, if detected
82
+
79
83
"""
80
84
# try to infer driver from path
81
85
drivers = _get_drivers_for_path (path )
@@ -106,14 +110,15 @@ def list_layers(path_or_buffer, /):
106
110
Parameters
107
111
----------
108
112
path_or_buffer : str, pathlib.Path, bytes, or file-like
113
+ A dataset path or URI, raw buffer, or file-like object with a read method.
109
114
110
115
Returns
111
116
-------
112
117
ndarray shape (2, n)
113
118
array of pairs of [<layer name>, <layer geometry type>]
114
119
Note: geometry is `None` for nonspatial layers.
115
- """
116
120
121
+ """
117
122
return ogr_list_layers (get_vsi_path_or_buffer (path_or_buffer ))
118
123
119
124
@@ -136,6 +141,7 @@ def read_bounds(
136
141
Parameters
137
142
----------
138
143
path_or_buffer : str, pathlib.Path, bytes, or file-like
144
+ A dataset path or URI, raw buffer, or file-like object with a read method.
139
145
layer : int or str, optional (default: first layer)
140
146
If an integer is provided, it corresponds to the index of the layer
141
147
with the data source. If a string is provided, it must match the name
@@ -172,8 +178,8 @@ def read_bounds(
172
178
fids are global IDs read from the FID field of the dataset
173
179
bounds are ndarray of shape(4, n) containing ``xmin``, ``ymin``, ``xmax``,
174
180
``ymax``
175
- """
176
181
182
+ """
177
183
return ogr_read_bounds (
178
184
get_vsi_path_or_buffer (path_or_buffer ),
179
185
layer = layer ,
@@ -222,6 +228,7 @@ def read_info(
222
228
Parameters
223
229
----------
224
230
path_or_buffer : str, pathlib.Path, bytes, or file-like
231
+ A dataset path or URI, raw buffer, or file-like object with a read method.
225
232
layer : [type], optional
226
233
Name or index of layer in data source. Reads the first layer by default.
227
234
encoding : [type], optional (default: None)
@@ -257,8 +264,8 @@ def read_info(
257
264
"dataset_metadata": "<dict of dataset metadata or None>"
258
265
"layer_metadata": "<dict of layer metadata or None>"
259
266
}
260
- """
261
267
268
+ """
262
269
dataset_kwargs = _preprocess_options_key_value (kwargs ) if kwargs else {}
263
270
264
271
return ogr_read_info (
@@ -288,8 +295,8 @@ def set_gdal_config_options(options):
288
295
configuration options. ``True`` / ``False`` are normalized to ``'ON'``
289
296
/ ``'OFF'``. A value of ``None`` for a config option can be used to clear out a
290
297
previously set value.
291
- """
292
298
299
+ """
293
300
_set_gdal_config_options (options )
294
301
295
302
@@ -305,8 +312,8 @@ def get_gdal_config_option(name):
305
312
-------
306
313
value of the option or None if not set
307
314
``'ON'`` / ``'OFF'`` are normalized to ``True`` / ``False``.
308
- """
309
315
316
+ """
310
317
return _get_gdal_config_option (name )
311
318
312
319
@@ -316,5 +323,6 @@ def get_gdal_data_path():
316
323
Returns
317
324
-------
318
325
str, or None if data directory was not found
326
+
319
327
"""
320
328
return _get_gdal_data_path ()
0 commit comments