Deals Of The Week - hours only!Up to 80% off on all courses and bundles.-Close
Introduction
Functions returning geometries
Collections
10. Introduction to collections
Summary

Instruction

Let's now move on to the second topic of this part: collections.

PostGIS makes it possible to organize spatial data into collections. This means you can throw multiple points, linestrings or polygons into a single row. For instance, this can be helpful if you want to store all hotels of a given chain in one place.

Generally speaking, there are four types of collections:

  • Multipoint - collection type that stores one or more points.
  • Multilinestring - collection type that stores one or more linestrings.
  • Multipolygon - collection type that stores one or more polygons.
  • GeometryCollection - a generic collection type that can store one or more geometry types (any mix of points, linestrings and polygons, essentialy).

Just like other geometry types, collections are stored in the internal PostGIS format, but can be converted to a human-readable format with ST_AsText(collection).

Let's find out what an example collection looks like.

Exercise

For this section, we've created a table called sf_chains. It has only three columns:

  • id - the unique identifier of the collection,
  • description - a textual description of what is inside the collection,
  • geo_data - the collection itself, stored in the internal PostGIS format.

Now, for id = 79, show the following columns: description, geo_data and geo_data shown as text.

As you can see, this query retrieves all Alpha Bank ATMs in San Francisco. Recall that ATMs are represented as points, so this query returns a Multipoint collection.

Stuck? Here's a hint!

Invoke the ST_AsText function on the geo_data column.