Skip to content

Commit

Permalink
Merge e473251 into 5c13d25
Browse files Browse the repository at this point in the history
  • Loading branch information
Jesus89 committed Apr 22, 2024
2 parents 5c13d25 + e473251 commit 2e2e7f6
Show file tree
Hide file tree
Showing 27 changed files with 680 additions and 226 deletions.
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"))
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"))

0 comments on commit 2e2e7f6

Please sign in to comment.