I see the example of a PathLayer and it shows the input data is a list of lists within a regular pandas df, as opposed to a geopandas df.
Let's say I'm coming from a GeoPandas df (let's say called consline
) that has a shapely MULTILINESTRING geometry column. What's the proper/best syntax to use that? I tried different combinations between calling it a PathLayer and a GeoJsonLayer with using the get_path
parameter and nothing seemed to work except for doing json.loads(consline.geometry.to_json())['features'][0]['geometry']['coordinates']
The consline
can be loaded as
consline=gpd.read_file("https://github.com/deanm0000/SOexamples/raw/main/consline.gpkg")
For instance, this doesn't work:
mylayers=[
pdk.Layer(
'PathLayer',
data=consline,
get_path="geometry",
pickable=True,
get_fill_color=[0,255,0],
width_scale=20,
width_min_pixels=2,
)
]
view_state = pdk.ViewState(
longitude=-98.99,
latitude=31.79,
zoom=5,
min_zoom=1,
max_zoom=15)
r = pdk.Deck(layers=mylayers, initial_view_state=view_state, map_style='light')
r.to_html("example.html")
but this does:
mylayers=[
pdk.Layer(
'PathLayer',
data=json.loads(consline.geometry.to_json())['features'][0]['geometry']['coordinates'],
get_path="-",
pickable=True,
get_fill_color=[0,255,0],
width_scale=20,
width_min_pixels=2,
)
]
view_state = pdk.ViewState(
longitude=-98.99,
latitude=31.79,
zoom=5,
min_zoom=1,
max_zoom=15)
r = pdk.Deck(layers=mylayers, initial_view_state=view_state, map_style='light')
r.to_html("example.html")
I can't imagine having shapely convert it to json and then python to convert it to a dict and then have pydeck convert it back to json for deck.gl is the best way to do this but I can't get it to work any other way.