Difference between revisions of "Spatial data management using PostGIS"
Line 93: | Line 93: | ||
::<pre>createdb -E UTF8 -T template0 template_postgis</pre> |
::<pre>createdb -E UTF8 -T template0 template_postgis</pre> |
||
− | + | :*The following command will define a new procedural language, which will basically add the plpgsql programming language to the template. <ref>PostgreSQL 8.4 Documentation - http://www.postgresql.org/docs/8.4/static/app-createlang.html</ref> |
|
::-d specifies the db name |
::-d specifies the db name |
||
Revision as of 13:01, 5 December 2010
Contents
Introduction
In a postindustrial society, data is undeniably perhaps the most important asset that an organization possesses to conduct operations on a daily basis. Data is the foundation of many outcomes for tasks conducted in organizations, that ultimately often revolve around decision-making. The gravity of data isn't only confined to large organizations conducting business, data is also an important asset for the scholar, the home business entrepreneur, research organizations, et cetera. In a postindustrial society which places an emphasis on gathering and analyzing data, there has been over the years a multitude of innovations specializing in the discipline of data management.
In this tutorial data management will be introduced for a specific data known as spatial data. Spatial data unlike regular data or other forms of data, has the intent of representing the geographic location of features & boundaries using coordinates and topology.{{[1]}}Further more, spatial data requires its own stream of technology for management, which distinguishes spatial data even more from other forms of data.
The intent of this tutorial will be to demonstrate the basic aspects of the discipline of data management specific to spatial data within a spatial database, and continue with demonstrating what can be achieved using a spatial database in terms of advance functionality. In addition to the primary intent, the entire tutorial will be conducted utilizing FOSS4G software and open source software, which FOSS4G is Free and Open Source Software for Geospatial. The benefit of giving a tutorial completely in open source software is that anyone could participate because the software is free of charge. Here is a list of open source software that will be utilized in this tutorial;
- Ubuntu
- PostgreSQL
- PostGIS
- Quantum GIS
- Open Jump
This tutorial's target audience is for individuals with little to no knowledge of database management software, but have some experience in Geomatics.
Data
In this tutorial, all the data was acquired from geobase.ca for the Ottawa region. For simplicity, it is suggested to download the identical or similar data from Geobase. It is necessary to have at least have a polyline and polygon vector ESRI shapefile.
About the Tutorial
The tutorial will be divided into four main modules, with one optional module. The modules are as follows;
- Installation of PostgreSQL & PostGIS
- Uploading Data
- Retrieving Data
- Advance Functionality & Data Processing
- PostGIS Raster Functionality (Optional)
During the entire tutorial, Linux commands will often be utilized for the execution of procedures, if it is not clear what the functionality of the command is, please refer to the external links sections for a link to a Linux command help page, or simply write man in the terminal followed by the command to get an instant help page.
Example of using man (manual):
man sudo
Installation
PostgreSQL
The first part of the installation for developing a spatial database, is the installation of PostgreSQL. This will be performed using what is known as the synaptic package manager, but via the terminal. (command line)
- In the Applications menu (top-left), in accessories click terminal. A terminal will open.
- In the terminal enter the following line;
sudo apt-get install postgresql postgresql-client postgresql-contrib pgadmin3
- This line will get and install packages for postgresql, the postgresql-client, postgresql-contrib, and pgadmin3. The postgresql package is the database itself, the postgresql-client is the client to communicate to the database from the shell(terminal), the postgresql-contrib is a library of additional tools for postgresql, and pgadmin3 is a gui interface that will easily allow user interaction with the database.
- Following the execution of that command, PostgreSQL will be installed on your computer.
- A quick test to ensure the database works, enter the following command in the terminal;
sudo su postgres
- you should see the following;
- The following procedure will be to create a user for the PostGreSQL database.
- Enter the following command within the terminal, in the PostgreSQL Client;[2]
createuser -sP [enter username]
- This command will create a new user, the -s & P before the name of the new user are parameters that will make the user a superuser and prompt the user for a password to ensure a password is set.
- Enter the following in the postgresql-client to exit the PostgreSQL Client, and properly logout.
Exit
PostGIS
PostGIS is a spatial database extender for the open source PostgreSQL database.[3] This extender is what will grant the capability to manage spatial data within the PostgreSQL database.
- Now its time to install the postGIS extension to PostgreSQL, which is performed using the following line in the terminal;
sudo apt-get install postgresql-8.4-postgis
There should be a similar output to what was seen when postgresql was installed.
- Now we will create a postgis spatial database template, which will be used as a model to create spatial databases. [4] The template is a quick method of creating a spatial database without having to go through the entire process each time, as seen in the creation of the spatial template.
- If you are not already in the postgres-client, enter the following
sudo su postgres
- The following command when execute will create a database using the UTF8 character encoding, and built modelled after the default PostgreSQL template that will be utilized as the spatial database template.
- The options are;
- -E specify the character encoding
- -T Use the postgresql template to build the database upon
createdb -E UTF8 -T template0 template_postgis
- The following command will define a new procedural language, which will basically add the plpgsql programming language to the template. [5]
- -d specifies the db name
createlang -d template_postgis plpgsql
References
Schuurman, N., Bell, N. J., L'Heureux, R., & Hameed, S. M. (2009), "Modelling optimal location for pre-hospital helicopter emergency medical services" BMC Emergency Medicine, 9, 6. [1]
- ↑ Webopedia - http://www.webopedia.com/TERM/S/spatial_data.html
- ↑ PostgreSQL Documentation - http://www.postgresql.org/docs/8.4/static/app-createuser.htm
- ↑ Obe, Regina O. & Leo S. Hsu. 2010. PostGIS in Action. Manning Publishing.
- ↑ GeoLabs - http://geospatial.nomad-labs.com/2006/12/24/postgis-template-database/
- ↑ PostgreSQL 8.4 Documentation - http://www.postgresql.org/docs/8.4/static/app-createlang.html