Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(pydeck): support v9 in bindings #8577

Merged
merged 14 commits into from Apr 26, 2024
Merged
Show file tree
Hide file tree
Changes from 12 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
3 changes: 3 additions & 0 deletions bindings/pydeck-carto/Makefile
Expand Up @@ -16,6 +16,9 @@ lint:
test:
$(BIN)/pytest tests --cov=pydeck_carto

test-scripts:
for file in examples/scripts/*.py; do $(BIN)/python "$$file"; done

publish-pypi:
rm -rf $(DIST) $(BUILD) *.egg-info
$(BIN)/python setup.py sdist bdist_wheel
Expand Down
21 changes: 12 additions & 9 deletions bindings/pydeck-carto/README.md
Expand Up @@ -31,16 +31,19 @@ from carto_auth import CartoAuth
# Authentication with CARTO
carto_auth = CartoAuth.from_oauth()

# Register CartoLayer in pydeck
pdkc.register_carto_layer()

# Render CartoLayer in pydeck
# Register new layer types in pydeck
pdkc.register_layers()

# Render CARTO layer in pydeck
data = pdkc.sources.vector_query_source(
access_token=carto_auth.get_access_token(),
api_base_url=carto_auth.get_api_base_url(),
connection_name="carto_dw",
sql_query="SELECT geom, name FROM carto-demo-data.demo_tables.world_airports",
)
layer = pdk.Layer(
"CartoLayer",
data="SELECT geom, name FROM carto-demo-data.demo_tables.airports",
type_=pdkc.MapType.QUERY,
connection=pdkc.CartoConnection.CARTO_DW,
credentials=pdkc.get_layer_credentials(carto_auth),
"VectorTileLayer",
data=data,
get_fill_color=[238, 77, 90],
point_radius_min_pixels=2.5,
pickable=True,
Expand Down
19 changes: 12 additions & 7 deletions bindings/pydeck-carto/examples/scripts/carto_layer_geo_query.py
Expand Up @@ -7,17 +7,22 @@
import pydeck as pdk
import pydeck_carto as pdkc
from carto_auth import CartoAuth
from os.path import join, dirname

carto_auth = CartoAuth.from_oauth()

pdkc.register_carto_layer()
pdkc.register_layers()

data = pdkc.sources.vector_query_source(
access_token=carto_auth.get_access_token(),
api_base_url=carto_auth.get_api_base_url(),
connection_name="carto_dw",
sql_query="SELECT geom, name FROM carto-demo-data.demo_tables.world_airports",
)

layer = pdk.Layer(
"CartoLayer",
data="SELECT geom, name FROM carto-demo-data.demo_tables.airports",
type_=pdkc.MapType.QUERY,
connection=pdkc.CartoConnection.CARTO_DW,
credentials=pdkc.get_layer_credentials(carto_auth),
"VectorTileLayer",
data=data,
get_fill_color=[238, 77, 90],
point_radius_min_pixels=2.5,
pickable=True,
Expand All @@ -26,4 +31,4 @@
view_state = pdk.ViewState(latitude=0, longitude=0, zoom=1)

r = pdk.Deck(layer, map_style=pdk.map_styles.ROAD, initial_view_state=view_state)
r.to_html("carto_layer_geo_query.html", open_browser=True)
r.to_html(join(dirname(__file__), "carto_layer_geo_query.html"))
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Changed this line — in all example scripts — to ensure example output is written to the same folder as the example itself. This makes it easier to run all the example scripts together ...

make test-scripts

... and verify the output ...

npx serve examples/scripts

Expand Up @@ -7,19 +7,24 @@
import pydeck as pdk
import pydeck_carto as pdkc
from carto_auth import CartoAuth
from os.path import join, dirname

carto_auth = CartoAuth.from_oauth()

pdkc.register_carto_layer()
pdkc.register_layers()

layer = pdk.Layer(
"CartoLayer",
data="SELECT geom, event FROM carto-demo-data.demo_tables"
data = pdkc.sources.vector_query_source(
access_token=carto_auth.get_access_token(),
api_base_url=carto_auth.get_api_base_url(),
connection_name="carto_dw",
sql_query="SELECT geom, event FROM carto-demo-data.demo_tables"
".spain_earthquakes where depth > ?",
query_parameters=[2],
type_=pdkc.MapType.QUERY,
connection=pdkc.CartoConnection.CARTO_DW,
credentials=pdkc.get_layer_credentials(carto_auth),
)

layer = pdk.Layer(
"VectorTileLayer",
data=data,
get_fill_color=[238, 77, 90],
point_radius_min_pixels=2.5,
pickable=True,
Expand All @@ -28,4 +33,4 @@
view_state = pdk.ViewState(latitude=36, longitude=-7.44, zoom=5)

r = pdk.Deck(layer, map_style=pdk.map_styles.ROAD, initial_view_state=view_state)
r.to_html("carto_layer_geo_query_param.html", open_browser=True)
r.to_html(join(dirname(__file__), "carto_layer_geo_query_param.html"))
19 changes: 12 additions & 7 deletions bindings/pydeck-carto/examples/scripts/carto_layer_geo_table.py
Expand Up @@ -7,17 +7,22 @@
import pydeck as pdk
import pydeck_carto as pdkc
from carto_auth import CartoAuth
from os.path import join, dirname

carto_auth = CartoAuth.from_oauth()

pdkc.register_carto_layer()
pdkc.register_layers()

data = pdkc.sources.vector_table_source(
access_token=carto_auth.get_access_token(),
api_base_url=carto_auth.get_api_base_url(),
connection_name="carto_dw",
table_name="carto-demo-data.demo_tables.world_airports",
)

layer = pdk.Layer(
"CartoLayer",
data="carto-demo-data.demo_tables.airports",
type_=pdkc.MapType.TABLE,
connection=pdkc.CartoConnection.CARTO_DW,
credentials=pdkc.get_layer_credentials(carto_auth),
"VectorTileLayer",
data=data,
get_fill_color=[200, 0, 80],
point_radius_min_pixels=2,
pickable=True,
Expand All @@ -26,4 +31,4 @@
view_state = pdk.ViewState(latitude=0, longitude=0, zoom=1)

r = pdk.Deck(layer, map_style=pdk.map_styles.ROAD, initial_view_state=view_state)
r.to_html("carto_layer_geo_table.html", open_browser=True)
r.to_html(join(dirname(__file__), "carto_layer_geo_table.html"))
19 changes: 12 additions & 7 deletions bindings/pydeck-carto/examples/scripts/carto_layer_geo_tileset.py
Expand Up @@ -7,17 +7,22 @@
import pydeck as pdk
import pydeck_carto as pdkc
from carto_auth import CartoAuth
from os.path import join, dirname

carto_auth = CartoAuth.from_oauth()

pdkc.register_carto_layer()
pdkc.register_layers()

data = pdkc.sources.vector_tileset_source(
access_token=carto_auth.get_access_token(),
api_base_url=carto_auth.get_api_base_url(),
connection_name="carto_dw",
table_name="carto-demo-data.demo_tilesets.pointsofinterest_esp",
)

layer = pdk.Layer(
"CartoLayer",
data="carto-demo-data.demo_tilesets.pointsofinterest_esp",
type_=pdkc.MapType.TILESET,
connection=pdkc.CartoConnection.CARTO_DW,
credentials=pdkc.get_layer_credentials(carto_auth),
"VectorTileLayer",
data=data,
get_fill_color=[200, 0, 80],
stroked=False,
point_radius_min_pixels=2,
Expand All @@ -27,4 +32,4 @@
view_state = pdk.ViewState(latitude=36, longitude=-7.44, zoom=5)

r = pdk.Deck(layer, map_style=pdk.map_styles.ROAD, initial_view_state=view_state)
r.to_html("carto_layer_geo_tileset.html", open_browser=True)
r.to_html(join(dirname(__file__), "carto_layer_geo_tileset.html"))
23 changes: 14 additions & 9 deletions bindings/pydeck-carto/examples/scripts/carto_layer_h3_query.py
Expand Up @@ -7,24 +7,29 @@
import pydeck as pdk
import pydeck_carto as pdkc
from carto_auth import CartoAuth
from os.path import join, dirname

carto_auth = CartoAuth.from_oauth()

pdkc.register_carto_layer()
pdkc.register_layers()

layer = pdk.Layer(
"CartoLayer",
data="select * from carto-demo-data.demo_tables"
data = pdkc.sources.h3_query_source(
access_token=carto_auth.get_access_token(),
api_base_url=carto_auth.get_api_base_url(),
connection_name="carto_dw",
sql_query="select * from carto-demo-data.demo_tables"
".derived_spatialfeatures_usa_h3res8_v1_yearly_v2",
type_=pdkc.MapType.QUERY,
connection=pdkc.CartoConnection.CARTO_DW,
credentials=pdkc.get_layer_credentials(carto_auth),
geo_column=pdkc.GeoColumnType.H3,
aggregation_exp="sum(population) as population_sum",
)

layer = pdk.Layer(
"H3TileLayer",
data=data,
get_fill_color=[200, 0, 80],
pickable=True,
)

view_state = pdk.ViewState(latitude=44, longitude=-122, zoom=3)

r = pdk.Deck(layer, map_style=pdk.map_styles.ROAD, initial_view_state=view_state)
r.to_html("carto_layer_h3_query.html", open_browser=True)
r.to_html(join(dirname(__file__), "carto_layer_h3_query.html"))
22 changes: 14 additions & 8 deletions bindings/pydeck-carto/examples/scripts/carto_layer_h3_table.py
Expand Up @@ -7,23 +7,29 @@
import pydeck as pdk
import pydeck_carto as pdkc
from carto_auth import CartoAuth
from os.path import join, dirname

carto_auth = CartoAuth.from_oauth()

pdkc.register_carto_layer()
pdkc.register_layers()

data = pdkc.sources.h3_table_source(
access_token=carto_auth.get_access_token(),
api_base_url=carto_auth.get_api_base_url(),
connection_name="carto_dw",
table_name="carto-demo-data.demo_tables"
".derived_spatialfeatures_esp_h3res8_v1_yearly_v2",
aggregation_exp="sum(population) as population_sum",
)

layer = pdk.Layer(
"CartoLayer",
data="carto-demo-data.demo_tables.derived_spatialfeatures_esp_h3res8_v1_yearly_v2",
type_=pdkc.MapType.TABLE,
connection=pdkc.CartoConnection.CARTO_DW,
credentials=pdkc.get_layer_credentials(carto_auth),
geo_column=pdkc.GeoColumnType.H3,
"H3TileLayer",
data=data,
get_fill_color=[200, 0, 80],
pickable=True,
)

view_state = pdk.ViewState(latitude=36, longitude=-7.44, zoom=5)

r = pdk.Deck(layer, map_style=pdk.map_styles.ROAD, initial_view_state=view_state)
r.to_html("carto_layer_h3_table.html", open_browser=True)
r.to_html(join(dirname(__file__), "carto_layer_h3_table.html"))
22 changes: 14 additions & 8 deletions bindings/pydeck-carto/examples/scripts/carto_layer_h3_tileset.py
Expand Up @@ -7,23 +7,29 @@
import pydeck as pdk
import pydeck_carto as pdkc
from carto_auth import CartoAuth
from os.path import join, dirname

carto_auth = CartoAuth.from_oauth()

pdkc.register_carto_layer()
pdkc.register_layers()

layer = pdk.Layer(
"CartoLayer",
data="carto-demo-data.demo_tilesets"
data = pdkc.sources.h3_tileset_source(
access_token=carto_auth.get_access_token(),
api_base_url=carto_auth.get_api_base_url(),
connection_name="carto_dw",
table_name="carto-demo-data.demo_tilesets"
".derived_spatialfeatures_usa_h3res8_v1_yearly_v2_tileset",
type_=pdkc.MapType.TILESET,
connection=pdkc.CartoConnection.CARTO_DW,
credentials=pdkc.get_layer_credentials(carto_auth),
aggregation_exp="sum(population) as population_sum",
)

layer = pdk.Layer(
"H3TileLayer",
data=data,
get_fill_color=[200, 0, 80],
pickable=True,
)

view_state = pdk.ViewState(latitude=44, longitude=-122, zoom=3)

r = pdk.Deck(layer, map_style=pdk.map_styles.ROAD, initial_view_state=view_state)
r.to_html("carto_layer_h3_tileset.html", open_browser=True)
r.to_html(join(dirname(__file__), "carto_layer_h3_tileset.html"))
Expand Up @@ -7,24 +7,29 @@
import pydeck as pdk
import pydeck_carto as pdkc
from carto_auth import CartoAuth
from os.path import join, dirname

carto_auth = CartoAuth.from_oauth()

pdkc.register_carto_layer()
pdkc.register_layers()

layer = pdk.Layer(
"CartoLayer",
data="select * from carto-demo-data.demo_tables"
data = pdkc.sources.quadbin_query_source(
access_token=carto_auth.get_access_token(),
api_base_url=carto_auth.get_api_base_url(),
connection_name="carto_dw",
sql_query="select * from carto-demo-data.demo_tables"
".derived_spatialfeatures_usa_quadbin15_v1_yearly_v2",
type_=pdkc.MapType.QUERY,
connection=pdkc.CartoConnection.CARTO_DW,
credentials=pdkc.get_layer_credentials(carto_auth),
geo_column=pdkc.GeoColumnType.QUADBIN,
aggregation_exp="sum(population) as population_sum",
)

layer = pdk.Layer(
"QuadbinTileLayer",
data=data,
get_fill_color=[200, 0, 80],
pickable=True,
)

view_state = pdk.ViewState(latitude=44, longitude=-122, zoom=3)

r = pdk.Deck(layer, map_style=pdk.map_styles.ROAD, initial_view_state=view_state)
r.to_html("carto_layer_quadbin_query.html", open_browser=True)
r.to_html(join(dirname(__file__), "carto_layer_quadbin_query.html"))
Expand Up @@ -7,24 +7,29 @@
import pydeck as pdk
import pydeck_carto as pdkc
from carto_auth import CartoAuth
from os.path import join, dirname

carto_auth = CartoAuth.from_oauth()

pdkc.register_carto_layer()
pdkc.register_layers()

layer = pdk.Layer(
"CartoLayer",
data="carto-demo-data.demo_tables"
data = pdkc.sources.quadbin_table_source(
access_token=carto_auth.get_access_token(),
api_base_url=carto_auth.get_api_base_url(),
connection_name="carto_dw",
table_name="carto-demo-data.demo_tables"
".derived_spatialfeatures_esp_quadbin15_v1_yearly_v2",
type_=pdkc.MapType.TABLE,
connection=pdkc.CartoConnection.CARTO_DW,
credentials=pdkc.get_layer_credentials(carto_auth),
geo_column=pdkc.GeoColumnType.QUADBIN,
aggregation_exp="sum(population) as population_sum",
)

layer = pdk.Layer(
"QuadbinTileLayer",
data=data,
get_fill_color=[200, 0, 80],
pickable=True,
)

view_state = pdk.ViewState(latitude=36, longitude=-7.44, zoom=5)

r = pdk.Deck(layer, map_style=pdk.map_styles.ROAD, initial_view_state=view_state)
r.to_html("carto_layer_quadbin_table.html", open_browser=True)
r.to_html(join(dirname(__file__), "carto_layer_quadbin_table.html"))