@@ -264,35 +264,49 @@ cdef str get_crs(OGRLayerH ogr_layer):
264
264
return wkt
265
265
266
266
267
- cdef detect_encoding(OGRDataSourceH ogr_dataset, OGRLayerH ogr_layer):
268
- """ Attempt to detect the encoding of the layer.
269
- If it supports UTF-8, use that.
270
- If it is a shapefile, it must otherwise be ISO-8859-1.
271
-
267
+ cdef get_driver(OGRDataSourceH ogr_dataset):
268
+ """ Get the driver for a dataset.
269
+
272
270
Parameters
273
271
----------
274
272
ogr_dataset : pointer to open OGR dataset
275
- ogr_layer : pointer to open OGR layer
276
-
277
273
Returns
278
274
-------
279
275
str or None
280
276
"""
281
277
cdef void * ogr_driver
282
278
283
- if OGR_L_TestCapability(ogr_layer, OLCStringsAsUTF8):
284
- return ' UTF-8'
285
-
286
279
try :
287
280
ogr_driver = exc_wrap_pointer(GDALGetDatasetDriver(ogr_dataset))
288
281
289
282
except NullPointerError:
290
- raise DataLayerError(f" Could not detect encoding of layer " ) from None
283
+ raise DataLayerError(f" Could not detect driver of dataset " ) from None
291
284
292
285
except CPLE_BaseError as exc:
293
286
raise DataLayerError(str (exc))
294
287
295
288
driver = OGR_Dr_GetName(ogr_driver).decode(" UTF-8" )
289
+ return driver
290
+
291
+
292
+ cdef detect_encoding(OGRDataSourceH ogr_dataset, OGRLayerH ogr_layer):
293
+ """ Attempt to detect the encoding of the layer.
294
+ If it supports UTF-8, use that.
295
+ If it is a shapefile, it must otherwise be ISO-8859-1.
296
+
297
+ Parameters
298
+ ----------
299
+ ogr_dataset : pointer to open OGR dataset
300
+ ogr_layer : pointer to open OGR layer
301
+
302
+ Returns
303
+ -------
304
+ str or None
305
+ """
306
+ if OGR_L_TestCapability(ogr_layer, OLCStringsAsUTF8):
307
+ return ' UTF-8'
308
+
309
+ driver = get_driver(ogr_dataset)
296
310
if driver == ' ESRI Shapefile' :
297
311
return ' ISO-8859-1'
298
312
@@ -973,7 +987,7 @@ def ogr_read(
973
987
' crs' : crs,
974
988
' encoding' : encoding,
975
989
' fields' : fields[:,2 ], # return only names
976
- ' geometry_type' : geometry_type
990
+ ' geometry_type' : geometry_type,
977
991
}
978
992
979
993
finally :
@@ -1205,6 +1219,7 @@ def ogr_read_info(str path, object layer=None, object encoding=None, **kwargs):
1205
1219
' dtypes' : fields[:,3 ],
1206
1220
' geometry_type' : get_geometry_type(ogr_layer),
1207
1221
' features' : OGR_L_GetFeatureCount(ogr_layer, 1 ),
1222
+ ' driver' : get_driver(ogr_dataset),
1208
1223
" capabilities" : {
1209
1224
" random_read" : OGR_L_TestCapability(ogr_layer, OLCRandomRead),
1210
1225
" fast_set_next_by_index" : OGR_L_TestCapability(ogr_layer, OLCFastSetNextByIndex),
0 commit comments