PostGIS 2PostGIS 2.x Olivier Courtin PostgreSQL Session #6 - 2014 – Paris. PostGIS spatial...

44
PostGIS 2.x Olivier Courtin PostgreSQL Session #6 - 2014 – Paris

Transcript of PostGIS 2PostGIS 2.x Olivier Courtin PostgreSQL Session #6 - 2014 – Paris. PostGIS spatial...

Page 1: PostGIS 2PostGIS 2.x Olivier Courtin PostgreSQL Session #6 - 2014 – Paris. PostGIS spatial database 2.0.0 04/2012 2.1.0 08/2013 Current version: 2.1.4 Coming 2.2. Management Advanced

PostGIS 2.x

Olivier Courtin

PostgreSQL Session #6 - 2014 – Paris

Page 2: PostGIS 2PostGIS 2.x Olivier Courtin PostgreSQL Session #6 - 2014 – Paris. PostGIS spatial database 2.0.0 04/2012 2.1.0 08/2013 Current version: 2.1.4 Coming 2.2. Management Advanced

PostGIS spatial database

2.0.0 04/2012

2.1.0 08/2013

Current version: 2.1.4

Coming 2.2

Page 3: PostGIS 2PostGIS 2.x Olivier Courtin PostgreSQL Session #6 - 2014 – Paris. PostGIS spatial database 2.0.0 04/2012 2.1.0 08/2013 Current version: 2.1.4 Coming 2.2. Management Advanced

Management

Advanced spatial analysis

Topology

Raster

Point Cloud

3D

Page 4: PostGIS 2PostGIS 2.x Olivier Courtin PostgreSQL Session #6 - 2014 – Paris. PostGIS spatial database 2.0.0 04/2012 2.1.0 08/2013 Current version: 2.1.4 Coming 2.2. Management Advanced

Management

Advanced spatial analysis

Topology

Raster

Point Cloud

3D

Page 5: PostGIS 2PostGIS 2.x Olivier Courtin PostgreSQL Session #6 - 2014 – Paris. PostGIS spatial database 2.0.0 04/2012 2.1.0 08/2013 Current version: 2.1.4 Coming 2.2. Management Advanced

CREATE EXTENSION postgis ;

CREATE EXTENSION postgis_topology ;

Page 6: PostGIS 2PostGIS 2.x Olivier Courtin PostgreSQL Session #6 - 2014 – Paris. PostGIS spatial database 2.0.0 04/2012 2.1.0 08/2013 Current version: 2.1.4 Coming 2.2. Management Advanced

geometry_columns (and geography_columns)

are now views (rather than table)

Page 7: PostGIS 2PostGIS 2.x Olivier Courtin PostgreSQL Session #6 - 2014 – Paris. PostGIS spatial database 2.0.0 04/2012 2.1.0 08/2013 Current version: 2.1.4 Coming 2.2. Management Advanced
Page 8: PostGIS 2PostGIS 2.x Olivier Courtin PostgreSQL Session #6 - 2014 – Paris. PostGIS spatial database 2.0.0 04/2012 2.1.0 08/2013 Current version: 2.1.4 Coming 2.2. Management Advanced

UPDATE my_schema.my_table SET geom = ST_CollectionExtract(ST_MakeValid(geom), 3);

Page 9: PostGIS 2PostGIS 2.x Olivier Courtin PostgreSQL Session #6 - 2014 – Paris. PostGIS spatial database 2.0.0 04/2012 2.1.0 08/2013 Current version: 2.1.4 Coming 2.2. Management Advanced

Management

Advanced spatial analysis

Topology

Raster

Point Cloud

3D

Page 10: PostGIS 2PostGIS 2.x Olivier Courtin PostgreSQL Session #6 - 2014 – Paris. PostGIS spatial database 2.0.0 04/2012 2.1.0 08/2013 Current version: 2.1.4 Coming 2.2. Management Advanced

ST_ConvexHull ST_ConcaveHull

Page 11: PostGIS 2PostGIS 2.x Olivier Courtin PostgreSQL Session #6 - 2014 – Paris. PostGIS spatial database 2.0.0 04/2012 2.1.0 08/2013 Current version: 2.1.4 Coming 2.2. Management Advanced

ST_Split

Page 12: PostGIS 2PostGIS 2.x Olivier Courtin PostgreSQL Session #6 - 2014 – Paris. PostGIS spatial database 2.0.0 04/2012 2.1.0 08/2013 Current version: 2.1.4 Coming 2.2. Management Advanced

ST_Snap

Page 13: PostGIS 2PostGIS 2.x Olivier Courtin PostgreSQL Session #6 - 2014 – Paris. PostGIS spatial database 2.0.0 04/2012 2.1.0 08/2013 Current version: 2.1.4 Coming 2.2. Management Advanced
Page 14: PostGIS 2PostGIS 2.x Olivier Courtin PostgreSQL Session #6 - 2014 – Paris. PostGIS spatial database 2.0.0 04/2012 2.1.0 08/2013 Current version: 2.1.4 Coming 2.2. Management Advanced

KNN-GIST: Spatial nearest neighbors

SELECT name, gid FROM geonames ORDER BY geom <-> ST_SetSRID(ST_MakePoint(-90,40),4326) LIMIT 10;

Distance operator: <-> or <#> (center or bbox)

Page 15: PostGIS 2PostGIS 2.x Olivier Courtin PostgreSQL Session #6 - 2014 – Paris. PostGIS spatial database 2.0.0 04/2012 2.1.0 08/2013 Current version: 2.1.4 Coming 2.2. Management Advanced

Management

Advanced spatial analysis

Topology

Raster

Point Cloud

3D

Page 16: PostGIS 2PostGIS 2.x Olivier Courtin PostgreSQL Session #6 - 2014 – Paris. PostGIS spatial database 2.0.0 04/2012 2.1.0 08/2013 Current version: 2.1.4 Coming 2.2. Management Advanced

Topology

node / edge / face model

ISO SQL/MM functions

Source: Sandro Santilli

Page 17: PostGIS 2PostGIS 2.x Olivier Courtin PostgreSQL Session #6 - 2014 – Paris. PostGIS spatial database 2.0.0 04/2012 2.1.0 08/2013 Current version: 2.1.4 Coming 2.2. Management Advanced

Using ST_Simplify without topology

Page 18: PostGIS 2PostGIS 2.x Olivier Courtin PostgreSQL Session #6 - 2014 – Paris. PostGIS spatial database 2.0.0 04/2012 2.1.0 08/2013 Current version: 2.1.4 Coming 2.2. Management Advanced
Page 19: PostGIS 2PostGIS 2.x Olivier Courtin PostgreSQL Session #6 - 2014 – Paris. PostGIS spatial database 2.0.0 04/2012 2.1.0 08/2013 Current version: 2.1.4 Coming 2.2. Management Advanced
Page 20: PostGIS 2PostGIS 2.x Olivier Courtin PostgreSQL Session #6 - 2014 – Paris. PostGIS spatial database 2.0.0 04/2012 2.1.0 08/2013 Current version: 2.1.4 Coming 2.2. Management Advanced
Page 21: PostGIS 2PostGIS 2.x Olivier Courtin PostgreSQL Session #6 - 2014 – Paris. PostGIS spatial database 2.0.0 04/2012 2.1.0 08/2013 Current version: 2.1.4 Coming 2.2. Management Advanced

Rec

urs

ive

CT

E 1

2

3

Page 22: PostGIS 2PostGIS 2.x Olivier Courtin PostgreSQL Session #6 - 2014 – Paris. PostGIS spatial database 2.0.0 04/2012 2.1.0 08/2013 Current version: 2.1.4 Coming 2.2. Management Advanced
Page 23: PostGIS 2PostGIS 2.x Olivier Courtin PostgreSQL Session #6 - 2014 – Paris. PostGIS spatial database 2.0.0 04/2012 2.1.0 08/2013 Current version: 2.1.4 Coming 2.2. Management Advanced

Join result set fromprevious iterationto connected upstreamedges

Stack the gid to the path for this record

Sum up the cost( it's the length here)

If the record gid is alreadyin the path, we have a cycle

Do not take elementswhich make a cycle

Page 24: PostGIS 2PostGIS 2.x Olivier Courtin PostgreSQL Session #6 - 2014 – Paris. PostGIS spatial database 2.0.0 04/2012 2.1.0 08/2013 Current version: 2.1.4 Coming 2.2. Management Advanced

Better limit recursive queriesto avoid unfinite loops

Join CTE results to originaltable to get geometries

Page 25: PostGIS 2PostGIS 2.x Olivier Courtin PostgreSQL Session #6 - 2014 – Paris. PostGIS spatial database 2.0.0 04/2012 2.1.0 08/2013 Current version: 2.1.4 Coming 2.2. Management Advanced
Page 26: PostGIS 2PostGIS 2.x Olivier Courtin PostgreSQL Session #6 - 2014 – Paris. PostGIS spatial database 2.0.0 04/2012 2.1.0 08/2013 Current version: 2.1.4 Coming 2.2. Management Advanced

Management

Advanced spatial analysis

Topology

Raster

Point Cloud

3D

Page 27: PostGIS 2PostGIS 2.x Olivier Courtin PostgreSQL Session #6 - 2014 – Paris. PostGIS spatial database 2.0.0 04/2012 2.1.0 08/2013 Current version: 2.1.4 Coming 2.2. Management Advanced

● Raster / vector analysis● New raster datatype (using tiles)● Multiresolution, multiband, tile coverage● Import/export (GDAL)● Raster functions

Page 28: PostGIS 2PostGIS 2.x Olivier Courtin PostgreSQL Session #6 - 2014 – Paris. PostGIS spatial database 2.0.0 04/2012 2.1.0 08/2013 Current version: 2.1.4 Coming 2.2. Management Advanced

Source: Pierre Racine

Page 29: PostGIS 2PostGIS 2.x Olivier Courtin PostgreSQL Session #6 - 2014 – Paris. PostGIS spatial database 2.0.0 04/2012 2.1.0 08/2013 Current version: 2.1.4 Coming 2.2. Management Advanced

Source: Pierre Racine

Page 30: PostGIS 2PostGIS 2.x Olivier Courtin PostgreSQL Session #6 - 2014 – Paris. PostGIS spatial database 2.0.0 04/2012 2.1.0 08/2013 Current version: 2.1.4 Coming 2.2. Management Advanced

Management

Advanced spatial analysis

Topology

Raster

Point Cloud

3D

Page 31: PostGIS 2PostGIS 2.x Olivier Courtin PostgreSQL Session #6 - 2014 – Paris. PostGIS spatial database 2.0.0 04/2012 2.1.0 08/2013 Current version: 2.1.4 Coming 2.2. Management Advanced

As PostgreSQL and PostGIS extension

Handle Patches

Arbitrary dimension handling

Data compression

PDAL (as a loader)

Page 32: PostGIS 2PostGIS 2.x Olivier Courtin PostgreSQL Session #6 - 2014 – Paris. PostGIS spatial database 2.0.0 04/2012 2.1.0 08/2013 Current version: 2.1.4 Coming 2.2. Management Advanced

Management

Advanced spatial analysis

Topology

Raster

Point Cloud

3D

Page 33: PostGIS 2PostGIS 2.x Olivier Courtin PostgreSQL Session #6 - 2014 – Paris. PostGIS spatial database 2.0.0 04/2012 2.1.0 08/2013 Current version: 2.1.4 Coming 2.2. Management Advanced

PostGIS

GEOS SFCGAL

CGAL

Page 34: PostGIS 2PostGIS 2.x Olivier Courtin PostgreSQL Session #6 - 2014 – Paris. PostGIS spatial database 2.0.0 04/2012 2.1.0 08/2013 Current version: 2.1.4 Coming 2.2. Management Advanced
Page 35: PostGIS 2PostGIS 2.x Olivier Courtin PostgreSQL Session #6 - 2014 – Paris. PostGIS spatial database 2.0.0 04/2012 2.1.0 08/2013 Current version: 2.1.4 Coming 2.2. Management Advanced

ST_3DIntersection

ST_Tesselate

ST_3DArea

ST_Extrude

ST_ForceLHR

ST_Orientation

ST_MinkowskiSum

ST_StraightSkeleton

SFCGAL functions

Page 36: PostGIS 2PostGIS 2.x Olivier Courtin PostgreSQL Session #6 - 2014 – Paris. PostGIS spatial database 2.0.0 04/2012 2.1.0 08/2013 Current version: 2.1.4 Coming 2.2. Management Advanced
Page 37: PostGIS 2PostGIS 2.x Olivier Courtin PostgreSQL Session #6 - 2014 – Paris. PostGIS spatial database 2.0.0 04/2012 2.1.0 08/2013 Current version: 2.1.4 Coming 2.2. Management Advanced

2D Building Footprint

Straight Skeleton Extrusion & roof computation

Page 38: PostGIS 2PostGIS 2.x Olivier Courtin PostgreSQL Session #6 - 2014 – Paris. PostGIS spatial database 2.0.0 04/2012 2.1.0 08/2013 Current version: 2.1.4 Coming 2.2. Management Advanced

ST_Intersects

ST_3DIntersects

ST_Intersection

ST_Area

ST_Distance

ST_3DDistance

Both GEOS & SFCGAL

Page 39: PostGIS 2PostGIS 2.x Olivier Courtin PostgreSQL Session #6 - 2014 – Paris. PostGIS spatial database 2.0.0 04/2012 2.1.0 08/2013 Current version: 2.1.4 Coming 2.2. Management Advanced

SET postgis.backend = 'geos' ;

SET postgis.backend = 'sfcgal' ;

Page 40: PostGIS 2PostGIS 2.x Olivier Courtin PostgreSQL Session #6 - 2014 – Paris. PostGIS spatial database 2.0.0 04/2012 2.1.0 08/2013 Current version: 2.1.4 Coming 2.2. Management Advanced

SFCGAL perfomances similar to GEOS ones for 2D

(but with SFCGAL we gain arbitrary precision)

Page 41: PostGIS 2PostGIS 2.x Olivier Courtin PostgreSQL Session #6 - 2014 – Paris. PostGIS spatial database 2.0.0 04/2012 2.1.0 08/2013 Current version: 2.1.4 Coming 2.2. Management Advanced

SFCGAL perfomances similar to GEOS ones for 2D

(but with SFCGAL we gain arbitrary precision)

But some 3D computation could take time.

Page 42: PostGIS 2PostGIS 2.x Olivier Courtin PostgreSQL Session #6 - 2014 – Paris. PostGIS spatial database 2.0.0 04/2012 2.1.0 08/2013 Current version: 2.1.4 Coming 2.2. Management Advanced

https://vimeo.com/74869530

Page 43: PostGIS 2PostGIS 2.x Olivier Courtin PostgreSQL Session #6 - 2014 – Paris. PostGIS spatial database 2.0.0 04/2012 2.1.0 08/2013 Current version: 2.1.4 Coming 2.2. Management Advanced

https://vimeo.com/105323534

Page 44: PostGIS 2PostGIS 2.x Olivier Courtin PostgreSQL Session #6 - 2014 – Paris. PostGIS spatial database 2.0.0 04/2012 2.1.0 08/2013 Current version: 2.1.4 Coming 2.2. Management Advanced

www.oslandia.com

http://www.postgresql-sessions.org/6/start