MapServer for Sahana
From IOSN-InWent FOSS GIS & Sahana Training
Contents |
Overview
Sahana using GoogleMap or OpenLayer as a map source for it's GIS features. With OpenLayer framework we can fetch not only online maps from public map service (YahooMap, MultiMap etc.) but also from our own WMS (Web Map Service) server. We can build WMS server using the opensource MapServer. All we need is:
- MapServer installed ($> sudo apt-get install mapserver-bin)
- Map file (shapefile) or PostGIS database (For this example we'll use Map shapefile)
- Some html files and configuration map (*.map)
Server Configuration
Roughly here are the structure of the web server directory (if we're using shapefile, not PostgreSQL/PostGIS):
/var/www/sahana
/var/www/mentawai
/var/www/mentawai/view.html
/var/www/mentawai/blablabla.map
/var/www/mentawai/(*.shp, *.shx, *.prj, *.dbf files)
Map File Configuration
File blablabla.map is the map file, to create it we can use qGIS, GRASS, MapBender etc. , example:
MAP
NAME 'Kemiringan Lereng'
SIZE 550 400
EXTENT 98.506380 -3.212124 100.579115 -0.929394
UNITS dd
SHAPEPATH '/var/www/mentawai'
STATUS on
IMAGECOLOR 255 255 255
IMAGETYPE png24
PROJECTION
"init=epsg:4326"
END
WEB
MINSCALE 0
TEMPLATE "/var/www/mentawai/view.html"
IMAGEPATH "/var/www/tmp/"
IMAGEURL "/tmp/"
METADATA
wms_title "View1"
wms_onlineresource "http://127.0.0.1/cgi-bin/mapserv?map=/var/www/mentawai/slope.map&"
wms_srs "EPSG:4326"
END #METADATA
END #WEB
LAYER #slope.shp
NAME 'kelas_kemiringan'
DATA kelas_kemiringan
METADATA
gix_layername "kelas_kemiringan"
gix_layerfieldnames "cat|label"
gix_layerfieldalias "Kategori|Kelas Slope"
wms_abstract "Kelas kemiringan Kepulauan Mentawai"
wms_srs "EPSG:4326 EPSG:32747"
wms_title "Kelas kemiringan"
wms_latlonboundingbox "98.506380 -3.212124 100.579115 -0.929394"
END #METADATA
TOLERANCE 3
TOLERANCEUNITS pixels
LABELCACHE on
STATUS on
TRANSFORM true
TYPE polygon #BENTUK
CLASS
NAME 'kelas_kemiringan 1'
TEMPLATE '/var/www/mentawai/view.html'
EXPRESSION ([cat]=1)
STYLE
COLOR 66 150 220
BACKGROUNDCOLOR 255 255 255
END #STYLE
END #CLASS
CLASS
NAME 'kelas_kemiringan 2'
TEMPLATE '/var/www/mentawai/view.html'
EXPRESSION ([cat]=2)
STYLE
COLOR 66 150 0
BACKGROUNDCOLOR 255 255 255
END #STYLE
END #CLASS
CLASS
NAME 'kelas_kemiringan 3'
TEMPLATE '/var/www/mentawai/view.html'
EXPRESSION ([cat]=3)
STYLE
COLOR 66 0 220
BACKGROUNDCOLOR 255 255 255
END #STYLE
END #CLASS
END #LAYER
Configuring Openlayers
- In menu Administration > Config Utils > Config Values, there's some OpenLayers configuration that we can adjust. This is the part where we define how many layer that we'd like to use.
- By default Sahana only provides maximum 2 layers for WMS, but we can do a little hacks to create more than 2 layers:
- $> sudo gedit /home/username/sahana/mod/gis/conf.inc
- Copy and change the [2]'s part (duplicating to 3 or more for examples...)
- Before:
...
$conf['ol_wms_2_description'] = ;
$conf['ol_wms_2_name'] = 'VMap1';
... - After:
...
$conf['ol_wms_2_description'] = ;
$conf['ol_wms_2_name'] = 'VMap1';
...
$conf['ol_wms_3_description'] = ;
$conf['ol_wms_3_name'] = 'VMap1';
...
- By default Sahana also using JPG in some part of the WMS feature so sometimes we need to hack another file to change it to transparent PNG
- $> sudo gedit /home/username/sahana/mod/gis/plugins/openlayers/openlayers-fns.php
- (Mr. Dudi will posting the modified script on the mailing list, also there'll be some coordination with Sahana's main developer)

