Chapter 2. Spatial data types

 

This chapter covers

  • Geometry, geography, and raster spatial types and subtypes
  • Geometry and geography type modifiers
  • Spatial catalog tables
  • How to create spatial columns and populate them

In the first chapter, we teased you with the potential that you can unlock with PostGIS. This chapter will start to show you how, by delving deeper into the core spatial data types bundled with PostGIS. We’ll discuss each spatial type in detail. Once you’ve completed this chapter, you’ll know how to create table columns of these various types and how to populate them with spatial data.

Do keep in the back of your mind that PostgreSQL has its own built-in geometric types. These are point, polygon, lseg, box, circle, and path. PostgreSQL geometry types are incompatible with the PostGIS geometry type and have little or no third-party visualization support. These geometry types have existed since the dawn of PostgreSQL and don’t follow the SQL/MM standards, nor do they support spatial coordinate systems. Using them as mathematical tools is fine, but stay away from them for GIS use or if you need visualization support.

If you’re in too deep, PostGIS 2.1 introduced functions and casts to convert the PostgreSQL types to PostGIS geometry. For example, this line converts a PostgreSQL polygon to an equivalent PostGIS geometry:

SELECT polygon('((10,20),(30,40),(35,40),(10,20))')::geometry;

Layers

2.1. Type modifiers

2.2. Geometry

2.3. Geography

2.4. Raster

2.5. Summary

sitemap