Only this week, get the SQL Complete Track of 9 courses in a special prize of $330$89!
Introduction
Functions returning geometries
5. ST_Centroid vs ST_PointOnSurface
Collections
Summary

Instruction

Great! To sum things up, here is the difference between ST_Centroid and ST_PointOnSurface.

• ST_Centroid is quick, but can potentially return a point outside the bounds of a given geometry.
• ST_PointOnSurface is much slower, but always finds a point that lie inside or on the bounds of a given geometry.

The difference is also illustrated in the picture below.

Exercise

Mark the cyclist strikes again! He wants to find the number of bicycle routes for which the centroid equals the point on surface.

Stuck? Here's a hint!

Use COUNT(*). In the WHERE clause, use ST_Centroid and ST_PointOnSurface passing in the same column as an argument.