Databases and web mapping the Open Source way
-
Upload
joanne-cook -
Category
Technology
-
view
1.952 -
download
0
Transcript of Databases and web mapping the Open Source way
![Page 1: Databases and web mapping the Open Source way](https://reader033.fdocuments.net/reader033/viewer/2022060108/55507864b4c90524138b5114/html5/thumbnails/1.jpg)
Databases and Web Mapping the Open Source WayOpen Source GIS Masterclass, Lancaster UniversityJanuary 2010
Jo CookOA Digital
[email protected] 880212
![Page 2: Databases and web mapping the Open Source way](https://reader033.fdocuments.net/reader033/viewer/2022060108/55507864b4c90524138b5114/html5/thumbnails/2.jpg)
Introduction
![Page 3: Databases and web mapping the Open Source way](https://reader033.fdocuments.net/reader033/viewer/2022060108/55507864b4c90524138b5114/html5/thumbnails/3.jpg)
Introduction
1
2
3
![Page 4: Databases and web mapping the Open Source way](https://reader033.fdocuments.net/reader033/viewer/2022060108/55507864b4c90524138b5114/html5/thumbnails/4.jpg)
Databases
● Serverbased database (not like access)● Enterpriselevel, with support for
transactions and multiple users
+
www.postgresql.orgpostgis.refractions.net
![Page 5: Databases and web mapping the Open Source way](https://reader033.fdocuments.net/reader033/viewer/2022060108/55507864b4c90524138b5114/html5/thumbnails/5.jpg)
How to connect to a database
● HOST: localhost, 192.168.3.40, myserver.com● DATABASE● USERNAME● PASSWORD● PORT: Usually 5432
![Page 6: Databases and web mapping the Open Source way](https://reader033.fdocuments.net/reader033/viewer/2022060108/55507864b4c90524138b5114/html5/thumbnails/6.jpg)
Ways to connect
![Page 7: Databases and web mapping the Open Source way](https://reader033.fdocuments.net/reader033/viewer/2022060108/55507864b4c90524138b5114/html5/thumbnails/7.jpg)
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
![Page 8: Databases and web mapping the Open Source way](https://reader033.fdocuments.net/reader033/viewer/2022060108/55507864b4c90524138b5114/html5/thumbnails/8.jpg)
Querying data
● SQL: Structured Query Language
SELECT some comma delimited columns FROM your_table WHERE some condition is met;
● Use PSQL from command line or PgAdmin3
![Page 9: Databases and web mapping the Open Source way](https://reader033.fdocuments.net/reader033/viewer/2022060108/55507864b4c90524138b5114/html5/thumbnails/9.jpg)
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;
![Page 10: Databases and web mapping the Open Source way](https://reader033.fdocuments.net/reader033/viewer/2022060108/55507864b4c90524138b5114/html5/thumbnails/10.jpg)
Map Servers
![Page 11: Databases and web mapping the Open Source way](https://reader033.fdocuments.net/reader033/viewer/2022060108/55507864b4c90524138b5114/html5/thumbnails/11.jpg)
Types of Map Server
● Minnesota Map Server (aka Mapserver)
cgi program on a web server. Configuration via text files
● Geoserver
javabased program. Configuration via web interface
![Page 12: Databases and web mapping the Open Source way](https://reader033.fdocuments.net/reader033/viewer/2022060108/55507864b4c90524138b5114/html5/thumbnails/12.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 'globalraster' TYPE RASTER STATUS DEFAULT DATA bluemarble.gif ENDEND
![Page 13: Databases and web mapping the Open Source way](https://reader033.fdocuments.net/reader033/viewer/2022060108/55507864b4c90524138b5114/html5/thumbnails/13.jpg)
Checking the map file
● SHP2IMG
$shp2img m /location/of/mapfile.map o /location/of/outputfile.png
● WITH THE BROWSER
http://yourserver.com/cgibin/mapserv?map=/location/of/mapfile.map&mode=map
![Page 14: Databases and web mapping the Open Source way](https://reader033.fdocuments.net/reader033/viewer/2022060108/55507864b4c90524138b5114/html5/thumbnails/14.jpg)
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
![Page 15: Databases and web mapping the Open Source way](https://reader033.fdocuments.net/reader033/viewer/2022060108/55507864b4c90524138b5114/html5/thumbnails/15.jpg)
Web Servers and Web Pages
![Page 16: Databases and web mapping the Open Source way](https://reader033.fdocuments.net/reader033/viewer/2022060108/55507864b4c90524138b5114/html5/thumbnails/16.jpg)
Structure of a web page
<html>
<head><title> My Home Page </title>
</head>
<body>HELLO WORLD!
</body>
</html>
![Page 17: Databases and web mapping the Open Source way](https://reader033.fdocuments.net/reader033/viewer/2022060108/55507864b4c90524138b5114/html5/thumbnails/17.jpg)
Scripting
● SERVERSIDE:
php, asp● CLIENTSIDE:
javascript
![Page 18: Databases and web mapping the Open Source way](https://reader033.fdocuments.net/reader033/viewer/2022060108/55507864b4c90524138b5114/html5/thumbnails/18.jpg)
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/cgibin/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 19: Databases and web mapping the Open Source way](https://reader033.fdocuments.net/reader033/viewer/2022060108/55507864b4c90524138b5114/html5/thumbnails/19.jpg)
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
![Page 20: Databases and web mapping the Open Source way](https://reader033.fdocuments.net/reader033/viewer/2022060108/55507864b4c90524138b5114/html5/thumbnails/20.jpg)
Beyond OpenLayers
•MapGuide Open Source http://mapguide.osgeo.org•Mapfish http://mapfish.org/•Mapchat http://mapchat.ca/•Featureserver http://featureserver.org/
![Page 21: Databases and web mapping the Open Source way](https://reader033.fdocuments.net/reader033/viewer/2022060108/55507864b4c90524138b5114/html5/thumbnails/21.jpg)
And Finally...
Jo CookOA Digitalhttp://[email protected]+44 (0)1524 880212
This work is licenced under the Creative Commons AttributionShare Alike 2.0 UK: England & Wales License. To view a copy of this licence, visit http://creativecommons.org/licenses/bysa/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!!!