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)

Slicing geometries


PostGIS is good at splitting geometries too. There are methods for splitting line and polygon geometries using a second geometry (blade), and for extracting sections of linear features based on distance.

Splitting a polygon by LineString

In our first example, we'll split a polygon (county boundary) using a line (river). We will use an ST_Split function for that.

This function accepts two arguments: a geometry to be split, which can be of the (Multi)Polygon or (Multi)LineString type, and a blade, which can be a LineString for polygons and LineStrings or a Point for lines:.

A polygon about to be split with a LineString used as a blade

SELECT ST_Split( 
 (SELECT wkb_geometry FROM multipolygons WHERE osm_id = '2417246'), 
 (SELECT wkb_geometry FROM lines WHERE osm_id = '224461074')) 

This yields a GeometryCollection, which isn't supported in most GIS software, including QGIS. To extract individual parts after splitting, and to visualize the result in QGIS, we'll need to use the...