When working with PostGIS, we sometimes want to calculate the "center" point of a given geometry. We may want to find the midpoint of a cycling route or the central point of a district, for example. PostGIS offers two functions for this purpose:
ST_Centroid returns the geometric center (centroid) of a geometry. You can think of it in the following way: if you put a cutout of your geometry on the tip of a pin in the geometric center, the cutout would be perfectly balanced.
ST_Centroid is very quick, so it should be your first choice in most cases. Take a look at how it's used:
The query above will find the centroid of each hotel in San Francisco. By default,
ST_Centroid returns a geometry in the internal PostGIS format so you can easily store it in the database. If you need a human-readable format, recall that you can always use
ST_AsText, like so: