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)

Merging geometries


In the previous chapter, we learned how to use ST_Collect function to compose Multi-geometries from components. This is computationally cheap, but sometimes, retaining the borders between components (for example, land parcels) is not desirable. This is where union functions come into play.

PostGIS has three unioning functions:

  • ST_Union
  • ST_MemUnion, which is memory optimized (that is, it will take more time but less memory)
  • ST_UnaryUnion, which operates at geometry component-level (and hence is more suitable for Multi-geometries)

Merging polygons

The usage of unioning functions is similar to other spatial aggregate functions. The first possibility is to supply two geometries. For example, let's pick two town boundaries and simulate the administrative boundary if they were merged:

 SELECT ST_Union( 
    (SELECT wkb_geometry FROM multipolygons WHERE osm_id = '2828737'), 
    (SELECT wkb_geometry FROM multipolygons WHERE osm_id = '2828740') 
); 

The resulting polygon has no boundary...