+ All Categories
Home > Technology > Chris Hill RPS Postgis threeoutoffouraintbad 20150505

Chris Hill RPS Postgis threeoutoffouraintbad 20150505

Date post: 20-Jul-2015
Category:
Upload: ross-mcdonald
View: 78 times
Download: 5 times
Share this document with a friend
5
rpsgroup.com/ rpsgroup.com/ rpsgroup.com/ rpsgroup.com/uk uk uk uk PostGIS: three out of four ain’t bad Chris Hill 05 May 2015 A slide from 11 years ago… A slide from 11 years ago… A slide from 11 years ago… A slide from 11 years ago… PostgreSQL/ PostgreSQL/ PostgreSQL/ PostgreSQL/PostGIS PostGIS PostGIS PostGIS It’s a relational database We’ll look at this… Use QGIS or st_astext() We’ll look at this too… W W Why you should use hy you should use hy you should use hy you should use PostGIS PostGIS PostGIS PostGIS over a desktop GIS over a desktop GIS over a desktop GIS 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
Transcript

rpsgroup.com/rpsgroup.com/rpsgroup.com/rpsgroup.com/ukukukuk

PostGIS: three out

of four ain’t badChris Hill

05 May 2015

A slide from 11 years ago…A slide from 11 years ago…A slide from 11 years ago…A slide from 11 years ago…

PostgreSQL/PostgreSQL/PostgreSQL/PostgreSQL/PostGISPostGISPostGISPostGIS

✓ It’s a relational database

✓ We’ll look at this…

✘ Use QGIS or st_astext()

✓ We’ll look at this too…

WWWWhy you should use hy you should use hy you should use hy you should use PostGISPostGISPostGISPostGIS over a desktop GISover a desktop GISover a desktop GISover 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

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 My top 20 My top 20 My top 20 PostGISPostGISPostGISPostGIS functionsfunctionsfunctionsfunctions Fuzzy polygon matching 1Fuzzy polygon matching 1Fuzzy polygon matching 1Fuzzy polygon matching 1

Fuzzy polygon matching Fuzzy polygon matching Fuzzy polygon matching Fuzzy polygon matching 2222

--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?Perhaps use the logic of all three options?Perhaps use the logic of all three options?Perhaps use the logic of all three options?

select a.poly_id, b.poly_id from

dodgypolys1 a,

dodgypolys2 b

where

Measuring closest distances 1Measuring closest distances 1Measuring closest distances 1Measuring 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 2Measuring closest distances 2Measuring closest distances 2Measuring 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 1Create simple transects 1Create simple transects 1Create simple transects 1

Create simple transects 2Create simple transects 2Create simple transects 2Create simple transects 2with

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 rotationCreate simple transects 3: add rotationCreate simple transects 3: add rotationCreate simple transects 3: add rotation

Create simple transects 4: add rotationCreate simple transects 4: add rotationCreate simple transects 4: add rotationCreate 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 directionalityCreate simple transects 5: add directionalityCreate simple transects 5: add directionalityCreate simple transects 5: add directionality

Create simple transects 6: add directionalityCreate simple transects 6: add directionalityCreate simple transects 6: add directionalityCreate simple transects 6: add directionality

update transects2

set geom = st_reverse(geom)

where line_id % 2 = 0;

Homework: to make the rays you might use…Homework: to make the rays you might use…Homework: to make the rays you might use…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()


Recommended