Skip to content

Instantly share code, notes, and snippets.

@matt-baker
Last active February 17, 2023 10:01
Show Gist options
  • Save matt-baker/5461349 to your computer and use it in GitHub Desktop.
Save matt-baker/5461349 to your computer and use it in GitHub Desktop.
Select lat/long centroid from a polygon in PostGIS.
-- SELECT polygon centroid as latitude/longitude in PostGIS
SELECT
st_x(st_transform(ST_Centroid(the_geom),4326)) as lat,
st_y(st_transform(ST_Centroid(the_geom),4326)) as long
FROM table;
@louis-takealot
Copy link

x and y are swapped!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment