Monday, May 19, 2008

Mapserver Kick start for newbies :)

I met many mapserver enthusiasts (esp students) who wants to see a map quickly by using mapserver. All though mapserver has an abundance in terms of docs and tutorials, I never found a sinlge straightway solution which can help you to do this :

AIM: Write your first map file, and see the rendered map on the browser.

I suggest few easy steps to show a map using your shapefile. Remember YOU WILL HAVE TO WRITE ONE AND ONLY ONE MAPFILE. nothing else :)

Steps:

a. Download ms4w(For windows). Else install FOSS for Linux
b. Open a notepad (or anyother text editor). Write your first map file which will look like this:


MAP
NAME "mapfilename" #write your map file name here
STATUS ON
SIZE 512 512
imagetype png
SHAPEPATH "/ms4w/data" #path where you kept your shapefiles
EXTENT 68.1271 6.75621 97.4023 37.0675
#(extent of shapefile. you can get this info by using arcgis, qgis, etc)
FONTSET "C:\ms4w\YourDirectory\fonts.txt"
PROJECTION
'proj=longlat' #projection
'ellps=WGS84' #ellipsoid
'datum=WGS84' #surface of the earth
'no_defs'
END
DEBUG ON
CONFIG "MS_ERRORFILE" "C:\Temp\mapserver.log"

OUTPUTFORMAT
NAME png
DRIVER "GD/PNG"
MIMETYPE "image/png"
IMAGEMODE RGB
EXTENSION "png"
END

WEB
IMAGEPATH "/ms4w/YourTempDir/tmp/"
IMAGEURL "/tmp/"
END

LAYER
NAME "your_layer_name"
DATA "/ms4w//data/shapefileName" #name of your shapefile
TYPE POLYGON
STATUS ON
PROJECTION
'proj=longlat' #projection
'ellps=WGS84' #ellipsoid
'datum=WGS84' #surface of the earth
'no_defs'
END #projection
CLASS
Name 'your_class_name'
COLOR 0 0 0
OUTLINECOLOR 0 0 0
STYLE # thick outline (could use a circle symbol with size too)
OUTLINECOLOR 255 218 185
WIDTH 2
ANTIALIAS FALSE
END #style
END # Class
END # Layer

END#map end




3. Save this map file (eg. test.map) in ms4w/apache/cgi-bin/
4. On command line, run this command:
C:\ms4w\apache-install.bat
C:\ms4w\apache-restart.bat
5. Open up a browser (IE,Opera,FF) and write this url :

http://localhost/cgi-bin/mapserv.exe?map=test.map&layers=your_layer_name&mode=map


Thats all !! You will see a map rendered using the shapefile you wished.

Reading Recommendations:
1. Mapserver
2. OpenLayers
3. PostGIS
4. Mapserver tutorial


1 comment:

Amby Rit said...

Sample shapefile can be downloaded from this URL:

http://examples.oreilly.com/webmapping/


*The shapefile link is sole property of oreilly.com, and the blog author has posted it for educational purpose only.