Mapserver Postgis CC
Mapserver Postgis CC
Using MapServer
with
PostgreSQL / PostGIS
1
(Creative Commons by-nc-sa, 3.0)
D.Magni, Using
1. PostgreSQL
2
(Creative Commons by-nc-sa, 3.0)
D.Magni, Using
2. PostGIS
PostGIS adds support for geographic objects to the PostgreSQL
object-relational database.
In effect, PostGIS "spatially enables" the PostgreSQL server,
allowing it to be used as a backend spatial database
for geographic information systems (GIS) (citation from PostGIS website)
Link : http://postgis.refractions.net/
Release for exercises : 8.2 for Windows
OpenSource License : GPL (General Public License)
3
(Creative Commons by-nc-sa, 3.0)
D.Magni, Using
2. PostGIS
Allows to geo-refer tables of PostgreSQL (tables become spatial tables)
This is possible by adding a Geometry Column to tables
The Geometry Column (type=geometry) contains data with the syntax:
SRID=<crs_id>;<GEOMETRY_TYPE>(<COORDINATES>,<COORDINATES>)
Example:
SRID=3003;LINESTRING(1503032.67 5071234.09,1503052.55 5073234.21)
For Gauss-Boaga (West) SRID=3003; if the CRS is not specified, set SRID=-1
4
(Creative Commons by-nc-sa, 3.0)
D.Magni, Using
2. PostGIS
<GEOMETRY_TYPE> can be:
POINT(0 0)
LINESTRING(0 0,1 1,1 2)
POLYGON((0 0,4 0,4 4,0 4,0 0),(1 1, 2 1, 2 2, 1 2,1 1))
MULTIPOINT(0 0,1 2)
MULTILINESTRING((0 0,1 1,1 2),(2 3,3 2,5 4))
MULTIPOLYGON(((0 0,4 0,4 4,0 4,0 0),(1 1,2 1,2 2,1 2,1 1)),
((-1 -1,-1 -2,-2 -2,-2 -1,-1 -1)))
GEOMETRYCOLLECTION(POINT(2 3),LINESTRING((2 3,3 4)))
5
(Creative Commons by-nc-sa, 3.0)
D.Magni, Using
2. PostGIS
A DB spatially enabled by PostGIS has two special tables:
geometry_columns: contains a row for each spatial table of that DB
Name of geometry column
Geometry dimensions
CRS (SRID)
Geometry type
spatial_ref_sys: is a list of CRSs, like the EPSG file seen for PROJ library
6
(Creative Commons by-nc-sa, 3.0)
D.Magni, Using
3. pgAdmin III
Frontend application for working with PostgreSQL without command line
Link : http://www.pgadmin.org/
Release for exercises : 1.6.2 for Windows
License : http://www.pgadmin.org/licence.php
4. Exercises
4.1 - Connect a remote PostgreSQL server
1. Open pgAdmin III on your local PC (Start J Programs J PostgreSQL J pgAdmin III)
2. Connect the PostgreSQL remote server
File J Aggiungi server
File J Add server
A
B
A - Service name: GIS course
B - Host name: 192.168.157.30
C
D
C Manager DB: gis
E
D - User name: ugisNR
E - Password: ugisNR
3. Click OK
NR is the same number of your PSF;
Example: psf34 J ugis34
D.Magni, Using
(Creative Commons by-nc-sa, 3.0)
Database
geometry_columns
Tables
spatial_ref_sys
9
(Creative Commons by-nc-sa, 3.0)
Name = tableNR
Holder = your user
Then, OK
10
D.Magni, Using
Column name = id
Column type = integer
Then, OK
11
(Creative Commons by-nc-sa, 3.0)
D.Magni, Using
12
(Creative Commons by-nc-sa, 3.0)
D.Magni, Using
12
Constraints
4) Select id column
as primary key
D.Magni, Using
13
14
(Creative Commons by-nc-sa, 3.0)
D.Magni, Using
15
(Creative Commons by-nc-sa, 3.0)
D.Magni, Using
5. Check result
16
(Creative Commons by-nc-sa, 3.0)
D.Magni, Using
17
(Creative Commons by-nc-sa, 3.0)
Table columns
Primary key
Geometry column indexes
GiST index
18
(Creative Commons by-nc-sa, 3.0)
A B
or
1. Select the table
2. Click on A to display all rows
or B to display filtered rows
(Creative Commons by-nc-sa, 3.0)
19
20
Web Server
Architecture
Map file
CGI
Data
2
4.b
3.a
5
Template file
(HTML)
BROWSER
PostgreSQL
3.b
4.a
21
23
(Creative Commons by-nc-sa, 3.0)
24
25
(Creative Commons by-nc-sa, 3.0)
26
27
(Creative Commons by-nc-sa, 3.0)
28
(Creative Commons by-nc-sa, 3.0)
License
This document is released under the following license:
29