www.iirs.gov.in
Kamal Pandey
kamal@iirs.gov.in
iirs
Lecture Outline
Introduction
Definition and Classification of Spatial Database
Systems
Evolution of spatial data processing
Introduction to PostgreSQL & PostGIS
Spatial Data (Shapefile) in PostgreSQL/PostGIS
Spatial Queries using PostGIS
Visualizing queries result in QGIS
iirs
Introduction
iirs
Definition
iirs
Definition Contd
iirs
iirs
iirs
Spatial Database
Management
System
Data
Task
Data load
Editing
Visualization
Mapping
Analysis
Storage
Indexing
Security
Query
iirs
(Internet)
GIS Desktop
Applications
Wireless
Mobile
Devices
Network
Custom
Applications
Map Renderer
Spatial
DB
Server Side
Applications
iirs
Classification
of
Spatial Operators
iirs
iirs
Reliability
Integrity: enforces
consistency
Security
User views
User interface
Querying
Updating
DB theory has a
Mathematical basis
Data independence
Data Abstraction
Self-describing
Concurrency
Distributed capabilities
High performance
Supports spatial data
types using ADTs.
Alternative: files
iirs
distance
adjacency
containment
area
length
intersection
union
buffer
iirs
iirs
Database that:
Stores spatial objects
Manipulates spatial objects just like other objects
in the database
Three aspects
Spatial data types
Spatial indexing
Spatial functions
iirs
iirs
iirs
Has functions
Has spatial functions
Work against standard Work against spatial types
types
ST_Area(geometry)
lower()
ST_Distance(geometry,geometry)
round()
ST_Intersects(geometry,geometry)
substring()
ST_DWithin(geometry,geometry,radius)
trim()
dayofweek ()
iirs
iirs
iirs
About PostgreSQL
http://www.postgresql.org/
iirs
Value
Unlimited
32 TB
1.6 TB
1 GB
Unlimited
250 - 1600
Unlimited
About PostGIS
iirs
http://postgis.net/
Open source
Proprietary/open source clients
iirs
iirs
Installing PostgreSQL/PostGIS
http://www.postgresql.org/download/windows/
Both 32 bit and 64 bit installers
Many options
Download
PostgreSQL/PostGIS Installation
iirs
iirs
iirs
iirs
iirs
iirs
iirs
iirs
iirs
iirs
Metadata tables
iirs
GEOMETRY_COLUMNS VIEW
-------------------+------------------------+-----------
auth_name VARCHAR(256),
auth_srid INTEGER,
srtext VARCHAR(2048),
proj4text VARCHAR(2048)
coord_dimension | integer
srid | integer |
type | character varying(30) |
iirs
iirs
PostGIS Functions
Single Geometry
Float : st_Length(Geometry)
Float : st_Area(Geometry)
Geometry : st_Buffer(Geometry,Float)
Text : st_AsText(Geometry)
Multiple Geometry
Float : st_Distance(Geometry,Geometry)
Boolean : st_Touches(Geometry,Geometry)
Boolean : st_Intersects(Geometry,Geometry)
Boolean : st_Disjoint(Geometry,Geometry)
Geometry : st_Intersection(Geometry,Geometry)
iirs
iirs
Simple query
iirs
iirs
(3,
iirs
DropGeometryColumn()
removes the meta information from the geometry_columns
iirs
iirs
iirs
d postgis
U postgres
f bc_data.sql
psql d database U postgres f file.sql
iirs
iirs
iirs
iirs
iirs
Desktop GIS
uDig
QGIS
gvSIG
MapGuide
Mapserver
Geoserver
iirs
PgAdmin (GUI)
iirs
SELECT queries
A select query is generally of the form:
SELECT some_columns FROM some_data_source WHERE some_condition;
iirs
PgAdmin (GUI)
iirs
PgAdmin (GUI)
iirs
iirs
iirs
iirs
iirs
iirs
iirs
SPATIAL JOIN
SELECT
m.name,sum(ST_Length(r.the_geom)) as roads_km
FROM bc_roads as r, bc_municipality as m
WHERE
ST_Contains(m.the_geom,r.the_geom)
GROUP BY m.name;
iirs
Overlays
ST_Intersects() = TRUE
ST_Intersection() =
iirs
Overlays Contd
iirs
Overlays Contd
CREATE TABLE pg_voting_areas AS
SELECT
ST_Intersection(v.the_geom, m.the_geom)
AS intersection_geom,
ST_Area(v.the_geom) AS va_area,
v.*, m.name
FROM
bc_voting_areas v, bc_municipality m
WHERE
ST_Intersects(v.the_geom, m.the_geom) AND
m.name = PRINCE GEORGE;
iirs
iirs
iirs
iirs
Start pgAdmin
Database Backup
Right click on specific
DB to take Backup
Select backup menu
item.
Select filename and
press OK.
iirs
iirs