SlideShare a Scribd company logo
rpsgroup.com/uk
PostGIS: three out
of four ain’t bad
Chris Hill
05 May 2015
A slide from 11 years ago…
PostgreSQL/PostGIS
✓ It’s a relational database
✓ We’ll look at this…
✘ Use QGIS or st_astext()
✓ We’ll look at this too…
Why you should use PostGIS over a desktop GIS
• Spatial and attribute querying together
• Permits advanced joins
• Aggregate (group by) functions
• Transcript of all work done
• Scripting in SQL
– Repeatability
– Enforced documenting of processes
• Good raster/vector integration
• Can link to R, Python, QGIS…
Will it take longer than a desktop GIS?
– Possibly, if you only do something once
Chris hill rps_postgis_threeoutoffouraintbad_20150505_1
st_intersects 703
st_transform 461
st_union 454
st_length 435
st_buffer 386
st_area 362
st_centroid 307
st_setsrid 280
st_y 257
st_startpoint 255
st_x 244
st_endpoint 232
st_makevalid 225
st_buildarea 212
st_dump 198
st_intersection 180
st_collect 176
st_azimuth 168
st_makeline 143
st_makepoint 121
Analysis functions
Management functions
My top 20 PostGIS functions
Fuzzy polygon matching 1
Fuzzy polygon matching 2
--This works nicely (in this case)
st_intersects(st_centroid(a.geom),b.geom);
--But for holes or very irregular polygons try
st_intersects(st_pointonsurface(a.geom),b.geom);
--first attempt (will be greedy)
st_intersects(a.geom,b.geom);
Perhaps use the logic of all three options?
select a.poly_id, b.poly_id from
dodgypolys1 a,
dodgypolys2 b
where
Measuring closest distances 1
Copyright Scottish Natural Heritage Contains Ordnance Survey data © Crown copyright and database right 2015
Contains Ordnance Survey data © Crown copyright and database right 2015
Measuring closest distances 2
Optionally create a view UNIONing all target polygons together
with turbines1 as (select st_union(geom) as
geom from turbines)
copy (
select b.designation, b.name,
st_distance(a.geom, b.geom) from
turbines1 a,
designations b
where st_dwithin(a.geom,b.geom,20000)
order by 3
) to E'C:designationsWithin20km.csv' with csv
header;
Create simple transects 1
Create simple transects 2
with
linetemplate as
(select st_geomFromText('LINESTRING(0 0,0 10)')
as geom),
x_intervals as
(select generate_series(0,10,2) as deltax)
create table transects1 as
select deltax,
st_translate(geom,deltax,0) as geom
from
linetemplate
cross join
x_intervals;
Create simple transects 3: add rotation
Create simple transects 4: add rotation
create table transects2 as
with lines1 as
(select st_union(geom)as geom from transects1)
select
(st_dump(
st_rotate(geom,radians(45), st_centroid(geom))
)).geom as geom
from lines1;
alter table transects2
add column line_id serial;
Create simple transects 5: add directionality
Create simple transects 6: add directionality
update transects2
set geom = st_reverse(geom)
where line_id % 2 = 0;
Chris hill rps_postgis_threeoutoffouraintbad_20150505_1
Homework: to make the rays you might use…
st_makeline()
st_length()
generate_series()
ST_Line_Interpolate_Point()
st_exteriorring()
st_buffer()
CROSS JOIN
st_makepoint()
Chris hill rps_postgis_threeoutoffouraintbad_20150505_1

More Related Content

PDF
2016 SMU Research Day
PDF
Plotting position and velocity
PPTX
Geek Sync | Having Fun with Spatial Data
PDF
Pgrouting_foss4guk_ross_mcdonald
PDF
8th TUC Meeting | Lijun Chang (University of New South Wales). Efficient Subg...
PDF
Creating and indoor routable network with QGIS and pgRouting
PPTX
GeoTuple a Framework for Web Based Geo-Analytics with R and PostGIS
PDF
Javascript Array map method
2016 SMU Research Day
Plotting position and velocity
Geek Sync | Having Fun with Spatial Data
Pgrouting_foss4guk_ross_mcdonald
8th TUC Meeting | Lijun Chang (University of New South Wales). Efficient Subg...
Creating and indoor routable network with QGIS and pgRouting
GeoTuple a Framework for Web Based Geo-Analytics with R and PostGIS
Javascript Array map method

What's hot (20)

ODP
Intro To PostGIS
PDF
Data visualization using the grammar of graphics
ODP
Introduction To PostGIS
PDF
Data visualization with multiple groups using ggplot2
PDF
Geo CO - RTD Denver
ODP
OSRM - Open Source Routing Machine
PPT
Algorithm to count number of disjoint paths
PPTX
Day 6 - PostGIS
PDF
Geo Spatial Plot using R
ODP
OSM Cycle Map
PPTX
Formalising paging in memory management
PPT
Thematic mapping at AGU 2008
PDF
It Jam 2009
PPTX
Making data storage more efficient
KEY
触地図自動作成システム「tmacs」の開発
PPTX
carry maskable look ahead adder for approximate computing
PDF
Circos
PPT
Spatial SQL
DOCX
Gis (model questions)777
PDF
Quantum espresso G Vector distributon
Intro To PostGIS
Data visualization using the grammar of graphics
Introduction To PostGIS
Data visualization with multiple groups using ggplot2
Geo CO - RTD Denver
OSRM - Open Source Routing Machine
Algorithm to count number of disjoint paths
Day 6 - PostGIS
Geo Spatial Plot using R
OSM Cycle Map
Formalising paging in memory management
Thematic mapping at AGU 2008
It Jam 2009
Making data storage more efficient
触地図自動作成システム「tmacs」の開発
carry maskable look ahead adder for approximate computing
Circos
Spatial SQL
Gis (model questions)777
Quantum espresso G Vector distributon
Ad

Similar to Chris hill rps_postgis_threeoutoffouraintbad_20150505_1 (20)

PDF
Getting Started with PostGIS
 
PPT
Stockage, manipulation et analyse de données matricielles avec PostGIS Raster
PDF
QGIS training class 3
PDF
Postgres Vision 2018: PostGIS and Spatial Extensions
 
PPT
LinuxFest NW - Using Postgis To Add Some Spatial Flavor To Your App
PDF
State of the Art Web Mapping with Open Source
PDF
Opensource gis development - part 2
PDF
2017 RM-URISA Track: Spatial SQL - The Best Kept Secret in the Geospatial World
PPT
remote sesing resolution for satelitte imag
PDF
Post gispguk
PDF
Kaggle Winning Solution Xgboost algorithm -- Let us learn from its author
PDF
Location Analytics Real-Time Geofencing using Kafka
PDF
Working with spatial trajectories in Boost Geometry
PDF
"Optimization of a .NET application- is it simple ! / ?", Yevhen Tatarynov
PDF
Aileen heal postgis osmm cou
KEY
Handling Real-time Geostreams
KEY
Handling Real-time Geostreams
PDF
Covering the earth and the cloud the next generation of spatial in sql server...
ODP
Scaling PostgreSQL With GridSQL
PPTX
LocationTech Projects
Getting Started with PostGIS
 
Stockage, manipulation et analyse de données matricielles avec PostGIS Raster
QGIS training class 3
Postgres Vision 2018: PostGIS and Spatial Extensions
 
LinuxFest NW - Using Postgis To Add Some Spatial Flavor To Your App
State of the Art Web Mapping with Open Source
Opensource gis development - part 2
2017 RM-URISA Track: Spatial SQL - The Best Kept Secret in the Geospatial World
remote sesing resolution for satelitte imag
Post gispguk
Kaggle Winning Solution Xgboost algorithm -- Let us learn from its author
Location Analytics Real-Time Geofencing using Kafka
Working with spatial trajectories in Boost Geometry
"Optimization of a .NET application- is it simple ! / ?", Yevhen Tatarynov
Aileen heal postgis osmm cou
Handling Real-time Geostreams
Handling Real-time Geostreams
Covering the earth and the cloud the next generation of spatial in sql server...
Scaling PostgreSQL With GridSQL
LocationTech Projects
Ad

Recently uploaded (20)

PPTX
Oracle Fusion HCM Cloud Demo for Beginners
PDF
Designing Intelligence for the Shop Floor.pdf
PDF
Internet Downloader Manager (IDM) Crack 6.42 Build 41
PPTX
Agentic AI Use Case- Contract Lifecycle Management (CLM).pptx
PDF
Nekopoi APK 2025 free lastest update
PDF
Internet Downloader Manager (IDM) Crack 6.42 Build 42 Updates Latest 2025
PDF
How to Make Money in the Metaverse_ Top Strategies for Beginners.pdf
PDF
Product Update: Alluxio AI 3.7 Now with Sub-Millisecond Latency
PPTX
history of c programming in notes for students .pptx
PPTX
WiFi Honeypot Detecscfddssdffsedfseztor.pptx
PPTX
Log360_SIEM_Solutions Overview PPT_Feb 2020.pptx
PDF
CCleaner Pro 6.38.11537 Crack Final Latest Version 2025
PDF
Download FL Studio Crack Latest version 2025 ?
PPTX
Patient Appointment Booking in Odoo with online payment
PPTX
CHAPTER 2 - PM Management and IT Context
PDF
Design an Analysis of Algorithms I-SECS-1021-03
PDF
How AI/LLM recommend to you ? GDG meetup 16 Aug by Fariman Guliev
PDF
Adobe Premiere Pro 2025 (v24.5.0.057) Crack free
PDF
Adobe Illustrator 28.6 Crack My Vision of Vector Design
PDF
AI-Powered Threat Modeling: The Future of Cybersecurity by Arun Kumar Elengov...
Oracle Fusion HCM Cloud Demo for Beginners
Designing Intelligence for the Shop Floor.pdf
Internet Downloader Manager (IDM) Crack 6.42 Build 41
Agentic AI Use Case- Contract Lifecycle Management (CLM).pptx
Nekopoi APK 2025 free lastest update
Internet Downloader Manager (IDM) Crack 6.42 Build 42 Updates Latest 2025
How to Make Money in the Metaverse_ Top Strategies for Beginners.pdf
Product Update: Alluxio AI 3.7 Now with Sub-Millisecond Latency
history of c programming in notes for students .pptx
WiFi Honeypot Detecscfddssdffsedfseztor.pptx
Log360_SIEM_Solutions Overview PPT_Feb 2020.pptx
CCleaner Pro 6.38.11537 Crack Final Latest Version 2025
Download FL Studio Crack Latest version 2025 ?
Patient Appointment Booking in Odoo with online payment
CHAPTER 2 - PM Management and IT Context
Design an Analysis of Algorithms I-SECS-1021-03
How AI/LLM recommend to you ? GDG meetup 16 Aug by Fariman Guliev
Adobe Premiere Pro 2025 (v24.5.0.057) Crack free
Adobe Illustrator 28.6 Crack My Vision of Vector Design
AI-Powered Threat Modeling: The Future of Cybersecurity by Arun Kumar Elengov...

Chris hill rps_postgis_threeoutoffouraintbad_20150505_1

  • 1. rpsgroup.com/uk PostGIS: three out of four ain’t bad Chris Hill 05 May 2015
  • 2. A slide from 11 years ago… PostgreSQL/PostGIS ✓ It’s a relational database ✓ We’ll look at this… ✘ Use QGIS or st_astext() ✓ We’ll look at this too…
  • 3. Why you should use PostGIS over a desktop GIS • Spatial and attribute querying together • Permits advanced joins • Aggregate (group by) functions • Transcript of all work done • Scripting in SQL – Repeatability – Enforced documenting of processes • Good raster/vector integration • Can link to R, Python, QGIS… Will it take longer than a desktop GIS? – Possibly, if you only do something once
  • 5. st_intersects 703 st_transform 461 st_union 454 st_length 435 st_buffer 386 st_area 362 st_centroid 307 st_setsrid 280 st_y 257 st_startpoint 255 st_x 244 st_endpoint 232 st_makevalid 225 st_buildarea 212 st_dump 198 st_intersection 180 st_collect 176 st_azimuth 168 st_makeline 143 st_makepoint 121 Analysis functions Management functions My top 20 PostGIS functions
  • 7. Fuzzy polygon matching 2 --This works nicely (in this case) st_intersects(st_centroid(a.geom),b.geom); --But for holes or very irregular polygons try st_intersects(st_pointonsurface(a.geom),b.geom); --first attempt (will be greedy) st_intersects(a.geom,b.geom); Perhaps use the logic of all three options? select a.poly_id, b.poly_id from dodgypolys1 a, dodgypolys2 b where
  • 8. Measuring closest distances 1 Copyright Scottish Natural Heritage Contains Ordnance Survey data © Crown copyright and database right 2015 Contains Ordnance Survey data © Crown copyright and database right 2015
  • 9. Measuring closest distances 2 Optionally create a view UNIONing all target polygons together with turbines1 as (select st_union(geom) as geom from turbines) copy ( select b.designation, b.name, st_distance(a.geom, b.geom) from turbines1 a, designations b where st_dwithin(a.geom,b.geom,20000) order by 3 ) to E'C:designationsWithin20km.csv' with csv header;
  • 11. Create simple transects 2 with linetemplate as (select st_geomFromText('LINESTRING(0 0,0 10)') as geom), x_intervals as (select generate_series(0,10,2) as deltax) create table transects1 as select deltax, st_translate(geom,deltax,0) as geom from linetemplate cross join x_intervals;
  • 12. Create simple transects 3: add rotation
  • 13. Create simple transects 4: add rotation create table transects2 as with lines1 as (select st_union(geom)as geom from transects1) select (st_dump( st_rotate(geom,radians(45), st_centroid(geom)) )).geom as geom from lines1; alter table transects2 add column line_id serial;
  • 14. Create simple transects 5: add directionality
  • 15. Create simple transects 6: add directionality update transects2 set geom = st_reverse(geom) where line_id % 2 = 0;
  • 17. Homework: to make the rays you might use… st_makeline() st_length() generate_series() ST_Line_Interpolate_Point() st_exteriorring() st_buffer() CROSS JOIN st_makepoint()