Book Image

Mastering PostGIS

By : Dominik Mikiewicz, Michal Mackiewicz , Tomasz Nycz
Book Image

Mastering PostGIS

By: Dominik Mikiewicz, Michal Mackiewicz , Tomasz Nycz

Overview of this book

PostGIS is open source extension onf PostgreSQL object-relational database system that allows GIS objects to be stored and allows querying for information and location services. The aim of this book is to help you master the functionalities offered by PostGIS- from data creation, analysis and output, to ETL and live edits. The book begins with an overview of the key concepts related to spatial database systems and how it applies to Spatial RMDS. You will learn to load different formats into your Postgres instance, investigate the spatial nature of your raster data, and finally export it using built-in functionalities or 3th party tools for backup or representational purposes. Through the course of this book, you will be presented with many examples on how to interact with the database using JavaScript and Node.js. Sample web-based applications interacting with backend PostGIS will also be presented throughout the book, so you can get comfortable with the modern ways of consuming and modifying your spatial data.
Table of Contents (9 chapters)

Geometry validation


Invalid geometries are a spatial analyst's nightmare. They can appear in any dataset, and can break a carefully-designed, long-running query in the middle of execution. Or even worse, a failing query might break an application's functionality. Luckily, PostGIS is equipped with the tools to find and repair them.

Simplicity and validity

In PostGIS, there are two concepts: simplicity and validity. For most spatial analyses to succeed, input geometries have to be both simple and valid. Here are some rules:

  • Does not have repeated points (with the exception of closed rings, whose first and last point are identical)
  • Does not self-intersect
  • A point must always be simple and valid
  • A MultiPoint must always be valid, and simple when there are no repeated points with identical coordinates
  • A LineString or MultiLineString must always be valid, and is simple if the line:

Example of a non-simple line: self-intersecting autogenerated contours.

A polygon is always simple, and is valid if:

  • All interior...