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)

Analytic and statistical functions


Do you remember ST_Reclass? How about getting good classes? There are two very interesting tools in PostGIS. ST_Histogram() and ST_Quantile(). First, return SETOF record of the defined number of histogram bins. The only thing we need to set is the raster column, band, and number of bins. We can break results into min, max, count, and percent with SELECT (histogram).* syntax.

mastering_postgis=# SELECT (stat).* FROM (SELECT ST_Histogram(rast,1,6) AS stat FROM eudem.clip) AS foo; 
       min        |       max        | count |       percent        
------------------+------------------+-------+--------------------- 
 440.980010986328 | 549.598332722982 | 19517 |   0.103899491602119 
 549.598332722982 | 658.216654459635 | 76015 |   0.404668742846496 
 658.216654459635 | 766.834976196289 | 55312 |    0.29445553514866 
 766.834976196289 | 875.453297932943 | 26941 |    0.14342143788762 
 875.453297932943 | 984.071619669597 |  8320 |  0.0442918363544412 
 984.071619669597...