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)

Importing Simple Feature data into topology


PostGIS can convert Simple Feature geometries into topology. Let's assume a countries table containing country boundaries from the Natural Earth dataset, with a geometry column named geom, and the WGS84 coordinate system.

Checking the validity of input geometries

The first step is to check the validity of input geometries. PostGIS will refuse to convert invalid geometries to topology elements, so it's very important to fix them or filter them out. We will use the ST_IsValidReason and ST_IsValid functions that we learned in Chapter 1, Importing Spatial Data:

SELECT ST_IsValidReason(geom) FROM countries WHERE ST_IsValid(geom) = FALSE; 

Luckily, in this case the query returned 0 rows, meaning that all geometries are valid, so we can proceed to the next step.

Note

It may happen that invalid geometries sneak into some revised version of Natural Earth, in which case the query will return a non-zero result. In that case, the invalid geometries must be repaired...