6 Geometry and geography functions

 

This chapter covers

  • Output functions
  • Constructor functions
  • Accessor and setter functions
  • Measurement functions
  • Composition and decomposition functions
  • Simplification functions

In previous chapters we’ve discussed PostGIS spatial types—how to create them and how to add them to your database. In this chapter we’ll introduce the core set of functions that work with the geometry and geography spatial types. This chapter concentrates on functions that work with single geometries and geographies.

PostGIS offers lots of functions and operators, and in this chapter we’ve grouped them by intent of use. This is by no means a rigorous classification, nor one that will neatly sort each function into a unique group without ambiguity, but grouping functions by the type of tasks you’re trying to accomplish is the handiest approach, in our experience. We’ll refer to geometries and geographies as spatial objects when discussing both. This is the classification scheme we’ll use:

6.1 Output functions

6.1.1 Well-known text (WKT) and well-known binary (WKB)

6.1.2 Keyhole Markup Language (KML)

6.1.3 Geography Markup Language (GML)

6.1.4 Geometry JavaScript Object Notation (GeoJSON)

6.1.5 Scalable Vector Graphics (SVG)

6.1.6 Mapbox Vector Tiles (MVT) and protocol buffers

6.1.7 Tiny WKB (TWKB)

6.1.8 Extensible 3D Graphics (X3D)

6.1.9 Examples of output functions

6.1.10 Geohash

6.2 Constructor functions

6.2.1 Creating geometries from text and binary formats

6.2.2 Creating geographies from text and binary formats