concept surface in category postgis

appears as: The surface, surface, surface
PostGIS in Action, Third Edition

This is an excerpt from Manning's book PostGIS in Action, Third Edition.

When you gaze down at the terrain from your private jet, what you witness is not distinct geometries on a barren terrestrial plane, but an interwoven network of points, linestrings, and polygons. A cornfield abuts a wheat field, abuts a pasture, abuts a large expanse of prairie. Roads, rivers, fences, or other artificial boundaries divide them all. The surface of the earth (at least the parts that host humanity) resembles a completed jigsaw puzzle. Topology models take on this jigsaw perspective of the world. Topology recognizes the inherent interconnection of geographic features and exploits it to help you better manage data.

Spherical coordinates literally throw a curve into our commonsense grasp of lengths, areas, and perimeters. Take the simple question of what the length is of the shortest line that connects Houston and Mumbai. The only straight line would pass through the center of the earth. Along the surface of the earth, an infinite number of curved lines connect the two cities. Even if you should always take the shortest curve, there’s no guarantee that it will be unique. Try drawing the shortest line between the two geographic poles. You’ll end up with not one but infinitely many.

Listing 6.10. Centroid and point on surface of various geometries
SELECT
    name,
    ST_AsEWKT(ST_Centroid(geom)) As centroid,
    ST_AsEWKT(ST_PointOnSurface(geom)) As point_on_surface,
    CASE WHEN ST_GeometryType(geom) ILIKE '%Point%'
      THEN ST_AsEWKT(ST_GeometricMedian(geom))
      ELSE NULL END As geom_median
FROM (VALUES
    ('Multipoint',ST_GeomFromText('MULTIPOINT(-1 1,0 0,2 3)')),
    ('Multipoint 3D',ST_GeomFromText('MULTIPOINT(-1 1 1,0 0 2,2 3 1)')),
    ('Multilinestring',
        ST_GeomFromText('MULTILINESTRING((0 0,0 1,1 1),(-1 1,-1 -1))')
    ),
    ('Polygon',ST_GeomFromEWKT('
        POLYGON(
            (-0.25 -1.25,-0.25 1.25,2.5 1.25,2.5 -1.25,-0.25 -1.25),
            (2.25 0,1.25 1,1.25 -1,2.25 0),
            (1 -1,1 1,0 0,1 -1)
        )')
    )
)
As x(name,geom);

The code in listing 6.10 outputs both the centroid, the point on the surface, and geometric median of various geometries. We only apply ST_GeometricMedian to multipoints because for other geometries it will return a "Geometry type not supported" error. Although the centroid may not always be part of the geometry, the point on the surface is. Figure 6.2 uses the code in listing 6.10 to show the centroid overlaid with the original geometry.