Vous êtes sur la page 1sur 47

1

PostGIS:
A Standards Based
Geographic Extension
for PostgreSQL
Frank Warmerdam
President, OSGeo
Open Source Geospat i al Foundat i on 2
Overview
Bri ef background
Post GIS Det ai ls
Post GIS Examples
Survey of Simpl e Feat ures 1.1 Geomet ri es
Si mple Feat ures 1.2 Geomet ry
A survey of si mple f eat ures based sof t ware
Comment ary
Open Source Geospat i al Foundat i on 3
What is a Spatial Database?
Support f or a Geomet ry Type
Indexing f or t he Geomet ry Type
Funct i ons f or t he Geomet ry Type
Dat abase t hat can answer GIS quest ions:
qui ckly
on l arge vol umes of dat a
Open Source Geospat i al Foundat i on 4
Why a Spatial Database?
(instead of just using files)
Transact i onal Int egrit y
Mul t iple Users, Mult i pl e Edit s
Uni f ied St orage, Management , Access
SQL Everywhere
Because Dat abases are Bet t er t han Fi les
NOT!
5
Database
Guys
Unified Storage
Corporate
Database
GIS
Files
GIS
Guys
Open Source Geospat i al Foundat i on 6
PostGS
Geographic Ext ension f or Post greSQL
Based on OGC Si mple Feat ures f or SQL
By Ref ract i ons Research (Vict oria,BC)
Fi rst rel ease in 2001
GPL l icensed (l ikel y why not i n mai n src t ree)
R- Tree- over- Gi ST used f or spat ial index
Int roduces:
new geomet ry t ypes
many new f unct i ons
new support t abl es
ht t p:/ / www.post gi s.org
Open Source Geospat i al Foundat i on 7
So!e Geo!etry "un#tions
Area(POLYGON)
Di st ance(GEOMETRY,GEOMETRY)
Cont ains(GEOMETRY,GEOMETRY)
Int ersect ion(GEOMETRY,GEOMETRY)
Int ersect s(GEOMETRY,GEOMETRY)
Uni on(GEOMETRY,GEOMETRY)
Buf f er(GEOMETRY,doubl e)
ConvexHull (GEOMETRY)
Perimet er(GEOMETRY)
Crosses(GEOMETRY,GEOMETRY)
Transf orm(GEOMETRY,i nt egerSRID)
Open Source Geospat i al Foundat i on 8
So!e $##essor "un#tions
Di mensi on(GEOMETRY)
AsText (GEOMETRY)
ST_X(POINT)
ST_Y(POINT)
NumPoi nt s(GEOMETRY)
Point N(GEOMETRY,i nt eger)
NumGeomet ri es(GEOMETRY)
Geomet ryN(GEOMETRY,i nt eger)
Geomet ryType(GEOMETRY)
Open Source Geospat i al Foundat i on 9
GS %uestions
How many peopl e l ive wit hi n 5 mi l es of t he
t oxi c gas l eak?
SELECT sum(popul at ion)
FROM census_t racks
WHERE
di st ance(census_geom,
'POINT(210030 3731201)')
< (5 * 1609.344)
Open Source Geospat i al Foundat i on 10
GS %uestions
What is t he area of muni ci pal parks inside t he
West side nei ghbourhood?
SELECT sum(area(park_geom))
FROM parks, nhoods
WHERE
cont ai ns(nd_geom,park_geom)
AND nhood_name = 'West si de'
Open Source Geospat i al Foundat i on 11
GS %uestions
What is t he maximum di st ance a st udent has
t o t ravel t o school ?
SELECT
max(dist ance(st udent _l ocat i on,
school_locat i on))
FROM st udent s, school s
WHERE st udent s.school _id = schools.i d;
Open Source Geospat i al Foundat i on 12
&reate a 'able Si!ply
CREATE TABLE ROADS
(ID i nt 4,
NAME varchar(255),
GEOM geomet ry)

Open Source Geospat i al Foundat i on 13
&reate a 'able Properly
CREATE TABLE ROADS
(ID i nt 4,
NAME varchar(255))
SELECT AddGeomet ryCol umn
('roads','geom',423,'LINESTRING',2)
'roads': Table name
'geom': Geomet ry col umn name
423: SRID (coordinat e syst em)
'LINESTRING': geomet ry t ype const raint
2: Di mension

Open Source Geospat i al Foundat i on 14
nsert Data
INSERT INTO roads
( road_i d, road_geom, road_name)
VALUES
(1,
GeomFromText (
'LINESTRING(19123 24311,19110 23242)',
242),
'Jef f Rd.')
Open Source Geospat i al Foundat i on 15
Spatial nde(
CREATE INDEX roads_geom_index
ON roads
USING GIST(geom)
Open Source Geospat i al Foundat i on 16
geo!etry)#olu!ns
CREATE TABLE geometry_columns (
f_table_catalog VARRCHAR(256) NOT NULL,
f_table_schema VARCHAR(256) NOT NULL,
f_table_name VARCHAR(256) NOT NULL,
f_geometry_column VARCHAR(256) NOT NULL,
coord_dimension INTEGER NOT NULL,
srid INTEGER NOT NULL,
type VARCHAR(30) NOT NULL
)
par t of OGC s pecificat ion
impor t ant t o s pat ial applicat ions
fr om AddGeomet r yColumn()
Open Source Geospat i al Foundat i on 17
spatial)ref)sys
CREATE TABLE spatial_ref_sys (
srid INTEGER NOT NULL PRIMARY KEY,
auth_name VARCHAR(256),
auth_srid INTEGER,
srtext VARCHAR(2048),
proj4text VARCHAR(2048)
)
Defines Coor dinat e Sys t em
Par t of OGC s pecificat ion
Impor t ant t o s pat ial applicat ions
Lis t is pr epopulat ed
Open Source Geospat i al Foundat i on 18
PostGS $ppli#ation Support
Web Mapping:
MapServer, MapGuide, GeoServer
Deskt op GIS :
Udig, QGIS, JUMP, GRASS
Propri et ary GIS:
Cadcorp SIS, ArcGIS 9.3(?)
ETL:
FME, GDAL/ OGR
Open Source Geospat i al Foundat i on 19
PostGS nstallation
Included i n st andard Post greSQL Wi n Inst aller
(buried back i n t he ext ra packages)
Post greSQL+ Post GIS MacOS X bi naries
avai l able
El sewhere i nst al li ng f rom source pret t y easy
Opt ional ly depends on GEOS and PROJ..4
Two SQL script s need t o be run t o set up
post gis t ypes, and set up support t abl es
Open Source Geospat i al Foundat i on 20
OG& and Si!ple "eatures
OGC i s t he Open Geospat i al Consort i um
Coll aborat ive devel opment of specif i cat i ons
f or geospat i al servi ces
Indust ry dri ven
About Open St andards, not Open Source
Si mple Feat ures
Abst ract geomet ry model
Base of Si mpl e Feat ures f or SQL
Fi rst concret e OGC spec (mid 90's)
Open Source Geospat i al Foundat i on 21
Si!ple "eatures Geo!etries (*+,)
Open Source Geospat i al Foundat i on 22
Point
2D (x,y) poi nt l ocat i on
WKT (Wel l Known Text ) Represent at i on:
POINT(- 117.25 35.0)
Open Source Geospat i al Foundat i on 23
-ine String
Chai n of poi nt l ocat i on
No rest ri ct i ons on sel f - i nt ersect i on
Dupl i cat e poi nt s ok
LINESTRING(0 10, 20 15, 30 15)
Open Source Geospat i al Foundat i on 24
-ine String
Open Source Geospat i al Foundat i on 25
Polygon
Pol ygon wi t h one out er ri ng, and zero or
more i nner ri ngs (hol es)
Pol ygons are cl osed (l ast poi nt of ri ng
equal s f i rst poi nt )
Ri ngs may not cross
Ri ngs may t ouch
Pol ygon i nt eri or i s a connect ed poi nt set
Wi ndi ng di rect i on of ri ngs not si gni f i cant
POLYGON((0 0,10 10,10 0,0 0),
(3 1,4 1,4 2,3 1))
Open Source Geospat i al Foundat i on 26
Polygon
Open Source Geospat i al Foundat i on 27
Polygon
Open Source Geospat i al Foundat i on 28
.ulti/Polygon
A col l ect i on of pol ygons
May be nest ed (and i sl and i n a l ake)
May not be overl appi ng
May t ouch at a poi nt
May not t ouch al ong an edge
MULTIPOLYGON(((0 0,10 10,10 0,0 0),
(3 1,4 1,4 2, 3 1)),
((20 20, 30 30, 30 20, 20 20)))
Open Source Geospat i al Foundat i on 29
.ulti/Polygon
Open Source Geospat i al Foundat i on 30
.ulti/Polygon
Open Source Geospat i al Foundat i on 31
.ulti -ine String
A col l ect i on of l i nest ri ngs
MULTILINESTRING((0 0,10 10,10 0),
(3 1,4 1,4 2,5 1))
Open Source Geospat i al Foundat i on 32
.ulti Point
A col l ect i on of poi nt s
MULTIPOINT((0 0),(10 10),(10 0))
Open Source Geospat i al Foundat i on 33
Geo!etry &olle#tion
A col l ect i on of geomet ri es
GEOMETRYCOLLECTION(
POINT(0 5),
LINESTRING(3 5, 2 9, 1 3),
POLYGON((0 0, 10 10, 10 0, 0 0)))

Open Source Geospat i al Foundat i on 34
Si!ple "eatures Geo!etries (*+,)
Open Source Geospat i al Foundat i on 35
Si!ple "eatures *+0
Ext ends vert i ces t o 3D/ 4D (Z/ Measure)
Geomet ri c operat i ons done i n 2D
Adds Pol yhedral Surf ace
Adds TIN
Al t ers def act o 3D/ 4D WKT/ WKB f ormat s
Adds Annot at i on Text t o f eat ure model

Open Source Geospat i al Foundat i on 36
Polyhedral Surfa#e
A surf ace consi st i ng of adj acent pol ygons
St ored as col l ect i on of pol ygons
TIN i s speci al case, al l t ri angl es
POLYHEDRALSURFACE(
((0 10,0 0,10 0,10 10,0 10)),
((0 10,5 15, 10 10,0 10)))

Open Source Geospat i al Foundat i on 37
S%-/..
ISO SQL Geomet ry Speci f i cat i on
SF 1.2 al i gned wi t h SQL- MM
Post GIS support s t hese SQL- MM t ypes:
Ci rcul arSt ri ng (arcs of a ci rcl e)
CompoundCurve (arcs+ l i nest ri ngs)
CompoundSurf ace (curved pol ygons)
Mul t i Curve
Mul t i Surf ace
SQL- MM al so addresses t opol ogy,
net works, di rect i ons, angl es, ...

Open Source Geospat i al Foundat i on 38
S%-/..1 &ir#ularString
A st ri ng of part i al ci rcl e arcs connect ed
end t o end (a Li neSt ri ng of arcs)
Each arc def i ned by t hree poi nt s
arc st art
a poi nt on t he arc
arc end
Whol e ci rcl es have same f i rst / l ast and t he
mi ddl e poi nt i s opposi t e si de of ci rcl e
CIRCULARSTRING( 0 0, 1 1, 1 0)

Open Source Geospat i al Foundat i on 39
S%-/..1 &ir#ularString


Open Source Geospat i al Foundat i on 40
Software Survey
OGC Si mpl e Feat ures 1.0 f or SQL
Post gres/ Post GIS:Ful l i mpl ement at i on
i ncl udi ng al l geomet ry f unct i ons
MySQL: Support s geomet ry, and spat i al
i ndexi ng, very l i mi t ed addi t i onal f unct i ons
Oracl e: Apparent l y compl i ant , many
ext ensi ons
MSSQL: Support s geomet ry, spat i al
i ndexi ng, very l i mi t ed addi t i onal f unct i ons
Spat i al Li t e: Part i al SFSQL.
Ingres: Bei ng i mpl ement ed! 1.2?

Open Source Geospat i al Foundat i on 41
Software Survey
Si mpl e Feat ures based/ i nspi red:
OGR: Geomet ry i s Si mpl e Feat ures 1.0
FDO: Geomet ry i s ext ensi on of SF
QGIS: Geomet ry i s Si mpl e Feat ures 1.0
SDE: Cl ose t o SF + ext ensi ons
GEOS: SF 1.0 geomet ry model
Not Si mpl e Feat ures:
MapServer, OpenEV, GRASS
MapInf o, Mi crost at i on
Open Source Geospat i al Foundat i on 42
"or!at Survey
GML: Geomet ry i s SF (+ ext ensi ons i n 3?)
Shapef i l e: Not si mpl e f eat ures
Mapi nf o: Not si mpl e f eat ures
Most maj or GIS product s do not exact l y
map t o Si mpl e Feat ures, t hough t hey may
be si mi l ar.
Open Source Geospat i al Foundat i on 43
S"1 What is !issing?
Nonl i near curves (el l i pse/ spl i ne/ et c)
3D sol i ds
Topol ogy
Non- pl anar surf aces
Represent at i on
Open Source Geospat i al Foundat i on 44
Universal Geo!etry .odel for GS?
No, because:
l ack of real curves, hampers CAD l i nks
l ack of t opol ogy
Yes, because:
Underst andabl e
Li ngua f ranca f or i nt erchange/ di scussi on
Wi de adopt i on
Open Source Geospat i al Foundat i on 45
'a2eaway -essons
Post greSQL+ Post GIS i s t he l eadi ng spat i al
dat abase combi nat i on
Post GIS i s st andards based
OGC Si mpl e Feat ures i s usef ul , wi del y
adopt ed way of expressi ng geomet ry
Open Source Geospat i al Foundat i on 46
Opportunities
Dracones t al k here at 1:30!
OSBoot Camp 6 (Geoboot camp)
June2nd, Ot t awa (Carl et on)
Free!
www.osboot camp.org
OSGeo Ot t awa
Mont hl y meet i ngs at a pub
wi ki .osgeo.org/ wi ki / Ot t awa_Chapt er
Open Source Geospat i al Foundat i on 47
Questions?
PostGIS:
www.postgis.org
OGC (standards):
opengeospatia.org

Vous aimerez peut-être aussi