Skip to content

Commit

Permalink
high-level viz api (#32)
Browse files Browse the repository at this point in the history
  • Loading branch information
kylebarron authored Oct 2, 2023
1 parent a564d18 commit 8cd1a19
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 0 deletions.
1 change: 1 addition & 0 deletions lonboard/__init__.py
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
from .layer import LineStringLayer, PointLayer, PolygonLayer
from .viz import viz
from .widget import Map
30 changes: 30 additions & 0 deletions lonboard/viz.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
"""High-level, super-simple API for visualizing GeoDataFrames
"""

# TODO: avoid geopandas hard dependency
import geopandas as gpd

from lonboard.geoarrow.geopandas_interop import geopandas_to_geoarrow
from lonboard.layer import LineStringLayer, PointLayer, PolygonLayer
from lonboard.widget import Map


def viz(data: gpd.GeoDataFrame, **kwargs) -> Map:
table = geopandas_to_geoarrow(data)
geometry_ext_type = table.schema.field("geometry").metadata.get(
b"ARROW:extension:name"
)

if geometry_ext_type == "geoarrow.point":
layer = PointLayer.from_pyarrow(table, **kwargs)
return Map(layers=[layer])
elif geometry_ext_type == "geoarrow.linestring":
layer = LineStringLayer.from_pyarrow(table, **kwargs)
return Map(layers=[layer])
elif geometry_ext_type == "geoarrow.point":
layer = PolygonLayer.from_pyarrow(table, **kwargs)
return Map(layers=[layer])

raise ValueError(
"Only point, linestring, and polygon geometry types currently supported."
)

0 comments on commit 8cd1a19

Please sign in to comment.