Ga1 2 lecture2

43
Dr.-Ing. Peter Korduan GI Advanced UMN-MapServer 1 Rostock University, Chair for Geodesy and Geoinformatics X 2007 GIS Advanced Topics Part 2, UMN - MapServer University of Rostock, Dr.-Ing. Peter Korduan E-Mail: [email protected] Introduction Installation Principals Mapfile Extensions Examples Rostock University, Chair for Geodesy and Geoinformatics Motivation UMN MapServer Introduction, Mapfiles, Templates, Client applications In the module you learn more about UMN-MapServer and how to realize an Internet mapping application After this module You are able to estimate the ability of the UMN MapServer You can create simple map configuration files You are able to generate HTML templates for map display in the browser You can bind vector and raster data in your map server application You can create your own internet GIS application!

Transcript of Ga1 2 lecture2

Page 1: Ga1 2 lecture2

Dr.-Ing. Peter Korduan GI Advanced

UMN-MapServer 1

Rostock University, Chair for Geodesy and Geoinformatics X 2007

GIS Advanced TopicsPart 2, UMN - MapServer

University of Rostock, Dr.-Ing. Peter KorduanE-Mail: [email protected]

Introduction

Installation

Principals

Mapfile

Extensions

Examples

Rostock University, Chair for Geodesy and Geoinformatics

Motivation

• UMN MapServer• Introduction, Mapfiles, Templates, Client applications

• In the module• you learn more about UMN-MapServer and how to realize an Internet

mapping application• After this module

• You are able to estimate the ability of the UMN MapServer• You can create simple map configuration files• You are able to generate HTML templates for map display in the

browser• You can bind vector and raster data in your map server application• You can create your own internet GIS application!

Page 2: Ga1 2 lecture2

Dr.-Ing. Peter Korduan GI Advanced

UMN-MapServer 2

Rostock University, Chair for Geodesy and Geoinformatics

Content

• Introduction• Features, Constraints, History

• Installation• Principals• MapServer mapfile

• Structure• Templates• Substitution strings

• Extend MapServer• Development environments• Server side extension (MapScript)• Client side extensions (Rosa Applet)• Utilities

• Client Examples• Basic HTML MapServer client• JavaScript client• Java Applet client

Rostock University, Chair for Geodesy and Geoinformatics

Introduction

• Open Source development environment for building spatially-enabled internet applications

• Developed by the University of Minnesota (UMN)• Server program, which creates and delivers maps related to certain

requirements• Interaction with HTTP – GET or POST method with forms or Java-

applets

Quelle: Fuepasz, http://www.carto.net/~fuerpass/icc2001-fuerpass.pdf

Introduction

Page 3: Ga1 2 lecture2

Dr.-Ing. Peter Korduan GI Advanced

UMN-MapServer 3

Rostock University, Chair for Geodesy and Geoinformatics

MapServer Features• Advanced cartographic output

• Scale dependent feature drawing and application execution• Feature labeling including label collision mediation• Fully customizable, template driven output• TrueType fonts• Map element automation (scale bar, reference map and legend)• Thematic mapping using logical- or regular expression-based classes• Feature selection by values and geometry and output in template or GML

• Support for popular scripting and development environments• PHP, Python, Perl, Ruby, Java, and C#

• Cross-platform support• Linux, Windows, Mac OS X, Solaris, and more

• A multitude of raster and vector data formats• TIFF/GeoTIFF, EPPL7, and many others via GDAL• ESRI shape files, PostGIS, ESRI ArcSDE, Oracle Spatial, MySQL and many

others via OGR• Quadtree indexing for shape files and raster/vector tiling

• Open Geospatial Consortium (OGC) web specifications• WMS (client/server), non-transactional WFS (client/server)• WMC, WCS, Filter Encoding, SLD, GML, SOS

• Map projection support• On-the-fly map projection with 1000s of projections through the Proj.4 library

Introduction

Rostock University, Chair for Geodesy and Geoinformatics

MapServer Client

Rasterdata

HTML-Template

Referencemaps

Functionselectors

Scalebar

True type fonts

Thematicdata

(Tables)

Legend

Symbols

Vectordata

Navigationselectors

Map Projections

Introduction

Page 4: Ga1 2 lecture2

Dr.-Ing. Peter Korduan GI Advanced

UMN-MapServer 4

Rostock University, Chair for Geodesy and Geoinformatics

• Open Source:• Usage of the software and the documentation is free of charge• Including - without any limitation - the rights to use, copy, modify,

merge, publish, distribute, sublicense, and/or sell copies of the software and to permit persons to whom the software is furnished to do so

• But:• No guaranty for the software.• The authors are not responsible for any problems or damage or

disprofit.

• Credits:• MapServer and MapScript have been developed by Stephen Lime. • Raster access module developed by Pete Olson and Stephen Lime. • PHP/MapScript module was developed and is maintained by DM

Solutions Group.

Introduction

Use constraints and authors rights

Rostock University, Chair for Geodesy and Geoinformatics

How to learn Mapserver

• prior knowledge• HTML form elements http://www.w3schools.com/html/• MapServer CGI parameters

http://ms.gis.umn.edu/doc40/cgi-reference.html• HTML-template parameter

http://ms.gis.umn.edu/doc40/template-reference.html

• Learn MapServer• Tutorial http://hypnos.cbs.umn.edu/projects/tutorial/• Demo http://maps.dnr.state.mn.us/mapserver_demos/workshop/

Introduction

Page 5: Ga1 2 lecture2

Dr.-Ing. Peter Korduan GI Advanced

UMN-MapServer 5

Rostock University, Chair for Geodesy and Geoinformatics

MapServer History

• 1995 originally developed by the University of Minnesota (UMN) in ForNet-project in cooperation with NASA and the Minnesota Department of Natural Resources (MNDNR)

• Presently hosted by the TerraSIP project (sponsored by NASA)• Maintained by a growing number of developers (20).• 1996 ShapeLib and GD Release => Map Server• 1997 UMN MapServer 1.0• 1998 Version 2.0 Public Release as ForNet MapServer• 1999 Version 3.0 called UMN Map Server (Raster + True Type added)• 2000 Version 3.3 MapScript, Proj 4• 2001 Version 3.6 WMS, OGR, GDAL, ArcSDE, Oracle Spatial, PostGIS• 2003 Version 4.0 phpMapScript, On-the-fly-projection, MySQL, WFS, WMC• 2004 Version 4.2 WMS 1.1.1, SLD, Filter for WFS• 2005 Version 4.6 SVG Output, Filter for OGR, WCS, OWS-Metadata• 15.12.2005 New Home Page http://mapserver.gis.umn.edu• 2006 Version 4.8, cooperation with Autodesk• 2006 Version 4.10 GEOS functions in mapScript, MULTIPOLYGON,

MULTILINESTRING, and MULTIPOINT, INCLUDE in mapfiles, SOS • See HISTORY.TXT in source code distribution

Introduction

Rostock University, Chair for Geodesy and Geoinformatics

Actual distribution of Mapbender user

Introduction

Page 6: Ga1 2 lecture2

Dr.-Ing. Peter Korduan GI Advanced

UMN-MapServer 6

Rostock University, Chair for Geodesy and Geoinformatics

Installation - System requirements

• Hardware• Standard PC• Network card with fixed network connection

• Web Server• Should work with each web server• Apache (recommended) and Internet Information Server (IIS)• CGI muss be supported• Web server based user authentication helpful• Server side script and programming for dynamic mapping systems

• PHP (recommended), JSP, Perl, Python, C#, Java used by mapscript• Operating system on the server side

• Linux (recommended)• SuSE, RedHat, Debian• Precompiled packages FGS from www.maptools.org/fgs

• Windows• Windows XP and higher• Binary versions MS4W from www.maptools.org/ms4w

Installation

Rostock University, Chair for Geodesy and Geoinformatics

Download

http://mapserver.gis.umn.edu/download

Source code for Linux distributions

Windows Binaries

Binaries for Mac OS

Linux RPM Packages

Linux Installer including a lot of useful components

Demo Application

Installation

Page 7: Ga1 2 lecture2

Dr.-Ing. Peter Korduan GI Advanced

UMN-MapServer 7

Rostock University, Chair for Geodesy and Geoinformatics

Download reference MS4W

http://www.maptools.org/ms4w/index.phtml?page=downloads.html

MapServer for Windows base package

Additional preconfigured ready to

use applications

Installation

Rostock University, Chair for Geodesy and Geoinformatics

Documentation

• Important MapServer Docs:

• MapServer New User Page:

http://mapserver.gis.umn.edu/docs

Installation

http://mapserver.gis.umn.edu/new_users

Page 8: Ga1 2 lecture2

Dr.-Ing. Peter Korduan GI Advanced

UMN-MapServer 8

Rostock University, Chair for Geodesy and Geoinformatics

• Linux• Unpack source tar ball

tar -zxvf mapserver-4.10.0.tar.gz

• Compile with options# ./configure <options># make# make install

• Some libraries must beinstalled before

• Windows• Unpack binary file

e.g. ms4w_1.3.0.zip to C:/• Start apache-install.bat• Ready to use• No compiling options

Installation

Operating System

Rostock University, Chair for Geodesy and Geoinformatics

Compiling options

• Source code can be compiled with different libraries• GD: for rendering graphics• Proj4: for on-the-fly map projections, required for WMS, WFS …• LibCURL: for WMS/WFS server side client connections • LibTIFF: for TIFF support (optional)• LibGeoTIFF: for GeoTIFF support (optional)• LibJPEG: for JPEG support (optional).• Free Type: for True Type Font support, used by GD (optional but strong

recommended).• OGR Simple Features Library: for conversion and access of different VECTOR data

formats (optional)• GDAL Geospatial Data Abstraction Library: supporting different RASTER data

formats (optional)• SDE Client: support access to ESRI's spatial database engine ArcSDE (optional)• PostgreSQL Client: access to PostGIS data, PostgreSQL client libraries required

(optional)• Oracle Spatial Client: access to Oracle spatial database (optional)• MING: supports Macromedia Flash data format (optional)• PDFLib: supports PDF Output (optional)

Installation

Page 9: Ga1 2 lecture2

Dr.-Ing. Peter Korduan GI Advanced

UMN-MapServer 9

Rostock University, Chair for Geodesy and Geoinformatics

Installation under Linux

• Unpack the source code under: /usr/local/mapserver-<version>• Setting the compiling options with MapServers configure script• Help relating the parameter: #>./configure --help

• Redirect the output: #>./configure --help > configure-help.txt• Useful compile options:• ./configure --with-prefix=/usr/local --with-gd=/usr/local/gd --with-gif

--with-png --with-jpeg --without-tiff --with-gdal --with-ogr --with-freetype--with-wmsclient --with-wfs --with-wfsclient --with-wcs --with-pdf--with-svg --with-postgis --with-debug

• ./make• ./make install• Copy mapserv• Approve compilation result:

/usr/local/apache/cgi-bin>mapserv -vMapServer version 4.6.1 OUTPUT=GIF OUTPUT=PNG OUTPUT=JPEG

OUTPUT=PDF OUTPUT=SVG SUPPORTS=PROJ SUPPORTS=FREETYPE SUPPORTS=WMS_SERVER SUPPORTS=WMS_CLIENT SUPPORTS=WFS_SERVER SUPPORTS=WFS_CLIENT SUPPORTS=WCS_SERVER INPUT=JPEG INPUT=POSTGIS INPUT=OGR INPUT=GDAL INPUT=SHAPEFILE DEBUG=MSDEBUG

Installation

Rostock University, Chair for Geodesy and Geoinformatics

Installation of MS4W

• Unzip to C:/• Start apache, start script apache-install.bat only one-time• Apache running as a service• Deinstall with Start->Settings->System Control->Management-

>Services or apache-uninstall.bat

Apache Web Server

Installation

Page 10: Ga1 2 lecture2

Dr.-Ing. Peter Korduan GI Advanced

UMN-MapServer 10

Rostock University, Chair for Geodesy and Geoinformatics

Start the web application

• http://localhost/

Apache help

PHP 4.4.0 Info

Links to PHP infos supporting

different phpMapScript

versions

Link to different MapServer CGI

Applications

PHP mit sqlite

MapServerDocumentation for utility programms

Installation

Rostock University, Chair for Geodesy and Geoinformatics

• http://localhost/

MapServerutility programs

Infos zu OWTCharts

OGR/PHP extension

Additional optional installed

applications in MS4W Package

Start the web application II

Installation

GDAL and OGRUtility programs

Page 11: Ga1 2 lecture2

Dr.-Ing. Peter Korduan GI Advanced

UMN-MapServer 11

Rostock University, Chair for Geodesy and Geoinformatics

Methods of operationsprincipals

• Common Gateway Interface (CGI) native• described below

• Application Programming Interface (API)• in chapter MapServer extensions

• OGC Web Services (OWS)• see OGC lesson

Rostock University, Chair for Geodesy and Geoinformatics

About GET and POST

Gethttp://www.server.de/adressen.php?mitarbeiter_id=1&action=Anzeigen

http://www.gis-server.de/cgi-bin/mapserver?map=karte.map&layer=gebaeude&layer=kataster&mode=browse&zoom=2

<img src="/cgi-bin/mapserver?map=karte.map&layer=strassen&layer=gebaeude&layer=kataster&mode=browse&zoom=2”>

POST<html><head><title>Beispiel Post</title></head><body><form method="post" action="adressen.php"><select name=„mitarbeiter_id"><option value="1">Korduan</option><option value="2">Bill</option><option value="3">Zehner</option>

</select><input type= "submit" name= "action" value="Anzeigen">

</form></body></html>

<?php echo adresseAnzeigen($mitarbeiter_id); ?>

principals

Page 12: Ga1 2 lecture2

Dr.-Ing. Peter Korduan GI Advanced

UMN-MapServer 12

Rostock University, Chair for Geodesy and Geoinformatics

MapServer- read TEMPLATE (mymap.html)- replace Placeholder in TEMPLATE<input type="image" src="[img]">

- deliver mymap.html to the WebServer

Activity chain for mapfile production with CGI

Browser- send request (http://www.server.de/cgi-bin/mapserver?map=mymap.map&...&...)

MapServer- read configuration file (Mapfile) (mymap.map)

…WEB

TEMPLATE mymap.htmlIMAGEPATH „D:\webserver\tmp\“IMAGEURL „/tmp/“

END…LAYER

NAME „water“DATA „rivers“

…- Create and write map in IMAGEPATH

WebServer- receive request- call mapserver program - mapserv(.exe)- deliver CGI parameter to mapserver

WebServer- send mymap.html to the browser- provide image with the map- provide image with the legend etc.

Browser- receive web page mymap.html with source links to the map image and the web form- Visualize the page with functions for navigation and query- mymap.html include link to http://www.server.de/cgi-bin/mapserver?parameter=wert&...&..

principals

Rostock University, Chair for Geodesy and Geoinformatics

Empty placeholders in template

placeholderfor legend

placeholder for scale bar

placeholder for map

menu for background raster data

choice of layers

switcher for zoom

switcher for query mode

placeholder for reference map

principals

Page 13: Ga1 2 lecture2

Dr.-Ing. Peter Korduan GI Advanced

UMN-MapServer 13

Rostock University, Chair for Geodesy and Geoinformatics

Template form HTML sourceprincipals

Rostock University, Chair for Geodesy and Geoinformatics

Template with content

principals

Page 14: Ga1 2 lecture2

Dr.-Ing. Peter Korduan GI Advanced

UMN-MapServer 14

Rostock University, Chair for Geodesy and Geoinformatics

Another Example, same techniqueprincipals

Rostock University, Chair for Geodesy and Geoinformatics

MapServer mode

• CGI parameter mode determines how MapServer process requestshttp://server.vn/cgi-bin/mapserv.exe?map=mapfile.map&layer=rivers&mode=map• BROWSE

• default• create maps• build the interactive client page with template• substitution strings for dynamic changes in the template e.g. [img]

• MAP• creates only the map• use in conjunction with the HTML <img …> tag

• REFERENCE, SCALEBAR and LEGEND• create exactly this• Also as images in MapServer’s temp directory

principals

Page 15: Ga1 2 lecture2

Dr.-Ing. Peter Korduan GI Advanced

UMN-MapServer 15

Rostock University, Chair for Geodesy and Geoinformatics

MapServer mode II

• ZOOMIN and ZOOMOUT• do exactly this• ZOOMSIZE as zoom factor• ZOOMDIR with positive or negative value for zoom in or out• switch to the mode BROWSE

• QUERY• used for spatial search closest to a point clicked previously in a map

• NQUERY• find more than the nearest feature from the selected search point• or user defined search box

• ITEMQUERY and ITEMNQUERY• For text search in the same way like QUERY and NQUERY

• Additional Modes for querying features

principals

Rostock University, Chair for Geodesy and Geoinformatics

MapServer - Mapfile

• Central map configuration file• A Map consists of Layers and some descriptive elements• Divided in sections for:

• map,• legend,• query map,• reference map,• scale bar,• projection,• layer.

• Declarations of data sources• Combining thematic related layers in one map service• Metadata descriptions for the map and layers

Mapfile

Page 16: Ga1 2 lecture2

Dr.-Ing. Peter Korduan GI Advanced

UMN-MapServer 16

Rostock University, Chair for Geodesy and Geoinformatics

Mapfile - conventions

• Objects (sections)KEYWORD

ContentEND

• DeclarationsKEYWORD VALUEPossible value types:• Key (Constants), e.g. STATUS On• Strings, e.g. NAME „rivers“• Number [number…], e.g. COLOR 0 255 0• space delimiter for values sequences

• NestingLAYER

CLASS…

END…

END• Colors in RGB values

255 0 0 Red, 0 255 0 Green, 0 0 255 Blue

NAME VietnamGISDemo

EXTENT 4503828 5992705 4514813 6001570SIZE 500 500SHAPEPATH “C:/ms4w/apps/vgis/data"

WEBTEMPLATE vdemo.htmIMAGEPATH "C:/ms4w/tmp/ms_tmp/"IMAGEURL "/tmp/"

END

LEGENDSTATUS ONLABELCOLOR 0 0 0

ENDEND

REFERENCESTATUS ONIMAGE „graphics/overview.png“SIZE 200 135EXTENT 4503828 5992705 4514813 6001570 COLOR -1 -1 -1OUTLINECOLOR 255 0 0

END

LAYER NAME “River"DATA „river“STATUS ONTYPE LINECLASSNAME “all"COLOR 0 0 0TEMPLATE “river_tablebody.htm"

ENDHEADER “river_tableheader.htm"FOOTER "tablefooter.htm"

ENDEND

Mapfile

Rostock University, Chair for Geodesy and Geoinformatics

Mapfile - conventions II

• Variable names must be NOT case-sensitive• KEYWORDS in upper case• Strings in double-quotes is recommended• Limitation per default

• MS_MAXLAYERS 200 - max layers per mapfile, changeable in map.h• MAXCLASSES 250 - max classes per layer, changeable in map.h• MAXSTYLES 5 - max styles per class, changeable in map.h• MAXSYMBOLS 64 - max symbols in symbol set, changeable in mapsymbol.h• After edition recompile

• File paths as absolute paths or as paths relative to the location of the mapfile

• In addition, data files may be specified relative to the SHAPEPATH• Comments are designated with a #• Attribute names are case sensitive using the following syntax:

[ATTRIBUTENAME]• Generally ESRI generated shape files have their attributes (.dbf column

names) all in upper-case for instance, and for PostGIS, ALWAYS use lower-case.

• MapServer uses regular expressions supported by operating system's C Library (regex)

Mapfile

Page 17: Ga1 2 lecture2

Dr.-Ing. Peter Korduan GI Advanced

UMN-MapServer 17

Rostock University, Chair for Geodesy and Geoinformatics

Mapfile - Header

• For the representation of the maps on the screen

• Settings for the map itself• Web object to define how the

web image is created• Output formats• Reference or overview• Scale bar• Legend• Use pre-canned header and

modify

The mapfile statements are not complete! See mapserver documentation for full documentation.

MAPNAME "Efate"STATUS ONSIZE 400 400EXTENT 16 105 34 130UNITS DEGREETRANSPARENT OFFSHAPEPATH "/var/www/html/map/"IMAGETYPE png24FONTSET "fonts/fontset.txt"

Mapfile

Rostock University, Chair for Geodesy and Geoinformatics

Mapfile - Header II

MAPNAME <name> Name of the mapEXTENT <minX minY maxX maxY> Extend of the map in real world

coordinate systemSIZE <width height> Size of the image representing

the mapSHAPEPATH <directory> Path to the directory holding the

shape files or tiles STATUS <ON|OFF> To turn off the mapSYMBOLSET <filename> File name of symbols definitionFONTSET <filename> File name of the True-Type font

definitionsIMAGECOLOR <Red Green Blue> Background colour, marked as

transparentEND # end of map file

Mapfile

Page 18: Ga1 2 lecture2

Dr.-Ing. Peter Korduan GI Advanced

UMN-MapServer 18

Rostock University, Chair for Geodesy and Geoinformatics

Mapfile - WEB Object

WEBTEMPLATE <filename> Template for the user interfaceIMAGEPATH <directory> Path for writing temporary images and filesIMAGEURL <URL> base URL to the IMAGEPATH, used from

browser[MIN|MAX]SCALE <scale value> [min|max] scale[MIN|MAX]TEMPLATE <filename>Template used for exceeding or

undershooting of the MIN- or MAXSCALE in stead of TEMPLATE

ERROR <URL> delivered page in the case of errorsEMPTY <URL> delivered page in the case of empty query

resultsLOG <filename> Path to the LogfileMETADATA

… Descriptive info related to the mapEND

END # end of web object

Mapfile

Rostock University, Chair for Geodesy and Geoinformatics

Mapfile - REFERECE

• Current extent is displayed in the reference map• Reference map also usable for panning by single clickREFERENCE

IMAGE <path> Location of the imageEXTENT <minx, miny, maxx, maxy> Extent of the image in the SRS

of the mapSTATUS <ON | OFF> The overview is on by default COLOR <R G B> Transparent background of the

reference imageOUTLINECOLOR <R G B> Color of the outline SIZE <width height> Size of the image in pixels

END # end of reference image

Mapfile

Page 19: Ga1 2 lecture2

Dr.-Ing. Peter Korduan GI Advanced

UMN-MapServer 19

Rostock University, Chair for Geodesy and Geoinformatics

Mapfile - LEGEND classic

• Static legend or with template• With template ability to combine legend with layer and group control • Legend is created by MapServer as image and included with

<img src=„[legend]“> in map template

LEGENDKEYSIZE <w h> Size of the legend graphic representing the

layer objectsLABEL

TYPE BITMAP Font type for the legend layer and class namesSIZE <MEDIUM> Font sizeCOLOR <R G B> Font color

END # end of labelSTATUS ON Legend is on by default

END # end of legendRiversBuildingsLanduse

Mapfile

Rostock University, Chair for Geodesy and Geoinformatics

RegisterPlottsBuildingsLanduse

Mapfile - LEGEND with template

• Template based legend• Support HTML-Code with form elements for layer control• Customizable layout

Mapfile

Page 20: Ga1 2 lecture2

Dr.-Ing. Peter Korduan GI Advanced

UMN-MapServer 20

Rostock University, Chair for Geodesy and Geoinformatics

Mapfile - Legend template example

• Leg_group_html loop for groups• Leg_layer_html loop for layer• Leg_class_html loop for classes• If - control structure

Mapfile

Rostock University, Chair for Geodesy and Geoinformatics

Mapfile - SCALEBAR

SCALEBARIMAGECOLOR 255 0 0 Background color of the image

placeholderLABEL

COLOR 0 0 0 Color of the labels indicating the distanceSIZE Tiny Size of the labels

ENDSTYLE [0 | 1] Style of the scale barSIZE 160 3 Size in pixels of the scale barCOLOR 0 0 0 Color used in the scale barBACKGROUNDCOLOR 200 200 0 Background color of the drawn scale barOUTLINECOLOR 0 0 0 Outline color of the scale barUNITS kilometers Units to be usedINTERVALS 5 How many intervals in total in the scale

barSTATUS ON The scale bar is on by default

END

Mapfile

Page 21: Ga1 2 lecture2

Dr.-Ing. Peter Korduan GI Advanced

UMN-MapServer 21

Rostock University, Chair for Geodesy and Geoinformatics

Mapfile - QUERYMAP

QUERYMAPSTATUS ON The map is queryable by defaultSTYLE HILITE The selected object is highlighted

END

OUTPUTFORMATNAME png Supported output format

(gif, png, jpeg, wbmp, swf, GTiff) DRIVER "GD/PNG“ Used library for image

rendering (Driver)MIMETYPE "image/png“ Mime typeIMAGEMODE RGB Image mode

(PC256, RGB, RGBA, INT16, FLOAT32) EXTENSION "png“ File extensionTRANSPARENT ON TransparencyFORMATOPTION “INTERLACE=ON” Options depending on format

END

Mapfile

Rostock University, Chair for Geodesy and Geoinformatics

• Definition of layer projection in the LAYER Section• Definition of map projection in global map section• The two types of settings:PROJECTION Customized Definition„proj=utm“ Projection type„ellps=GRS80“ Based on ellipsoid„zone=32“ Meridian zone number„north“ North or south of the sphere

END # end of projection

PROJECTION EPSG - Codes (European Petroleum Survey Group)

„init=epsg:4326“END # end of projection• Without projection no recalculation• Respectively map use the projection, the layer are projected with

Mapfile

Mapfile - PROJECTION

Page 22: Ga1 2 lecture2

Dr.-Ing. Peter Korduan GI Advanced

UMN-MapServer 22

Rostock University, Chair for Geodesy and Geoinformatics

Mapfile - LAYER

• Drawing order: last layer is drawn firstLAYER

NAME <name> Layer nameDATA <filename> Name of the shape file, relative to

SHAPEPATH or sde parameters, postgis table/column,oracle table/column

STATUS <ON|OFF|DEFAULT> Visibility of the layerTYPE <POINT|LINE|POLYGON> Geometry typeGROUP <groupname> Name of the group the layer belongs toCONNECTION <string> Database connection stringCONNECTIONTYPE <type> Type of connection local is default or

sde, ogr, postgis, oraclespatial, wms)CLASS Start of a class object

…END # end of class

END # end of layer

…&layers=districts,counties&…

Mapfile

Rostock University, Chair for Geodesy and Geoinformatics

Mapfile – more layer parameter

REQUIRES <Expression> Condition to draw the layerExample:LAYER

NAME „TK 25“STATUS ON Layer TK25 is drawn if layer TK50 is not activeREQUIRES „[TK50] !=1“

END # end of layer

CLASSITEM <column name> Name of the column used for classificationMAX|MINSCALE <scale> Max|Minimal scale to draw layerLABELANGLEITEM <column name> Column with the angle for labelsLABELMAX|MINSCALE <scale> Scale range for drawing labelsLABELREQUIRES <expression> Conditions for drawing labelsMAXFEATURES <integer> Max feature to drawOFFSITE <R G B> Color in a raster layer set to transparentPOSTLABELCACHE <TRUE|FALSE> Draw labels before or after the layersSYMBOLSCALE <double> Scale related to the symbol and label sizeFILTER Regular expression to filter the features

([country] eq “vietnam”)JOIN…END Start a join object

Mapfile

Page 23: Ga1 2 lecture2

Dr.-Ing. Peter Korduan GI Advanced

UMN-MapServer 23

Rostock University, Chair for Geodesy and Geoinformatics

Raster and vector layer example

LAYERNAME land_shallowGROUP "RASTER"PROJECTION

"init=epsg:4326"ENDTYPE RASTERSTATUS ONDATA "../../data/land_shallow.tif"DUMP TRUEHEADER "land_shallow_head.htm“TEMPLATE "land_shallow_body.htm"TOLERANCE 5

END # end of layer

LAYERNAME riversGROUP "VECTOR"PROJECTION

"init=epsg:4326“ENDTYPE LINESTATUS ONDATA ../../data/riversDUMP TRUEHEADER "rivers_query_head.htm"TEMPLATE “rivers_query_body.htm"TOLERANCE 5CLASS

NAME "Rivers"COLOR 0 0 255

END # end of classEND # end of layer

Mapfile

Rostock University, Chair for Geodesy and Geoinformatics

Mapfile - LAYER JOIN

• Joins are defined within a LAYER object• Only available for queries• Not to affect the look of a map• Primary to enable lookup tables for coded data (e.g. 1 => Forest)LAYER

DATA prov.shpTEMPLATE "../htdocs/cgi-query-templates/prov.html"HEADER "../htdocs/cgi-query-templates/prov-header.html"FOOTER "../htdocs/cgi-query-templates/footer.html"JOIN

NAME "test“TABLE "../data/lookup.dbf“FROM "ID“TO "IDENT“TYPE ONE-TO-ONE

ENDEND # layer

Mapfile

Page 24: Ga1 2 lecture2

Dr.-Ing. Peter Korduan GI Advanced

UMN-MapServer 24

Rostock University, Chair for Geodesy and Geoinformatics

• Used for classification• Included layer sections• Define the layout of layers data• Filter expressions

• for data constriction (only parts of data) or for creation of classes (thematic maps)• Class will be drawn in order of definition

CLASSSYMBOL [number|name|filename] Symbol definition (number and name related to symbol file, starting at 1, default is 0 (single pixel, single width line, or solid polygon fill), gif or png for filename path relative to mapfileBACKGROUNDCOLOR [r] [g] [b] Color to use for non-transparent symbolsCOLOR 0 200 255 Color of the symbolNAME "Bathymetry 2.5m >-50m“ Name of classes used in legendEXPRESSION ([Value]>-50) Filter to define class membersLABEL Starting a label object

…END # end of lable

END # end of class

Mapfile

Mapfile - CLASS

Rostock University, Chair for Geodesy and Geoinformatics

Mapfile - Class expression

• Four types of expression• String comparisons• regular expressions• simple logical expressions• string functions

Examples:EXPRESSION „Xi Jiang“

Matching with the values of the column CLASSITEMEXPRESSION ([SYSTEM] eq „Amazonas“ and [LENGTH] > 200000)

Logical combination of expressions with more than one attributeEXPRESSION „^A“

Matching with values in column CLASSITEM starting with AEXPRESSION „/./“

ALL• If no expression is given, then all features are said to belong to this class.

Mapfile

Page 25: Ga1 2 lecture2

Dr.-Ing. Peter Korduan GI Advanced

UMN-MapServer 25

Rostock University, Chair for Geodesy and Geoinformatics

LAYER Type raster

• LAYER (TYPE RASTER)• Keep apart formats for input and for output

LAYERNAME <Name> DATA <imgsource.tif> Path and name for the raster data fileTYPE RASTER Layer type defined as raster…

END• Tile imagesTILEINDEX <Shapedatei>Shape file with shapes represents the image extentsTILEITEM <Spaltenname> Colum name include the name of image files

Mapfile

Rostock University, Chair for Geodesy and Geoinformatics

Mapfile - LABEL

LAYERNAME „streetnames“GROUP „Anotation “TYPE ANNOTATION Layer type defined as annotationCLASSITEM „STREETNAME“LABELITEM „STREETNAME“ Column name including the annotation textCLASS

LABELTYPE BITMAP Type of text (bitmap)SIZE NORMAL Size of the textCOLOR 0 0 0 Color of the textPOSITION CR Relative position of the labelBUFFER 5 Margin to the adjacent textPARTIALS TRUE Clip the text at map boundary

true|falseMAX|MINSIZE <n> Max/min size of the text

END # end of labelEND # end of clas

END # end of layer

UL

CL

LL

CR

LC

CC

UC UR

LRAuto, XYPosible positionsfor lables

Mapfile

Page 26: Ga1 2 lecture2

Dr.-Ing. Peter Korduan GI Advanced

UMN-MapServer 26

Rostock University, Chair for Geodesy and Geoinformatics

Mapfile - LABEL II

• TrueType – Fonts• Additional functions for annotation with text

ANGLE <double> Rotation angle of labels, AUTO aligns the textalong lines if the layer type is LINE

ANTIALIAS <true|false> Anti-alising of textFONT <name> Name of the font in font file fonts.fnt

Example:LABEL

TYPE TRUETYPE Type of text representationFONT „Courier“ Font CourierSIZE 10 Size in PixelCOLOR 0 0 0 Color of the textOUTLINECOLOR 255 255 255

Color of marginaround the text

END # end of label

Mapfile

Rostock University, Chair for Geodesy and Geoinformatics

Mapfile - SYMBOL

• Symbols are defined in the symbol file• Four types of symbols VECTOR, ELLIPSE, PIXMAP, TRUETYPEVector symbol example:

SYMBOLTYPE VECTOR Symbol typeNAME „treeangle“ Name of the symbol in symbol filePOINTS Start of a POINTS object

1 1 Start drawing the vector figure3 13 41 1 End drawing, must be the same point for an areaEND # end points

END # end symbol• Symbols can be identified by name or number in the symbol file

1,1

3,4

3,1

Mapfile

Page 27: Ga1 2 lecture2

Dr.-Ing. Peter Korduan GI Advanced

UMN-MapServer 27

Rostock University, Chair for Geodesy and Geoinformatics

Mapfile - SYMBOL II

Example TRUETYPE-Symbol:SYMBOL

NAME „Shaft“ Name of the symbol (here Drain Shaft)TYPE TRUETYPE Symbol typeFONT „ESRI Cartography“ Name of the font set to useCHARACTER „&#71“ Character in the font set

ENDExample Pixmap-Symbol:

SYMBOLNAME „Trafficlights“ Name of the symbolTYPE PIXMAP Symbol typeFONT „landeswappen.jpg“ File name of symbols imageTRANSPARENT 0 Display transparent true|false or 1|0

END• More than one symbol can be drawn on top of others• For example to draw a dashed line in the middle of a road, bordered

by two other coloured lines

Mapfile

Rostock University, Chair for Geodesy and Geoinformatics

Symbol - style example

Mapfile

Symboldefinition

Styledefinition

Style in the map and legend

Page 28: Ga1 2 lecture2

Dr.-Ing. Peter Korduan GI Advanced

UMN-MapServer 28

Rostock University, Chair for Geodesy and Geoinformatics

Supported input formats with GDAL/OGR

GDAL• Geospatial Data Abstraction

Library• Supporting reading and partly

writing of raster data• Use gdalinfo --formatsOGR• Is a part of GDAL• Simple Features open source

library in C++• For reading and partly writing

of different GIS vector formats• Use ogrinfo --formats

Mapfile

Rostock University, Chair for Geodesy and Geoinformatics

Mapfile

Load a MapInfo data set with OGR

Page 29: Ga1 2 lecture2

Dr.-Ing. Peter Korduan GI Advanced

UMN-MapServer 29

Rostock University, Chair for Geodesy and Geoinformatics

Mapfile

Load TIGER 2000 data with OGR

Rostock University, Chair for Geodesy and Geoinformatics

• For thematic data• Instead of dbf-file access• Import dbf table content into a database• Database connection in server side scripts• e.g. PHP und MySQL

• For geometry data• With MapServer and OGR• Supported databases

PostGIS spatial extension for PostgreSQL (open source),

SDE (Spatial Database Engine, ESRI)

Oracle Spatial (Oracle)

MySQL spatial extension ~ since v 5.0 (open source)

Mapfile

Database connection

Page 30: Ga1 2 lecture2

Dr.-Ing. Peter Korduan GI Advanced

UMN-MapServer 30

Rostock University, Chair for Geodesy and Geoinformatics

PostGIS database connection example

• PostGIS (postgis.refractions.net) spatial extension for PostgreSQL (www.postgresql.org)

• Load a shape file into a PostGIS database table with tool shp2pgsql#>shp2pgsql roads.shp roads traficdb > roads.sql#>psql –f roads.sql

• Create a GIST Index for fastening the accesspostgres#>CREATE INDEX roads_the_geom_gist ON roads USING GIST

the_geom GIST_GEOMETRY_OPS;• Bind the table in a mapfile

LAYERNAME „roads“TYPE „LINE“STATUS ONCONNECTIONTYP POSTGISCONNECTION „user=postgisuser dbname=traficdb host=localhost“DATA “the_geom from roads”CLASS

COLOR 255 255 0END

END

Mapfile

Rostock University, Chair for Geodesy and Geoinformatics

• Enable GEOS for PostGIS (Geometry Engine - Open Source)for spatial analysis

• Within() Geometry in polygon tests

• Intersects() Intersection test for geometries

• Touches() Touches geometries ?

? ?

??

Using spatial analysis functions in PostGIS

Mapfile

Page 31: Ga1 2 lecture2

Dr.-Ing. Peter Korduan GI Advanced

UMN-MapServer 31

Rostock University, Chair for Geodesy and Geoinformatics

MapServer extensions

• Tools for the development of applications• Chameleon, MapServer Workbench, AveiN!, MapLab

• Server site extensions• MapScript• MapBender

• Client site extensions• Mapplet• PMapper• Rosa Applet• Jbox

MapS

erver extensions

Rostock University, Chair for Geodesy and Geoinformatics

MapServer extensions II

• OGC Services• MapServer as OGC conform server• MapServer as OGC conform client• Web Map Service, Web Feature Service, Web Coverage Service,

Sensor Observation Services• Shplib Utilities

• MapServer uses library shplib• Shplib package comes with: shpdump, shpinfo, shpcreate, shpadd,

dbfdump, dbfinfo, dbfcreate, dbfadd• MapServer utilities

• shptree, shptreevis• GDAL/OGR Utilities

• gdalinfo, gdaltindex, gdaladdo, gdal_contour, gdal_rasterize, gdalwarp,• ogrinfo, ogrtindex, ogr2ogr, testogrsf

MapS

erver extensions

Page 32: Ga1 2 lecture2

Dr.-Ing. Peter Korduan GI Advanced

UMN-MapServer 32

Rostock University, Chair for Geodesy and Geoinformatics

Chameleon

• Distributed, configurable development environment for web mapping applications

• Based on OGC-Standards for WMS und Web Map Context Document• Usage of predefined Widgets, extension with self developed Widgets

possible• Realised in PHP• Freeware, source: www.maptools.org/chameleon

MapS

erver extensions

Rostock University, Chair for Geodesy and Geoinformatics

MapServer Workbench

• Tool for the development of web application based on UMN-MapServer http://msworkbench.sourceforge.net

• Stand alone software

• Freeware

• Based on tcl/tkPlatform independent

• For Linux andWindows

• Application Wizards

MapS

erver extensions

Page 33: Ga1 2 lecture2

Dr.-Ing. Peter Korduan GI Advanced

UMN-MapServer 33

Rostock University, Chair for Geodesy and Geoinformatics

MapServer Workbench - Editor

• For the modification of mapfilesM

apServer extensions

Rostock University, Chair for Geodesy and Geoinformatics

MapServer Workbench - Explorer

• For a preview display of the map

MapS

erver extensions

Page 34: Ga1 2 lecture2

Dr.-Ing. Peter Korduan GI Advanced

UMN-MapServer 34

Rostock University, Chair for Geodesy and Geoinformatics

MapServer Workbench –Shape Explorer

• For shape file visualization and its dbf tablesM

apServer extensions

Rostock University, Chair for Geodesy and Geoinformatics

AveiN!

• MapServer extension for ArcView GIScommercial product www.terrestris.de/gis/avein.html M

apServer extensions

Page 35: Ga1 2 lecture2

Dr.-Ing. Peter Korduan GI Advanced

UMN-MapServer 35

Rostock University, Chair for Geodesy and Geoinformatics

MapLab

• From DM Solution - another Internet map workbench• Client server based• Platform independent (running in browsers)• Available for the ms4w package with Apache, MapScript and

RosaApplet• Freeware, www.dmsolutions.on.ca/techserv/maplab.html

MapEdit MapBrowser GMapFactory

MapS

erver extensions

Rostock University, Chair for Geodesy and Geoinformatics

• MapScript (PHP-MapScript)

• Mapfile projected in class library• Enables read and write access to MapObjects and shape files with

PHP• Highest flexibility• Also available for PHP, Python, Perl, Ruby, Java, C# and other

Server side extension

MapS

erver extensions

Page 36: Ga1 2 lecture2

Dr.-Ing. Peter Korduan GI Advanced

UMN-MapServer 36

Rostock University, Chair for Geodesy and Geoinformatics

• MapBender – Free WMS Client Suite• Development of applications completely based on OGC data sources• Permission management

OGC ClientM

apServer extensions

Rostock University, Chair for Geodesy and Geoinformatics

• Mapplet

• Jbox• Zoom with a rubber band box• Query with a rectangle• Switch between different layers without loading the complete page• Distance measurement, single segments or cumulative• Display of cursor coordinates

mapserver.gis.umn.edu/doc40/jbox-howto.html

• ROSA Applet• DMSolutions Free PHP Map Script (www.dmsolutions.ca)

Client side extension

MapS

erver extensions

Page 37: Ga1 2 lecture2

Dr.-Ing. Peter Korduan GI Advanced

UMN-MapServer 37

Rostock University, Chair for Geodesy and Geoinformatics

MapServer Client with Java Applet

http://www2.dmsolutions.on.ca/gmap/gmap75.phtml

MapS

erver extensions

Rostock University, Chair for Geodesy and Geoinformatics

MapServer Client with kmap

http://maps.dmsolutions.ca/demo/us_streets/

MapS

erver extensions

Page 38: Ga1 2 lecture2

Dr.-Ing. Peter Korduan GI Advanced

UMN-MapServer 38

Rostock University, Chair for Geodesy and Geoinformatics

UMN MapServer User in Germany (Source CCGIS)

http://wms.ccgis.de => UMN User

MapS

erver examples

Rostock University, Chair for Geodesy and Geoinformatics

Public MapServer of German town Halle

http://halgis.halle.de/scripts/mapserv.exe

MapS

erver examples

Page 39: Ga1 2 lecture2

Dr.-Ing. Peter Korduan GI Advanced

UMN-MapServer 39

Rostock University, Chair for Geodesy and Geoinformatics

City map of Kanton Solothurn in the Swiss

http://www.so.ch/de/pub/departemente/bjd/gis/mapserver.htm

MapS

erver examples

Rostock University, Chair for Geodesy and Geoinformatics

Soil erosion model in Schwalmtal-Lüttelforst

http://www.terrestris.de/projects/schwalmtal.html

MapS

erver examples

Page 40: Ga1 2 lecture2

Dr.-Ing. Peter Korduan GI Advanced

UMN-MapServer 40

Rostock University, Chair for Geodesy and Geoinformatics

GGH online Geophysical survey Germany

http://www.ggh-mapservice.de/index.php3

MapS

erver examples

Rostock University, Chair for Geodesy and Geoinformatics

GDV MapServer Rheinland-Pfalz Germany

http://www.gdv-gis.de/mapserv/bereich/rlp/rlp.html

MapS

erver examples

Page 41: Ga1 2 lecture2

Dr.-Ing. Peter Korduan GI Advanced

UMN-MapServer 41

Rostock University, Chair for Geodesy and Geoinformatics

Geological map in south west Germany

http://www.webgeo.de/mapserver/php_mapscript/geologie_bw/geologische_einheiten_bw/geologie_bw.phtml

MapS

erver examples

Rostock University, Chair for Geodesy and Geoinformatics

Natural danger mapping in Kanton Solothurn Swiss

http://www.so.ch/de/pub/departemente/bjd/gis/mapserver.htm

MapS

erver examples

Page 42: Ga1 2 lecture2

Dr.-Ing. Peter Korduan GI Advanced

UMN-MapServer 42

Rostock University, Chair for Geodesy and Geoinformatics

http://www.webgis.de/teleregion/

Facility management system Teleregion-OberrheinM

apServer exam

ples

Rostock University, Chair for Geodesy and Geoinformatics

Costal zone management Alaska USA

http://squid.dnr.state.ak.us/website/DHTML_WMSClient/default.htm

MapS

erver examples

Page 43: Ga1 2 lecture2

Dr.-Ing. Peter Korduan GI Advanced

UMN-MapServer 43

Rostock University, Chair for Geodesy and Geoinformatics

http://www.terrestris.de/maps/

Examples from terrestris (Land register, Business admin…)M

apServer exam

ples