Skip to content

Commit 9b67b19

Browse files
authored
[pydeck] Doc: Update geopandas_integration.py (#9632)
1 parent e25d735 commit 9b67b19

File tree

1 file changed

+21
-5
lines changed

1 file changed

+21
-5
lines changed
Lines changed: 21 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,42 @@
11
import pydeck as pdk
22
import geopandas as gpd
33

4-
world = gpd.read_file(gpd.datasets.get_path("naturalearth_lowres"))
4+
world = gpd.read_file("https://naciscdn.org/naturalearth/110m/cultural/ne_110m_admin_0_countries.zip")
5+
# deck.gl is only compatible with WGS84
6+
world = world.to_crs("EPSG:4326")
7+
# Convert any multi polygons into individual polygons
8+
world = world.explode()
59

6-
centroids = gpd.GeoDataFrame()
7-
centroids["geometry"] = world.geometry.centroid
8-
centroids["name"] = world.name
10+
centroids = gpd.GeoDataFrame(geometry=world.geometry.centroid)
11+
centroids["name"] = world.NAME
912

1013
layers = [
14+
# Black background of the country polygons
1115
pdk.Layer(
1216
"GeoJsonLayer",
1317
data=world,
1418
get_fill_color=[0, 0, 0],
1519
),
20+
21+
# # Alternative way using PolygonLayer, should the above not work
22+
# pdk.Layer(
23+
# "PolygonLayer",
24+
# data=world,
25+
# get_polygon="geometry.coordinates",
26+
# get_fill_color=[0, 0, 0],
27+
# ),
28+
29+
30+
# Overlay country names at their centroids.
1631
pdk.Layer(
1732
"TextLayer",
1833
data=centroids,
34+
# Use this to get geometry coordinates out of a raw GeoDataFrame
1935
get_position="geometry.coordinates",
2036
get_size=16,
2137
get_color=[255, 255, 255],
2238
get_text="name",
2339
),
2440
]
2541

26-
pdk.Deck(layers, map_provider=None).to_html("geopandas_integration.html", css_background_color="cornflowerblue")
42+
pdk.Deck(layers, map_provider=None).to_html("geopandas_integration.html", css_background_color="cornflowerblue", open_browser=True)

0 commit comments

Comments
 (0)