Filed under: Mapserver | Tags: mapserver wms, mapserver wms server, openlayer wms, osgeo mapserver wms, umn mapserver wms
While I have been working with Google map api, a lots tutorial over the web can be found. But unfortunately, Map server developer are only working but not willing to anything for new developer. May be they think it is very simple, why you need more than the mapserver documentation? But true is that it is very difficult to new developer to run their first hello world program. So, very first time in my blog I have started to write tutorial on map server related issue.
The main objective of this writing is that a simple wms map repository will be created using Osgeo Mapserver and view the map with openlayer. In this example I have used three layers Bangladesh district boundary, Main Road and District head quarter location. The first two layer map source is ESRI Shape file and third one is postgis. For all the layer I have used wgs84(EPSG:4326) projection system. In my another post I wrote on mapserver projection system, click here to check article.
Map file Creation with WMS support:
I am using osgeo mapserver in windows OS. Below definition have been added for top level in mapfile,
NAME BdDistMap STATUS ON SIZE 500 550 # Extent based on full extent of QGIS view EXTENT 86.7316 20.5896 93.9623 26.6341 UNITS dd IMAGECOLOR 225 225 255 IMAGETYPE png FONTSET "fontlist.txt"
Now the web section is very important for wms. It requires to add meta data information to give WMS support. This example I have added minimum wms definition which are all most mandatory.
WEB
IMAGEPATH "/OSGeo4W/tmp/tmp_img/"
IMAGEURL "/tmp/tmp_img/"
HEADER "query_header.html"
FOOTER "query_footer.html"
METADATA
"wms_title" "WMS Demo Server"
"wms_onlineresource" "http://localhost:8080/cgi-bin/mapserv.exe?map=C:\OSGeo4W\apache\htdocs\openlayer\sampleapps\distGeo.map"
"wms_srs" "EPSG:4326"
"wms_feature_info_mime_type" "text/html"
END
END
In metadata section, wms_title, wms_srs are mendatory. Wms_srs is the projection system definition. wms_feature_info_mime_type is used to GetFeatureInfo request output format.
I have used map lavel projection system for all layers. Below is definition,
PROJECTION "init=epsg:4326" END
Now in layer definition, I have added meta info tag again. Below is the definition,
LAYER
NAME dist_geo
PROJECTION
"init=epsg:4326"
END
HEADER "hq_query_header.html"
TEMPLATE "hq_query_body.html"
METADATA
"wms_title" "distwms"
END
TYPE POLYGON
STATUS OFF
DATA "C:/OSGeo4W/apache/htdocs/openlayer/sampleapps/shp/dist_GEO.shp"
CLASS
NAME "State Boundary"
STYLE
COLOR 150 123 90
OUTLINECOLOR 229 210 191
END
END
END
Here I add projection parameter again. If you want use map level projection, this section can be removing. This include Bangladesh administrator boundary with wms support. The data source is shape file in wgs84 projection.
Below the complete working mapfile is given which is able response wms request.
MAP
NAME BdDistMap
STATUS ON
SIZE 500 550
# Extent based on full extent of QGIS view
EXTENT 86.7316 20.5896 93.9623 26.6341
UNITS dd
IMAGECOLOR 225 225 255
IMAGETYPE png
FONTSET "fontlist.txt"
WEB
IMAGEPATH "/OSGeo4W/tmp/tmp_img/"
IMAGEURL "/tmp/tmp_img/"
HEADER "query_header.html"
FOOTER "query_footer.html"
METADATA
"wms_title" "WMS Demo Server"
"wms_onlineresource" "http://localhost:8080/cgi-bin/mapserv.exe?map=C:\OSGeo4W\apache\htdocs\openlayer\sampleapps\distGeo.map" "wms_srs" "EPSG:4326"
"wms_feature_info_mime_type" "text/html"
END
END
QUERYMAP
STATUS ON
SIZE 500 550
STYLE HILITE
COLOR 255 255 0
END
SYMBOL
NAME "Circle"
FILLED true
TYPE ellipse
POINTS 5 5 END
END
PROJECTION
"init=epsg:4326"
END
LAYER
NAME dist_geo
PROJECTION
"init=epsg:4326"
END
HEADER "hq_query_header.html"
TEMPLATE "hq_query_body.html"
METADATA
"wms_title" "distwms"
END
TYPE POLYGON
STATUS OFF
DATA "C:/OSGeo4W/apache/htdocs/openlayer/sampleapps/shp/dist_GEO.shp"
CLASS
NAME "State Boundary"
STYLE
COLOR 150 123 90
OUTLINECOLOR 229 210 191
END
END
END
LAYER
NAME road_geo
HEADER "hq_query_header.html"
TEMPLATE "hq_query_body.html"
PROJECTION
"init=epsg:4326"
END
METADATA
"wms_title" "Cities"
END
TYPE LINE
STATUS OFF
DATA "C:/OSGeo4W/apache/htdocs/openlayer/sampleapps/shp/rds_nr_geo.shp"
CLASS
NAME "State Road"
STYLE
COLOR 32 32 32
END
END
END
LAYER
NAME dist_hq_geo
# for HTML queries
HEADER "hq_query_header.html"
TEMPLATE "hq_query_body.html"
PROJECTION
"init=epsg:4326"
END
METADATA
"wms_title" "DistHQ"
END
TYPE POINT
STATUS OFF
CONNECTION "user=postgres password=cegis dbname=postgis host=localhost port=5432"
CONNECTIONTYPE postgis
DATA "the_geom from dist_hq_geo USING UNIQUE gid"
LABELITEM "distname"
CLASS
NAME "dist_hq_geo"
COLOR 200 255 0
SYMBOL "Circle"
LABEL
COLOR 132 31 31
SHADOWCOLOR 218 218 218
SHADOWSIZE 2 2
TYPE TRUETYPE
FONT arial
SIZE 11
ANTIALIAS TRUE
POSITION CL
PARTIALS FALSE
MINDISTANCE 300
BUFFER 4
END # end of label
STYLE
OPACITY 100
END
END
END
END # Map File
Call mapserver WMS Layer:
Now the important part, how we can test this repository? Write below address in your web browser,
http://localhost:8080/cgi-bin/mapserv.exe?SERVICE=WMS&VERSION=1.1.1&REQUEST=GetCapabilities&map=C:\OSGeo4W\apache\htdocs\openlayer\sampleapps\distGeo.map
This will return respose wms request if everything is okay. And also write below address for testing map image generation of mapserver,
http://localhost:8080/cgi-bin/mapserv.exe?mode=map&layer=dist_geo&layer=road_geo&map=C:\OSGeo4W\apache\htdocs\openlayer\sampleapps\distGeo.map
In another article, I wrote how to add mapserver wms layer using openlayer.
Click here
For more information about wms layer, please check below links,
here
here
……………………………..
Abul Khayer
GIS programmer
CEGIS
Bangladesh
Filed under: Mapserver | Tags: BTM, btm projection, BUTM, EPSG:3106, mapserver bangladesh, mapserver porjection, osgeo mapserver projection, umn mapserver projection
I am not a projection expert. So, who know projection very well, this article does not come to any help. Here I give some reference information for new mapserver developer.
We can add projection parameter in map file by two ways,
1. Inline projection
It use detail projection parameter. If you use shape file, using arcgis parameter can be found. And also there .prj file where contains this parameters. Below I give the projection parameter of wgs84,
PROJECTION
“proj=longlat”
“ellps=WGS84″
“datum=WGS84″
“no_defs”
END
2. EPSG Projection reference
For simplicity, some reference number is introducing to identify a set of projection parameter, known as ESPG. We can find epsg from below site,
http://spatialreference.org
In all list reference tab, require reference number can be search. For example, if we search Bangladesh then we get EPSG:3106 code for Bangladesh(BUTM).
EPSG list can be found also in local pc in “OSGeo4W\share\proj\epsg” file.
Now for WGS84 projection, we have add below projection code in map file in EPSG,
PROJECTION
“init=epsg:4326″
END
The projection can be add in layer level in map file. But if the entire layers are in same projection, then no need to add projection in layer level. It is better at in map level.
If we use WMS layer, wms_srs is a mandatory parameter. So the for wgs84 parameter value should be,
METADATA
“wms_srs” “EPSG:4326″
END
Fow more mapserver project documentation, click here.
…………………………
Abul Khayer
GIS programmer
CEGIS
Filed under: Mapserver | Tags: mapserver, mapserver bangladesh, mapserver framework, Mapserver using PHP, mapserver viewer, OSGeo Mapserver
OSGeo Mapserver (Previous UNM Mapserver) is a very strong opensource tools for web based GIS mapping. It is support all of the server side language like PHP, Perl and JSP. It can render map from ESRI Shape file, Wms, Spitial Database, Raster and others popular format.
For a begainer, it is very easy to display a hello world map. But for industry use, programmers need to use framework like GMap, Kmap, Openlayer and so on. The Gmap map is a nice tool which is written in PHP. Unfortunately, there is no regular update for GMAP. Besides, OpenLayer is a javaScript API for using Mapser server. But all of available framework are little bit complex to work. They require major changes for minor modification.
I have got chances to work with .NET component of mapping like ASP Map, Map Object (Desktop Application), SharpMap (Opensource) and MapWindowGIS (Opensource). They need small number of line code for creating mapping tool. All the time I am waiting for a Mapserver framework to work like .NET component. Unfortunately most of the Mapserver developer are very high skill, so they can not realize my simple requirement. At last I decided to write a viewer using phpMapscript only for use myself. I gave the viewer name BDMapper.

-Live Demo of BDMapper
-Source Code of BDMapper
BDMapper has developed using PHPMapscript, Mysql and Java Script. Some functions of GMAP are exteded here. User can create a mapping tool with writing some lines of code. But the main objective of BDMapper development is to easy enhancement with other application and easy modification.


If you want to use BDMapper, the first thing you need to install the BDMapper demo in your local machine. You should follow below steps to run the demo in your local machine,
Installing Mapserver
Download mapserver form mapserver.org. To install the OSGeo mapserver, follow the installation guide. For BD mapper some extra configuration is recommended.
Apache Configuration (httpd.conf):
- Add temp director alias. Here is my local machine setting for temp directory
## Alias for MapServer tmp directory
##
Alias /ms_tmp/ “c:\OSGeo4w/tmp/ms_tmp/”
- Create a folder named ms_tmp in “c:\OSGeo4w/tmp/” directory.
####
** PHP Configuration (php.ini):
- Load PHP MapScript Extension
extension=php_mapscript.dll
- Load PHP_dbase Extension
extension=php_dbase.dll
Restart Apache service.
BD Mapper Demo Installation
- Download Source from here
- Unzip Source and copy in Apache hottdocs root directory
- Dirrctory Descrioption
/classes Main Class Modules
/data_files Map Shape Files
/Documentation Help and Documentation
/images Default Images
/JS JS API
- Change tha MySQL Connection Paramere in Class/clsUmnMapDB.php
if(!($dbCon=mysql_connect(“localhost”,”root”,”cegis”)))
- Check the default map file (testMap.map) parameters. Extends parameter set a dummy value. Please keep extends value unchanged.
Mysql Database Creation
- Install Mysql 5 or higher
- Restore mysql dump using Mysql GUI Administration tools from Doccumentation\bdmapper 20090616 1619.sql file.
- Make sure that the Connection paramert in class/clsUmnMapDB.php is updated.
Description of the Main pages:
bdmapper.php:
This the main page of the viewer. There the MapID is hard coded to 102. Currently two map date created as example in Mysql database. You should assign this value dynamically. Program use a default map testMap.map. In every post back program store its view state crating temporary (tmp123.map) map in current directory.
testMap.map:
Default Map for the BDMapper.
clsUmnMap.php:
Main Mapping module.
clsUmnMapDB.php:
Data Access Layer of the program
clsGenFunc.php:
Collection of general use functions.
Please read the Doccumentation/Doccumentation.pdf carefully before any modification of the code.
I have published this script without any restriction. You are free to use this script in your product. You just need to acknowledge me.
Sample GIS Data (/data_files) are not available with the source code. You can mail me for the sample data.
Please give your feedback if this post is helpful.
Thanks,
Md. Abul Khayer
GIS Programmer,
CEGIS, Bangladesh.
Khayer.wordpress.com
Khayer117@yahoo.com