worskhop osgis2010
DESCRIPTION
Databases and web mapping the open source wayTRANSCRIPT
![Page 1: Worskhop OSGIS2010](https://reader033.vdocuments.net/reader033/viewer/2022052823/55507862b4c90524138b5112/html5/thumbnails/1.jpg)
Databases and Web Mapping the Open Source WayOSGIS 2010: Centre for Geospatial Sciences, NottinghamJune 2010
Jo CookOA Digital
[email protected] 880212
![Page 2: Worskhop OSGIS2010](https://reader033.vdocuments.net/reader033/viewer/2022052823/55507862b4c90524138b5112/html5/thumbnails/2.jpg)
Beyond Google Maps and Mashups
![Page 3: Worskhop OSGIS2010](https://reader033.vdocuments.net/reader033/viewer/2022052823/55507862b4c90524138b5112/html5/thumbnails/3.jpg)
Practicalities
● Download: www.archaeogeek.com/downloads/osgis2010.zip●Save to /home/user and extract●The folder /home/user/osgis2010 contain:shape_files (folder)demo.mapmapserver.htmlbaselayers.htmlosgis_2010_notes.pdf (same as handout)
![Page 4: Worskhop OSGIS2010](https://reader033.vdocuments.net/reader033/viewer/2022052823/55507862b4c90524138b5112/html5/thumbnails/4.jpg)
Introduction
![Page 5: Worskhop OSGIS2010](https://reader033.vdocuments.net/reader033/viewer/2022052823/55507862b4c90524138b5112/html5/thumbnails/5.jpg)
Introduction
1
2
3
![Page 6: Worskhop OSGIS2010](https://reader033.vdocuments.net/reader033/viewer/2022052823/55507862b4c90524138b5112/html5/thumbnails/6.jpg)
Databases
● Server-based database (not like access)● Enterprise-level, with support for
transactions and multiple users
+
www.postgresql.orgpostgis.refractions.net
![Page 7: Worskhop OSGIS2010](https://reader033.vdocuments.net/reader033/viewer/2022052823/55507862b4c90524138b5112/html5/thumbnails/7.jpg)
Ways to connect
![Page 8: Worskhop OSGIS2010](https://reader033.vdocuments.net/reader033/viewer/2022052823/55507862b4c90524138b5112/html5/thumbnails/8.jpg)
How to connect to a database
● HOST: localhost, 192.168.3.40, myserver.com● DATABASE: ??? (your choice)● USERNAME: user● PASSWORD: user● PORT: 5432 (default)
![Page 9: Worskhop OSGIS2010](https://reader033.vdocuments.net/reader033/viewer/2022052823/55507862b4c90524138b5112/html5/thumbnails/9.jpg)
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
![Page 10: Worskhop OSGIS2010](https://reader033.vdocuments.net/reader033/viewer/2022052823/55507862b4c90524138b5112/html5/thumbnails/10.jpg)
Installing Quantum GIS plugins
![Page 11: Worskhop OSGIS2010](https://reader033.vdocuments.net/reader033/viewer/2022052823/55507862b4c90524138b5112/html5/thumbnails/11.jpg)
Loading data with SPIT
Create new database with pgadmin3and connect to it with SPIT in QGIS
![Page 12: Worskhop OSGIS2010](https://reader033.vdocuments.net/reader033/viewer/2022052823/55507862b4c90524138b5112/html5/thumbnails/12.jpg)
SPIT (continued)
Change to lower-case!
![Page 13: Worskhop OSGIS2010](https://reader033.vdocuments.net/reader033/viewer/2022052823/55507862b4c90524138b5112/html5/thumbnails/13.jpg)
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
indexCREATE INDEX yourtable_idx ON yourtable USING GIST(geometry_column);
![Page 14: Worskhop OSGIS2010](https://reader033.vdocuments.net/reader033/viewer/2022052823/55507862b4c90524138b5112/html5/thumbnails/14.jpg)
Querying data
● SQL: Structured Query LanguageSELECT 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!
![Page 15: Worskhop OSGIS2010](https://reader033.vdocuments.net/reader033/viewer/2022052823/55507862b4c90524138b5112/html5/thumbnails/15.jpg)
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);
![Page 16: Worskhop OSGIS2010](https://reader033.vdocuments.net/reader033/viewer/2022052823/55507862b4c90524138b5112/html5/thumbnails/16.jpg)
Map Servers
![Page 17: Worskhop OSGIS2010](https://reader033.vdocuments.net/reader033/viewer/2022052823/55507862b4c90524138b5112/html5/thumbnails/17.jpg)
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
![Page 18: Worskhop OSGIS2010](https://reader033.vdocuments.net/reader033/viewer/2022052823/55507862b4c90524138b5112/html5/thumbnails/18.jpg)
The Map FileMAP 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 ENDEND
![Page 19: Worskhop OSGIS2010](https://reader033.vdocuments.net/reader033/viewer/2022052823/55507862b4c90524138b5112/html5/thumbnails/19.jpg)
Checking and Viewing a map file
● SHP2IMG at the command lineshp2img -m /home/user/osgis2010/demo.map -o /home/user/demo.png
● With a browserhttp://localhost.com/cgi-bin/mapserv?map=/home/user/osgis2010/demo.map&mode=map
![Page 20: Worskhop OSGIS2010](https://reader033.vdocuments.net/reader033/viewer/2022052823/55507862b4c90524138b5112/html5/thumbnails/20.jpg)
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 60COLOR 255 255 0SYMBOL 0
ENDEND
![Page 21: Worskhop OSGIS2010](https://reader033.vdocuments.net/reader033/viewer/2022052823/55507862b4c90524138b5112/html5/thumbnails/21.jpg)
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
![Page 22: Worskhop OSGIS2010](https://reader033.vdocuments.net/reader033/viewer/2022052823/55507862b4c90524138b5112/html5/thumbnails/22.jpg)
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
![Page 23: Worskhop OSGIS2010](https://reader033.vdocuments.net/reader033/viewer/2022052823/55507862b4c90524138b5112/html5/thumbnails/23.jpg)
Web Servers and Web Pages
![Page 24: Worskhop OSGIS2010](https://reader033.vdocuments.net/reader033/viewer/2022052823/55507862b4c90524138b5112/html5/thumbnails/24.jpg)
Structure of a web page
<html>
<head><title> My Home Page
</title></head>
<body>HELLO WORLD!
</body>
</html>
![Page 25: Worskhop OSGIS2010](https://reader033.vdocuments.net/reader033/viewer/2022052823/55507862b4c90524138b5112/html5/thumbnails/25.jpg)
Scripting
● SERVER-SIDE:php, asp
<?phpphpinfo();
?>● CLIENT-SIDE:
javascript
![Page 26: Worskhop OSGIS2010](https://reader033.vdocuments.net/reader033/viewer/2022052823/55507862b4c90524138b5112/html5/thumbnails/26.jpg)
Solving Problems using Firefox
![Page 27: Worskhop OSGIS2010](https://reader033.vdocuments.net/reader033/viewer/2022052823/55507862b4c90524138b5112/html5/thumbnails/27.jpg)
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
![Page 28: Worskhop OSGIS2010](https://reader033.vdocuments.net/reader033/viewer/2022052823/55507862b4c90524138b5112/html5/thumbnails/28.jpg)
And finally...Web Mapping
![Page 29: Worskhop OSGIS2010](https://reader033.vdocuments.net/reader033/viewer/2022052823/55507862b4c90524138b5112/html5/thumbnails/29.jpg)
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>
![Page 30: Worskhop OSGIS2010](https://reader033.vdocuments.net/reader033/viewer/2022052823/55507862b4c90524138b5112/html5/thumbnails/30.jpg)
Adding Controls
Scale Bars, Permalink and Mouse Position
Layer Switcher and Overview Map
![Page 31: Worskhop OSGIS2010](https://reader033.vdocuments.net/reader033/viewer/2022052823/55507862b4c90524138b5112/html5/thumbnails/31.jpg)
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 directivemap.addLayers([layer1,layer2]);
![Page 32: Worskhop OSGIS2010](https://reader033.vdocuments.net/reader033/viewer/2022052823/55507862b4c90524138b5112/html5/thumbnails/32.jpg)
Beyond OpenLayers
•MapGuide Open Source http://mapguide.osgeo.org•Mapfish http://mapfish.org/•Mapchat http://mapchat.ca/•Featureserver http://featureserver.org/
![Page 33: Worskhop OSGIS2010](https://reader033.vdocuments.net/reader033/viewer/2022052823/55507862b4c90524138b5112/html5/thumbnails/33.jpg)
And Finally...
Jo CookOA Digitalhttp://[email protected]+44 (0)1524 880212
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.
Open Source Web Mapping is Great Fun!!!