This query lets us grab the locality (point geometry and attributes) that represents the United States and its associated area, in this case a multipolygon geometry.
CREATE VIEW admins_view AS (
SELECT
*
FROM
read_parquet('s3://overturemaps-us-west-2/release/2024-02-15-alpha.0/theme=admins/type=*/*', filename=true, hive_partitioning=1)COPY (
COPY (
SELECT
admins.id,
admins.subType,
admins.isoCountryCodeAlpha2,
names.primary AS primary_name,
sources[1].dataset AS primary_source,
areas.areaId,
ST_GeomFromWKB(areas.areaGeometry) as geometry
FROM admins_view AS admins
INNER JOIN (
SELECT
id as areaId,
localityId,
geometry AS areaGeometry
FROM admins_view
) AS areas ON areas.localityId == admins.id
WHERE admins.adminLevel = 1
AND admins.isoCountryCodeAlpha2 = 'US'
) TO 'us-boundary.geojson'
WITH (FORMAT GDAL, DRIVER 'GeoJSON');
Would something like this work to get all the buildings within that multipolygon area for the United States?
CREATE VIEW buildings_view AS (
SELECT
*
FROM
read_parquet('s3://overturemaps-us-west-2/release/2024-02-15-alpha.0/theme=buildings/type=*/*', filename=true, hive_partitioning=1)
);
SELECT
admins.id,
admins.subType,
admins.isoCountryCodeAlpha2,
admins.names.primary,
sources[1].dataset AS primary_source,
--areas.areaId,
buildings.id,
buildings.names.primary AS building_name,
ST_GeomFromWKB(areas.areaGeometry) as geometry
FROM admins_view as admins
INNER JOIN (
buildings_view as buildings ON ST_Intersects(ST_GeomFromWKB(areas.areaGeometry), ST_GeomFromWKB(buildings.geometry))
WHERE
admins.adminLevel = 1
AND admins.names.primary LIKE 'United States'
LIMIT 10;