Databases and Web Mapping the Open Source Way
OSGIS 2010: Centre for Geospatial Sciences, Nottingham
June 2010



Jo Cook
...
Beyond Google Maps and Mashups
Practicalities


● Download:
www.archaeogeek.com/downloads/osgis2010.zip
●Save to /home/user and extract

●The folder /hom...
Introduction
Introduction




               3




               2


               1
Databases



                          +
            www.postgresql.org
            postgis.refractions.net
 ●   Server-ba...
Ways to connect
How to connect to a database


●   HOST: localhost, 192.168.3.40, myserver.com
●   DATABASE: ??? (your choice)
●   USERNAM...
Getting spatial data into PostgreSQL

●   OGR2OGR (command line)
●   SHP2PGSQL (command line)
●   SPIT plugin for Quantum ...
Installing Quantum GIS plugins
Loading data with SPIT

Create new database with pgadmin3
 and connect to it with SPIT in QGIS
SPIT (continued)




                   Change to lower-case!
Database house-keeping

●   Each table should have a primary key
●   Each spatial table should be recorded in
     the geo...
Querying data
●   SQL: Structured Query Language
    SELECT some comma de-limited
     columns FROM your_table WHERE
     ...
Spatial Querying

●   Find out which county a point is in and
      show it on the map:
    CREATE VIEW whichcounty AS SEL...
Map Servers
Types of Map Server

●   Minnesota Map Server (aka Mapserver)
    cgi program on a web server.
      Configuration via tex...
The Map File
MAP
      NAME "sample"
      STATUS ON
      SIZE 600 400
      EXTENT -180 -90 180 90
      UNITS DD
      ...
Checking and Viewing a map file


●   SHP2IMG at the command line
    shp2img -m
     /home/user/osgis2010/demo.map
     -...
Adding new layers to a mapfile

LAYER
  NAME "your layer"
  STATUS DEFAULT
  TYPE POLYGON
  DATA "yourshapefile.shp" (rela...
Displaying single layers



●   Set the Layer status to “ON” rather than
     “DEFAULT”
●   Specify the layers as part of ...
Connecting to PostgreSQL from Mapserver

LAYER
  NAME "UK Counties"
  STATUS DEFAULT
  TYPE POLYGON
  CONNECTIONTYPE POSTG...
Web Servers and Web Pages
Structure of a web page

<html>

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

   <body>
     HELLO WORLD!
   </b...
Scripting


●   SERVER-SIDE:
    php, asp
         <?php
                 phpinfo();
         ?>
●   CLIENT-SIDE:
    java...
Solving Problems using Firefox
Solving Problems using the mailing lists

              RTFM j00 n00b!!!
• Get latest version of software
• Read the manua...
And finally...Web Mapping
OpenLayers page structure
<html>
   <head>
       <script
src="http://www.openlayers.org/api/OpenLayers.js"></script>
    ...
Adding Controls



                     Scale Bars, Permalink
                     and Mouse Position




Layer Switcher a...
Base Mapping
●   Can use base data from Google, Microsoft,
     Yahoo, Openstreetmap etc
●   Specify base layer (not alway...
Beyond OpenLayers

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


       Open Source Web Mapping is Great Fun!!!




This work is licenced under the Creative Commons Attri...
Upcoming SlideShare
Loading in …5
×

Worskhop OSGIS2010

1,372 views

Published on

Databases and web mapping the open source way

Published in: Technology
0 Comments
0 Likes
Statistics
Notes
  • Be the first to comment

  • Be the first to like this

No Downloads
Views
Total views
1,372
On SlideShare
0
From Embeds
0
Number of Embeds
3
Actions
Shares
0
Downloads
25
Comments
0
Likes
0
Embeds 0
No embeds

No notes for slide

Worskhop OSGIS2010

  1. 1. Databases and Web Mapping the Open Source Way OSGIS 2010: Centre for Geospatial Sciences, Nottingham June 2010 Jo Cook OA Digital j.cook@oadigital.net 01524 880212
  2. 2. Beyond Google Maps and Mashups
  3. 3. Practicalities ● Download: www.archaeogeek.com/downloads/osgis2010.zip ●Save to /home/user and extract ●The folder /home/user/osgis2010 contain: shape_files (folder) demo.map mapserver.html baselayers.html osgis_2010_notes.pdf (same as handout)
  4. 4. Introduction
  5. 5. Introduction 3 2 1
  6. 6. Databases + www.postgresql.org postgis.refractions.net ● Server-based database (not like access) ● Enterprise-level, with support for transactions and multiple users
  7. 7. Ways to connect
  8. 8. How to connect to a database ● HOST: localhost, 192.168.3.40, myserver.com ● DATABASE: ??? (your choice) ● USERNAME: user ● PASSWORD: user ● PORT: 5432 (default)
  9. 9. Getting spatial data into PostgreSQL ● OGR2OGR (command line) ● SHP2PGSQL (command line) ● SPIT plugin for Quantum GIS ● Essential Parameters: host, username, password, dbname, port (as before) name and location of shapefile, name of table in database, coordinate system of data
  10. 10. Installing Quantum GIS plugins
  11. 11. Loading data with SPIT Create new database with pgadmin3 and connect to it with SPIT in QGIS
  12. 12. SPIT (continued) Change to lower-case!
  13. 13. Database house-keeping ● Each table should have a primary key ● Each spatial table should be recorded in the geometry_columns table ● Each spatial table should have a spatial index CREATE INDEX yourtable_idx ON yourtable USING GIST(geometry_column);
  14. 14. 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, PgAdmin3, or PostgreSQL Manager/SQL Editor ● There is no escape from typing out your query!
  15. 15. Spatial Querying ● Find out which county a point is in and show it on the map: CREATE VIEW whichcounty AS SELECT “PROV3NAME” FROM united_kingdom_counties WHERE st_within(geomfromtext('point(-1.4 52.6)', 4326), the_geom);
  16. 16. Map Servers
  17. 17. 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
  18. 18. 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
  19. 19. Checking and Viewing a map file ● SHP2IMG at the command line shp2img -m /home/user/osgis2010/demo.map -o /home/user/demo.png ● With a browser http://localhost.com/cgi- bin/mapserv? map=/home/user/osgis2010/demo.map &mode=map
  20. 20. Adding new layers to a mapfile LAYER NAME "your layer" STATUS DEFAULT TYPE POLYGON DATA "yourshapefile.shp" (relative to the “data” parameter in your mapfile) CLASS NAME "your name for this symbology" OUTLINECOLOR 60 60 60 COLOR 255 255 0 SYMBOL 0 END END
  21. 21. Displaying single layers ● Set the Layer status to “ON” rather than “DEFAULT” ● Specify the layers as part of the URL: http://localhost/cgi- bin/mapserv? map=/home/user/osgis2010/demo. map&layer=layer1
  22. 22. Connecting to PostgreSQL from Mapserver LAYER NAME "UK Counties" STATUS DEFAULT TYPE POLYGON CONNECTIONTYPE POSTGIS CONNECTION "host=localhost port=5432 dbname=osgis2010 user=user password=user" DATA "the_geom from united_kingdom_counties" CLASS … END END
  23. 23. Web Servers and Web Pages
  24. 24. Structure of a web page <html> <head> <title> My Home Page </title> </head> <body> HELLO WORLD! </body> </html>
  25. 25. Scripting ● SERVER-SIDE: php, asp <?php phpinfo(); ?> ● CLIENT-SIDE: javascript
  26. 26. Solving Problems using Firefox
  27. 27. Solving Problems using the mailing lists RTFM j00 n00b!!! • Get latest version of software • Read the manual/help documentation • Search the mailing list archives • Strip as much detail out of your code as possible • Provide as much information as you can about your setup and the steps you have already taken
  28. 28. And finally...Web Mapping
  29. 29. OpenLayers page structure <html> <head> <script src="http://www.openlayers.org/api/OpenLayers.js"></script> <script type="text/javascript"> var map, mylayer; 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>
  30. 30. Adding Controls Scale Bars, Permalink and Mouse Position Layer Switcher and Overview Map
  31. 31. Base Mapping ● Can use base data from Google, Microsoft, Yahoo, Openstreetmap etc ● Specify base layer (not always necessary) {'isBaseLayer': true} ● Overlay needs to be transparent {'transparent':true, 'format': png} ● Change addlayers directive map.addLayers([layer1,layer2]);
  32. 32. Beyond OpenLayers •MapGuide Open Source http://mapguide.osgeo.org •Mapfish http://mapfish.org/ •Mapchat http://mapchat.ca/ •Featureserver http://featureserver.org/
  33. 33. 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

×