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 should 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 have almost no functional support, are not adapted for GIS work, and are incompatible with the PostGIS geometry type. 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. We advise staying away from them for GIS.

If you’ve already started using them, PostGIS rescues you with functions and casts to convert the PostgreSQL types to PostGIS geometry. For example, the following code converts a PostgreSQL polygon, path, box, and circle to an equivalent PostGIS geometry. PostGIS doesn’t have conversions for all PostgreSQL geometry types. As a work-around, we cast box and circle to PostgreSQL polygons before casting to PostGIS geometry:

2.1 Type modifiers

2.1.1 Subtype type modifiers

2.1.2 Spatial reference identifier

2.2 Geometry

2.2.1 Points

2.2.2 Linestrings

2.2.3 Polygons

2.2.4 Collection geometries

2.2.5 The M coordinate

2.2.6 The Z coordinate

2.2.7 Polyhedral surfaces and TINs

2.2.8 Generating TINs

2.2.9 Curved geometries

2.2.10 Spatial catalog for geometry

2.3 Geography

sitemap