Search

Recent Posts

Tags


« | Main | »

Installing MapServer – Open Source Web Mapping Solution

By Dale Reagan | September 24, 2010

MapServer is an Open Source solution for generating and manipulating maps (publishing spatial data and interactive web applications.)  While you could use Google Maps or some other provider I see advantages to creating your own maps (without any license restrictions.)  NOTE – kudos & ‘hats off!’ to the folks providing this solution!  As is usual for my posts my intent is to explore the solution and note what I find – and provide hopefully helpful suggestions to for anyone who finds this post…

I start out by downloading, compiling and installing the ‘mapserv’ binary.

During my initial exploration of MapServer via the Workshop and Tutorials that I located I encountered a number of problems – this post emphasizes resolving those problems…)

Workshop and Tutorial Examples

The default Apache options for this solution may work but I suggest some tweaking:

For the Workshop demo:


<!-- EDIT THESE HIDDEN VARIABLES -->
<input type="hidden" name="map" value="/mapserver/workshop-5.4/itasca.map">
<input type="hidden" name="root" value="/mapserver/workshop-5.4">

And then, I encountered a few problems…  Web page Error message is:

"msLoadMap(): Unable to access file. (http://localhost/mapserver/workshop-5.4/itasca.map)"

Hmm – the message is NOT CLEAR – does it mean:

The documentation for the ‘demo’ was not clear about how path related variables are used – you have to customize configuration values if they are different from the values in the test files, i.e. does IMAGEPATH mean:

Ok – you are thinking that you can quickly find the answer to the above problem using MapServer forums, email lists, FAQs, or perhaps a search of some kind – I was not so lucky…   So I went to the DOCUMENTATION – which is both on-line and in a ~700+ page PDF-   and then I TESTED…)  This is one of the true puzzles about Internet posts – folks can easily be found ‘searching for answers’ and seldom found providing posts with real answers or following up after they find a solution…  So if you find a solution – POST it! 🙂

After tinkering it appears that the mapserv binary needs an Operating System (OS) file system level path in order to function – if you see it in *.map files or in *.html files the IMAGEPATH variable  seems to mean, “this is the complete OS path to the resource that you are asking mapserver to access…”  Likewise, if you see HTML like, ‘name=”map” value=”/some_path/”‘, then ‘/some_path/’ means the operating system file path…  The documentation discusses this but it should be front-and-center for any examples that folks put on-line (during my reading I encountered references to ‘relative paths’ would led me to believe there must be some simple way to handle/configure this – I may standardize on the file system location of /var/data/mapserver for any files that require an OS path (vs a web server URL – which is where any HTML related files would reside).)

Ok, I have the ‘workshop’ files working after changing the indicated variables (and after figuring out what they are for…)  For the Workshop demo I make changes to the itasca.map file:

#### IMAGEPATH must be writeable by the web user/process
#### NOTE- IMAGEPATH references the full-file-system-path-to-the-file
#### NOTE – IMAGEURL references the relative, WEB Server path

IMAGEPATH “/usr/share/mapserver/workshop-5.4/tmp/”
IMAGEURL “/mapserver/workshop-5.4/tmp/”

And then, change the index.html file as indicated below.


<!-- EDIT THESE HIDDEN VARIABLES -->
<input type="hidden" name="map" value="/usr/share/mapserver/workshop-5.4/itasca.map">
<input type="hidden" name="root" value="/mapserver/workshop-5.4">
OR
<input type="hidden" name="root" value="http://hostname_OR_localhost/mapserver/workshop-5.4">

MapServer Tutorial Challenges

Ok, now that the ‘workshop’ works I target the Tutorial. The HTML files contain the same ‘path problem’ (and the docs do indicate that you would need to alter the paths…)  I create a Bash shell script and use sed to change the files:

for FILE in *.html *.map
do
 BAK=${FILE}.bak
 if [[ ! -e ${BAK} ]] ; then cp ${FILE} ${BAK} ; fi
 NEW=${FILE}.new
 sed -e 's/map=\/ms4w\//map=\/usr\/share\/mapserver\/ms4w\//g' < ${FILE} > ${NEW}
 #cp ${NEW} ${FILE}
 ls -l ${FILE} ${FILE}.new
done

This very brief script will:

I suggest running such tools at least twice – pass one is to confirm that the desired changes are being made (compare the old & new files to confirm your desired change); pass two (you remove the ‘#’ on the ‘cp’ line) copies the new file over the old file.   You could then simply erase the *.bak and *.new files.

Continuing work with the Tutorial

Examples 1-4 now render maps.  Yee_HA! 🙂

Examples 5-9 do not render maps…  Hmmm

To see what the problem might be I right-click on the ‘missing’ map and select ‘copy image location’ – this provides me with the URL for the map; I then ‘paste’ the URL into the browser.

http://hostname_OR_localhost/cgi-bin/mapserv.exe?map=/usr/share/mapserver/ms4w/apps/tutorial/htdocs/example1-5.map&layer=states&layer=states_line&layer=states_label&layer=modis&mode=map

and then I get:

msDrawMap(): Image handling error. Failed to draw layer named 'modis'. msDrawRasterLayerLow(): General error message. Attempt to render raster layer to IMAGEMODE RGB or RGBA but without GDAL available.  24bit output requires GDAL.

Ok, my mapserv binary is missing a feature needed for 24 bit image generation.  What else might I be missing?  I try the remaining examples.

  1. 1-6 & 1-7 error: loadProjection(): Projection library error. Projection support is not available.
  2. 1-8 error:  loadOutputFormat(): General error message. OUTPUTFORMAT clause references driver GDAL/GTiff, but this driver isn’t configured.
  3. 1-9 error: msLoadMap(): Unable to access file. (/ms4w/apps/tutorial/htdocs/example1-9.map) [this time the PATH error is found in the ‘example1-9.map’ file – once that is resolved then the same error found in 1-8 above occurs…

At this point you might be thinking that there should be an easier way to get this all working – there is (of course!)  You could try the ‘packaged’ solution found at: http://www.maptools.org/fgs/,  If you using Fedora (or a related Linux release) they you might try yum install mapserver-5.6.5-1.fc13.i686 – note that this will install the mapserv binary in /usr/sbin; if successful then you will need to copy the binary to the appropriate CGI-Bin folder…  Note that the RPM may not include the support tools that are found with the sources and perhaps with fgs; also, the install from the source package does not install anything – you have to manually copy  the binaries into your location of choice…  Another solution – HostGIS Slackware ISO base and second ISO with GUI; works out of the box!  However, this is a Slackware 12.1 version (9/2010- current release is 13.1) and updates seem to ‘break’ some portions of the solution; also, the version of slapt-get distributed on the ISO appears to be broken and must be replaced…

Completing the MapServer Binary – adding missing tools

I do suggest reviewing the documentation which provides a good bit of background covering building the solution for both Unix/Linux and other OSs.   I proceed to download, compile and install additional libraries – after several hours of locating, downloading, compiling, and installing several new libraries of tools are ready to be included with the MapServer build (and certainly, you may not need many of them…)  Sample libraries that may be needed (depends upon which types of data you want your mapserv binary to support):

You may want to update your /etc/ld.so.conf file to include /usr/local/lib (i.e. add ‘/usr/local/lib/’ to /etc/ld.so.conf.d/local.conf and then run ‘ldconfig‘.)  If the changes are successful then future software builds (on the system modified) will automatically search /usr/local/lib for libraries – of course you can continue to manually pass flags & paths…  NOTE – I decided to use the current RPM version of mapserv

Checking your MapServer binary – what options are included in your binary?

If the mapserv binary is in your path you can simply ‘call it’.  If not, then provide the complete path to explore these options (i.e. /path-to-folder-containing/mapserv.)  From a shell prompt I call the mapserv binary.   In the second example I re-format the output a bit with awk.  Note that the command line options are intentionally limited since this tool is not designed for command line use…

mapserv -v (or /path-to-web-server/cgin/bin/mapserv -v)
MapServer version 5.6.5 OUTPUT=GIF OUTPUT=PNG OUTPUT=JPEG OUTPUT=WBMP OUTPUT=SVG SUPPORTS=PROJ SUPPORTS=AGG SUPPORTS=CAIRO SUPPORTS=FREETYPE SUPPORTS=ICONV SUPPORTS=FRIBIDI SUPPORTS=WMS_SERVER SUPPORTS=WMS_CLIENT SUPPORTS=WFS_SERVER SUPPORTS=WFS_CLIENT SUPPORTS=WCS_SERVER SUPPORTS=SOS_SERVER SUPPORTS=FASTCGI SUPPORTS=THREADS SUPPORTS=GEOS SUPPORTS=RGBA_PNG INPUT=TIFF INPUT=POSTGIS INPUT=OGR INPUT=GDAL INPUT=MYGIS INPUT=SHAPEFILE

mapserv -v| awk -v RS=" " '!/^MapServer|^version/ {if (NR -gt 2) printf "\t%02d. %s\n", NR-2, $0}'
 01. 5.6.5
 02. OUTPUT=GIF
 03. OUTPUT=PNG
 04. OUTPUT=JPEG
 05. OUTPUT=WBMP
 06. OUTPUT=SVG
 07. SUPPORTS=PROJ
 08. SUPPORTS=AGG
 09. SUPPORTS=CAIRO
 10. SUPPORTS=FREETYPE
 11. SUPPORTS=ICONV
 12. SUPPORTS=FRIBIDI
 13. SUPPORTS=WMS_SERVER
 14. SUPPORTS=WMS_CLIENT
 15. SUPPORTS=WFS_SERVER
 16. SUPPORTS=WFS_CLIENT
 17. SUPPORTS=WCS_SERVER
 18. SUPPORTS=SOS_SERVER
 19. SUPPORTS=FASTCGI
 20. SUPPORTS=THREADS
 21. SUPPORTS=GEOS
 22. SUPPORTS=RGBA_PNG
 23. INPUT=TIFF
 24. INPUT=POSTGIS
 25. INPUT=OGR
 26. INPUT=GDAL
 27. INPUT=MYGIS
 28. INPUT=SHAPEFILE

Mapserver is designed to run as a CGI program which means it ‘expects’ to be working with a web server  – if you run the command by itself you should see something like the output below:

mapserv
This script can only be used to decode form results and
should be initiated as a CGI process via a httpd server.

You can also test by re-directing output to a file (forget to re-direct and you will get non-printable characters on your screen…)

mapserv -nh "QUERY_STRING=map=/path-to-any-map-file/example1-4.map&layer=states_poly&layer=states_line&mode=map" > ms.image.png

If the ‘.map’ file is valid then you should be able to view the image in your browser (and it should look like a map!)

BTW – using the ‘mapserver -nh “QUERY_STRING=map/path-to-mapfile-/some-mapfile.map’ command you could use this tool generate pre-defined maps without using a web server…  As always, your mileage should vary.  🙂


sudo cp libflashplayer.so /usr/lib/mozilla/plugins

Topics: Computer Technology, Internet Search, Problem Solving, System and Network Security, Unix-Linux-Os, Web Problem Solving, Web Technologies | Comments Off on Installing MapServer – Open Source Web Mapping Solution

Comments are closed.


________________________________________________
YOUR GeoIP Data | Ip: 73.21.121.1
Continent: NA | Country Code: US | Country Name: United States
Region: | State/Region Name: | City:
(US only) Area Code: 0 | Postal code/Zip:
Latitude: 38.000000 | Longitude: -97.000000
Note - if using a mobile device your physical location may NOT be accurate...
________________________________________________

Georgia-USA.Com - Web Hosting for Business
____________________________________