Introduction To PostGIS v1.0
Introduction To PostGIS v1.0
What is PostGIS? Why is PostGIS? What can PostGIS do? Who is using PostGIS? Why use PostGIS?
What is PostGIS?
Spatial Extensions for PostgreSQL Geometry represented by linear shapes Spatial Functions (Constructors, Accessors, Editors, Processors, Relational Operators, Processing Functions) Advanced geometric indexing
Why is PostGIS
Shapefile are limited in their transactional capacity Data management of files problematic Existing GIS data services (as of 2001) were terribly expensive No existing integrated spatial databases Refractions had some time to kill
Installation - Requirements
Proj4 - Cartographic Projections Library GEOS - Geometry Engine - Open Source Provides spatial predicate functions, spatial operators and topological functions. PostgreSQL - helpful little application
Installation - Debian
sudo apt-get install postgresql-8.3-postgis
Installation - Debian
sudo apt-get install postgresql-8.3-postgis
or from source svn co http://svn.refractions.net/postgis/trunk/ postgis/ cd postgis ./autogen.sh ./configure make sudo make install
Installation - Windows
Included in the PostgreSQL installer
Installation - Windows
Included in the PostgreSQL installer
or need a more recent version? Use the Stack Builder application for version PostgreSQL 8.3
Installation - Windows
Included in the PostgreSQL installer
or need a more recent version? Use the Stack Builder application for version PostgreSQL 8.3 Download the installer for PostgreSQL 8.3 from http://postgis.refractions.net/download/windows/
-s 4326 Use WGA83 coordinate reference system -D Use PostgreSQL dump format (faster than inserts) -I Create spatial (GIST) index after loading -S Generate simple geometries (eg. Line instead of Multiline)
On Windows use: shp2pgsql -s 4326 -D -I -S roads.shp roads > roads.sql psql -f roads.sql demo
Inserting Data
INSERT INTO fishing_hole (name, the_geom) VALUES ("Greenwich Ferry Wharf", ST_SetSRID(ST_GeometryAsText( "POINT(151.18323 -33.84162)"), 4283);
Inserting Data
INSERT INTO fishing_hole (name, the_geom) VALUES ("Greenwich Ferry Wharf", ST_SetSRID(ST_GeometryAsText("POINT(151.18323 -33.84162)"), 4283);
Inserting Data
INSERT INTO fishing_hole (name, the_geom) VALUES ("Greenwich Ferry Wharf", ST_SetSRID(ST_GeometryAsText("POINT(151.18323 -33.84162)"), 4283);
..."POLYGON((151.2111 -33.8754,151.2109 -33.8753,151.211 -33.8749,151.2111 -33.8749,151.2111 -33.8753)(151.211 -33.8750,151.2111 -33.8751,151.211 -33.8751,151.211 -33.875,151.211 -33.8750))"...
Inserting Data
INSERT INTO fishing_hole (name, the_geom) VALUES ("Greenwich Ferry Wharf", ST_SetSRID(ST_GeometryAsText("POINT(151.18323 -33.84162)"), 4283);
..."POLYGON((151.2111 -33.8754,151.2109 -33.8753,151.211 -33.8749,151.2111 -33.8749,151.2111 -33.8753)(151.211 -33.8750,151.2111 -33.8751,151.211 -33.8751,151.211 -33.875,151.211 -33.8750))"...
Inserting Data
INSERT INTO fishing_hole (name, the_geom) VALUES ("Greenwich Ferry Wharf", ST_SetSRID(ST_GeometryAsText("POINT(151.18323 -33.84162)"), 4283);
..."LINESTRING(151.18456 -33.84225,151.18424 -33.84196,151.18342 -33.84122)"... ..."POLYGON((151.2111 -33.8754,151.2109 -33.8753,151.211 -33.8749,151.2111 -33.8749,151.2111 -33.8753)(151.211 -33.8750,151.2111 -33.8751,151.211 -33.8751,151.211 -33.875,151.211 -33.8750))"...
Accessing Data
select the_geom from road where gid = 1; 0102000020E6100000020000000000008029F65B40000000 0000000000000000800BF65B4000000080F9595FBF
Accessing Data
select the_geom from road where gid = 1; 0102000020E6100000020000000000008029F65B4000000000000000000 00000800BF65B4000000080F9595FBF
Accessing Data
select the_geom from road where gid = 1; 0102000020E6100000020000000000008029F65B400000000000000000000000800BF65B 4000000080F9595FBF
select ST_asGML(the_geom) from road where gid = 1; <gml:LineString srsName="EPSG:4326"><gml:coordinates>111.8462829589 84,0 111.844451904297,0.00191354146227241</gml:coordinates></gml:LineString>
Accessing Data
select the_geom from road where gid = 1; 0102000020E6100000020000000000008029F65B400000000000000000000000800BF65B 4000000080F9595FBF
Accessing Data
select the_geom from road where gid = 1; 0102000020E6100000020000000000008029F65B400000000000000000000000800BF65B 4000000080F9595FBF
Relational Operators
Numerical relational operators work on 1d values with no width. <, <=, ==, >=, >, !=
Relational Operators
Numerical relational operators work on 1d values with no width. <, <=, ==, >=, >, !=
Geometric relational operators work on 2d-4d values with or without width, height or depth
ST_Within, ST_Contains
Geometry A is completely within Geometry B ST_Within(A, B) = ST_Contains(B, A)
ST_Overlaps
Geometries share space, are of the same dimension, but are not completely contained by each other.
ST_Disjoint
Geometries do not share any space together.
ST_Touches
Geometries have at least one point in common, but their interiors do not intersect.
ST_Crosses
Geometries have some, but not all, interior points in common.
ST_Intersects
Geometries share any portion of space.
ST_Covers, ST_CoveredBy
No point in Geometry B is outside Geometry A ST_Covers(A, B) = ST_CoveredBy(B, A)
Environmental Change
Data describes the type and coverage of vegetation in Australia in 1788 and 1988. nveg_1788, pveg_1988 the_geom Geometry (Polygon) tn_d Percentage of ground shaded by vegetation
Environmental Change
SELECT n.ts_d as n_ts_d, p.ts_d as p_ts_d, CASE WHEN n.ts_d > p.ts_d THEN 'Loss' WHEN n.ts_d < p.ts_d THEN 'Gain' ELSE 'No Change' END as change, ST_Intersection(n.the_geom, p.the_geom) as the_geom FROM nveg_1788 as n, pveg_1988 as p WHERE ST_Intersects(n.the_geom, p.the_geom);
Verify Assumptions
Better Verification
SELECT ST_Area(ST_SymDifference(a.the_geom, b.the_geom)) FROM (SELECT ST_Union(the_geom) AS the_geom FROM nveg_1788) a, (SELECT ST_Union(the_Geom) AS the_geom FROM pveg_1988) b; st_area 4.58800965870143e-05
Environmental Change
SELECT count(*), change FROM change GROUP BY change; count | change -------+----------4785 | No Change 2013 | Gain 2465 | Loss
Environmental Change
SELECT count(*), change, sum(ST_Area(ST_Intersection)) AS area FROM change GROUP BY change; | sum count | change -------+-----------+-----------------4785 | No Change | 521.507080938973 2013 | Gain | 54.5533372716394 2465 | Loss | 119.174361913388
Environmental Change
ST_Relate
<http://docs.codehaus.org/display/GEOTDOC/Point+Set+ Theory+and+the+DE9IM+Matrix#PointSetTheoryandtheDE-9IMMatrix9IntersectionMatrix>
Advanced Operations
Nearest Neighbor <http://postgis.refractions.net/support/wiki/ index.php?Nearest%20Neighbor%20Search> Relational Constraints <http://www.nabble.com/AnyProjected-Straights-Function--td19439097.html#a19448155> Tiger Geocoder <http://postgis.refractions.net/support/wiki/index.php?Tiger %20Geocoder> Topology <http://postgis.refractions.net/support/wiki/index.php? PostgisTopology>
Infoterra, a leading European satellite and aerial imagery provider, runs their data provision and sales systems on PostGIS, and stores the complete Ordnance Survey database on PostGIS.
EU Joint Research Centre With billion dollar satellites and PostGIS, the EU Joint Research Centre monitors fishing vessels in the North Atlantic and provides real-time reporting and mapping to decision makers and regulators.
MADEIRA GPS MADEIRA GPS, a company that started in 2005, with a simple project in mind: Deliver PDA-based navigation, with auto-routing, for Madeira Island's tourism.
Advanced indexing Transformation support Variety of output format options ((E)WKB, (E)WKT, GeoJSON, GML, KML, SVG)
Wide variety of processing and relational operators Accessors and editors Measurement and Linear Referencing Spatial Aggregates http://www.bostongis.com/PrinterFriendly.aspx? content_name=sqlserver2008_postgis_mysql_compar e
Limitations
No true geodetic support
Fewer hosting providers than Oracle/MSSQLServer/mySQL Incomplete curve support Non-production topology support
Resources
Support WIKI http://postgis.refractions.net/support/wiki/ User List http://postgis.refractions.net/mailman/listinfo/postgis-users IRC irc://chat.freenode.net/postgis Me [email protected]
Presentations Workshops and tutorials Climate Change Integration Plugfest Installfest Bird of a Feather sessions Code Sprint Good times