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)

Exporting vector data using pgsql2shp


pgsql2shp is a command-line tool that can be used to output PostGIS data into shapefiles. Similarly to outgoing \COPY, it can either export a full table or the result of a query, so this gives us flexibility when we only need a subset of data to be outputted and we do not want to either modify the source tables or create temporary, intermediate ones.

pgsql2sph command line

In order to get some help with the tool just type the following in the console:

pgsql2shp

The general syntax for the tool is as follows:

pgsql2shp [<options>] <database> [<schema>.]<table>
    pgsql2shp [<options>] <database> <query>

Shapefile is a format that is made up of a few files. The minimum set is SHP, SHX, and DBF. If PostGIS is able to determine the projection of the data, it will also export a PRJ file that will contain the SRS information, which should be understandable by the software able to consume a shapefile.

If a table does not have...