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)

Accessing the topology data


Elements used to compose TopoGeometries can be retrieved by manually querying the topology tables, but PostGIS provides specialized functions for that purpose. First, we will find topological elements of Poland using the topology.GetTopoGeomElements function:

SELECT topology.GetTopoGeomElements(topogeom) FROM countries WHERE name='Poland'; 

 gettopogeomelements 
--------------------- 
 {3155,3} 

The function returns a set of rows, each one with one column of topoelement (which is just a two-element integer array) type. The first array element is a topological element ID, and the second is its type (1 - node, 2 - edge, 3 - face). Here we got one row, meaning the country is built from just one face.

For Norway, with lots of islands, the element list will be much longer:

SELECT topology.GetTopoGeomElements(topogeom) FROM countries WHERE name = 'Norway'; 
gettopogeomelements 
--------------------- 
 {2713,3} 
 {2714,3} 
 {2724,3} 
 ... 
 {2831,3} 
 {2832,3} 
(120 rows...