Home / Blog / The centroid of Mosel is in a forest

June 23, 2026Β· Wine World Map

The centroid of Mosel is in a forest

The Mosel region polygon traces the river of the same name for about 250 kilometres, from Trier to Koblenz. It's narrow β€” usually less than four kilometres wide β€” because vineyards only grow on the slate hills directly facing the water. Its shape on the map looks like a worm that's been thinking about coiling but never committed.

When you ask PostGIS for the centroid of that polygon, you get a point in a forest north of Wittlich. Nowhere near the river, nowhere near a single vineyard. Click "Mosel" on the world map and the camera was flying to a stand of beech trees.

Why ST_Centroid lies

ST_Centroid returns the geometric center of mass. For a circle it's the middle. For a square it's the middle. For a C-shape it's outside the shape entirely. Long, curved, narrow polygons β€” exactly the geometry of every river-valley wine region β€” produce centroids that land in the empty space the polygon wraps around.

SELECT
  slug,
  ST_AsText(ST_Centroid(boundary))         AS centroid,
  ST_Contains(boundary, ST_Centroid(boundary)) AS inside
FROM regions
WHERE slug IN ('mosel','douro','wachau','rheingau','napa-valley');

| Region | Inside its own polygon? | |---|---| | Mosel | false | | Douro | false | | Wachau | false | | Rheingau | true | | Napa Valley | true |

Roughly a quarter of regions in the database fail this check. Every one of them is a river valley or a coastal strip. Napa is a wide basin, so it survives. Rheingau is short enough to round out. But the Mosel, the Douro, the RhΓ΄ne, the Loire, the Wachau, the Mosel's own tributaries (Saar, Ruwer) β€” all centroids in the wrong place.

The one-line fix

PostGIS has ST_PointOnSurface, which is contractually obligated to return a point inside the polygon. It's not the visual center, but it's somewhere on the geometry.

UPDATE regions
SET
  center_lat = ST_Y(ST_PointOnSurface(boundary)),
  center_lng = ST_X(ST_PointOnSurface(boundary))
WHERE NOT ST_Contains(boundary, ST_Centroid(boundary));

For Mosel that puts the camera near Bernkastel-Kues, which is exactly where you'd put a pin if you had to pick one town to represent the region. Lucky, but not coincidence β€” ST_PointOnSurface tends to find the fattest interior part of a thin polygon, and the fattest part of the Mosel is the bend around Bernkastel where the valley widens.

For the truly twisted shapes you can go further with ST_MaximumInscribedCircle, which returns the pole of inaccessibility β€” the point inside the polygon that is furthest from any boundary edge. Slower, more precise, and overkill for our needs. Surface point is good enough.

Why this matters for the camera

The map's fly-to logic uses (center_lat, center_lng) plus a zoom bucket from the zoom-per-region post. Get the center wrong and the user sees forest at zoom 9. The boundary polygon still draws correctly β€” Mapbox doesn't care β€” but the initial framing is off, and on a touch device the user has to pan to find anything.

This is also why the vineyard-hull fallback works so well for regions where OSM has no boundary at all. The hull is roughly convex, and a convex polygon's centroid is always inside it. The pathological case is specifically real appellation boundaries, which are drawn by lawyers tracing rivers.

Lesson

Geometric centroid is the function you reach for. Surface point is the function you want. The difference only shows up for polygons that bend more than they bulge β€” which, in wine, is most of the old-world ones, because vines follow rivers and rivers don't run in straight lines. When the math gives you a point in a forest, ask the math for a different point.

#postgis#geo#import