Take the 2-minute tour ×
Geographic Information Systems Stack Exchange is a question and answer site for cartographers, geographers and GIS professionals. It's 100% free, no registration required.

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:

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

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.

EDIT: Included first wget attempt that I tried.

share|improve this question
add comment

2 Answers 2

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.

share|improve this answer
    
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. –  iant Oct 30 '12 at 14:35
    
what is in the file? –  iant 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 –  iant Oct 30 '12 at 14:42
show 1 more comment
up vote 1 down vote accepted

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.

share|improve this answer
    
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
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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