Mastering PostGIS
上QQ阅读APP看书,第一时间看更新

Composing and decomposing geometries

One can think of PostGIS geometries as building blocks. The smallest unit, the point, consists of a tuple (in the most common scenario of 2D geometries, a pair) of coordinates. Points can be then used as independent units or arranged into more complex shapes: MultiPoints and LineStrings. LineStrings can constitute a MultiLineString. Closed LineStrings can be treated as rings and form a Polygon. Finally, multiple polygons may form a MultiPolygon. PostGIS is equipped with functions for coupling and decoupling those geometric building blocks, which will be outlined in this section.

Composition and decomposition functions have different names, but in general they follow a similar pattern: composition is done by supplying an array of components or using a PostgreSQL aggregation, and decomposition is done by extracting individual components by their index or by exploding a geometry into multiple rows using a set-returning function. For details of each geometry type, read on.