Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
pydeck: Add IconLayer, LineLayer, and PathLayer examples (#4216)
- Loading branch information
1 parent
efe8c59
commit ecc5c71
Showing
3 changed files
with
92 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 |
---|---|---|
@@ -0,0 +1,36 @@ | ||
import pydeck | ||
import pandas as pd | ||
|
||
|
||
# Data from OpenStreetMap, accessed via osmpy | ||
DATA_URL = 'https://raw.githubusercontent.com/ajduberstein/geo_datasets/master/biergartens.json' | ||
ICON_URL = 'https://upload.wikimedia.org/wikipedia/commons/c/c4/Projet_bi%C3%A8re_logo_v2.png' | ||
|
||
icon_data = { | ||
# Icon from Wikimedia, used the Creative Commons Attribution-Share Alike 3.0 | ||
# Unported, 2.5 Generic, 2.0 Generic and 1.0 Generic licenses | ||
"url": ICON_URL, | ||
"width": 242, | ||
"height": 242, | ||
"anchorY": 242 | ||
} | ||
|
||
data = pd.read_json(DATA_URL) | ||
data['icon_data'] = None | ||
for i in data.index: | ||
data['icon_data'][i] = icon_data | ||
|
||
view_state = pydeck.data_utils.compute_view(data[['lon', 'lat']], 0.1) | ||
|
||
icon_layer = pydeck.Layer( | ||
type='IconLayer', | ||
data=data, | ||
get_icon='icon_data', | ||
get_size=4, | ||
size_scale=15, | ||
get_position=['lon', 'lat'], | ||
pickable=True | ||
) | ||
|
||
r = pydeck.Deck(layers=[icon_layer], initial_view_state=view_state, tooltip={'text': '{tags}'}) | ||
r.to_html('icon_layer.html', notebook_display=False) |
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,22 @@ | ||
import pydeck | ||
|
||
|
||
DATA_URL = "https://raw.githubusercontent.com/uber-common/deck.gl-data/master/examples/line/heathrow-flights.json" | ||
|
||
view_state = pydeck.ViewState( | ||
latitude=51.51, longitude=-0.11, zoom=8, max_zoom=16, pitch=50, bearing=0 | ||
) | ||
|
||
line_layer = pydeck.Layer( | ||
type="LineLayer", | ||
data=DATA_URL, | ||
get_source_position="start", | ||
get_target_position="end", | ||
get_color=[21, 255, 255, 200], | ||
get_width=8, | ||
auto_highlight=True, | ||
pickable=True, | ||
) | ||
|
||
r = pydeck.Deck(layers=[line_layer], initial_view_state=view_state) | ||
r.to_html("line_layer.html", notebook_display=False) |
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,34 @@ | ||
import pydeck | ||
import pandas as pd | ||
|
||
|
||
DATA_URL = "https://raw.githubusercontent.com/uber-common/deck.gl-data/master/website/bart-lines.json" | ||
df = pd.read_json(DATA_URL) | ||
|
||
def hex_to_rgb(h): | ||
h = h.lstrip('#') | ||
return tuple(int(h[i:i+2], 16) for i in (0, 2, 4)) | ||
|
||
|
||
df['color'] = df['color'].apply(hex_to_rgb) | ||
|
||
|
||
view_state = pydeck.ViewState( | ||
latitude=37.782556, | ||
longitude=-122.3484867, | ||
zoom=10 | ||
) | ||
|
||
layer = pydeck.Layer( | ||
type='PathLayer', | ||
data=df, | ||
pickable=True, | ||
get_color='color', | ||
width_scale=20, | ||
width_min_pixels=2, | ||
get_path='path', | ||
get_width=5 | ||
) | ||
|
||
r = pydeck.Deck(layers=[layer], initial_view_state=view_state, tooltip={'text': '{name}'}) | ||
r.to_html("path_layer.html", notebook_display=False) |