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 adopted 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 advice 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 conversion 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.3  Geography

2.3.1  Differences between geography and geometry

2.3.2  Spatial catalogs for geography

2.4  Raster

2.4.1  Properties of rasters

2.4.2  Creating rasters

2.4.3  Spatial catalog for rasters

2.5  Summary

sitemap