Skip to content

Instantly share code, notes, and snippets.

@mbforr
Last active January 8, 2023 11:31
Show Gist options
  • Save mbforr/0013a8b54caa356cd345dba24ca0b744 to your computer and use it in GitHub Desktop.
Save mbforr/0013a8b54caa356cd345dba24ca0b744 to your computer and use it in GitHub Desktop.
Example Spatial SQL Post
-- written for PostGIS
-- table states is US State Polygons
-- table capitals are US State Capital points
select
a.name,
a.id,
-- create a centroid of the state polygon
st_centroid(a.geom) as centroid,
-- measure the distance from the state centroid to the capital
st_distance(st_centroid(a.geom), b.geom)
from states a
join capitals b using (abbreviation)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment