H3-quickstart (Databricks SQL)
De quickstart voor georuimtelijke H3-functies op deze pagina illustreert het volgende:
- How to load geolocation dataset(s) into the Unity Catalog.
- Kolommen met breedtegraad en lengtegraad converteren naar H3-celkolommen.
- Veelhoek of multipolygon WKT-kolommen converteren naar H3-celkolommen.
- Hoe query's uit te voeren op de analyse van ophalen en afleveren van de Luchthaven La Query naar Het Financiƫle District van Manhattan.
- Het genereren van H3-aggregaties op een kaart.
Voorbeeldnotebooks en query's
Unity Catalog-gegevens voorbereiden
In dit notitieblok doen we het volgende:
- Stel de openbare taxigegevensset in vanuit het Databricks-bestandssysteem.
- Stel de gegevensset nyc-postcode in.
Unity Catalog-gegevens voorbereiden
Databricks SQL-query's met Databricks Runtime 11.3 LTS en hoger
Query 1: Controleer of basisgegevens zijn ingesteld. Zie Notitieblok.
use catalog geospatial_docs;
use database nyc_taxi;
show tables;
-- Verify initial data is setup (see instructions in setup notebook)
-- select format_number(count(*),0) as count from yellow_trip;
-- select * from nyc_zipcode;
Query 2: H3 NYC Postcode - H3_polyfillash3 toepassen op resolutie12
.
use catalog geospatial_docs;
use database nyc_taxi;
-- drop table if exists nyc_zipcode_h3_12;
create table if not exists nyc_zipcode_h3_12 as (
select
explode(h3_polyfillash3(geom_wkt, 12)) as cell,
zipcode,
po_name,
county
from
nyc_zipcode
);
-- optional: zorder by `cell`
optimize nyc_zipcode_h3_12 zorder by (cell);
select
*
from
nyc_zipcode_h3_12;
Query 3: H3 TaxiRitten - H3_longlatash3 bij oplossing 12
toepassen.
use catalog geospatial_docs;
use database nyc_taxi;
-- drop table if exists yellow_trip_h3_12;
create table if not exists yellow_trip_h3_12 as (
select
h3_longlatash3(pickup_longitude, pickup_latitude, 12) as pickup_cell,
h3_longlatash3(dropoff_longitude, dropoff_latitude, 12) as dropoff_cell,
*
except
(
rate_code_id,
store_and_fwd_flag
)
from
yellow_trip
);
-- optional: zorder by `pickup_cell`
-- optimize yellow_trip_h3_12 zorder by (pickup_cell);
select
*
from
yellow_trip_h3_12
where pickup_cell is not null;
Query 4: H3 LGA Pickups - 25M pickups van LaCate (LGA)
use catalog geospatial_docs;
use database nyc_taxi;
create
or replace view lga_pickup_h3_12 as (
select
t.*
except(cell),
s.*
from
yellow_trip_h3_12 as s
inner join nyc_zipcode_h3_12 as t on s.pickup_cell = t.cell
where
t.zipcode = '11371'
);
select
format_number(count(*), 0) as count
from
lga_pickup_h3_12;
-- select
-- *
-- from
-- lga_pickup_h3_12;
Query 5: H3 Financial District Dropoffs - 34M totale drop offs in Financial District
use catalog geospatial_docs;
use database nyc_taxi;
create
or replace view fd_dropoff_h3_12 as (
select
t.*
except(cell),
s.*
from
yellow_trip_h3_12 as s
inner join nyc_zipcode_h3_12 as t on s.dropoff_cell = t.cell
where
t.zipcode in ('10004', '10005', '10006', '10007', '10038')
);
select
format_number(count(*), 0) as count
from
fd_dropoff_h3_12;
-- select * from fd_dropoff_h3_12;
Query 6: H3 LGA-FD - 827K drop offs in FD met ophalen van LGA
use catalog geospatial_docs;
use database nyc_taxi;
create
or replace view lga_fd_dropoff_h3_12 as (
select
*
from
fd_dropoff_h3_12
where
pickup_cell in (
select
distinct pickup_cell
from
lga_pickup_h3_12
)
);
select
format_number(count(*), 0) as count
from
lga_fd_dropoff_h3_12;
-- select * from lga_fd_dropoff_h3_12;
Query 7: LGA-FD per postcode - Aantal FD-afgiftes per postcode + staafdiagram
use catalog geospatial_docs;
use database nyc_taxi;
select
zipcode,
count(*) as count
from
lga_fd_dropoff_h3_12
group by
zipcode
order by
zipcode;
Query 8: LGA-FD by H3 - Aantal FD-afgiftes per H3-cel + kaartmarkeringsvisualisatie
use catalog geospatial_docs;
use database nyc_taxi;
select
zipcode,
dropoff_cell,
h3_centerasgeojson(dropoff_cell) :coordinates [0] as dropoff_centroid_x,
h3_centerasgeojson(dropoff_cell) :coordinates [1] as dropoff_centroid_y,
format_number(count(*), 0) as count_disp,
count(*) as `count`
from
lga_fd_dropoff_h3_12
group by
zipcode,
dropoff_cell
order by
zipcode,
`count` DESC;
Notebooks voor Databricks Runtime 11.3 LTS en hoger
Quickstart-Python: H3 NYC Taxi LaGin naar Manhattan
Dezelfde snelstartstructuur als in Databricks SQL, met behulp van Spark Python-bindingen in Notebooks + kepler.gl.
Quickstart-Scala: H3 NYC Taxi La Toegewezen naar Manhattan
Dezelfde snelstartstructuur als in Databricks SQL, met behulp van Spark Scala-bindingen in Notebooks + kepler.gl via Python-cellen.
Quickstart-SQL: H3 NYC Taxi LaGin naar Manhattan
Dezelfde snelstartstructuur als in Databricks SQL, met behulp van Spark SQL-bindingen in Notebooks + kepler.gl via Python-cellen.