SlideShare a Scribd company logo
© 2015 EnterpriseDB Corporation. All rights reserved. 1
Getting started with PostGIS
Adam Wright – Database Consultant
© 2015 EnterpriseDB Corporation. All rights reserved. 2
•  Introduction to EDB
•  A little bit about Postgres
•  About PostGIS
•  Geospatial basics
•  Now, let us get started
•  Maintenance
Agenda
© 2015 EnterpriseDB Corporation. All rights reserved. 3
POSTGRES
innovation
ENTERPRISE
reliability
24/7
support
Services
& training
Enterprise-class
features, tools &
compatibility
Indemnification
Product
road-map
Control
Thousands
of developers
Fast
development
cycles
Low cost
No vendor
lock-in
Advanced
features
Enabling commercial
adoption of Postgres
© 2015 EnterpriseDB Corporation. All rights reserved. 4
Postgres: A Proven Track Record
•  Most mature open source DBMS technology
•  Enterprise-class features (built like Oracle, DB2,
SQL Server)
•  Strong, independent community driving rapid
innovation
4
Fully ACID Compliant
MVCC
Point in Time Recovery (PITR)‫‏‬
Data and Index Partitioning
Bitmap Indexes
ANSI Constraints
Triggers & Stored Functions
Views & Data Types
Nested Transactions
Online Backup
Online Reorganization
Foreign Keys
Streaming Replication
Multi-Core Support
JSON Support
Hstore
Table Partition
Materialized Views
Grouping Sets and CUBE (9.5)
UPSERT (9.5)
Row Level Security (9.5)
© 2015 EnterpriseDB Corporation. All rights reserved. 5
Scalable
© 2015 EnterpriseDB Corporation. All rights reserved. 6
•  Refractions Research released first version in 2001
under the GNU license
•  Follows the Simple Features for SQL specification
from the Open Geospatial Consortium (OGC)
•  Spatial operators and spatial functions
•  Spatial data types
•  Spatial indexing
•  Spatial reprojection
•  Import / Export Esri shapefiles
•  Commands for importing raster data
•  SQL to render and import data from multiple
formats
About PostGIS
6
© 2015 EnterpriseDB Corporation. All rights reserved. 7
PostGIS Data Types
Geometry
Geography
Raster Topology
© 2015 EnterpriseDB Corporation. All rights reserved. 8
PostGIS Data subtypes
Point
Linestring
Polygon
Multipoint
Multilinestring
Multipolygon
© 2015 EnterpriseDB Corporation. All rights reserved. 9
Spatial Definitions Examples (1 of 5)
Boundary
© 2015 EnterpriseDB Corporation. All rights reserved. 10
Spatial Definitions Examples (2 of 5)
© 2015 EnterpriseDB Corporation. All rights reserved. 11
Spatial Definitions Examples (3 of 5)
Contains
© 2015 EnterpriseDB Corporation. All rights reserved. 12
Spatial Definitions Examples (4 of 5)
Equals
© 2015 EnterpriseDB Corporation. All rights reserved. 13
Spatial Definitions Examples (5 of 5)
© 2015 EnterpriseDB Corporation. All rights reserved. 14
•  Repository
•  Binary
Step 1: Install PostGIS - two methods
14
RedHat
‘yum install postgis2_94’
Debian
‘apt-get install postgres-9.4-postgis’
© 2015 EnterpriseDB Corporation. All rights reserved. 15
•  For a New Database
CREATE DATABASE geodb
WITH template = template_postgis;
•  For an Existing Database
CREATE EXTENSION postgis;
CREATE EXTENSION postgis_toplogy;
•  Verify
SELECT postgis_version();
Step 2: Enable PostGIS
© 2015 EnterpriseDB Corporation. All rights reserved. 16
•  Load shapefiles
shp2pgsql –c –s 4629 –I /
tmp/
boston_massachusetts_osm_l
ine.shp boston_osm_line |
pgsql –d geodb
•  Inserting a point in SQL
INSERT into
cities(name,state,geom)
Values(‘Boston’,’MA’,
ST_GeomFromText(‘POINT(-71
.0589 42.3601)’,4326));
Step 3: Load Data
16
© 2015 EnterpriseDB Corporation. All rights reserved. 17
Load data from standard to geospatial
17
INSERT into events_geo(eventname,geom,date)
SELECT eventname, st_setsrid(st_makepoint(lon,lat),4326)
as geom,date FROM events;
Events Table
eventname – character varying
lat - double precision
lon - double precision
Date - timestamp with time zone
Events_geo Table
eventname - character
varying geom – geometry (Point,4326)
Date – timestamp with time zone
INSERT
© 2015 EnterpriseDB Corporation. All rights reserved. 18
Visual Inspection of data
18
© 2015 EnterpriseDB Corporation. All rights reserved. 19
Visual Inspection of data
19
© 2015 EnterpriseDB Corporation. All rights reserved. 20
•  Output geometry data types to other data types
SELECT st_astext(geom), st_asgeojson(geom),
stasgml(geom) FROM atm_locations LIMIT 1;
-[ RECORD 1 ]+----------------------------------
st_astext | POINT(-81.7842060002066 30.2915309995561)
st_asgeojson | {"type":"Point","coordinates":
[-81.7842060002066,30.2915309995561]}
st_asgml | <gml:Point srsName="EPSG:
4629"><gml:coordinates>-81.784206000206609,30.2915309995
5613</gml:coordinates></gml:Point>
Geometry Input and Output Functions
20
© 2015 EnterpriseDB Corporation. All rights reserved. 21
•  Create geometry type from text
Insert into cities (name,state,geom)
Values (‘Bedford’,’MA’,
ST_GeomFromText(‘POINT(-71.248063 42.510547)’,4326));
Geometry Input and Output Functions
21
© 2015 EnterpriseDB Corporation. All rights reserved. 22
•  Write a function to tell whether a given lat/lon pair is
within a Point-Radius ring
IF ST_Dwithin(check_pt, point_pt, outerRadius)
AND NOT ST_Dwithin(chevk_pt, point_pt,
innerRadius)
THEN return 1;
ELSE
Return 0;
END IF;
•  Create a route from a collection of waypoints captured
in sequence
CREATE TABLE PATHS as SELECT routeid, seq, geom
FROM waypoints ORDER BY seq) a GROUP BY routeid;
Power of GIS & SQL
© 2015 EnterpriseDB Corporation. All rights reserved. 23
•  Simple distance query
between two points
SELECT ST_Distance
(ST_GeomFromText
('POINT(34 9)’,4629),
ST_GeomFromText
('POINT(70 12)’,4629));
Power of GIS & SQL
34, 9
70, 12
© 2015 EnterpriseDB Corporation. All rights reserved. 24
•  Write a function to tell whether a given lat/lon pair is
within a Point-Radius ring
IF ST_Dwithin(check_pt, point_pt, outerRadius) AND
NOT ST_Dwithin(chevk_pt, point_pt, innerRadius)
THEN return 1;
ELSE
Return 0;
END IF;
•  Create a route from a collection of waypoints captured in
sequence
CREATE TABLE PATHS as SELECT routeid, st_make(gem)
as geom FROM (SELECT routeid, seq, geom FROM
waypoints ORDER BY seq)a GROUP BY routeid;
Power of GIS & SQL
© 2015 EnterpriseDB Corporation. All rights reserved. 25
•  Answer powerful questions with a simple query
−  Input function
Insert into cities (name,state,geom)
Values (‘Bedford’,’MA’,
ST_GeomFromText(‘POINT(-71.248063 42.510547)’,
4326));
Power of GIS & SQL
© 2015 EnterpriseDB Corporation. All rights reserved. 26
Power of GIS & SQL
© 2015 EnterpriseDB Corporation. All rights reserved. 27
Power of GIS & SQL
© 2015 EnterpriseDB Corporation. All rights reserved. 28
Maintenance of a PostGIS database
•  After bulk inserts and updates – VACUUM ANALYZE
•  Loading large dataset: Build indexes after
•  Use EXPLAIN
•  Add Indexes on PostGIS columns
•  Backup/Recovery and SR considerations
© 2015 EnterpriseDB Corporation. All rights reserved. 29
•  Power of Postgres
−  Binary replication, Table Partitions, Text search function and operators, PL/SQL, PL/Python,
PLV8, PL/R, Indexes
−  Grouping sets, cube and rollup (now in EDB Postgres Plus, coming in Postgres 9.5)
−  Foreign table inheritance (new in 9.5)
•  ogr2ogr
•  Web Maps
−  Open Layers
−  Map Server
−  GeoServer
Notes:
© 2015 EnterpriseDB Corporation. All rights reserved. 30

More Related Content

What's hot (20)

PPT
Using PostGIS To Add Some Spatial Flavor To Your Application
Steven Pousty
 
PDF
지리정보체계(GIS) - [1] GIS 데이터 유형, 구조 알기
Byeong-Hyeok Yu
 
PPTX
Introduction to NoSQL Databases
Derek Stainer
 
PPTX
Metadata ppt
Shashikant Kumar
 
PPTX
Oracle Spatial de la A a la Z - Unidad 3
Jorge Ulises
 
PPTX
RDF data model
Jose Emilio Labra Gayo
 
PDF
PostGIS 시작하기
Byeong-Hyeok Yu
 
PPTX
Relational databases
Fiddy Prasetiya
 
PDF
Snowflake free trial_lab_guide
slidedown1
 
PPTX
QGIS 활용
Sungjin Kang
 
PPTX
공간정보거점대학 1.geo server_고급과정
BJ Jang
 
PDF
Data Visualisation: Types, Principles, and Tools
Sumandro C
 
PPTX
Introduction to MongoDB.pptx
Surya937648
 
PPTX
DBMS Notes: DDL DML DCL
Sreedhar Chowdam
 
PPT
Introduction to mongodb
neela madheswari
 
PPT
Hive(ppt)
Abhinav Tyagi
 
PDF
RDBMS to Graph
Neo4j
 
PPTX
Spatial databases
Seraphic Nazir
 
PPT
Hadoop Map Reduce
VNIT-ACM Student Chapter
 
PPTX
공간SQL을 이용한 공간자료분석 기초실습
BJ Jang
 
Using PostGIS To Add Some Spatial Flavor To Your Application
Steven Pousty
 
지리정보체계(GIS) - [1] GIS 데이터 유형, 구조 알기
Byeong-Hyeok Yu
 
Introduction to NoSQL Databases
Derek Stainer
 
Metadata ppt
Shashikant Kumar
 
Oracle Spatial de la A a la Z - Unidad 3
Jorge Ulises
 
RDF data model
Jose Emilio Labra Gayo
 
PostGIS 시작하기
Byeong-Hyeok Yu
 
Relational databases
Fiddy Prasetiya
 
Snowflake free trial_lab_guide
slidedown1
 
QGIS 활용
Sungjin Kang
 
공간정보거점대학 1.geo server_고급과정
BJ Jang
 
Data Visualisation: Types, Principles, and Tools
Sumandro C
 
Introduction to MongoDB.pptx
Surya937648
 
DBMS Notes: DDL DML DCL
Sreedhar Chowdam
 
Introduction to mongodb
neela madheswari
 
Hive(ppt)
Abhinav Tyagi
 
RDBMS to Graph
Neo4j
 
Spatial databases
Seraphic Nazir
 
Hadoop Map Reduce
VNIT-ACM Student Chapter
 
공간SQL을 이용한 공간자료분석 기초실습
BJ Jang
 

Viewers also liked (17)

PDF
EnterpriseDB Postgres Survey Results - 2013
EDB
 
PDF
NoSQL on ACID - Meet Unstructured Postgres
EDB
 
PDF
Top 10 Tips for an Effective Postgres Deployment
EDB
 
PDF
Come with an idea - go home with a web map: Tools for sharing maps and vector...
Stefan Keller
 
PPTX
Create Spatialite Database Using Quantum GIS
bramantiyo marjuki
 
PPTX
PGEncryption_Tutorial
Vibhor Kumar
 
PPTX
Day 6 - PostGIS
Barry Jones
 
PDF
Migrating from Oracle to Postgres
EDB
 
PPTX
What is spatial sql
shawty_ds
 
PDF
Building enterprise applications using open source
Peter Batty
 
PDF
Spatial query tutorial for nyc subway income level along subway
Vivian S. Zhang
 
PDF
Key Methodologies for Migrating from Oracle to Postgres
EDB
 
PDF
Partition and conquer large data in PostgreSQL 10
Ashutosh Bapat
 
PDF
Best Practices for a Complete Postgres Enterprise Architecture Setup
EDB
 
PPS
Jdbc architecture and driver types ppt
kamal kotecha
 
PPSX
JDBC: java DataBase connectivity
Tanmoy Barman
 
EnterpriseDB Postgres Survey Results - 2013
EDB
 
NoSQL on ACID - Meet Unstructured Postgres
EDB
 
Top 10 Tips for an Effective Postgres Deployment
EDB
 
Come with an idea - go home with a web map: Tools for sharing maps and vector...
Stefan Keller
 
Create Spatialite Database Using Quantum GIS
bramantiyo marjuki
 
PGEncryption_Tutorial
Vibhor Kumar
 
Day 6 - PostGIS
Barry Jones
 
Migrating from Oracle to Postgres
EDB
 
What is spatial sql
shawty_ds
 
Building enterprise applications using open source
Peter Batty
 
Spatial query tutorial for nyc subway income level along subway
Vivian S. Zhang
 
Key Methodologies for Migrating from Oracle to Postgres
EDB
 
Partition and conquer large data in PostgreSQL 10
Ashutosh Bapat
 
Best Practices for a Complete Postgres Enterprise Architecture Setup
EDB
 
Jdbc architecture and driver types ppt
kamal kotecha
 
JDBC: java DataBase connectivity
Tanmoy Barman
 
Ad

Similar to Getting Started with PostGIS (20)

PDF
Discover PostGIS: Add Spatial functions to PostgreSQL
EDB
 
PPTX
Presto query optimizer: pursuit of performance
DataWorks Summit
 
PDF
The Real Scoop on Migrating from Oracle Databases
EDB
 
PPTX
EDB: Power to Postgres
Ashnikbiz
 
PPTX
PaaS - google app engine
J Singh
 
PDF
The Central View of your Data with Postgres
EDB
 
PDF
Postgres NoSQL - Delivering Apps Faster
EDB
 
PPTX
LocationTech Projects
Jody Garnett
 
PPTX
New enhancements for security and usability in EDB 13
EDB
 
PPTX
Doing More with Postgres - Yesterday's Vision Becomes Today's Reality
EDB
 
PPTX
MySQL performance monitoring using Statsd and Graphite
DB-Art
 
PDF
Supersized PostgreSQL: Postgres-XL for Scale-Out OLTP and Big Data Analytics
mason_s
 
PDF
Around the world with extensions | PostgreSQL Conference Europe 2018 | Craig ...
Citus Data
 
PDF
Agile Oracle to PostgreSQL migrations (PGConf.EU 2013)
Gabriele Bartolini
 
PPTX
Analyzing Real-World Data with Apache Drill
tshiran
 
PPTX
Triple C - Centralize, Cloudify and Consolidate Dozens of Oracle Databases (O...
Lucas Jellema
 
PDF
SQL on Hadoop
Swiss Big Data User Group
 
PDF
SQL on Hadoop - 12th Swiss Big Data User Group Meeting, 3rd of July, 2014, ET...
Romeo Kienzler
 
PDF
Pivotal Greenplum 次世代マルチクラウド・データ分析プラットフォーム
Masayuki Matsushita
 
PPTX
How to use postgresql.conf to configure and tune the PostgreSQL server
EDB
 
Discover PostGIS: Add Spatial functions to PostgreSQL
EDB
 
Presto query optimizer: pursuit of performance
DataWorks Summit
 
The Real Scoop on Migrating from Oracle Databases
EDB
 
EDB: Power to Postgres
Ashnikbiz
 
PaaS - google app engine
J Singh
 
The Central View of your Data with Postgres
EDB
 
Postgres NoSQL - Delivering Apps Faster
EDB
 
LocationTech Projects
Jody Garnett
 
New enhancements for security and usability in EDB 13
EDB
 
Doing More with Postgres - Yesterday's Vision Becomes Today's Reality
EDB
 
MySQL performance monitoring using Statsd and Graphite
DB-Art
 
Supersized PostgreSQL: Postgres-XL for Scale-Out OLTP and Big Data Analytics
mason_s
 
Around the world with extensions | PostgreSQL Conference Europe 2018 | Craig ...
Citus Data
 
Agile Oracle to PostgreSQL migrations (PGConf.EU 2013)
Gabriele Bartolini
 
Analyzing Real-World Data with Apache Drill
tshiran
 
Triple C - Centralize, Cloudify and Consolidate Dozens of Oracle Databases (O...
Lucas Jellema
 
SQL on Hadoop - 12th Swiss Big Data User Group Meeting, 3rd of July, 2014, ET...
Romeo Kienzler
 
Pivotal Greenplum 次世代マルチクラウド・データ分析プラットフォーム
Masayuki Matsushita
 
How to use postgresql.conf to configure and tune the PostgreSQL server
EDB
 
Ad

More from EDB (20)

PDF
Cloud Migration Paths: Kubernetes, IaaS, or DBaaS
EDB
 
PDF
Die 10 besten PostgreSQL-Replikationsstrategien für Ihr Unternehmen
EDB
 
PDF
Migre sus bases de datos Oracle a la nube
EDB
 
PDF
EFM Office Hours - APJ - July 29, 2021
EDB
 
PDF
Benchmarking Cloud Native PostgreSQL
EDB
 
PDF
Las Variaciones de la Replicación de PostgreSQL
EDB
 
PDF
NoSQL and Spatial Database Capabilities using PostgreSQL
EDB
 
PDF
Is There Anything PgBouncer Can’t Do?
EDB
 
PDF
Data Analysis with TensorFlow in PostgreSQL
EDB
 
PDF
Practical Partitioning in Production with Postgres
EDB
 
PDF
A Deeper Dive into EXPLAIN
EDB
 
PDF
IOT with PostgreSQL
EDB
 
PDF
A Journey from Oracle to PostgreSQL
EDB
 
PDF
Psql is awesome!
EDB
 
PDF
EDB 13 - New Enhancements for Security and Usability - APJ
EDB
 
PPTX
Comment sauvegarder correctement vos données
EDB
 
PDF
Cloud Native PostgreSQL - Italiano
EDB
 
PDF
New enhancements for security and usability in EDB 13
EDB
 
PPTX
Best Practices in Security with PostgreSQL
EDB
 
PDF
Cloud Native PostgreSQL - APJ
EDB
 
Cloud Migration Paths: Kubernetes, IaaS, or DBaaS
EDB
 
Die 10 besten PostgreSQL-Replikationsstrategien für Ihr Unternehmen
EDB
 
Migre sus bases de datos Oracle a la nube
EDB
 
EFM Office Hours - APJ - July 29, 2021
EDB
 
Benchmarking Cloud Native PostgreSQL
EDB
 
Las Variaciones de la Replicación de PostgreSQL
EDB
 
NoSQL and Spatial Database Capabilities using PostgreSQL
EDB
 
Is There Anything PgBouncer Can’t Do?
EDB
 
Data Analysis with TensorFlow in PostgreSQL
EDB
 
Practical Partitioning in Production with Postgres
EDB
 
A Deeper Dive into EXPLAIN
EDB
 
IOT with PostgreSQL
EDB
 
A Journey from Oracle to PostgreSQL
EDB
 
Psql is awesome!
EDB
 
EDB 13 - New Enhancements for Security and Usability - APJ
EDB
 
Comment sauvegarder correctement vos données
EDB
 
Cloud Native PostgreSQL - Italiano
EDB
 
New enhancements for security and usability in EDB 13
EDB
 
Best Practices in Security with PostgreSQL
EDB
 
Cloud Native PostgreSQL - APJ
EDB
 

Recently uploaded (20)

PPTX
Equipment Management Software BIS Safety UK.pptx
BIS Safety Software
 
PPTX
Revolutionizing Code Modernization with AI
KrzysztofKkol1
 
PPTX
Engineering the Java Web Application (MVC)
abhishekoza1981
 
PDF
Powering GIS with FME and VertiGIS - Peak of Data & AI 2025
Safe Software
 
PPTX
Agentic Automation Journey Session 1/5: Context Grounding and Autopilot for E...
klpathrudu
 
PPTX
Java Native Memory Leaks: The Hidden Villain Behind JVM Performance Issues
Tier1 app
 
PDF
Thread In Android-Mastering Concurrency for Responsive Apps.pdf
Nabin Dhakal
 
PDF
Linux Certificate of Completion - LabEx Certificate
VICTOR MAESTRE RAMIREZ
 
PDF
Automate Cybersecurity Tasks with Python
VICTOR MAESTRE RAMIREZ
 
PPTX
Feb 2021 Cohesity first pitch presentation.pptx
enginsayin1
 
PPTX
How Apagen Empowered an EPC Company with Engineering ERP Software
SatishKumar2651
 
PDF
GetOnCRM Speeds Up Agentforce 3 Deployment for Enterprise AI Wins.pdf
GetOnCRM Solutions
 
PPTX
A Complete Guide to Salesforce SMS Integrations Build Scalable Messaging With...
360 SMS APP
 
PPTX
Tally_Basic_Operations_Presentation.pptx
AditiBansal54083
 
PDF
Revenue streams of the Wazirx clone script.pdf
aaronjeffray
 
PPTX
MiniTool Power Data Recovery Full Crack Latest 2025
muhammadgurbazkhan
 
PDF
Mobile CMMS Solutions Empowering the Frontline Workforce
CryotosCMMSSoftware
 
PDF
vMix Pro 28.0.0.42 Download vMix Registration key Bundle
kulindacore
 
PDF
iTop VPN With Crack Lifetime Activation Key-CODE
utfefguu
 
PDF
Build It, Buy It, or Already Got It? Make Smarter Martech Decisions
bbedford2
 
Equipment Management Software BIS Safety UK.pptx
BIS Safety Software
 
Revolutionizing Code Modernization with AI
KrzysztofKkol1
 
Engineering the Java Web Application (MVC)
abhishekoza1981
 
Powering GIS with FME and VertiGIS - Peak of Data & AI 2025
Safe Software
 
Agentic Automation Journey Session 1/5: Context Grounding and Autopilot for E...
klpathrudu
 
Java Native Memory Leaks: The Hidden Villain Behind JVM Performance Issues
Tier1 app
 
Thread In Android-Mastering Concurrency for Responsive Apps.pdf
Nabin Dhakal
 
Linux Certificate of Completion - LabEx Certificate
VICTOR MAESTRE RAMIREZ
 
Automate Cybersecurity Tasks with Python
VICTOR MAESTRE RAMIREZ
 
Feb 2021 Cohesity first pitch presentation.pptx
enginsayin1
 
How Apagen Empowered an EPC Company with Engineering ERP Software
SatishKumar2651
 
GetOnCRM Speeds Up Agentforce 3 Deployment for Enterprise AI Wins.pdf
GetOnCRM Solutions
 
A Complete Guide to Salesforce SMS Integrations Build Scalable Messaging With...
360 SMS APP
 
Tally_Basic_Operations_Presentation.pptx
AditiBansal54083
 
Revenue streams of the Wazirx clone script.pdf
aaronjeffray
 
MiniTool Power Data Recovery Full Crack Latest 2025
muhammadgurbazkhan
 
Mobile CMMS Solutions Empowering the Frontline Workforce
CryotosCMMSSoftware
 
vMix Pro 28.0.0.42 Download vMix Registration key Bundle
kulindacore
 
iTop VPN With Crack Lifetime Activation Key-CODE
utfefguu
 
Build It, Buy It, or Already Got It? Make Smarter Martech Decisions
bbedford2
 

Getting Started with PostGIS

  • 1. © 2015 EnterpriseDB Corporation. All rights reserved. 1 Getting started with PostGIS Adam Wright – Database Consultant
  • 2. © 2015 EnterpriseDB Corporation. All rights reserved. 2 •  Introduction to EDB •  A little bit about Postgres •  About PostGIS •  Geospatial basics •  Now, let us get started •  Maintenance Agenda
  • 3. © 2015 EnterpriseDB Corporation. All rights reserved. 3 POSTGRES innovation ENTERPRISE reliability 24/7 support Services & training Enterprise-class features, tools & compatibility Indemnification Product road-map Control Thousands of developers Fast development cycles Low cost No vendor lock-in Advanced features Enabling commercial adoption of Postgres
  • 4. © 2015 EnterpriseDB Corporation. All rights reserved. 4 Postgres: A Proven Track Record •  Most mature open source DBMS technology •  Enterprise-class features (built like Oracle, DB2, SQL Server) •  Strong, independent community driving rapid innovation 4 Fully ACID Compliant MVCC Point in Time Recovery (PITR)‫‏‬ Data and Index Partitioning Bitmap Indexes ANSI Constraints Triggers & Stored Functions Views & Data Types Nested Transactions Online Backup Online Reorganization Foreign Keys Streaming Replication Multi-Core Support JSON Support Hstore Table Partition Materialized Views Grouping Sets and CUBE (9.5) UPSERT (9.5) Row Level Security (9.5)
  • 5. © 2015 EnterpriseDB Corporation. All rights reserved. 5 Scalable
  • 6. © 2015 EnterpriseDB Corporation. All rights reserved. 6 •  Refractions Research released first version in 2001 under the GNU license •  Follows the Simple Features for SQL specification from the Open Geospatial Consortium (OGC) •  Spatial operators and spatial functions •  Spatial data types •  Spatial indexing •  Spatial reprojection •  Import / Export Esri shapefiles •  Commands for importing raster data •  SQL to render and import data from multiple formats About PostGIS 6
  • 7. © 2015 EnterpriseDB Corporation. All rights reserved. 7 PostGIS Data Types Geometry Geography Raster Topology
  • 8. © 2015 EnterpriseDB Corporation. All rights reserved. 8 PostGIS Data subtypes Point Linestring Polygon Multipoint Multilinestring Multipolygon
  • 9. © 2015 EnterpriseDB Corporation. All rights reserved. 9 Spatial Definitions Examples (1 of 5) Boundary
  • 10. © 2015 EnterpriseDB Corporation. All rights reserved. 10 Spatial Definitions Examples (2 of 5)
  • 11. © 2015 EnterpriseDB Corporation. All rights reserved. 11 Spatial Definitions Examples (3 of 5) Contains
  • 12. © 2015 EnterpriseDB Corporation. All rights reserved. 12 Spatial Definitions Examples (4 of 5) Equals
  • 13. © 2015 EnterpriseDB Corporation. All rights reserved. 13 Spatial Definitions Examples (5 of 5)
  • 14. © 2015 EnterpriseDB Corporation. All rights reserved. 14 •  Repository •  Binary Step 1: Install PostGIS - two methods 14 RedHat ‘yum install postgis2_94’ Debian ‘apt-get install postgres-9.4-postgis’
  • 15. © 2015 EnterpriseDB Corporation. All rights reserved. 15 •  For a New Database CREATE DATABASE geodb WITH template = template_postgis; •  For an Existing Database CREATE EXTENSION postgis; CREATE EXTENSION postgis_toplogy; •  Verify SELECT postgis_version(); Step 2: Enable PostGIS
  • 16. © 2015 EnterpriseDB Corporation. All rights reserved. 16 •  Load shapefiles shp2pgsql –c –s 4629 –I / tmp/ boston_massachusetts_osm_l ine.shp boston_osm_line | pgsql –d geodb •  Inserting a point in SQL INSERT into cities(name,state,geom) Values(‘Boston’,’MA’, ST_GeomFromText(‘POINT(-71 .0589 42.3601)’,4326)); Step 3: Load Data 16
  • 17. © 2015 EnterpriseDB Corporation. All rights reserved. 17 Load data from standard to geospatial 17 INSERT into events_geo(eventname,geom,date) SELECT eventname, st_setsrid(st_makepoint(lon,lat),4326) as geom,date FROM events; Events Table eventname – character varying lat - double precision lon - double precision Date - timestamp with time zone Events_geo Table eventname - character varying geom – geometry (Point,4326) Date – timestamp with time zone INSERT
  • 18. © 2015 EnterpriseDB Corporation. All rights reserved. 18 Visual Inspection of data 18
  • 19. © 2015 EnterpriseDB Corporation. All rights reserved. 19 Visual Inspection of data 19
  • 20. © 2015 EnterpriseDB Corporation. All rights reserved. 20 •  Output geometry data types to other data types SELECT st_astext(geom), st_asgeojson(geom), stasgml(geom) FROM atm_locations LIMIT 1; -[ RECORD 1 ]+---------------------------------- st_astext | POINT(-81.7842060002066 30.2915309995561) st_asgeojson | {"type":"Point","coordinates": [-81.7842060002066,30.2915309995561]} st_asgml | <gml:Point srsName="EPSG: 4629"><gml:coordinates>-81.784206000206609,30.2915309995 5613</gml:coordinates></gml:Point> Geometry Input and Output Functions 20
  • 21. © 2015 EnterpriseDB Corporation. All rights reserved. 21 •  Create geometry type from text Insert into cities (name,state,geom) Values (‘Bedford’,’MA’, ST_GeomFromText(‘POINT(-71.248063 42.510547)’,4326)); Geometry Input and Output Functions 21
  • 22. © 2015 EnterpriseDB Corporation. All rights reserved. 22 •  Write a function to tell whether a given lat/lon pair is within a Point-Radius ring IF ST_Dwithin(check_pt, point_pt, outerRadius) AND NOT ST_Dwithin(chevk_pt, point_pt, innerRadius) THEN return 1; ELSE Return 0; END IF; •  Create a route from a collection of waypoints captured in sequence CREATE TABLE PATHS as SELECT routeid, seq, geom FROM waypoints ORDER BY seq) a GROUP BY routeid; Power of GIS & SQL
  • 23. © 2015 EnterpriseDB Corporation. All rights reserved. 23 •  Simple distance query between two points SELECT ST_Distance (ST_GeomFromText ('POINT(34 9)’,4629), ST_GeomFromText ('POINT(70 12)’,4629)); Power of GIS & SQL 34, 9 70, 12
  • 24. © 2015 EnterpriseDB Corporation. All rights reserved. 24 •  Write a function to tell whether a given lat/lon pair is within a Point-Radius ring IF ST_Dwithin(check_pt, point_pt, outerRadius) AND NOT ST_Dwithin(chevk_pt, point_pt, innerRadius) THEN return 1; ELSE Return 0; END IF; •  Create a route from a collection of waypoints captured in sequence CREATE TABLE PATHS as SELECT routeid, st_make(gem) as geom FROM (SELECT routeid, seq, geom FROM waypoints ORDER BY seq)a GROUP BY routeid; Power of GIS & SQL
  • 25. © 2015 EnterpriseDB Corporation. All rights reserved. 25 •  Answer powerful questions with a simple query −  Input function Insert into cities (name,state,geom) Values (‘Bedford’,’MA’, ST_GeomFromText(‘POINT(-71.248063 42.510547)’, 4326)); Power of GIS & SQL
  • 26. © 2015 EnterpriseDB Corporation. All rights reserved. 26 Power of GIS & SQL
  • 27. © 2015 EnterpriseDB Corporation. All rights reserved. 27 Power of GIS & SQL
  • 28. © 2015 EnterpriseDB Corporation. All rights reserved. 28 Maintenance of a PostGIS database •  After bulk inserts and updates – VACUUM ANALYZE •  Loading large dataset: Build indexes after •  Use EXPLAIN •  Add Indexes on PostGIS columns •  Backup/Recovery and SR considerations
  • 29. © 2015 EnterpriseDB Corporation. All rights reserved. 29 •  Power of Postgres −  Binary replication, Table Partitions, Text search function and operators, PL/SQL, PL/Python, PLV8, PL/R, Indexes −  Grouping sets, cube and rollup (now in EDB Postgres Plus, coming in Postgres 9.5) −  Foreign table inheritance (new in 9.5) •  ogr2ogr •  Web Maps −  Open Layers −  Map Server −  GeoServer Notes:
  • 30. © 2015 EnterpriseDB Corporation. All rights reserved. 30