Skip to content

Commit 6934382

Browse files
authored
Merge pull request #9 from ATL2001/fid-table-fixes
Fid table fixes
2 parents b1fd3b6 + a42184f commit 6934382

File tree

4 files changed

+19
-9
lines changed

4 files changed

+19
-9
lines changed

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[project]
22
name = "spatial-polars"
3-
version = "0.1.2" # dont forget __init__.py and uv lock
3+
version = "0.1.3" # dont forget __init__.py and uv lock
44
description = "A package that extends polars for working with geospatial data."
55
readme = "README.md"
66
authors = [

src/spatial_polars/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,4 +12,4 @@
1212
"SpatialExpr",
1313
]
1414

15-
__version__ = "0.1.2" # dont forget pyproject.toml and uv lock
15+
__version__ = "0.1.3" # dont forget pyproject.toml and uv lock

src/spatial_polars/io.py

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -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)

uv.lock

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)