Friday, 23 January 2015

wms - Use OpenLayers WMSGetFeatureInfo on Mapserver Layer?



I'm able to use OpenLayers' OpenLayers.Layer.Mapserver declaration to generate a raster from GRIB data. I've read in the MapServer docs and on forums that it should be possible to get point information back from the raster using OL's WMSGetFeatureInfo. I've tried a few combinations of others' reported solutions. However, as the control is for a regular WMS and also nearly all of the solutions involve GeoServer, I've pretty much reached a wall. So this is my code:




And my mapfile (some url and file locations changed for privacy, but not necessary for this question)


MAP
NAME "testgrib"
IMAGETYPE PNG
EXTENT -14000000 3000000 -7000000 7000000
STATUS ON
SIZE 2145 1377


SHAPEPATH "../shapefiles"
SYMBOLSET "../symbols/symbols35.sym"
FONTSET "../fonts/fonts.list"
DATAPATTERN "^.*$"
IMAGECOLOR 255 255 255

PROJECTION
"init=epsg:3857"
END
WEB

IMAGEPATH "test/img/tmp/ms_tmp/"
IMAGEURL "http://localhost:8080/wxmap/test/img/tmp/ms_tmp/"
METADATA
"wms_title" "WMS Test " ## REQUIRED
"wms_onlineresource" "http://localhost:8080/cgi-bin/mapserv?" ## Recommended
"wms_srs" "ESPG:3857 EPSG:4326 EPSG:4269 EPSG:3978 EPSG:900913" ## Recommended
"wms_abstract" "This text describes my WMS service." ## Recommended
"wms_enable_request" "*"
"ows_sld_enable" "true"
# testing

"wms_feature_info_mime_type" "text/html"
END
END

OUTPUTFORMAT
NAME "png"
DRIVER GD/PNG
MIMETYPE "image/png"
IMAGEMODE RGBA
EXTENSION "png"

TRANSPARENT ON
END


LAYER # GRIB attempt
NAME mosaic
STATUS ON
TYPE RASTER

DATA ../grib/ds.vis.bin


CLASSITEM "[pixel]"
METADATA
"gml_include_items" "all"
"wms_include_items" "all"
END

# testing
DUMP TRUE
HEADER "../templates/test_header.html"

TEMPLATE "../templates/test_body.html"
FOOTER "../templates/test_footer.html"

PROJECTION
"proj=lcc"
"lat_1=25"
"lat_2=25"
"lat_0=0"
"lon_0=-95"
"x_0=0"

"y_0=0"
"a=6371200"
"es=0.0"
"+no_defs"
END

PROCESSING "NODATA=32129"
PROCESSING "BANDS=01"
PROCESSING "SCALE=0,11200"
LABELITEM "[pixel]"


CLASS
NAME "< 1/4"
EXPRESSION ([pixel] < 400 )
STYLE
COLOR 100 0 100
END
END
CLASS
NAME "1/4 - 1/2"

EXPRESSION ([pixel] >= 400 AND [pixel] < 800 )
STYLE
COLOR 200 200 0
END
END
CLASS
NAME "1/2 - 3/4"
EXPRESSION ([pixel] >= 800 AND [pixel] < 1200 )
STYLE
COLOR 150 0 0

END
END
CLASS
NAME "3/4 - 1"
EXPRESSION ([pixel] >= 1200 AND [pixel] < 1600 )
STYLE
COLOR 200 0 200
END
END
CLASS

NAME "1 - 2"
EXPRESSION ([pixel] >= 1600 AND [pixel] < 3200 )
STYLE
COLOR 100 100 0
END
END
CLASS
NAME "2 - 3"
EXPRESSION ([pixel] >= 3200 AND [pixel] < 4800 )
STYLE

COLOR 255 153 0
END
END
CLASS
NAME "3 - 5"
EXPRESSION ([pixel] >= 4800 AND [pixel] < 8000 )
STYLE
COLOR 0 0 200
END
END

CLASS
NAME "5 - 6"
EXPRESSION ([pixel] >= 8000 AND [pixel] < 9600 )
STYLE
COLOR 0 100 0
END
END
CLASS
NAME "6 - 7"
EXPRESSION ([pixel] >= 9600 AND [pixel] < 11200 )

STYLE
COLOR 0 200 0
END
END
CLASS
NAME "> 7"
EXPRESSION ([pixel] >= 11200 )
STYLE
COLOR 250 250 250
END

END

END # End of mosaic layer

END

And I need template files here for the response: test_header.html



"http://www.w3.org/TR/html4/transitional.dtd">



MapServer Template Sample


test_body.html



band1: [value_0]



test_footer.html




I'm not positive that the test_body.html is correct. But, the main issue is that when I click on the image, nothing happens. Firebug doesn't indicate any query is sent to MapServer for the layer. Inserted a breakpoint in the WMSGetFeatureInfo code at the getfeatureinfo function but the execution didn't go into the code.


As I realize that perhaps the issue centered around not declaring the layer as OpenLayers.Layer.WMS instead of MapServer, I also attempted to create the layer using OpenLayers.Layer.WMS. But, that created issues of its own. Kind of a toss up then which question to ask. Might ask the other one later. So, if anyone has any thoughts on how to use this with the Mapserver layer or perhaps a different control, I'd really appreciate the help. Thanks!



Answer



I got maps like yours working and the only difference that I could spot is that I use OpenLayers.Layer.WMS instead of OpenLayers.Layer.MapServer.


Since GetFeatureInfo is a WMS protocol operation OL correctly should not apply it to Mapserver layers (even though Mapserver is fully capable of speaking WMS). Try to create the layer as follows:


var wmsmap = new OpenLayers.Layer.WMS( "grib plot",
"/cgi-bin/mapserv.exe?map=wxmap/glmpvis.map",

{layers: 'mosaic',
srs: 'YOUR SRS HERE',
format: 'image/png',
isBaseLayer: false,
visibility: true
}
);

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...