Skip to content

Instantly share code, notes, and snippets.

@mbforr
Created July 29, 2021 18:22
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save mbforr/b5b4f081a194db2e8e5aebae6fe9227c to your computer and use it in GitHub Desktop.
Save mbforr/b5b4f081a194db2e8e5aebae6fe9227c to your computer and use it in GitHub Desktop.
WITH
counties AS (
SELECT
a.total_pop,
b.*
FROM
`bigquery-public-data.census_bureau_acs.county_2018_1yr` a
JOIN
`bigquery-public-data.geo_us_boundaries.counties` b
USING
(geo_id) )
SELECT
state_fips_code,
st_union_agg(county_geom) AS geom
FROM
counties
# exclude counties with less than 500 people per square mile
WHERE
(total_pop/(st_area(county_geom)/2.59e+6)) > 500
GROUP BY
state_fips_code
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment