SlideShare a Scribd company logo
Databases and Web Mapping the Open Source Way
Open Source GIS Masterclass, Lancaster University
January 2010



Jo Cook
OA Digital

j.cook@oadigital.net
01524 880212



                         
Introduction
Introduction




               3




               2


               1
Databases



                          +
            www.postgresql.org
            postgis.refractions.net
 ●   Server­based database (not like access)
 ●   Enterprise­level, with support for 
      transactions and multiple users
How to connect to a database


●   HOST: localhost, 192.168.3.40, myserver.com
●   DATABASE
●   USERNAME
●   PASSWORD
●   PORT: Usually 5432
Ways to connect
Getting spatial data into PostgreSQL

●   OGR2OGR
●   SHP2PGSQL
    Syntax:
    $shp2pgsql /location/of/file.shp tablename 
     ­s coordinate system ­W latin1 | psql ­d 
     database ­U username ­W ­h host ­p 
     port
Querying data
●   SQL: Structured Query Language
    SELECT some comma de­limited columns 
     FROM your_table WHERE some 
     condition is met;
●   Use PSQL from command line or 
     PgAdmin3
Spatial Querying

●   Find out which county a point is in:
    SELECT name_2 FROM tblcounties WHERE 
     st_within(geomfromtext('point(­1.3 54.26)', 
     4326), the_geom);
●   Find out which counties border 
      Lancashire:
    SELECT a.name_2 FROM tblcounties a, 
     tblcounties b WHERE b.name_2='Lancashire' 
     AND a.the_geom && b.the_geom;
Map Servers
Types of Map Server

●   Minnesota Map Server (aka Mapserver)
    cgi program on a web server. 
      Configuration via text files
●   Geoserver
    java­based program. Configuration via 
      web interface
The Map File
MAP
    NAME "sample"
    STATUS ON
    SIZE 600 400
    EXTENT ­180 ­90 180 90
    UNITS DD
    SHAPEPATH "../data"
    IMAGECOLOR 255 255 255
    WEB
        IMAGEPATH "/ms4w/tmp/ms_tmp/"
        IMAGEURL "/ms_tmp/"
    END
    LAYER
        NAME 'global­raster'
        TYPE RASTER
        STATUS DEFAULT
        DATA bluemarble.gif
    END
END
Checking the map file



●   SHP2IMG
    $shp2img ­m /location/of/mapfile.map ­o 
     /location/of/outputfile.png
●   WITH THE BROWSER
    http://yourserver.com/cgi­bin/mapserv?
      map=/location/of/mapfile.map&mode=map
Connecting to PostgreSQL from Mapserver
 LAYER
   NAME "province"
   STATUS ON
   TYPE POLYGON
   CONNECTIONTYPE POSTGIS
   CONNECTION "host=localhost port=5432 dbname=canada user=postgres 
 password=postgres"
   DATA "the_geom from province"
 END
Web Servers and Web Pages
Structure of a web page

<html>

    <head>
        <title> My Home Page </title>
    </head>

    <body>
        HELLO WORLD!
    </body>

</html>
Scripting


●   SERVER­SIDE:
    php, asp
●   CLIENT­SIDE:
    javascript
And finally...Web Mapping
<html>
    <head>
        <script src="http://www.openlayers.org/api/OpenLayers.js"></script>
        <script type="text/javascript">
            var map;
             function init() {
            map = new OpenLayers.Map('map');
            mylayer = new OpenLayers.Layer.MapServer( "World Map",
                  "http://localhost/cgi­bin/mapserv.exe",
                  {map: 'C:/world_mapfile.map'});
            map.addLayer(mylayer);
            map.zoomToMaxExtent();
            }
        </script>
    </head>
    <body onload="init()">
        <div id="map"  style="width: 600px; height: 300px"></div>
    </body>
</html>
Base Mapping and Map Controls

●   Can use base data from Google, 
     Microsoft, Yahoo, Openstreetmap etc, 
     but may need to reproject to EPSG 
     900913 (spherical mercator)
●   Can add map controls such as layer 
     switchers, coordinates, reference maps 
     and so on
Beyond OpenLayers

•MapGuide Open Source http://mapguide.osgeo.org
•Mapfish http://mapfish.org/
•Mapchat http://mapchat.ca/
•Featureserver http://featureserver.org/
And Finally...



              Open Source Web Mapping is Great Fun!!!




This work is licenced under the Creative Commons Attribution­Share Alike 2.0 UK: England & Wales License. 
To view a copy of this licence, visit http://creativecommons.org/licenses/by­sa/2.0/uk/ or send a letter to Creative 
Commons, 171 Second Street, Suite 300, San Francisco, California 
94105, USA.

                                                                                             Jo Cook
                                                                                             OA Digital
                                                                                             http://oadigital.net
                                                                                             j.cook@oadigital.net
                                                                                             +44 (0)1524 880212

More Related Content

PDF
Worskhop OSGIS2010
PDF
Worskhop Leicester 2010
PDF
Osgis 2010 notes
DOC
AGI 2010 Notes
PDF
Lancaster University GIS Course 2010
PPT
Foss4g Portable Gis
PDF
Introduction to OSGeo:UK
PDF
Agi North
Worskhop OSGIS2010
Worskhop Leicester 2010
Osgis 2010 notes
AGI 2010 Notes
Lancaster University GIS Course 2010
Foss4g Portable Gis
Introduction to OSGeo:UK
Agi North

Similar to Databases and web mapping the Open Source way (20)

PDF
Mel McIntyre, OpenApp.ie LGMA
KEY
Web gis implementation notes
PPTX
OSi Local Gov User Group Presentation
PPT
Getting started with PostGIS geographic database
PPT
Getting Started with PostGIS geographic database - Lasma Sietinsone, EDINA
PPT
Web enabling your survey business ppt version
PDF
Leicester 2010 notes
PDF
GIS for Recorders
PPTX
PostGIS and Spatial SQL
PPT
Session 43 :: Accessing data using a common interface: OGSA-DAI as an example
PDF
Postgis for Enterprise
PPTX
Building good web_maps, Esri, Joris Bak
PPT
Using PostGIS To Add Some Spatial Flavor To Your Application
PPT
Geoservices Activities at EDINA
ODP
Open GeoData, Open GeoTools: An Introduction
PDF
Building A Spatial Database In Postgresql (Ppt).pdf
PDF
Bcs Talk Notes
PPTX
FOSS4G 2017 Spatial Sql for Rookies
PPT
Dotted Eyes - Open Software, Standards and Data
Mel McIntyre, OpenApp.ie LGMA
Web gis implementation notes
OSi Local Gov User Group Presentation
Getting started with PostGIS geographic database
Getting Started with PostGIS geographic database - Lasma Sietinsone, EDINA
Web enabling your survey business ppt version
Leicester 2010 notes
GIS for Recorders
PostGIS and Spatial SQL
Session 43 :: Accessing data using a common interface: OGSA-DAI as an example
Postgis for Enterprise
Building good web_maps, Esri, Joris Bak
Using PostGIS To Add Some Spatial Flavor To Your Application
Geoservices Activities at EDINA
Open GeoData, Open GeoTools: An Introduction
Building A Spatial Database In Postgresql (Ppt).pdf
Bcs Talk Notes
FOSS4G 2017 Spatial Sql for Rookies
Dotted Eyes - Open Software, Standards and Data
Ad

More from Joanne Cook (14)

PDF
Consuming open and linked data with open source tools
PDF
Intro to the Open Source Geospatial Foundation
PDF
Intro to Quantum GIS Desktop GIS
ODP
The Business Case for Open Source GIS
ODP
Open Source and Open Data
PDF
Consuming and Publishing Ordnance Survey Open Data with Open Source Software
PPT
AGI 2010: It's all one big opportunity
ODP
How archaeologists use GIS
ODP
The Impact of Open Source
ODP
Open Source GIS for Local Government
PPT
Bcs Talk Notes
PPT
Gateway Seminar
PPT
Agi 2008
PDF
Agi Techsig 2009
Consuming open and linked data with open source tools
Intro to the Open Source Geospatial Foundation
Intro to Quantum GIS Desktop GIS
The Business Case for Open Source GIS
Open Source and Open Data
Consuming and Publishing Ordnance Survey Open Data with Open Source Software
AGI 2010: It's all one big opportunity
How archaeologists use GIS
The Impact of Open Source
Open Source GIS for Local Government
Bcs Talk Notes
Gateway Seminar
Agi 2008
Agi Techsig 2009
Ad

Recently uploaded (20)

PPTX
Digital-Transformation-Roadmap-for-Companies.pptx
PPT
Teaching material agriculture food technology
PPTX
Understanding_Digital_Forensics_Presentation.pptx
PDF
TokAI - TikTok AI Agent : The First AI Application That Analyzes 10,000+ Vira...
PDF
Encapsulation theory and applications.pdf
PPTX
Cloud computing and distributed systems.
PPTX
20250228 LYD VKU AI Blended-Learning.pptx
PPTX
KOM of Painting work and Equipment Insulation REV00 update 25-dec.pptx
DOCX
The AUB Centre for AI in Media Proposal.docx
PDF
Build a system with the filesystem maintained by OSTree @ COSCUP 2025
PPTX
Big Data Technologies - Introduction.pptx
PDF
KodekX | Application Modernization Development
PDF
Unlocking AI with Model Context Protocol (MCP)
PDF
Modernizing your data center with Dell and AMD
PDF
Blue Purple Modern Animated Computer Science Presentation.pdf.pdf
PPTX
VMware vSphere Foundation How to Sell Presentation-Ver1.4-2-14-2024.pptx
PPTX
A Presentation on Artificial Intelligence
PDF
NewMind AI Weekly Chronicles - August'25 Week I
PDF
Machine learning based COVID-19 study performance prediction
PDF
Review of recent advances in non-invasive hemoglobin estimation
Digital-Transformation-Roadmap-for-Companies.pptx
Teaching material agriculture food technology
Understanding_Digital_Forensics_Presentation.pptx
TokAI - TikTok AI Agent : The First AI Application That Analyzes 10,000+ Vira...
Encapsulation theory and applications.pdf
Cloud computing and distributed systems.
20250228 LYD VKU AI Blended-Learning.pptx
KOM of Painting work and Equipment Insulation REV00 update 25-dec.pptx
The AUB Centre for AI in Media Proposal.docx
Build a system with the filesystem maintained by OSTree @ COSCUP 2025
Big Data Technologies - Introduction.pptx
KodekX | Application Modernization Development
Unlocking AI with Model Context Protocol (MCP)
Modernizing your data center with Dell and AMD
Blue Purple Modern Animated Computer Science Presentation.pdf.pdf
VMware vSphere Foundation How to Sell Presentation-Ver1.4-2-14-2024.pptx
A Presentation on Artificial Intelligence
NewMind AI Weekly Chronicles - August'25 Week I
Machine learning based COVID-19 study performance prediction
Review of recent advances in non-invasive hemoglobin estimation

Databases and web mapping the Open Source way