This is a class presentation on MapServer...
The facts and figures explained here are somebody else's work. The author has just accumulated and presented them.
2. Introduction
• Open Source platform for publishing spatial data and interactive
mapping applications to the web
• Written in C
• Originally developed in the mid-1990’s at the University of Minnesota
ForNet project in collaboration with NASA
• released under an MIT-style license
• not a full-featured GIS system, nor does it aspire to be.
12/13/2019 2
3. Features
• Advanced cartographic output
• Support for popular scripting and development environments
• Support of numerous Open Geospatial Consortium (OGC) standards
• A multitude of raster and vector data formats
• Map projection support
• runs on all major platforms (Windows, Linux, Mac OS X, Solaris)
12/13/2019 3
5. Anatomy
• Map file- tells the program where and how your
data and output images are
• Geographic data- default is ESRI Shape format
and if compiled with OGR, GDAL etc. supports
other formats like PostGIS, GML, MapInfo
• Html pages
• interface between user and mapserver.
• Mapserver places static maps in HTML page
• forms can be added to make interactive,
• MapServer CGI
• receives requests and returns images, data, etc.
• Execute rights required, for security reason
• Web/HTTP Server
• serves up the HTML pages when hit by the
user’s browser.
12/13/2019 5
7. CGI
• a CGI program that sits inactive on Web server.
• When a request is sent to MapServer, it uses information passed in the
request URL and the Mapfile to create an image of the requested map.
• The request may also return images for legends, scale bars, reference
maps, and values passed as CGI variables.
12/13/2019 7
8. CGI
• Has two html pages
• Initilization file
• uses a form with hidden variables to send an initial query to the web server and
MapServer.
• Template file
• controls how the maps and legends output by MapServer will appear in the
browser.
12/13/2019 8
9. Map file
• Heart of MapServer.
• defines the relationships between objects
• points MapServer to where data are located
• defines how things are to be drawn.
• consists of a MAP object, which has to start with the word MAP.
• Key component is the LAYER file
• is the combination of data plus styling.
• Data, in the form of attributes plus geometry, are given styling
using CLASS and STYLE directives.
12/13/2019 9
11. Data Optimization
• Index Your Data
• Tile Your Data
• Pre-classify your Data
• Pre-process your images
• Generalize For Overview
12/13/2019 11
12. Query
• Attribute query
• Spatial query
• Conditions:
• Querymap
• Mapfile layer and class should have template defined
• Qlayer
• Qstring
• Qitem
12/13/2019 12
13. Mapserver Vs Geoserver: Similarities
• Both work with Windows & Linux, both are well developed
• both are open source, completely free and extremely develop-able with
some great tools included out of the box.
• On paper, Geoserver and Mapserver are pretty identical, both publish
geospatial data from almost any format
• The components and way the core works is essentially the same,
12/13/2019 13
14. Mapserver Vs Geoserver: Differences
Mapserver
• Based on C and PHP
• Focused for map
• Faster response
• Better cartographic presentation
• Better for reprojection
Geoserver
• Java- based
• Also has a lot of support for data
sharing
• A bit slow response(due to size)
• Cartographically not fine as
mapserver
• Better without reprojection, with
cache
12/13/2019 14
15. Comparison Chart
Geoserver Mapserver
WMS good Better
WFS Better, supports WFS-T No WFS-T
Technology J2EE CGI
Administration Web tool Mapfile generation can be aided by QGIS, but not
comparable to Geoserver’s web admin tool
Extensibility Good for Java developers PHP Mapscript,
querying CQL and OGC filters Embedded SQL statement
Cartography Used standardized SLDs powerful; styles are part of mapfile
Services One WMS/WFS/WCS service for all
users
A mapfile means a service
12/13/2019 15
17. Mapserver vs ArcGIS Server
Mapserver
• run on all major operating
systems (Windows, Linux, Mac
OSX
• “Saving” of software licenses.
• Efficient performance for small
and medium scale purpose
• WFS files of smaller size
ArcGIS Server
• only works under Windows and
Linux
• Proprietary, so needs purchase
• Suitable for large scale projects
• WFS files of large size
12/13/2019 17
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 (scalebar, reference map, and legend)
Thematic mapping using logical- or regular expression-based classes
Support for popular scripting and development environments
PHP, Python, Perl, Ruby, Java, and .NET
Support of numerous Open Geospatial Consortium (OGC) standards
WMS (client/server), non-transactional WFS (client/server), WMC, WCS, Filter Encoding, SLD, GML, SOS, OM
A multitude of raster and vector data formats
TIFF/GeoTIFF, NetCDF, MrSID, ECW, and many others via GDAL
ESRI shapfiles, PostGIS, SpatiaLite, Mapbox Vector Tile (MVT), Oracle Spatial, MySQL and many others via OGR
Map projection support
On-the-fly map projection with 1000s of projections through the PROJ library
By referencing MapServer CGI variables in the template HTML, you allow MapServer to populate them with values related to the current state of your application (e.g. map image name, reference image name, map extent, etc.) as it creates the HTML page for the browser to read. The template also determines how the user can interact with the MapServer application (browse, zoom, pan, query).
a structured text configuration file for your MapServer application. It defines the area of your map, tells the MapServer program where your data is and where to output images. It also defines your map layers, including their data source, projections, and symbology. It must have a .map extension or MapServer will not recognize it.
Data Optimization
Data organization is at least as important as hardware configuration in optimizing a MapServer application for performance. MapServer is quite efficient at what it does, but by reducing the amount of processing that it needs to do at the time of a user request, you can greatly increase performance. Here are a few rules:
Index Your data - By creating spatial indexes for your Shape datasets using shptree. Spatial indexes should also be created for spatially aware databases such as PostGIS and Oracle Spatial.
Tile Your Data - Ideally, your data will be ‘sliced up’ into pieces about the size in which it will be displayed. There is unnecessary overhead when searching through a large Shape dataset or image of which you are only going to display a small area. By breaking the data up into tiles and creating a tile index, MapServer only needs to open up and search the data files of interest. Shape datasets can be broken into smaller tiles and then a tileindex Shape dataset can be created using the tile4ms utility. A tileindex Shape dataset for raster files can also be created.
Pre-Classify Your Data - MapServer allows for the use of quite complex EXPRESSIONs to classify data. However, using logical and regular expressions is more resource intensive than string comparisons. To increase efficiency, you can divide your data into classes ahead of time, create a field to use as the CLASSITEM and populate it with a simple value that identifies the class, such as 1,2,3, or 4 for a four class data set. You can then do a simple string comparison for the class EXPRESSION.
Pre-Process Your Images - Do resource intensive processing up front. See the Raster Data reference for more info.
Generalize for Overview - create a more simple, generalized data layer to display at small scales, and then use scale-dependent layers utilizing LAYER MINSCALE and LAYER MAXSCALE to show more detailed data layers as the user zooms in. This same concept applies to images.
Adding Query Capability
There are two primary ways to query spatial data. Both methods return data through the use of templates and CGI variable replacement. A QUERYMAP can be used to map the results of the query.
To be queryable, each mapfile LAYER must have a TEMPLATE defined, or each CLASS within the LAYER must have a TEMPLATE defined. More information about the CGI variables used to define queries can be found in the MapServer CGI Reference.
Attribute queries
The user selects features based on data associated with that feature. ‘Show me all of the lakes where depth is greater than 100 feet’, with ‘depth’ being a field in the Shape dataset or the spatial database. Attribute queries are accomplished by passing query definition information to MapServer in the URL (or form post). Mode=itemquery returns a single result, and mode=itemnquery returns multiple result sets.
The request must also include a QLAYER, which identifies the layer to be queried, and a QSTRING which contains the query string. Optionally, QITEM, can be used in conjunction with QSTRING to define the field to be queried. Attribute queries only apply within the EXTENT set in the map file.
Spatial queries
The user selects features based on a click on the map or a user-defined selection box. Again the request is passed through a URL or form post. By setting mode=QUERY, a user click will return the one closest feature. In mode=NQUERY, all features found by a map click or user-defined selection box are returned. Additional query options can be found in the CGI documentation.
Java 2 Platform Enterprise Edition. J2EE is a platform-independent, Java-centric environment from Sun for developing, building and deploying Web-based enterprise applications online. The J2EE platform consists of a set of services, APIs, and protocols that provide the functionality for developing multitiered, Web-based applications