Skip to content

Instantly share code, notes, and snippets.

Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@mbforr
mbforr / h3.sql
Created September 23, 2022 17:16
CALL `carto-un`.carto.CREATE_SPATIAL_INDEX_TILESET(
'project.dataset.osm_nodes_10',
'project.dataset.osm_nodes_tiles_10',
R'''{
"spatial_index_column": "h3:h3",
"resolution": 10,
"resolution_min": 0,
"resolution_max": 6,
"aggregation_resolution": 4,
"properties": {
CALL `carto-un`.carto.CREATE_POINT_AGGREGATION_TILESET(
R'''(
select id, st_geogpoint(longitude, latitude) as geom from bigquery-public-data.geo_openstreetmap.planet_nodes
)''',
'`project.dataset.osm_nodes_points_17`',
R'''
{
"zoom_min": 0,
"zoom_max": 17,
"aggregation_resolution": 7,
CALL `carto-un`.carto.CREATE_TILESET(
R'''(
select id, all_tags, st_geogpoint(longitude, latitude) as geom from bigquery-public-data.geo_openstreetmap.planet_nodes
)
''',
R'''`project.dataset.osm_nodes_tiles_17_and_down`''',
STRUCT(
"OSM Nodes" AS name,
"OSM nodes raw data for zooms 17 and below" AS description,
NULL AS legend,
WITH
nyc AS (
SELECT
*
FROM
PROJECT.DATASET.nyc
LIMIT
10000)
SELECT
WITH
nyc AS (
SELECT
*
FROM
PROJECT.DATASET.nyc
LIMIT
10000)
SELECT
WITH
nyc AS (
SELECT
*
FROM
PROJECT.DATASET.nyc
LIMIT
10000)
SELECT
SELECT
COUNT(a.vendor_id),
b.geo_id
FROM
PROJECT.DATASET.nyc a
JOIN
bigquery-public-data.geo_census_blockgroups.us_blockgroups_national b
ON
st_intersects(a.geom,
b.blockgroup_geom)
SELECT
a.vendor_id,
b.geo_id
FROM
PROJECT.DATASET.nyc a
JOIN
bigquery-public-data.geo_census_blockgroups.us_blockgroups_national b
ON
st_intersects(a.geom,
b.blockgroup_geom)
CREATE OR REPLACE TABLE
`PROJECT.DATASET.nyc` AS
SELECT
*,
st_geogpoint(pickup_longitude,
pickup_latitude) AS geom
FROM
`bigquery-public-data.new_york_taxi_trips.tlc_yellow_trips_2015`
WHERE
pickup_datetime BETWEEN '2015-06-01T00:00:00'