How can I save the results from a MapServer file as an image? I would like to be able to write a png file as a result of a query. My query which I can display in browser is the following:


I have tried the following (which does not seem to work):

wget http://mysite.com/mapserv.cgi?map=../../mapfiles/demo.map&layer=land&mode=map&FORMAT=image/png 

and also

wget http://mysite.com/mapserv.cgi?map=../../mapfiles/demo.map&layer=land&mode=map&FORMAT=image/png >> myfile.png

I have seen the shp2img function but that appears to be used just for testing mapfiles. In this case I would like to use a SQL filter with my mapfile, which I don't think I can do using shp2img.

Included first wget attempt that I tried.


I also asked this question on the MapServer mailing list, and Jukka Rahkonen suggested the following approach which fixed my problem:

Perhaps wget thinks that certain characters are cutting the URL string. Try wget "http://mysite.com/mapserv.cgi?map=../../mapfiles/demo.map&layer=land&mode=map&FORMAT=image/png" -O output.png

We have used wget a lot for downloading data from WCS so I guarantee you will make it work by reading documents and trying just like we did.

  • The problem is that the shell interprets the & as the fork to background command, so wget sends only part of the url to the server. – unicoletti Oct 31 '12 at 15:08

Just do:

wget http://mysite.com/mapserv.cgi?map=../../mapfiles/demo.map&layer=land&mode=map&FORMAT=image/png

You are getting some wget log output in your image file. See the manual for other information about how wget works.

  • That does not work for me. I get a file of this type mapserv.cgi?map=..%2F..%2Fmapfiles%2Fdemo.map. If I try renaming it to test.png it is not an image (I should have included this in my question as I had also tried it). – djq Oct 30 '12 at 14:33
  • I just tried it using GeoServer and it works for me. – Ian Turton Oct 30 '12 at 14:35
  • what is in the file? – Ian Turton Oct 30 '12 at 14:38
  • It turns out to be an error message mapserv(): Web application error. Traditional BROWSE mode requires a TEMPLATE in the WEB section, but none was provided. However, I can view it in my browser when I paste the same command in. – djq Oct 30 '12 at 14:41
  • so there's something wrong with your mapserver set up – Ian Turton Oct 30 '12 at 14:42

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.