Skip to content

Commit

Permalink
pydeck: ArcLayer, BitmapLayer, ColumnLayer examples (#4189)
Browse files Browse the repository at this point in the history
  • Loading branch information
ajduberstein authored and Andrew Duberstein committed Jan 29, 2020
1 parent 4dda32f commit 694edea
Show file tree
Hide file tree
Showing 4 changed files with 160 additions and 0 deletions.
56 changes: 56 additions & 0 deletions bindings/pydeck/examples/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
pydeck Examples
==============

All .ipynb files here can be individually executed and run.

All .py files are meant for individual execution and review, to be hosted on the pydeck website.



## Layers

- ArcLayer
- BitmapLayer
- ColumnLayer
- ContourLayer
- GeoJsonLayer
- HeatmapLayer
- IconLayer
- LineLayer
- PathLayer
- PointCloudLayer
- PolygonLayer
- SolidPolygonLayer
- ScatterplotLayer
- TextLayer
- GPUGridLayeradvanced
- GreatCircleLayer
- CPUGridLayeradvanced
- GridCellLayer
- HexagonLayer
- H3ClusterLayer
- H3HexagonLayer
- GridLayer
- S2Layer
- ScenegraphLayer
- ScreenGridLayer
- SimpleMeshLayer
- TileLayer
- Tile3DLayer
- TripsLayer

## Views

- MapView
- FirstPersonView
- OrthographicView
- OrbitView
- View State Transitions



Data sets used cited below:


US Census bureau-collected at census block level from LEHD Origin-Destination Employment Statistics (LODES) for 2017, published August 28, 2019.
[Source](https://lehd.ces.census.gov/data/)
30 changes: 30 additions & 0 deletions bindings/pydeck/examples/arc_layer.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
import pydeck


DATA_URL = 'https://raw.githubusercontent.com/ajduberstein/sf_public_data/master/bay_area_commute_routes.csv'

GREEN_RGB = [0, 255, 0, 40]
RED_RGB = [240, 100, 0, 40]

arc_layer = pydeck.Layer(
'ArcLayer',
data=DATA_URL,
get_width='S000 * 2',
get_source_position=['lng_h', 'lat_h'],
get_target_position=['lng_w', 'lat_w'],
get_tilt=15,
get_source_color=RED_RGB,
get_target_color=GREEN_RGB
)

view_state = pydeck.ViewState(
latitude=37.7576171,
longitude=-122.5776844,
bearing=45,
max_pitch=360,
pitch=50,
zoom=8
)

r = pydeck.Deck(arc_layer, initial_view_state=view_state)
r.to_html('arc_layer.html', notebook_display=False)
35 changes: 35 additions & 0 deletions bindings/pydeck/examples/bitmap_layer.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
import pydeck


# Map of San Francisco from 1906
IMG_URL = '"https://i.imgur.com/W95ked7.jpg"'

BOUNDS = [
[-122.52690000000051, 37.70313158980733],
[-122.52690000000051, 37.816395657523195],
[-122.34604834372873, 37.816134829424335],
[-122.34656848822227, 37.70339041384273]
]

bitmap_layer = pydeck.Layer(
'BitmapLayer',
data=None,
image=IMG_URL,
bounds=BOUNDS,
opacity=0.7
)

view_state = pydeck.ViewState(
latitude=37.7576171,
longitude=-122.5776844,
zoom=10,
bearing=-45,
pitch=60,
)

r = pydeck.Deck(
bitmap_layer,
initial_view_state=view_state,
map_style='mapbox://styles/mapbox/satellite-v9')

r.to_html('bitmap_layer.html', notebook_display=False)
39 changes: 39 additions & 0 deletions bindings/pydeck/examples/column_layer.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
import pydeck
import pandas as pd

DATA_URL = 'https://raw.githubusercontent.com/ajduberstein/geo_datasets/master/housing.csv'
df = pd.read_csv(DATA_URL)

view = pydeck.data_utils.compute_view(df[['lng', 'lat']])
view.pitch = 75
view.bearing = 60

column_layer = pydeck.Layer(
'ColumnLayer',
data=df,
get_position=['lng', 'lat'],
get_elevation='price_per_unit_area',
elevation_scale=100,
radius=50,
get_fill_color=['mrt_distance * 10', 'mrt_distance', 'mrt_distance * 10', 140],
pickable=True,
auto_highlight=True
)

tooltip = {
'html': '<b>{mrt_distance}</b> meters away from an MRT station, costs <b>{price_per_unit_area}</b> NTD/sqm',
'style': {
'background': 'grey',
'color': 'white',
'font-family': '"Helvetica Neue", Arial',
'z-index': '10000'
}
}

r = pydeck.Deck(
column_layer,
initial_view_state=view,
tooltip=tooltip,
map_style='mapbox://styles/mapbox/satellite-v9')

r.to_html('column_layer.html', notebook_display=False)

0 comments on commit 694edea

Please sign in to comment.