1.77k likes | 1.98k Views
EnterpriseDB Corporation. EnterpriseDB is the leading provider of enterprise-class products and services based on PostgreSQL, the world's most advanced open source database. Over 600 customers including: Sony, FTD, British Telecom, TDAmeritrade. Introduction to PostGIS.
E N D
EnterpriseDB Corporation EnterpriseDB is the leading provider of enterprise-class products and services based on PostgreSQL, the world's most advanced open source database. Over 600 customers including: Sony, FTD, British Telecom, TDAmeritrade
Introduction to PostGIS Installation – Tutorial - Exercises
What is PostGIS? • Like Oracle Spatial, DB2 Spatial, and SQL Server Spatial, PostGIS adds spatial capabilities to an existing relational database, in this case, PostgreSQL. • It could be renamed to “PostgreSQL Spatial” as it functions in the same way as proprietary database extensions.
What is PostGIS? • Adds support for geographic objects to the PostgreSQL object-relational database • PostgreSQL already has “geometric types” but native geometries are too limited for GIS data and analysis
What is PostGIS? • PostGIS adds an indexing mechanism to allow queries with spatial restrictions or filters (“within this bounding box”) to return records very quickly from large tables.
What is PostGIS? • PostGIS adds a “geometry” data type to the usual data types (ie. varchar, integer, date, etc.) • PostGIS adds spatial predicates and functions that use the geometry data type. • ST_Distance(geometry, geometry) • ST_Area(geometry) • ST_Intersects(geometry, geometry))
PostGIS Overview / History • Open source • General Public License (GPL) • Open development and support • History • 2001: First release, Mapserver support • 2002: Improved functions, indexes • 2003: GEOS support, many functions • 2004: SFSQL conformance • 2005: Lightweight geometries • 2006: OpenGIS SFSQL compliance • 2007: SQL/MM, curves & performance • 2008-2010: Performance enhancements
Why PostGIS? • Because databases are better than files • Unified Storage, Management, Access • SQL Everywhere • Transactional Integrity • Multiple Users, Multiple Edits
PostGIS PostGIS in the Spatial Stack LAN Internet Mapserver uDig OpenIMF GeoServer GRASS WebClient QGIS MapGuide ArcGIS OpenJUMP uDig
Who is using PostGIS? • Lots of people … • 1790 mailing list members • 14K visits/month10K visitors/month • 130 source code downloads per day • 970K Google search results • Great Google trends …
Who is using PostGIS? • North Dakota State Water Commission in Bismark uses PostGIS as the cost-effective foundation for managing the use of state-wide water resources. PostGIS tied unobtrusively into their existing desktop systems and pre-empted a costly migration to an ArcIMS/ArcSDE system.
Who is using PostGIS? • The Ministry of Sustainable Resource Management (British Columbia, Canada) uses PostGIS to store, manage and analyze their Digital Road Atlas, a large and complex road network database.
Who is using PostGIS? • Institut Géographique National (IGN France) uses PostGIS to underpin a system containing more than 100 million spatial objects, including a 3D national database of roads, rails, hydrography, vegetation, buildings and administrative boundaries.
Who is using PostGIS? • InfoTerra (United Kingdom) uses PostGIS to store >600 million features of topographic data. Sits at the back-end of their online DataStore. Notable load times of 12 hours for the entire data-suite ~14000 features per second. More notable savings of ~£1000000 per annum.
Workshop Summary • Introduction to Spatial Concepts • Installation (PostgreSQL and PostGIS) • Creating and Loading Data • Creating Indexes • Spatial Operations and Predicates • Spatial SQL • System Configuration
Introduction to Spatial Concepts • A Geographical Information System (GIS) is any system used for capturing, storing, analyzing, managing, or presenting geospatial data. • Geometric Datatypes • Geometry Validity
2.1 Geometric Datatypes • Each geometry has a Well-Known Text representation (WKT) • A geometry type • A comma-separated list of coordinate pairs
2.1 Geometric Datatypes • Some examples are: POINT ( 7 6 )
2.1 Geometric Datatypes • Some examples are: MULTIPOINT ( 1 4, 1 5, -0.5 5.5314 )
2.1 Geometric Datatypes • Some examples are: LINESTRING ( 1 3, 1 1, 3 0 )
2.1 Geometric Datatypes • Some examples are: MULTILINESTRING (( 2 1, 2 2, 3 4 ), ( 4 3, 3 2, 4 1, 3 3 ))
2.1 Geometric Datatypes • Some examples are: POLYGON (( 2 5, 3 8, 6 8, 5 4, 2 5 ), ( 3 6, 4 5, 5 7, 4 6, 3 6 ))
2.1 Geometric Datatypes • Some examples are: MULTIPOLYGON ((( 6 2, 6 4, 8 4, 9 1, 6 2 ), ( 7 3, 8 2, 8 3, 7 3 )), (( 9 2, 8 5, 10 4, 10 3, 9 2 )))
2.1 - Exercises • Time for some exercises!
2.3 - Geometry Validity • PostGIS is compliant with the Open Geospatial Consortium’s (OGC) OpenGIS Specifications • Most functions require / assume geometries are valid and in many cases, simple. • Geometry validity really only applies for areal geometries • Geometry simplicity applies to point and linear geometies
2.3 - Geometry Validity • A POINT is inherently simple as a 0-dimentional geometry object. • A MULTIPOINT is simple if no two POINTs are the same.
2.3 - Geometry Validity • By definition, a LINESTRING is always valid • It is simple if it does not pass through the same point twice. SIMPLE NOT SIMPLE SIMPLE NOT SIMPLE
2.3 - Geometry Validity • MULTILINESTRINGs are simple if all its elements are simple and they only intersect at boundary points. NOT SIMPLE SIMPLE SIMPLE
2.3 - Geometry Validity • By definition, a POLYGON is always simple. • It is valid if • The boundary is made up of simpleLINEARRINGs • boundary rings don’t cross • holes are completely within the outer ring and touch the outer ring at most one point. • it does not contain cutlines / spikes
2.3 - Geometry Validity • These POLYGONs are … valid invalid invalid invalid valid invalid
2.3 - Geometry Validity • By definition, a MULTIPOLYGON is valid iff • All elements are valid • Element interiors cannot intersect • Element boundaries can touch, but only at a finite number of POINTs.
2.3 - Geometry Validity • These MULTIPOLYGONs are … invalid invalid valid
3.1 – PostgreSQL Installation • Windows Installer • PostgreSQL 8.4.4 • Automatically installs itself as a Windows Service • PgAdmin III • Psql Interactive SQL Shell
3.1 – PostgreSQL Installation • Directories created during installation: • \bin - Executables • \include - Include files for compilation • \lib - DLL shared library files • \share - Extensions
3.1 – PostgreSQL Installation • Tools included with the install: • PgAdmin III • psql Command Line
3.1 – PostgreSQL Installation • Under Linux http://www.postgresql.org/docs/8.4/static/installation.html • ./configure • gmake • su • gmake install • adduser postgres • mkdir /usr/local/pgsql/data • chown postgres /usr/local/pgsql/data • su - postgres • /usr/local/pgsql/bin/initdb -D /usr/local/pgsql/data • /usr/local/pgsql/bin/postgres -D /usr/local/pgsql/data >logfile 2>&1 & • /usr/local/pgsql/bin/createdb dbname • /usr/local/pgsql/bin/psql dbname
3.2 – PostGIS Installation • As of PostgreSQL 8.3, an Application Stack Builder is used to obtain the latest installers for desired modules. • Demonstrate Installation …