Skip to content

Commit a3e125f

Browse files
authored
Fix CLI with geopackage files (#434)
Apparently the returned column name is not _always_ `"wkb_geometry"`. Closes #433
1 parent 3b6e89e commit a3e125f

File tree

3 files changed

+16
-2
lines changed

3 files changed

+16
-2
lines changed

lonboard/_cli.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,11 +27,13 @@ def read_pyogrio(path: Path) -> pa.Table:
2727
) from e
2828

2929
meta, table = read_arrow(path)
30-
# TODO: assert there are not two column names of wkb_geometry
30+
geometry_column_name = meta.get("geometry_name", "wkb_geometry")
31+
# TODO: assert there are not two column names of wkb_geometry, nor an existing
32+
# column named "geometry"
3133

3234
# Rename wkb_geometry to geometry
3335
geometry_column_index = [
34-
i for (i, name) in enumerate(table.column_names) if name == "wkb_geometry"
36+
i for (i, name) in enumerate(table.column_names) if name == geometry_column_name
3537
][0]
3638

3739
schema = table.schema
136 KB
Binary file not shown.

tests/test_cli.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
from pathlib import Path
2+
3+
from lonboard import PathLayer, viz
4+
from lonboard._cli import read_pyogrio
5+
6+
fixtures_dir = Path(__file__).parent / "fixtures"
7+
8+
9+
def test_viz_gpkg():
10+
table = read_pyogrio(fixtures_dir / "West_Devon_rail.gpkg")
11+
map_ = viz(table)
12+
assert isinstance(map_.layers[0], PathLayer)

0 commit comments

Comments
 (0)