The highest-income counties in the country
The simplest shape: one remote file, sorted. Returns in a second or
two, having read two columns out of a 13 MB table.
INSTALL spatial; LOAD spatial; INSTALL httpfs; LOAD httpfs;
SELECT name, state, median_hh_income, pct_below_poverty
FROM read_parquet('https://data.source.coop/portolan-mirrors/us-census-catalog/counties/county-income/county-income.parquet')
WHERE median_hh_income IS NOT NULL
ORDER BY median_hh_income DESC
LIMIT 5;
Result
┌────────────────────────────────┬─────────┬──────────────────┬───────────────────┐
│ name │ state │ median_hh_income │ pct_below_poverty │
├────────────────────────────────┼─────────┼──────────────────┼───────────────────┤
│ Loudoun County, Virginia │ VA │ 181765.0 │ 4.23 │
│ Santa Clara County, California │ CA │ 164281.0 │ 7.11 │
│ San Mateo County, California │ CA │ 158855.0 │ 6.71 │
│ Fairfax County, Virginia │ VA │ 153637.0 │ 5.94 │
│ Howard County, Maryland │ MD │ 149763.0 │ 5.23 │
└────────────────────────────────┴─────────┴──────────────────┴───────────────────┘
Joining two themes on geoid
Income and connectivity are separate collections. geoid
joins them — and joins either to any other theme at the same
geography.
LOAD spatial; LOAD httpfs;
SET VARIABLE base = 'https://data.source.coop/portolan-mirrors/us-census-catalog';
SELECT i.name, i.median_hh_income AS income, c.pct_no_internet
FROM read_parquet(getvariable('base') || '/counties/county-income/county-income.parquet') i
JOIN read_parquet(getvariable('base') || '/counties/county-connectivity/county-connectivity.parquet') c
USING (geoid)
WHERE i.median_hh_income IS NOT NULL AND c.pct_no_internet IS NOT NULL
ORDER BY c.pct_no_internet DESC
LIMIT 4;
Result
┌───────────────────────────────────┬─────────┬─────────────────┐
│ name │ income │ pct_no_internet │
├───────────────────────────────────┼─────────┼─────────────────┤
│ Maricao Municipio, Puerto Rico │ 21302.0 │ 60.51 │
│ Las Marías Municipio, Puerto Rico │ 16314.0 │ 58.8 │
│ Claiborne Parish, Louisiana │ 32831.0 │ 45.37 │
│ San Germán Municipio, Puerto Rico │ 18317.0 │ 43.63 │
└───────────────────────────────────┴─────────┴─────────────────┘
What changed between the two ACS releases
The trends collections hold both periods. Filter to one
period and the chg_ columns give you the
movement without a self-join.
LOAD spatial; LOAD httpfs;
SELECT name, period, median_gross_rent, chg_median_gross_rent
FROM read_parquet('https://data.source.coop/portolan-mirrors/us-census-catalog/trends/county-trends/county-trends.parquet')
WHERE period = '2020-2024' AND chg_median_gross_rent IS NOT NULL
ORDER BY chg_median_gross_rent DESC
LIMIT 4;
Result
┌───────────────────────────┬───────────┬───────────────────┬───────────────────────┐
│ name │ period │ median_gross_rent │ chg_median_gross_rent │
├───────────────────────────┼───────────┼───────────────────┼───────────────────────┤
│ Jackson County, Colorado │ 2020-2024 │ 1701.0 │ 1076.0 │
│ Park County, Colorado │ 2020-2024 │ 2161.0 │ 1036.0 │
│ Irion County, Texas │ 2020-2024 │ 1950.0 │ 919.0 │
│ Cameron Parish, Louisiana │ 2020-2024 │ 1688.0 │ 783.0 │
└───────────────────────────┴───────────┴───────────────────┴───────────────────────┘
Which tract contains this point
A spatial predicate against 85,184 tract geometries, straight over
HTTPS. No geocoder, no PostGIS, no upload.
LOAD spatial; LOAD httpfs;
SELECT geoid, name, median_hh_income
FROM read_parquet('https://data.source.coop/portolan-mirrors/us-census-catalog/tracts/tract-income/tract-income.parquet')
WHERE ST_Contains(geometry, ST_Point(-122.4862, 37.7694));
Result
┌─────────────┬─────────────────────────────────────────────────────┬──────────────────┐
│ geoid │ name │ median_hh_income │
├─────────────┼─────────────────────────────────────────────────────┼──────────────────┤
│ 06075980300 │ Census Tract 9803, San Francisco County, California │ 107188.0 │
└─────────────┴─────────────────────────────────────────────────────┴──────────────────┘
Reading only one city's worth of bytes
This is the cloud-native part made visible. The bbox
column lets DuckDB skip every row group outside the window, so a
national table answers a Manhattan question in about seven seconds
without being downloaded.
LOAD spatial; LOAD httpfs;
SELECT count(*) AS tracts_in_bbox
FROM read_parquet('https://data.source.coop/portolan-mirrors/us-census-catalog/tracts/tract-income/tract-income.parquet')
WHERE bbox.xmin > -74.02 AND bbox.xmax < -73.90
AND bbox.ymin > 40.70 AND bbox.ymax < 40.88;
Result
┌────────────────┐
│ tracts_in_bbox │
├────────────────┤
│ 596 │
└────────────────┘
All 8.2 million census blocks
The blocks collection is partitioned by state, so a two-state question
touches two files. A Hive-partitioned glob needs the anonymous S3
endpoint: the HTTPS gateway cannot list a directory, so a glob over it
returns 404.
LOAD spatial; LOAD httpfs;
SET s3_region = 'us-west-2';
SET s3_url_style = 'path'; -- the bucket name has dots; vhost URLs fail TLS
SELECT state, count(*) AS blocks, sum(pop_total) AS people
FROM read_parquet(
's3://us-west-2.opendata.source.coop/portolan-mirrors/us-census-catalog/blocks/state_fips=*/*.parquet',
hive_partitioning = true)
WHERE state_fips IN ('44', '50')
GROUP BY state
ORDER BY state;
Result
┌─────────┬────────┬─────────┐
│ state │ blocks │ people │
├─────────┼────────┼─────────┤
│ RI │ 25649 │ 1097379 │
│ VT │ 24611 │ 643077 │
└─────────┴────────┴─────────┘
Joining another catalog
Nothing about this is special to the census. Every catalog in the
Portolan
registry publishes files the same way, so a join across two of them is
one query against two URLs. Neither publisher has to agree to anything,
and no data moves anywhere.
Transit stops against transit commuting, Portland
Census tracts from this catalog, bus and rail stops from the
TriMet
catalog. TriMet publishes in Oregon State Plane feet, so the stops
are reprojected in the query — the one wrinkle worth knowing about
a cross-catalog join.
LOAD spatial; LOAD httpfs;
WITH pdx AS (
SELECT geoid, name, geometry, pct_commute_transit, pct_hh_no_vehicle
FROM read_parquet('https://data.source.coop/portolan-mirrors/us-census-catalog/tracts/tract-connectivity/tract-connectivity.parquet')
WHERE geoid LIKE '41051%' -- Multnomah County, Oregon
),
stops AS (
SELECT stop_id,
ST_Transform(geometry, 'EPSG:2913', 'EPSG:4326', always_xy := true) AS geom
FROM read_parquet('https://data.source.coop/cholmes/trimet/stops/stops.parquet')
)
SELECT p.name, p.pct_commute_transit, p.pct_hh_no_vehicle, count(s.stop_id) AS stops
FROM pdx p LEFT JOIN stops s ON ST_Contains(p.geometry, s.geom)
GROUP BY ALL ORDER BY stops DESC LIMIT 5;
Result
┌──────────────────────────────────────────────┬─────────────────────┬───────────────────┬───────┐
│ name │ pct_commute_transit │ pct_hh_no_vehicle │ stops │
├──────────────────────────────────────────────┼─────────────────────┼───────────────────┼───────┤
│ Census Tract 72.02, Multnomah County, Oregon │ 1.62 │ 1.01 │ 88 │
│ Census Tract 43, Multnomah County, Oregon │ 0.0 │ 4.11 │ 76 │
│ Census Tract 102, Multnomah County, Oregon │ 0.59 │ 4.07 │ 67 │
│ Census Tract 23.03, Multnomah County, Oregon │ 18.14 │ 38.05 │ 59 │
│ Census Tract 73, Multnomah County, Oregon │ 10.76 │ 0.0 │ 55 │
└──────────────────────────────────────────────┴─────────────────────┴───────────────────┴───────┘
The most-served tract barely commutes by transit; the tract with 59
stops sends 18% of its commuters on it and has 38% of households
without a car. Stop counts are not service, and this is the kind of
question that has no published answer to look up.
Who lives in the floodplain, Harris County
Census block groups here, flood zones from the
FEMA
National Flood Hazard Layer catalog, which publishes one file per
county. A block group counts as at risk when its centroid falls inside a
FEMA Special Flood Hazard Area.
LOAD spatial; LOAD httpfs;
WITH bg AS (
SELECT geoid, population, median_hh_income, ST_Centroid(geometry) AS pt
FROM read_parquet('https://data.source.coop/portolan-mirrors/us-census-catalog/block-groups/bg-income/bg-income.parquet')
WHERE geoid LIKE '48201%' -- Harris County, Texas
),
sfha AS (
-- FEMA publishes EPSG:4269, this catalog OGC:CRS84. Reconcile them or
-- DuckDB refuses the comparison.
SELECT ST_Transform(geometry, 'EPSG:4269', 'OGC:CRS84', always_xy := true) AS geom
FROM read_parquet('https://parquetry.geomermaids.com/nfhl/latest/state=TX/48201C.parquet')
WHERE sfha -- Special Flood Hazard Area
)
SELECT
CASE WHEN EXISTS (SELECT 1 FROM sfha f WHERE ST_Contains(f.geom, bg.pt))
THEN 'high-risk flood zone' ELSE 'outside it' END AS area,
count(*) AS block_groups,
sum(population) AS people,
round(median(median_hh_income)) AS median_income
FROM bg GROUP BY 1 ORDER BY people DESC;
Result
┌──────────────────────┬──────────────┬─────────┬───────────────┐
│ area │ block_groups │ people │ median_income │
├──────────────────────┼──────────────┼─────────┼───────────────┤
│ outside it │ 2468 │ 4242605 │ 72764.0 │
│ high-risk flood zone │ 362 │ 595698 │ 68857.0 │
└──────────────────────┴──────────────┴─────────┴───────────────┘
A centroid is in or out, so this counts whole block groups and will
miss people near a zone edge. It is an estimate of the order of
magnitude, not a flood-insurance determination.
Python, if you would rather
GeoPandas reads the same files. So does anything built on
Arrow or GDAL — QGIS will open these URLs directly.
# pip install geopandas pyarrow "fsspec[http]"
import fsspec
import geopandas as gpd
base = "https://data.source.coop/portolan-mirrors/us-census-catalog"
url = f"{base}/counties/county-income/county-income.parquet"
# pyarrow does not resolve https:// on its own, so open the URL with fsspec
# and hand GeoPandas the file object. Naming columns keeps the read small.
with fsspec.open(url) as f:
gdf = gpd.read_parquet(f, columns=["name", "median_hh_income", "geometry"])
gdf.nlargest(5, "median_hh_income")[["name", "median_hh_income"]]