@@ -223,6 +223,9 @@ def source_generator(
223223 [PYOGRIO_POLARS_DTYPES [dt ] for dt in layer_info ["dtypes" ]],
224224 )
225225 )
226+ if layer_info .get ("fid_column" ):
227+
228+ schema [layer_info .get ("fid_column" )] = pl .Int64
226229 if layer_info .get ("geometry_type" ):
227230 schema ["geometry" ] = spatial_series_dtype
228231
@@ -236,23 +239,30 @@ def source_generator(
236239 Generator function that creates the source.
237240 This function will be registered as IO source.
238241 """
242+ return_fids = False
239243
240244 if batch_size is None :
241245 batch_size = 100
242246
243247 if with_columns is None :
244248 read_geometry = True
249+ return_fids = True
245250 elif "geometry" in with_columns :
246251 read_geometry = True
247252 with_columns .remove ("geometry" )
248253 else :
249254 read_geometry = False
255+
256+ if with_columns is not None and layer_info .get ("fid_column" ) in with_columns :
257+ return_fids = True
258+ with_columns .remove (layer_info .get ("fid_column" ))
250259
251260 with pyogrio .open_arrow (
252261 path_or_buffer ,
253262 layer = layer ,
254263 encoding = encoding ,
255264 columns = with_columns ,
265+ return_fids = return_fids ,
256266 read_geometry = read_geometry ,
257267 force_2d = False ,
258268 bbox = bbox ,
@@ -261,18 +271,18 @@ def source_generator(
261271 use_pyarrow = True ,
262272 ) as source :
263273 meta , reader = source
264-
265- # extract the crs from the metadata
266- crs_wkt = pyproj . CRS ( meta [ " crs" ]). to_wkt ()
267-
268- geom_col = meta ["geometry_name" ] or "wkb_geometry"
274+
275+ if read_geometry is True and layer_info . get ( "geometry_type" ):
276+ # extract the crs from the metadata
277+ crs_wkt = pyproj . CRS ( meta [ "crs" ]). to_wkt ()
278+ geom_col = meta ["geometry_name" ] or "wkb_geometry"
269279
270280 while n_rows is None or n_rows > 0 :
271281 for batch in reader :
272282 if n_rows is not None and n_rows <= 0 :
273283 break
274284
275- if read_geometry :
285+ if read_geometry and layer_info . get ( "geometry_type" ) :
276286 # get the geometries from the batch
277287 geometries = batch [geom_col ][0 :n_rows ]
278288 shapely_goms = shapely .from_wkb (geometries )
0 commit comments