-
Notifications
You must be signed in to change notification settings - Fork 33
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
a564d18
commit 8cd1a19
Showing
2 changed files
with
31 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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." | ||
) |