Wednesday, 22 January 2020

Getting MapServer to show raster?



I am trying to use MapServer to display a raster image (png). That's it for now at least. However, I am having no luck. When I visit my map by using a link like:


*http://myurl.com/cgi-bin/mapserv?map=/path/to/file.map&layer=base&mode=map


I get the following error:



msLoadMap(): Regular expression error. MS_DEFAULT_MAPFILE_PATTERN validation failed. msEvalRegex(): Regular expression error. String failed expression test.



When I use shp2img:


shp2img -m file.map -o myimage.png -all_debug 5

I get no errors, but the image that's produced is completely gray except for the upper right quadrant which is white. This is nothing like my raster image.



My mapfile:


MAP
SHAPEPATH "/home/name/public_html/dir"
IMAGETYPE PNG
EXTENT -180 -90 180 90
SIZE 800 600
IMAGECOLOR 155 155 155
UNITS DD
STATUS ON
DEBUG ON


LAYER
NAME "base"
DATA "/home/name/public_html/dir/image.png"
STATUS ON
TYPE RASTER
END
END

What am I doing wrong?




Answer



Your map file is fine.


I've seen the Regular expression error. MS_DEFAULT_MAPFILE_PATTERN validation failed error when the extension to the map file in the URL is incorrect e.g.


.map Works: http://myurl.com/cgi-bin/mapserv?map=/path/to/file.map&layer=base&mode=map


.map2 fails with above error: http://myurl.com/cgi-bin/mapserv?map=/path/to/file.map2&layer=base&mode=map


In the MapServer source code you can see the regular expression used to check for a valid mapfile (.xml is also now allowed):


#define MS_DEFAULT_MAPFILE_PATTERN "\\.map$"

If your path and mapfile are correctly defined then it must be something in your URL request. Do you have any URL rewriters active? Maybe try and look at the web server logs to see the exact URL it receives.


No comments:

Post a Comment

arcpy - Changing output name when exporting data driven pages to JPG?

Is there a way to save the output JPG, changing the output file name to the page name, instead of page number? I mean changing the script fo...