Skip to content

Commit

Permalink
Fix CLI with geopackage files (#434)
Browse files Browse the repository at this point in the history
Apparently the returned column name is not _always_ `"wkb_geometry"`.
Closes #433
  • Loading branch information
kylebarron authored Mar 23, 2024
1 parent 3b6e89e commit a3e125f
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 2 deletions.
6 changes: 4 additions & 2 deletions lonboard/_cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,13 @@ def read_pyogrio(path: Path) -> pa.Table:
) from e

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

# Rename wkb_geometry to geometry
geometry_column_index = [
i for (i, name) in enumerate(table.column_names) if name == "wkb_geometry"
i for (i, name) in enumerate(table.column_names) if name == geometry_column_name
][0]

schema = table.schema
Expand Down
Binary file added tests/fixtures/West_Devon_rail.gpkg
Binary file not shown.
12 changes: 12 additions & 0 deletions tests/test_cli.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
from pathlib import Path

from lonboard import PathLayer, viz
from lonboard._cli import read_pyogrio

fixtures_dir = Path(__file__).parent / "fixtures"


def test_viz_gpkg():
table = read_pyogrio(fixtures_dir / "West_Devon_rail.gpkg")
map_ = viz(table)
assert isinstance(map_.layers[0], PathLayer)

0 comments on commit a3e125f

Please sign in to comment.