Professional Documents
Culture Documents
1. 2. 3. 4. !. $. (. Why Web Mapping? Explanation of stack/structure Data Map ser er WM"/W#" Mapping %&' )ataloging
What's a stack?
%he "stack" is the set of components needed to make a web-mapping application. %he formal name for the stack is a !patial &ata Infrastructure, or !&I. In some packages, various #or all$ aspects of the stack'!&I are merged into one application. It can, however, be easier to maintain a stack if you choose a modular approach and choose a dedicated piece of software for each aspect.
Data:
&ata comes in two main forms- vector and raster, as discussed in the earlier sessions. If you're going to display it online, you need to make sure that it is stored somewhere the web server can access it. %his means it must be in folders that the web server can read'write, and if it's stored in a database you need to make sure that the database is
configured for web access. It is even more necessary to ensure that your data is "clean" #topologically sound and so on$ and has the correct metadata and coordinate systems. %hat is all your web server has to go on- it can't come and ask where or what something is. %he cataloguing component #discussed later$ may help with this side of things.
Map server:
In simple terms, a map server takes a re,uest from a web page and returns some data. It interprets bounding bo+ re,uests to decide how much data to return, and ensures that it is in the correct pro-ection. %he two main options for map servers are minnesota mapserver #mapserver to it's friends$ and geoserver. Mapserver, in it's simplest form, is a cgi application that lives on a web server. It takes re,uests in the form of parameters tacked on to the end of a ./0, consults a te+tbased configuration file known as a map file, and returns data to the web server. It is very easy to install and use- binaries are available for Windows and Mac 1!2, packages are available for many linu+ distributions, and the source code is publically available. )or windows, it is possible to download a web server and mapserver setup preconfigured and ready to go with all the support files #mapserver uses a set of open source libraries and tools for dealing with spatial references and format read'write'conversion$. %his can be downloaded at http*''maptools.org'ms3w. lternatively it can be installed on an e+isting web server, although it's now ,uite hard to find the separate components in windows form4 1nce installed, you can test mapserver is running correctly by calling it from a command prompt* C:\path\to\mapserv.exe #or in this case 'var'www'cgi-bin'mapserv$ should return the following output* "%his script can only be used to decode form results and should be initiated as a 56I process via a httpd server". %his is good4 7ou can also check the version by running mapserv.e+e -v. %his will show you all the options mapserver was compiled with, including the input and output file formats, and the server options that it supports. )inally you can check mapserver from the web by running* http://localhost/cgi-bin/mapserv.exe? or in this case* http://www.maths.lancs.ac.uk/cgi-bin/mapserv? If mapserver is set up correctly you should get a web page saying "8o ,uery information to decode. 9.:/7;!%/I86 is set, but empty.", in other words, mapserver is working but hasn't been supplied with any information. 8ote the synta+ of the web re,uest- using uni+ it should say mapserv, rather than mapserv.e+e, but you always need the ,uestion mark.
s well as serving data in web-compatible formats, mapserver can also be used to create the map itself, so contains a lot of options for creating reference maps and scale bars that are not relevant when using it primarily to serve data. %he important part of any mapserver installation is the map file. %his is a plain-te+t configuration file that lists the components of the map as ob-ects. !ome are optional, some are not. %hese are nested within the main M < ob-ect, and all finish with an :8& statement. 5omment lines are marked with a = sign. 8ote that te+t within the map file is *not* case-sensitive4 %he basic components are as follows* M <- defines the settings for the whole map such as the si>e and e+tent #includes one or more 0 7:/ ob-ects$ 0 7:/- defines the individual layers or data sources within the map, including their name and type #polygon, point, line$ #includes one or more 50 !! ob-ects$ 50 !!- defines the set of ob-ects relating to the way the features will be rendered, such as whether they will be labelled #includes one or more !%70: ob-ects$ !%70:- defines how symbols will be rendered, such as the colour of dots or the thickness of lines. %hese work as follows* M < ... 0 7:/ ... 50 !! ... !%70: ... :8& :8& :8& :8& In order to make your data accessible to the web server, copy it from your ?* drive to @@wwwmaths@yourusername. %his translates to 'web'home'yourusername, and is web-accessible at http*''www.maths.ac.uk'Ayourusername Important things that you need to know about your data are the coordinate system, units of measurement, and e+tent #bounding bo+$. It is possible to find these things out in a number of ways, but perhaps the ,uickest way is to use the mapserver e+port plugin in 9uantum 6I!. 1nce loaded, this can be used to create the entire map file for you. t this stage, please tick the bo+ ":+port layer definition only", as we don't need the advanced elements. ?ere's an e+ample of a simple map with a single layer. 7ou should find this saved as test.map in your home folder. 7ou will need to edit the !? <:< %? line to use your username
M <
8 M: "My first map" .8I%! dd :2%:8% -BCDCEDFB.FG3HCB -IEBFFJG.D3GHEE EHEDIDE.BEIIJG BBDEHD3H.JJGBCH </1K:5%I18 'initLepsg*3FIH' :8& IM 6:%7<: <86 !IM: 3CC FCC !? <:< %? "'web'home'cook-B'data'vmapC;shapefiles" IM 6:5101/ IGG IGG IGG 0 7:/ 8 M: alaska & % alaska !% %.! on %7<: <107618 </1K:5%I18 'initLepsg*3FIH' :8& 50 !! 8 M: " laska" !%70: 5101/ IFI IFI IFI 1.%0I8:5101/ FI FI FI :8& :8& :8& :8&
Mapserver comes with built-in tools to convert a map into a static image* /path/to/shp2img -m my.map -o mymap.png 1r you can test it from a web page using the following url*
http://www.maths.lancs.ac.uk/cgi-bin/mapserv?map=/web/home/cook !/test.map"mo#e=map
7ou will need to change the map parameter to point at your username. %he end result of either of these should be a png image with a very e+citing map of laska. ny errors in your map file will result in the commands failing, so this is a good way of testing. ?owever, if you want to create a dynamic web-based map you have to do a little more work. Mapserver itself can generate dynamic maps in html pages, with some additions to the map file, but without a lot of php coding the results are a little old-fashioned. 1penlayers gives a more intuitive "slippy" interface so we'll concentrate on that. 7ou can use the demo setup #http*''www.maths.lancs.ac.uk'Arowlings'Map!erver'workshop-G.C'$ on the webserver to see how the different components work together to produce simple maps. 6eoserver is a -ava-based map server. It is purely a map server, and can't be used to create maps on it's own, it -ust serves data to mapping apis. It has more sophisticatedlayer styling and controls than mapserver, so can produce a more attractive result. It has binaries for windows, mac 1!2 and uni+ variants, and source code. Installation on windows is relatively straightforward- download the e+ecutable, follow the instructions, start the server, and go to the web configuration pages. It
generally runs as a service, so it starts automatically when you start windows, but can be run manually. ctually using geoserver is more comple+ than mapserver if all you want is to create simple web servers. 7ou start by creating & % !%1/:!, which point at data sources #eg shapefiles$. 7ou then create ): %./: %7<:!, which point at the & % !%1/:! and describe their symbology, their pro-ection and so on. )inally, you can preview the ): %./: %7<:! using the integrated openlayers client. %his is all done via the web interface, in comparison to mapserver's te+t-based configuration file. )or the purposes of today's session, we'll use mapserver as it's a bit easier to manage and understand.
%o understand the capabilities that a wms server has, you need to make a 6et5apabilities re,uest to it. 8ote that different types of webservers have slightly different addresess, or have simplified the ./0 that you need to enter. simple re,uest looks like this* http://wms. pl.nasa.gov/wms.cgi?re$uest=%etCapabilities 7ou can either type this as a ./0 in a web browser, or using something like wget. %his will produce an file that you need to save as +ml format and open with a te+t editor. When you open it up you will see information about the wms service offered by this server, such as the contact details for the person maintaining the data, the image formats it outputs in, and of course the layers that it offers. 6iven that information, you can manually re,uest a layer from the server by making up the ./0 using the above parameters. eg* http://wms. pl.nasa.gov/wms.cgi? re$uest=%et&ap"service=wms"version=!.!.!"srs='()%:*+2,"-ormat=image/ p eg"styles="bbox=-!./0 -,/0 !./0 .*"wi#th=,//"height=+//"layers=global1mosaic Mapserver has to be configured at both M < and 0 7:/ level to work as a WM! server. 7ou need to add a W:( ob-ect, in which you need to add a M:% & % ob-ect as follows* M < ... W:( ... ME,%D%,% -.*s/title- -My first .*s ser er-.*s/srs- -E&"01432$-.*s/onlineresource- -http1//....*aths.lancs.ac.uk/cgi2bin/*apser ? *ap3/.eb/ho*e/cook41/test/.*s.*ap E+D :8& ... :8& 8ote that there are many other optional parameters such as contact information, access permissions and so on. )or each layer that you want to enable as a web layer you also need to add a M:% & % ob-ect inside the 0 7:/ ob-ect, and change a couple of the other options* 0 7:/ ... ",%,5" 6+ MI8!5 0: BCCC M 2!5 0: BCCCCCCC ME,%D%,% -.*s/title- -My first .*s layer-.*s/srs- -E&"01432$-
E+D :8& %he status option allows the layer to be turned 18 and 1)). %he third option &:) .0% means that it is always on and can't be turned off. %he MI8 and M 2!5 0: prevent the layer being drawn at unsuitable scales such as too high a resolution. %hey are related to the .8I%! keyword, which specifies the units that the map is measured in. 7ou can check your map server is correctly configured by running your own 6et5apabilities re,uest. %he format of the re,uest differs slightly depending on how the server is set up, but it usually looks something like this* http://localhost/cgi-bin/mapserv? map=/path/to/map"re$uest=%etCapabilities"service=wms or in this case* http://www.maths.lancs.ac.uk/mapserv? map=/web/home/cook !/test1wms.map"re$uest=%etCapabilities"service=wms If things are correctly configured, this should return a file that needs saving as an +ml file as you did previously. 1pen it in a te+t editor and check that there are no errors. %o check a 6etMap re,uest at the command line re,uires manually typing in the bounding bo+. 7ou can do this if you want, or test it in 9uantum 6I! by adding a WM! layer and entering the 6et5apabilities ./0. (oth methods should highlight any errors in the ./0 that you are using. W#"* Web )eature !ervices return vector data rather than a raster image. %his is more labour intensive for the server, but the results can be nicely overlaid on to other data, and you may be able to save the features as a data file for your own purposes. gain, the capabilities of a W)! server can be determined using a ./0 re,uest* http*''map.ns.ec.gc.ca'envdat'map.asp+N serviceLW)!OversionLB.C.COre,uestL6et5apabilities In this case the "layers" are called ): %./:%7<:!. 5onfusingly these are referred to as %7<:8 M:! in the 6et)eature #e,uivalent to 6etMap$ re,uest. %he output will not be a map, but will be in 6eography Markup 0anguage #6M0$ format. !o, to manually re,uest data from a W)! source via a ./0* http*''map.ns.ec.gc.ca'envdat'map.asp+N serviceLW)!OversionLB.C.COre,uestL6et)eatureOtypenameLenvirodat gain, to convert your map server into a W)! server you -ust need to add some additional te+t to the W:( and 0 7:/ ob-ects. 8ote that your data can be served in both WM! and W)! format at the same time from the same map by adding both sets of parameters* M < ... W:(
... ME,%D%,% -.fs/title- -My first .fs ser er-.fs/srs- -E&"01432$-.fs/onlineresource- -http1//....*aths.lancs.ac.uk/cgi2bin/*apser ? *ap3/.eb/ho*e/cook41/test/.fs.*ap E+D :8& 0 7:/ ... !% %.! 18 MI8!5 0: BCCC M 2!5 0: BCCCCCCC D5M& ,75E ME,%D%,% -.fs/title- -My first .fs layer-g*l/featurei8- -cat-g*l/inclu8e/ite*s- -allE+D :8& ... :8& %he &.M< %/.: parameter gives mapserver permission to send the raw data to the client and works -ust as well for wms layers. %he gml;featureid parameter specifies the field from the attribute data that you wish to use as an I& field in gml. %he gml;include;items parameter is either "all", ie you wish to e+pose all of the attribute data in the gml output, or a comma-delimited list of fields. 7ou can run your own 6et5apabilities re,uest to check your server is correctly configured* http://localhost/cgi-bin/mapserv? map=/path/to/map"service=w-s"re$uest=getcapabilities"version=!././ or in this case* http://www.maths.lancs.ac.uk/mapserv? map=/web/home/cook !/test1w-s.map"re$uest=getcapabilities"version=!././
0uckily you don't really need to know much'any -avascript to work openlayers in it's basic form, but you do need to respect the synta+ and the order in which the components are declared and used. !ee the following code* PhtmlQ PheadQ Pscript srcL"http*''www.maths.lancs.ac.uk'ol'lib'1pen0ayers.-s"QP'scriptQ Pscript typeL"te+t'-avascript"Q var mapR function init#$ S map L new 1pen0ayers.Map#'map'$R var wms L new 1pen0ayers.0ayer.WM!# "1pen0ayers WM!", "http*''labs.metacarta.com'wms'vmapCN", Slayers* 'basic'T $R map.add0ayers#UwmsV$R map.>oom%oMa+:+tent#$R T P'scriptQ P'headQ Pbody onloadL"init#$"Q Pdiv idL"map" styleL"width* HCCp+R height* FCCp+"QP'divQ P'bodyQ P'htmlQ %his works in the following way* B. I. F. 3. G. H. %he 1pen0ayers library is loaded using the script tag. %here is a div element with the id WmapX that contains the map. map is created using Kava!cript. layer is created using Kava!cript, and then added to the map. %he map >ooms out as far as possible. Kava!cript gets called only after the body tagYs on0oad event.
%his is a container for the map that we are creating in our page markup. 0ater, when we initiali>e the WmapX ob-ect, we will give the id of this div element to the mapYs constructor. %he si>e of the map is determined by the si>e of the element that contains it. ?ere, we have set the si>e of the map with an inline style declaration to be HCC pi+els by FCC pi+els. #8ote that these style declarations are better placed in a PstyleQ element weYre -ust putting them directly on the div element for simplicity here$.
%his code tells the map to >oom out to its ma+imum e+tent, which by default is the entire world. It is possible to set a different ma+imum e+tent as an option in the Map constructor. 1pen0ayers maps need to be told what part of the world they should display before anything will appear on the page. 5alling map.>oom%oMa+:+tent#$ is one way to do this. lternative ways that offer more precision include using >oom%o:+tent#$ and set5enter#$.
%he parameters defined as Sob-ectsT take several options and enclose them in ST brackets. t the very least these will include the list of layers to return from the wms* var wms L new 1pen0ayers.0ayer.WM!#"8 ! 6lobal Mosaic", "http*''wms.-pl.nasa.gov'wms.cgi", Slayers* "modis,global;mosaic"T$R 8ote that the you can only have one base mapping layer in openlayers. (y default, WM! layers are baselayers, but if you don't want your layer to be a base layer you need to add the following* Sis(ase0ayer* falseT after the Slayers*...T parameter. )urthermore, to set the background of your wms tiles to be transparent you need to add the following key-pair WI%?I8 the layers parameter* S#layers* ...$, transparent* trueT
var wms L new 1pen0ayers.0ayer.WM!#" laska", "http*''www.maths.lancs.ac.uk'cgibin'mapservmapL'web'home'cook-B'test;wms.map", Slayers* "alaska"T, S'is(ase0ayer'* falseT$R Jrepro4ect1 trueN $R &on't forget to tell openlayers to load this layer at startup as well* map.add0ayers#Usatellite, wmsV$R 7ou can also set the initial e+tent of your map so that it doesn't show the whole world by default. It can be difficult to get the values for the e+tent that you want, but luckily with firebug it's easy. 1pen your )irebug console #5trl[!hift[0 or 5md[!hift[0 depending on your 1!$. In the console tab, enter the following* map.get:+tent#$R mapget5enter#$* Make a note of the values you get from these commands. %o set the map to centre on your new location at startup, add a second argument to the options variable* *axExtent1 ne. 6penCayers.=oun8sK21(?.(22M 33.$@!3M 1(?.$(?M D4.(D!(L and after the layers load* *ap.set)enterKne. 6penCayers.ConCatK21!2M $(LM 3L< %his command also sets the initial >oom level #in this case, F$.
W2S $aye s
%o use wfs layers in your map you may need to do some e+tra configuration at the server level. In your cgi-bin folder #where mapserv lives$ add a pro+y.cgi file #see http*''trac.openlayers.org'wiki')re,uently sked9uestions=<ro+y?ost$, and add the following to your web page above the map variable* 1pen0ayers.<ro+y?ost L "'cgi-bin'pro+y.cgiNurlL"R When this is configured correctly use the same set of parameters as for wms, eg* var wfs L new 1pen0ayers.0ayer.W)!# "!tates", "http*''localhost'geoserver'wfs", Stypename* "topp*states"T $R %hen tell openlayers to load this layer at startup as well* map.add0ayers#Uwms, wfsV$R
%o overlay vector layers such as wfs on top of commercial layers, you may need to set the pro-ection of each layer in your web page as well as the map itself. !ee http*''crschmidt.net'Acrschmidt'spherical;mercator.html for details.
#ina""y: $ata"og%ing
WhyN (ecause a catalogue is a much better way of storing your data, particularly once it's all web-enabled. 6eonetwork #http*''geonetwork.open-source.org$ is a "spatial data management system". In short, it allows you to upload, download, find and describe spatial data, belonging to you and others. It has a web-based interface, with a spatial browser and a search interface, and ensures that you fill in at least the bare minimum of metadata to make your data useful to you and others. (asically it's a content management system for spatial data. It's cross-platform and -ava-based, and comes with binary installers and source code for all platforms. 1n windows you install the e+ecutable, and start the server from the programme menu. 7ou then access the catalogue via http*''localhost*ECEC'geonetwork. When you upload data, you get the option to choose a particular metadata template, and assign access permissions for the data, ie is it read-only, can certa ingroups download it or -ust view it on the web etc. It's important to note that you can use geonetwork to store other types of data, such as videos, and conference proceedings.
&eference Materia":
Web Mapping Illustrated #1'/eilly$ by %yler Mitchell I!(8 C-GDH-CCEHG-B Mapserver main website* http*''mapserver.gis.umn.edu' Mapserver G tutorial http*''biometry.gis.umn.edu'tutorial' 6eoserver website* http*''geoserver.org' 1penlayers website* http*''openlayers.org'
Introduction to 1penlayers #Workshop, )1!!36 ICCE$ http*''workshops.opengeo.org'openlayers'intro'doc' 165 !tandards #for WM!'W)! etc$* http*''www.opengeospatial.org'standards 6eonetwork website* http*''geonetwork-opensource.org' Koanne 5ook !enior I% !upport and &evelopment 1 &igital'1+ford rchaeology -.cook\thehuman-ourney.ney [33 #C$BGI3 EECIBI %his work is licenced under the 5reative 5ommons ttribution-!hare like I.C .]* :ngland O Wales 0icense. %o view a copy of this licence, visit http*''creativecommons.org'licenses'by-sa'I.C'uk' or send a letter to 5reative 5ommons, BJB !econd !treet, !uite FCC, !an )rancisco, 5alifornia D3BCG, .! .