Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 8 additions & 3 deletions docs/getting-data/duckdb.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@ import Peaks from '!!raw-loader!@site/src/queries/duckdb/mountain_peaks.sql';
import DetroitBuildings from '!!raw-loader!@site/src/queries/duckdb/buildings_detroit.sql';
import CountyGeometries from '!!raw-loader!@site/src/queries/duckdb/county_level_geometries.sql';
import NewYorkPizza from '!!raw-loader!@site/src/queries/duckdb/new_york_pizza.sql';
import ParisRoads from '!!raw-loader!@site/src/queries/duckdb/paris_roads.sql';
import ParisRoadsContained from '!!raw-loader!@site/src/queries/duckdb/paris_roads_contained.sql';
import ParisRoadsIntersecting from '!!raw-loader!@site/src/queries/duckdb/paris_roads_intersecting.sql';
import WriteGeoparquet from '!!raw-loader!@site/src/queries/duckdb/write_geoparquet.sql';
import BuildingsInDivision from '!!raw-loader!@site/src/queries/duckdb/buildings_in_division_area.sql';

Expand Down Expand Up @@ -46,9 +47,13 @@ Access Overture buildings data hosted on Azure to download named buildings aroun

<TabItem value="Roads" label="Roads">

Download roads in Paris around the _Arc de Triomphe_ and save as GeoJSON.
Download all roads intersecting a given bounding box around the Arc de Triomphe in Paris and save as GeoJSON.

<QueryBuilder query={ParisRoads}></QueryBuilder>
<QueryBuilder query={ParisRoadsIntersecting}></QueryBuilder>
_Note: This will result in a GeoJSON file that contains all road segments that intersect the bounding box, not just road segments contained within the bounding box._

To download only roads contained within that bounding box around the Arc de Triomphe in Paris, use the following:
<QueryBuilder query={ParisRoadsContained}></QueryBuilder>
</TabItem>

<TabItem value="Mountains" label="Mountains">
Expand Down
14 changes: 9 additions & 5 deletions src/queries/duckdb/buildings_detroit.sql
Original file line number Diff line number Diff line change
@@ -1,14 +1,18 @@
LOAD spatial; --noqa
LOAD spatial; -- noqa

SET s3_region='us-west-2';

COPY(
SELECT
id,
names.primary as primary_name,
height,
geometry
FROM read_parquet('az://overturemapswestus2.blob.core.windows.net/release/__OVERTURE_RELEASE/theme=buildings/type=building/*', filename=true, hive_partitioning=1)
WHERE names.primary IS NOT NULL
AND bbox.xmin BETWEEN -84.36 AND -82.42
AND bbox.ymin BETWEEN 41.71 AND 43.33
FROM
read_parquet('az://overturemapswestus2.blob.core.windows.net/release/__OVERTURE_RELEASE/theme=buildings/type=building/*', filename=true, hive_partitioning=1)
WHERE
names.primary IS NOT NULL
AND bbox.xmin BETWEEN -84.36 AND -82.42
AND bbox.ymin BETWEEN 41.71 AND 43.33
LIMIT 100
) TO 'detroit_buildings.geojsonseq' WITH (FORMAT GDAL, DRIVER 'GeoJSONSeq');
23 changes: 12 additions & 11 deletions src/queries/duckdb/county_level_geometries.sql
Original file line number Diff line number Diff line change
@@ -1,16 +1,17 @@
LOAD spatial; -- noqa

SET s3_region='us-west-2';

COPY(
SELECT
id,
division_id,
names.primary,
geometry -- DuckDB v.1.1.0 will autoload this as a `geometry` type
FROM
read_parquet('s3://overturemaps-us-west-2/release/__OVERTURE_RELEASE/theme=divisions/type=division_area/*', hive_partitioning=1)
WHERE
subtype = 'county'
AND country = 'US'
AND region = 'US-PA'
SELECT
id,
division_id,
names.primary,
geometry -- DuckDB v.1.1.0 will autoload this as a `geometry` type
FROM
read_parquet('s3://overturemaps-us-west-2/release/__OVERTURE_RELEASE/theme=divisions/type=division_area/*', hive_partitioning=1)
WHERE
subtype = 'county'
AND country = 'US'
AND region = 'US-PA'
) TO 'pennsylvania_counties.gpkg' WITH (FORMAT GDAL, DRIVER 'GPKG');
21 changes: 12 additions & 9 deletions src/queries/duckdb/mountain_peaks.sql
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,17 @@ LOAD spatial; -- noqa
SET s3_region='us-west-2';

COPY(
SELECT
id,
names.primary as name,
CAST(elevation * 3.28084 AS INT) AS elevation_ft,
geometry -- DuckDB v.1.1.0 will autoload this as a `geometry` type
FROM read_parquet('s3://overturemaps-us-west-2/release/__OVERTURE_RELEASE/theme=base/type=land/*', filename=true, hive_partitioning=1)
WHERE subtype = 'physical' AND class IN ('peak','volcano') AND elevation IS NOT NULL
SELECT
id,
names.primary as name,
CAST(elevation * 3.28084 AS INT) AS elevation_ft,
geometry -- DuckDB v.1.1.0 will autoload this as a `geometry` type
FROM
read_parquet('s3://overturemaps-us-west-2/release/__OVERTURE_RELEASE/theme=base/type=land/*', filename=true, hive_partitioning=1)
WHERE
subtype = 'physical'
AND class IN ('peak','volcano')
AND elevation IS NOT NULL
AND bbox.xmin BETWEEN -124.71 AND -116.47
AND bbox.ymin BETWEEN 41.99 AND 46.30
) TO 'oregon_peaks.geojson'
WITH (FORMAT GDAL, DRIVER 'GeoJSON');
) TO 'oregon_peaks.geojson' WITH (FORMAT GDAL, DRIVER 'GeoJSON');
19 changes: 10 additions & 9 deletions src/queries/duckdb/new_york_pizza.sql
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,16 @@ LOAD spatial; -- noqa
SET s3_region='us-west-2';

COPY( -- COPY <query> TO <output> saves the results to disk.
SELECT
id,
names.primary as name,
confidence AS confidence,
CAST(socials AS JSON) as socials, -- Ensure each attribute can be serialized to JSON
geometry -- DuckDB understands this to be a geometry type
FROM read_parquet('s3://overturemaps-us-west-2/release/__OVERTURE_RELEASE/theme=places/type=place/*', filename=true, hive_partitioning=1)
WHERE categories.primary = 'pizza_restaurant'
SELECT
id,
names.primary as name,
confidence AS confidence,
CAST(socials AS JSON) as socials, -- Ensure each attribute can be serialized to JSON
geometry -- DuckDB understands this to be a geometry type
FROM
read_parquet('s3://overturemaps-us-west-2/release/__OVERTURE_RELEASE/theme=places/type=place/*', filename=true, hive_partitioning=1)
WHERE
categories.primary = 'pizza_restaurant'
AND bbox.xmin BETWEEN -75 AND -73 -- Only use the bbox min values
AND bbox.ymin BETWEEN 40 AND 41 -- because they are point geometries.

) TO 'nyc_pizza.geojson' WITH (FORMAT GDAL, DRIVER 'GeoJSON');
16 changes: 0 additions & 16 deletions src/queries/duckdb/paris_roads.sql

This file was deleted.

18 changes: 18 additions & 0 deletions src/queries/duckdb/paris_roads_contained.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
LOAD spatial; -- noqa

SET s3_region='us-west-2';

COPY(
SELECT
id,
names.primary as name,
class,
geometry -- DuckDB v.1.1.0 will autoload this as a `geometry` type
FROM
read_parquet('s3://overturemaps-us-west-2/release/__OVERTURE_RELEASE/theme=transportation/type=segment/*', filename=true, hive_partitioning=1)
WHERE
Comment thread
stepps00 marked this conversation as resolved.
bbox.xmin > 2.276
AND bbox.ymin > 48.865
AND bbox.xmax < 2.314
AND bbox.ymax < 48.882
) TO 'paris_roads_contained.geojson' WITH (FORMAT GDAL, DRIVER 'GeoJSON');
18 changes: 18 additions & 0 deletions src/queries/duckdb/paris_roads_intersecting.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
LOAD spatial; -- noqa

SET s3_region='us-west-2';

COPY(
SELECT
id,
names.primary as name,
class,
geometry -- DuckDB v.1.1.0 will autoload this as a `geometry` type
FROM
read_parquet('s3://overturemaps-us-west-2/release/__OVERTURE_RELEASE/theme=transportation/type=segment/*', filename=true, hive_partitioning=1)
WHERE
bbox.xmin < 2.314
AND bbox.ymin < 48.882
AND bbox.xmax > 2.276
AND bbox.ymax > 48.865
) TO 'paris_roads_intersecting.geojson' WITH (FORMAT GDAL, DRIVER 'GeoJSON');
5 changes: 4 additions & 1 deletion src/queries/duckdb/write_geoparquet.sql
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
LOAD spatial; -- noqa

SET s3_region='us-west-2';

COPY(
SELECT
*
FROM read_parquet('s3://overturemaps-us-west-2/release/__OVERTURE_RELEASE/theme=places/type=place/*')
FROM
read_parquet('s3://overturemaps-us-west-2/release/__OVERTURE_RELEASE/theme=places/type=place/*')
LIMIT 100000
) TO 'places.parquet';