You are on page 1of 30

WEB GIS – Geo Server -

PostgreSQL + PostGIS -
Quantum GIS

2011
WEB GIS – Geo Server - PostgreSQL + PostGIS - Quantum GIS

Contents

Chapter 1 Installing Software......................................................................................................... - 3 -


PostgreSQL Installation .............................................................................................................. - 3 -
PostGIS Installation.................................................................................................................... - 6 -
Quantum GIS Installation ........................................................................................................... - 9 -
Geo Server Installation ............................................................................................................ - 12 -
Java Installation ................................................................................................................... - 12 -
Geo Server Installation......................................................................................................... - 13 -
Chapter 2 Familiarize with Software ............................................................................................ - 17 -
Quantum GIS ........................................................................................................................... - 17 -
PostgreSQL DBMS.................................................................................................................... - 19 -
Creating Non-Spatial Database............................................................................................. - 20 -
Creating Spatial Database .................................................................................................... - 24 -
Geo Server............................................................................................................................... - 26 -
Chapter 3 Importing Data from PostgreSQL DBMS....................................................................... - 27 -
Import to Geo Server ............................................................................................................... - 27 -
Additional Stuff… ................................................................................................................. - 28 -
Importing to Quantum GIS....................................................................................................... - 29 -
Chapter 4 Additional Stuff ........................................................................................................... - 30 -
Importing data from a WMS to Quantum GIS .......................................................................... - 30 -

Page | - 2 -
Chanaka Alahakoon – Dinidu Jayalath
WEB GIS – Geo Server - PostgreSQL + PostGIS - Quantum GIS

Chapter 1 Installing Software

PostgreSQL Installation
Run the PostgreSQL software….. Please wait until the following window

Keep the default….

Page | - 3 -
Chanaka Alahakoon – Dinidu Jayalath
WEB GIS – Geo Server - PostgreSQL + PostGIS - Quantum GIS

Keep the default….

Here it is asking a password to the account “postgres”. We will give the same as the password
(postgres)

Note: “Please remember this password, we will need this later”

Page | - 4 -
Chanaka Alahakoon – Dinidu Jayalath
WEB GIS – Geo Server - PostgreSQL + PostGIS - Quantum GIS

Keep this one default and remember this port number…..

Keep this default….

Then go next and install……….

Page | - 5 -
Chanaka Alahakoon – Dinidu Jayalath
WEB GIS – Geo Server - PostgreSQL + PostGIS - Quantum GIS

PostGIS Installation
Here we have to choose the correct PostGIS package according to our PostgreSQL version

For an example if we choose the PostgreSQL version as 9.0 (postgresql-9.0) then we have to
download the corresponding version of PostGIS (postgis-pg90-setup-1.5)

For the moment remove the tick mark of “Create spatial database”.

Page | - 6 -
Chanaka Alahakoon – Dinidu Jayalath
WEB GIS – Geo Server - PostgreSQL + PostGIS - Quantum GIS

Keep the default…

Here in the password field we need add the password we gave on the PostgreSQL installation

(postgres).

Next …. And install…..

Page | - 7 -
Chanaka Alahakoon – Dinidu Jayalath
WEB GIS – Geo Server - PostgreSQL + PostGIS - Quantum GIS

Press on the yes button for this dialog box appears during the installation….

Page | - 8 -
Chanaka Alahakoon – Dinidu Jayalath
WEB GIS – Geo Server - PostgreSQL + PostGIS - Quantum GIS

Quantum GIS Installation

Page | - 9 -
Chanaka Alahakoon – Dinidu Jayalath
WEB GIS – Geo Server - PostgreSQL + PostGIS - Quantum GIS

Keep the default… and Install

Page | - 10 -
Chanaka Alahakoon – Dinidu Jayalath
WEB GIS – Geo Server - PostgreSQL + PostGIS - Quantum GIS

Restart your computer….

Page | - 11 -
Chanaka Alahakoon – Dinidu Jayalath
WEB GIS – Geo Server - PostgreSQL + PostGIS - Quantum GIS

Geo Server Installation


Before install geo server we have to install java package..

Java Installation

Next -> Keep Default -> Install ->

Go next..

Page | - 12 -
Chanaka Alahakoon – Dinidu Jayalath
WEB GIS – Geo Server - PostgreSQL + PostGIS - Quantum GIS

Then we can install Geo Server…

Geo Server Installation

Next  Agree 

Page | - 13 -
Chanaka Alahakoon – Dinidu Jayalath
WEB GIS – Geo Server - PostgreSQL + PostGIS - Quantum GIS

Keep the default…

Keep as it is…

Page | - 14 -
Chanaka Alahakoon – Dinidu Jayalath
WEB GIS – Geo Server - PostgreSQL + PostGIS - Quantum GIS

Keep the default….

This username and password will need to us when we logon to the GeoServer.

Note: Please remember this default values … (admin, geoserver)

Page | - 15 -
Chanaka Alahakoon – Dinidu Jayalath
WEB GIS – Geo Server - PostgreSQL + PostGIS - Quantum GIS

Keep the default..

Note: Please remember this…

Select the “Install as a service” option…. Next  Install …

Page | - 16 -
Chanaka Alahakoon – Dinidu Jayalath
WEB GIS – Geo Server - PostgreSQL + PostGIS - Quantum GIS

Chapter 2 Familiarize with Software

Quantum GIS
Q-GIS main window….

Some Important Tools…

Add vector layer (*.shp)


Add WMS layer
Add raster layer

Add PostGIS layer Add SpatiaLite layer

Page | - 17 -
Chanaka Alahakoon – Dinidu Jayalath
WEB GIS – Geo Server - PostgreSQL + PostGIS - Quantum GIS

Page | - 18 -
Chanaka Alahakoon – Dinidu Jayalath
WEB GIS – Geo Server - PostgreSQL + PostGIS - Quantum GIS

PostgreSQL DBMS

Open pgAdmin III from the start menu….

PostgreSQL Admin main window…

Page | - 19 -
Chanaka Alahakoon – Dinidu Jayalath
WEB GIS – Geo Server - PostgreSQL + PostGIS - Quantum GIS

Double click on the “PostgreSQL 9.0 (localhost: 5432)” link

Then it will ask the password for the user account named as postgres… Enter that password we gave
on the page 5 (postgres). Then mark the tick.

Then we can expand the tree in the left side(object browser)…

Creating Non-Spatial Database


RMB on the Databases  New Database…

Page | - 20 -
Chanaka Alahakoon – Dinidu Jayalath
WEB GIS – Geo Server - PostgreSQL + PostGIS - Quantum GIS

Name: could be any thing. Better to


give the name without space.

Owner: should be postgres

Encoding: keep the default

Template: postgres (since we are


going to create a non-spatial
database)

All others keep as they are…

 OK

Then expand the tree of the left window (object browser) again…

Page | - 21 -
Chanaka Alahakoon – Dinidu Jayalath
WEB GIS – Geo Server - PostgreSQL + PostGIS - Quantum GIS

Inside the test database, there are


some files already created…

Do not delete these files…

We can find tables inside Schemas


 public  tables

Here we can create new table,


insert, read, update and delete
data. (CRUD)

To create a new table  RMB on


tables (0) new table…

Properties tab…

Name: could be any name, don to


give any space

Owner: postgres

Columns tab…

Add column add some columns


to the table…

And there are some settings at the


Constraints tab…

Page | - 22 -
Chanaka Alahakoon – Dinidu Jayalath
WEB GIS – Geo Server - PostgreSQL + PostGIS - Quantum GIS

Or we can run SQL queries from…

Page | - 23 -
Chanaka Alahakoon – Dinidu Jayalath
WEB GIS – Geo Server - PostgreSQL + PostGIS - Quantum GIS

Creating Spatial Database

Go to the databases  RMB  New Database…

Name: Could be any, do not give


any spaces

Owner: postgres

Encoding: keep the default

Template: template_postgis

(This is the template we are using


to create spatial databases)

Note: If the PostGIS is not installed,


spatial queries or spatial data
storing cannot be done

Importing shape files to the spatial database

Select out spatial database  Main menu  Plugins  PostGIS Shapefile and DBF loader

Page | - 24 -
Chanaka Alahakoon – Dinidu Jayalath
WEB GIS – Geo Server - PostgreSQL + PostGIS - Quantum GIS

1. Browse one of our Shapefile


2. Check the contents under the PostGIS connection section
3. Set SRID as our spatial reference ID. (E.g.:- WGS84 - 4326)
4. Press the “Test Connection” button
5. If it display “Connection succeeded” at the Import Log (at the bottom)
6. Press on the import button. This will take some time…
7. To import many shapefiles, repeat the above procedure (1 to 5).

Then open the tables of our spatial database…

There are some other table (2)


inside our spatial database, known
as geometry_columns and
spatial_ref_sys. Geometry_columns
contains the geometric details of our
imported shapefiles. And the
spatial_ref_sys contains spatial
reference systems that can be used.
(All the SRS)

Page | - 25 -
Chanaka Alahakoon – Dinidu Jayalath
WEB GIS – Geo Server - PostgreSQL + PostGIS - Quantum GIS

Map Projection

We cannot calculate geometry directly from a GCS (geographic coordinate system: ellipsoid). There
for we have to transform it to a flat surface (UTM or National grids).

That can be done by transformation queries… (For more help: search for postgis cheat sheet)

Example:

We need to get the sum of the area of the districts;

SELECT sum(ST_AREA(ST_TRANSFORM(the_geom,32644))) FROM "District";

SELECT sum(st_length(st_transform(the_geom,32644))) as Total_Length FROM "Sri_railway";

Geo Server

Please prefer the note has been given to you for the basics…

Page | - 26 -
Chanaka Alahakoon – Dinidu Jayalath
WEB GIS – Geo Server - PostgreSQL + PostGIS - Quantum GIS

Chapter 3 Importing Data from PostgreSQL DBMS

Import to Geo Server


Create new workspace…

Add new stores to this work space…

Select  vector data source  PostGIS

1. Set data source name


2. Spatial database name
3. Give the user name and the password that can be used access the PostgreSQL DBMS
(postgres, postgres).
4. And check the other configurations
5. Save

Then publish the map(s) using different tabs or windows of your internet browser…

Then using open layers you can see your maps…

Page | - 27 -
Chanaka Alahakoon – Dinidu Jayalath
WEB GIS – Geo Server - PostgreSQL + PostGIS - Quantum GIS

Additional Stuff…

How to overlay maps in geo-server

Select Layer Groups  Add new layer group

1. Give a name to the group


2. Then add layers using the add layer link…
3. Click on generate bounds button
4. Save

The order of the layers must be: Top – polygon, Middle – Line, Bottom – Point. Then open this layer
group using OpenLayers.

Page | - 28 -
Chanaka Alahakoon – Dinidu Jayalath
WEB GIS – Geo Server - PostgreSQL + PostGIS - Quantum GIS

Importing to Quantum GIS

1. Main menu  Layers  Add PostGIS layers  Connection  New

Name: name for the connection

Host: localhost

Port: Our PostgreSQL port (5432)

Database: our spatial database name

Username: PostgreSQL username


(postgres)

Password: PostgreSQL password for


the above account (postgres)

 Click on the test connection


 If it is ok then click OK

2. Then Press on Connect button


3. If it ask for the username and password, give the above values
4. Select the layer(s) and add on the map

Page | - 29 -
Chanaka Alahakoon – Dinidu Jayalath
WEB GIS – Geo Server - PostgreSQL + PostGIS - Quantum GIS

Chapter 4 Additional Stuff

Importing data from a WMS to Quantum GIS

As the WMS we can use our own WMS or a WMS created at another computer.

For this practical session, we will use our Geo-Server WMS.

“http://localhost:8080/geoserver/wms?”

1. Main menu  Layers  Add WMS layer  New 

Name: any name for the


connection

URL: copy & paste your Geo-


Server WMS URL here…

 Ok

If it asks for username and


password, give the
PostgreSQL username and
password (postgres, postgres)

2. Connect
3. Then we can see a list of layers will popup at the middle…
4. Select your layers one by one and add to the map. (select one and add, then clear that selection
by clicking on that layer in the list and then select another and add)

Page | - 30 -
Chanaka Alahakoon – Dinidu Jayalath

You might also like