Introduction to Spatial Data Management with Postgis. Spatial Data Management



Similar documents
Introduction to the Mapbender OWS Security Proxy

Frank Warmerdam President, OSGeo

Open Source GIS. Open Source GIS. Agenda. Open Source. Typische GIS Funktionen. LOTS Bern

Building a Spatial Database in PostgreSQL

Introduction to Using PostGIS Training Workbook Last Updated 18 June 2014

IBM Informix. Reference Documentation on Why Informix Spatial for GIS Projects

OpenGIS Implementation Specification for Geographic information - Simple feature access - Part 2: SQL option

SQL SUPPORTED SPATIAL ANALYSIS FOR WEB-GIS INTRODUCTION

ELECTRONIC JOURNAL OF POLISH AGRICULTURAL UNIVERSITIES

PostGIS Data Integration

PostgreSQL as an integrated data analysis platform

Future Trends in Geospatial Data Management Process Squadron Leader Mudit Mathur

Oklahoma s Open Source Spatial Data Clearinghouse: OKMaps

Open Source GIS The Future?

Web-based public participation GIS application - a case study on flood emergency management

Standards based spatial data management, GIS and web mapping. Spatial data management, analysis & sharing the free & easy way!

GeoPackage, The Shapefile Of The Future

UK Location Programme

WebGD: Framework for Web-Based GIS/Database Applications

National critical geo infrastructure runs on open source database PostGIS

Supported DBMS platforms DB2. Informix. Enterprise ArcSDE Technology. Oracle. GIS data. GIS clients DB2. SQL Server. Enterprise Geodatabase 9.

An architecture for open and scalable WebGIS

DISMAR implementing an OpenGIS compliant Marine Information Management System

An Introduction to Open Source Geospatial Tools

GIS AS A DECISION SUPPORT FOR SUPPLY CHAIN MANAGEMENT

Geodatabase Programming with SQL

Introduction to PostGIS

CentropeSTATISTICS a Tool for Cross-Border Data Presentation Manfred Schrenk, Clemens Beyer, Norbert Ströbinger

Managing a Geographic Database From Mobile Devices Through OGC Web Services

OSGeo Web Mapping Typification: GeoMajas, Mapbender, MapFish and OpenLayers. Christoph Baudson Arnulf Christl FOSS4G 2010 Barcelona

GeoKettle: A powerful spatial ETL tool for feeding your Spatial Data Infrastructure (SDI)

Primitive type: GEOMETRY: matches SDO_GEOMETRY and GEOMETRY_COLUMN types.

Standardized data sharing through an open-source Spatial Data Infrastructure: the Afromaison project

OSM-in-a-box A Ready-Made Highly Configurable Map Server

Web Map Service Architecture for Topographic Data in Finland

Analysis of the Free GIS Software Applications in respect to INSPIRE services and OGC standards

Cloud-based Infrastructures. Serving INSPIRE needs

Pennsylvania Geospatial Data Sharing Standards (PGDSS) V 2.5

Building Geospatial Business Intelligence Solutions with Free and Open Source Components

Institute of Computational Modeling SB RAS

MyOra 3.0. User Guide. SQL Tool for Oracle. Jayam Systems, LLC

DEVELOPING AND IMPLEMENTING MULTIUSER, FULLY RELATIONAL GIS DATABASE FOR DESKTOP SYSTEMS USING OPEN SOURCE TECHNOLOGIES

A framework for a networkbased datastore for spatial and spatio-temporal geoscience data

Enabling embedded maps

Quality Assessment for Geographic Web Services. Pedro Medeiros (1)

Open Source Geospatial Software. Bob Bruce, P.Eng Mapping and Lands Branch, Manitoba Conservation

Mastering Advanced GeoNetwork

Lab 2: PostgreSQL Tutorial II: Command Line

A Web services solution for Work Management Operations. Venu Kanaparthy Dr. Charles O Hara, Ph. D. Abstract

Developing of A GIS Based Enviromental Monitoring System with Open Source Softwares

Chapter 6: Data Acquisition Methods, Procedures, and Issues

ARCHITECTURE OF INTEGRATED GIS AND GPS FOR VEHICLE MONITORING

Big Data: Using ArcGIS with Apache Hadoop. Erik Hoel and Mike Park

Introduction to OSGeo and QGIS

Secure your GIS. Protecting GIS applications suites. camptocamp / 9. septembre 2010 / / info@camptocamp.com

SQL Databases Course. by Applied Technology Research Center. This course provides training for MySQL, Oracle, SQL Server and PostgreSQL databases.

Open Source Tools for Spatial Analysis and Geoprocessing

Oracle Platform GIS & Location-Based Services. Fred Louis Solution Architect Ohio Valley

There are various ways to find data using the Hennepin County GIS Open Data site:

Spatial Data Mining: From Theory to Practice with Free Software

GeoKettle: A powerful open source spatial ETL tool

OPEN STANDARD WEB SERVICES FOR VISUALISATION OF TIME SERIES DATA OF FLOOD MODELS

GeoMedia Product Update. Title of Presentation. Lorilie Barteski October 15, 2008 Edmonton, AB

PostGIS Integration Tips

MyOra 3.5. User Guide. SQL Tool for Oracle. Kris Murthy

Neues vom QGIS Server und QGIS-Webclient

Data Visualization Using Web GIS Software

Web and Mobile GIS Applications Development

Geospatially Enabling the World: The Convergence of Geospatial and Architectural and Engineering Design

Sharding with postgres_fdw

About scope of OpenGIS technology in oceanographic data management and visualization Andrey V. Golik, Vitaly K. Fischenko, Stepan G.

ArcGIS 10.1 Geodatabase Administration. Gordon Sumerling & Christopher Brown

PostGIS Indexes. Geometries Require Special Index

Database Query 1: SQL Basics

FreeGIS.net, INSPIRE, Open Source Software and OGC standards

DEVELOPMENT OF THE INTEGRATING AND SHARING PLATFORM OF SPATIAL WEBSERVICES

Mississippi Private Schools 2015

A Brief Introduction to MySQL

Implementation of information system to respond to a nuclear emergency affecting agriculture and food products - Case of Morocco

PROPOSAL OF 3D GIS FOR SPATIAL DATA VISUALIZATION AND ANALYSIS OVER INTERNET

PostGIS Manual. Edited by Paul Ramsey

MapInfo SpatialWare Version 4.6 for Microsoft SQL Server

Programming Database lectures for mathema

Postgres Plus xdb Replication Server with Multi-Master User s Guide

A Hybrid Architecture for Mobile Geographical Data Acquisition and Validation Systems

EXPLORING AND SHARING GEOSPATIAL INFORMATION THROUGH MYGDI EXPLORER

<Insert Picture Here> Data Management Innovations for Massive Point Cloud, DEM, and 3D Vector Databases

Geodata-Management in the Thünen- Institute. Till Kirchner Thünen-Institute for Forest Ecosystems, Eberswalde

ADVANCED DATA STRUCTURES FOR SURFACE STORAGE

Linas Virbalas Continuent, Inc.

v4.8 Getting Started Guide: Using SpatialWare with MapInfo Professional for Microsoft SQL Server

Transcription:

Introduction to Spatial Data Management with Postgis

Content Introduction Managing Spatial Data with PostGIS PostGIS Data Model Creating a PostGIS enabled Database Insert Coordinates using SQL Uploading Flat File GIS Data Using Spatial Operators Creating Spatial Index Creating Maps with PostGIS Data using UMN MapServer Online Demonstration of a WebGIS Application

Abstract: What is PostGIS? PostGIS is a spatial language extension module to the PostgreSQL backend server The OGC WKT (Well-Known Text) and WKB (Well-Known Binary) form define type and coordinates of an object Data from a PostgreSQL/PostGIS database can be used as data source for spatial server software like MapServer and GeoServer PostGIS is licensed under the GNU GPL and operated as a Free Software Project PostGIS is developed by Refractions Research Inc, a GIS and database consulting company in Victoria, British Columbia, Canada http://postgis.refractions.net

Who did it? Credits to... Sandro Santilli (strk@refractions.net) coordinates all bug fixing and maintainance effort, integration of new GEOS functionality, and new function enhancements. Chris Hodgson (chodgson@refractions.net) Maintains new functions and the 7.2 index bindings. Paul Ramsey (pramsey@refractions.net) Maintains the JDBC objects and keeps track of the documentation and packaging. Jeff Lounsbury (jeffloun@refractions.net) Original development of the Shape file loader/dumper. Dave Blasby (dblasby@gmail.com) The original developer of PostGIS. Dave wrote the server side objects, index bindings, and many of the server side analytical functions. Other contributors in alphabetical order: Alex Bodnaru, Bernhard Reiter, Bruno Wolff III, Carl Anderson, David Skea, David Techer, IIDA Tetsushi, Geographic Data BC, Gerald Fenoy, Gino Lucrezi, Klaus Foerster, Kris Jurka, Mark Cave-Ayland, Mark Sondheim, Markus Schaber, Nikita Shulga, Norman Vine, Olivier Courtin, Ralph Mason, Steffen Macke.

PostgreSQL Architecture with Client Applications PostgreSQL is implemented as a client server system User 1 (databaseclient) User 2 (database client) Applications Web Server Map Server PostgreSQL database server postmaster Data

Foucs of Interest for this Presentation PostGIS spatial language extension module to the backend server User 1 (databaseclient) User 2 (database client) Applications Web Server Map Server PostgreSQL database server postmaster PostGIS Data

Overview: PostGIS PostGIS is implemented compliant to the OGC Simple Feature Specifications for SQL standard The OGC specification defines operations and the SQL schema to insert, query, manipulate and delete spatial objects The coordinates of the spatial objects are stored in Feature Tables One Feature Table can contain one type of geometry (point, line, polygon, multiple of each and geometry collection) The coordinates of each object is stored in a field of a special type The field type for a set of coordinates is WKT (Well Known Text) Meta data is collected for each Feature Table to organize the type and the coordinate system of the contained geometry The meta data for each Feature Table is stored in the special table geometry_columns

Spatial Data Type WKT as defined by the OGC WKT Examples: POINT(2572292.2 5631150.7) LINESTRING (2566006.4 5633207.9, 2566028.6 5633215.1, 2566062.3 5633227.1) MULTILINESTRING((2566006.4 5633207.9, 2566028.6 5633215.1), (2566062.3 5633227.1, 2566083 5633234.8)) POLYGON (2568262.1 5635344.1, 2568298.5 5635387.6, 2568261.04 5635276.15, 2568262.1 5635344.1); MULTIPOLYGON(((2568262.1 5635344.1, 2568298.5 5635387.6, 2568261.04 5635276.15, 2568262.1 5635344.1), (2568194.2 5635136.4, 2568199.6 5635264.2, 2568200.8 5635134.7, 2568194.2 5635136.4 )))

PostGIS Interfaces to GIS Data PostGIS ships with a Shape file loader an dumper Various file types (Shape, MapInfo, DGN, GML,...) can be read, converted and inserted to a PostGIS database using the OGC libraries A PostGIS Feature Table can be used as data source for a growing variety of map and feature server software like UMN MapServer, GeoServer, udgi, deegree, JUMP, etc... The data can be accessed using standard ODGB or JDBC connectors Several projects have evolved around PostGIS transforming and inserting geometries from highly specialized formats like SICAD C60, EDBS, DXF, WLDGE and many more

Creating a PostGIS Database Create database: createdb <dbname> Load PL/pgsql language for PostGIS: createlang plpgsql <dbname> Load PostGIS and object definitions: psql -d <dbname> -f postgis.sql This file also contains the CreateTable SQL for the metadata table geometry_columns CreateTable spatial_ref_sys (coordinate system codes): psql -d <dbname> -f spatial_ref_sys.sql

Insert Coordinates using SQL SQL with PostGIS Function Example: create table user_locations (gid int4, user_name varchar); select AddGeometryColumn ('db_mapbender','user_locations','the_geom','4326','point',2); insert into user_locations values ('1','Morissette',GeometryFromText ('POINT(-71.060316 48.432044)', 4326)); insert into user_locations values ('2', 'Sperb',GeometryFromText ('POINT(-48.6764-26.8916)', 4326));... AddGeometryColumn() this function adds the meta information of this field to the table geometry_columns DropGeometryColumn() removes the meta information from the table geometry_columns

Representation of the Data in the Table Meta information in geometry_columns f_table_catalog spatial f_table_schema db_mapbender f_table_name user_locations f_geometry_column the_geom coord_dimension 2 srid 4326 type POINT attrelid 8751803 varattnum 11 stats Data from Feature Table <user_locations> gid 1 user_name Sperb the_geom SRID=4326;POINT(-48.6764-26.8916)

Loading Flat File GIS Data PostGIS Shape Loader Create SQL input files: shp2pgsql s <epsgcode> <ShapeFileName> <TableName> <dbname> > <filename> Make sure that the EPSG code of the data you load is correct! If you do not know which coordinate system the data comes in you cannot combine it with any other spatial data! Load input file: psql -d <dbname> -f <filename>

Convert Non-Spatial X and Y fields to PostGIS First select both X and Y coordinates into one field of type character objgeom = "-48.6764-26.8916". Then call the function GeometryFromText, add the geometry type, brackets and append the EPSG code of the coordinates. UPDATE test SET the_geom = GeometryFromText( 'POINT '( objgeom ')"', 31467) Beware of brackets andd quotes, the code might look slightly nauseating. If you add brackets to the coordinate strings objgeom = "(-48.6764-26.8916)" then you do not have to add them in the INSERT string UPDATE test SET the_geom = GeometryFromText( 'POINT ' objgeom '"', 31467)

Converting binary to WKT Since PostGIS version 1.0 the internal storage of coordinates in the geometry column has changed to the binary format WKB (Well Known Binary). It is not readable but provides better performance. You can convert the binary WKB form with SQL into a readable WKT string using the PostGIS function <asewkt> (as extended WKT). The PostGIS extended WKT carries the coordinate system additionally to the basic WKT string syntax. That will effectively prevent anybody from ever forgetting the coordinate system ever again. Select asewkt(<geometrycolumn>) from <table name> Select user_name, asewkt(the_geom)from user_locations gid 1 user_name Sperb the_geom SRID=4326;POINT(-48.6764-26.8916)

Spatial Operators in PostGIS Query and manipulation of data using the SQL interface Implementation of these spatial operators was the original domain of every GIS software. Example: Query for the minimum bounding box rectangle geodata2=# SELECT EXTENT(the_geom) FROM tbl_spatial; extent -------------------------------------------- BOX3D(-48.57-26.89 0, -47.64-25.16 0) (1 row) PostGIS ships with all functions and operators required to comply to the OGC SFS (Simple Feature Specification for SQL) specification The Implementation of all relevant functionality has been done in the JTS (Java Topology Suite) which has been ported to GEOS and is used by most Open Source tools Example: touches(), intersects(), overlaps(), buffer()...

Spatial Index Spatial data has a slightly different need for indexing than common relational data. The efficiency of an index also greatly varies according to the kind of data that is being stored. Polygons with several thousand vertices that extend throughout the whole area can have devastating effects on performance because they appear in every section of interest. In those cases it might make sense to clip the geometry into several pieces. PostGIS implements the GiST-Index (Generalized Search Tree) The index is created using standard SQL CREATE INDEX <indexname> ON <tablename> USING GIST ( <geometrycolumn> GIST_GEOMETRY_OPS ); It is necessary to vacuum-analyze the database before the index takes effect. Frequent read/write operations might slow performance.

Web Mapping a Spatial Data Infrastructure Internet 1 Client request map 2 Firewall admits request 3 Webserver authenticates user 4 Authorisation of user 5 Standard WMS getmap request 6 Spatial data query (SFS SQL) 7 Native data 6A OGC WFS getfeature request 7A...returns GML 8... returns map image 5a OGC WFS getfeature request 6a Spatial data query (SFS SQL) 7a...returns WKT 8a...returns GML 9 GML and iamge are returned to the client Intranet A OWS requests B Webserver, 3 Authentication 4 Authorisation 5, 6, 7, C, A Standard WMS request 5a, 6a, 7a, D, A WFS request...

PostGIS tables as datasource for UMN MapServer Use a version of UMN MapServer that supports PostGIS. Enter the connection type and credentials (you might want to add the map server engine as a trusted client in the pg_hba.conf) LAYER...... END CONNECTIONTYPE postgis CONNECTION "user=<username> dbname=<database> host=<server> port=5432 password=<password>" DATA <geometry_column> from <table> Example of a most simplistic SQL selection: DATA "the_geom from nutzung"

Using Views as Data Source for UMN MapServer If you need more complex queries, create a view. Create view: CREATE VIEW qry_users AS SELECT * FROM users WHERE user_type LIKE 'professional' ORDER BY gid; You can use the USING pseudo-sql clause to add more complex queries. For views or subselects MapServer can neither determine the unique identifier for each row nor the SRID for the table because they are not identified in the meta data table <geometry_columns>. DATA string in MAP configuration file: DATA "the_geom from (select * from qry_ nutzung) as foo using unique gid using SRID=31467" Required information: Coordinate system as <SRID=number> (case sensitive) Field which contains unique identifier <using unique> (case sensitive) Alias for the table <as foo> (usage)

Using SQL Clauses in the MAP Configuration File Queries can also be added to the MAP configuration file directly. In that case the corresponding SQL with joins accross tables has to be added to the DATA section. Example: Select street names from table <str_name> as Label for geometries from tbale <str> DATA "the_geom from (SELECT landuse.object_id, landuse.area, forest.type, forest.the_geom FROM landuse INNER JOIN forest ON landuse.gid = forest.gid) as foo using unique gid using SRID=4326" Notice Always add a field that conatins the unique ID and explicitly specify the coordinate reference system EPSG code as shown in the example. UMN MapServer needs this information to be able to convert geometries to the correct coordinate system and query for each object with unique ID.

MAP File Filter Parameters The MAP configuration file allows to set a FILTER parameter to select features with defined properties. This is the "traditional" (nonstandardized) way to show selections. FILTER "[filteritem] = [Kriterium]" Example: Selection of users with type = "professional" DATA "the_geom from (select * from qry_users) as foo using unique gid using SRID=4326" FILTER "user_type > 'professional'" Example: Selection of numbered roads from a network (second character is a number like in A42, B52,...) DATA "the_geom from tbl_streets" FILTER "(substr(street_name, (length(street_name)-1), 1)) BETWEEN 0 and 9"

Create PostGIS Schema PostGIS enabled databases can be organized in schemas as any standard database. Create schema: z.b.: CREATE SCHEMA spatial_schema; Create table in schema: z.b.: CREATE TABLE spatial_schema.db_user_locations (id int8, user_name varchar, user_type int4) WITH OIDS; Standard SQL select clause: SELECT * FROM spatial_schema.db_user_locations;

Load CSV File Upload CSV files (comma separated value), for example if oyu need to include data from a DBF file (which contains the alphanumerical attributes of a flat GIS Shape file. Create CVS file: Example: Load DBF file with OpenOffice.org and store it as CSV Create table with corresponding fields: Example: CREATE TABLE mytable (id int8, area float8, boart varchar) WITH OIDS; Copy CVS file from hard disk Example: COPY mytable FROM /data/postgis_schulung/poi.csv ;

Spatial Enterprise System Online Presentation Most Spatial Data Infrastructure operated at enterprise level that use Free and Open Source Software operate a PostgreSQL database with PostGIS extension. There exisits as yet no viable alternative and currently there seems to be no need to get one. The system FLOrlp of the Ministry of Commerce, Infrastructure, Agriculture and Viticulture in Rhineland Palatinate, Germany allows farmers to use full GIS functionality to process their requests for EU subsidies. http://www.flo.rlp.de

What can PostGIS do for You Today? There is a wide field of application for Spatial Data. Recent publications by Google, Yahoo and related commercial providers has brought web mapping applications and satellite imagery to the broad public strongly increasing interest in this technology. To operate a standardized spatial data infrastructure you need the database, a map server and a client interface. Additionally you might want to include a Web Feature Service that returns GML (Geographic Markup Language) to search, find and navigate to geographic features. A "geographic feature" might be the position of a car (a dynamic point feature for tracking), that of the Grand Canyon (a polygon feature for sightseeing). Be creative!

Further Information and Contact The most important source of further information is the Internet. Check out the following adresses referencing everything that you might need. http://www.mapbender.org/ Mapbender (Web Mapping Suite Wiki) http://mapserver.gis.umn.edu/ UMN MapServer (Web Map Server) http://www.maptools.org/ Resources (Mapping Tools) http://freegis.org/ General Information about Free GIS http://www.eogeo.org/ Earth Observation and Geospatial Information Feel free to contact me directly: Arnulf Christl arnulf.christl@ccgis.de CCGIS Christl & Stamm GbR Siemensstr. 8 53121 Bonn Homepage: http://www.ccgis.de This Document is available under the GNU Free Documentation License 1.2 http://www.gnu.org/copyleft/fdl.html & for download at the Mapbender Wiki http://www.mapbender.org/