databases and web mapping the open source way open source gis

21
 Databases and Web Mapping the Open Source Way Open Source GIS Masterclass, Lancaster University January 2010 Jo Cook OA Digital [email protected] 01524 880212

Upload: others

Post on 12-Sep-2021

20 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: Databases and Web Mapping the Open Source Way Open Source GIS

   

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 Open Source GIS

Introduction

Page 3: Databases and Web Mapping the Open Source Way Open Source GIS

Introduction

1

2

3

Page 4: Databases and Web Mapping the Open Source Way Open Source GIS

Databases

● Server­based database (not like access)● Enterprise­level, with support for 

transactions and multiple users

+

www.postgresql.orgpostgis.refractions.net

Page 5: Databases and Web Mapping the Open Source Way Open Source GIS

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 Open Source GIS

Ways to connect

Page 7: Databases and Web Mapping the Open Source Way Open Source GIS

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 Open Source GIS

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

Page 9: Databases and Web Mapping the Open Source Way Open Source GIS

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 Open Source GIS

Map Servers

Page 11: Databases and Web Mapping the Open Source Way Open Source GIS

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 12: Databases and Web Mapping the Open Source Way Open Source GIS

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 13: Databases and Web Mapping the Open Source Way Open Source GIS

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

Page 14: Databases and Web Mapping the Open Source Way Open Source GIS

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 Open Source GIS

Web Servers and Web Pages

Page 16: Databases and Web Mapping the Open Source Way Open Source GIS

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 Open Source GIS

Scripting

● SERVER­SIDE:

php, asp● CLIENT­SIDE:

javascript

Page 18: Databases and Web Mapping the Open Source Way Open Source GIS

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>

Page 19: Databases and Web Mapping the Open Source Way Open Source GIS

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 Open Source GIS

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 Open Source GIS

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!!!