use /Query rest api to interrogate a raster in a map service

1519
1
04-06-2017 03:19 PM
PhilScadden
New Contributor II

I know you can use Identify to fetch the raster value under a point. Identify needs map bounds and pixel widths which are inconvenient to fetch in my context. I have point or rectangle in world coordinates. It seems it should be possible to ./query but in all my attempts I just "Error 400: invalid or missing parameters". Identical parameters are fine on a polygon layer. Its rasters that comes unstuck.

0 Kudos
1 Reply
FC_Basson
MVP Regular Contributor

You should use the REST API identify and you can do it through an esri.request or Ajax call.  For the bounds, just set it marginally wider than your query point.  Here is an esri.request example that outputs the pixel value for 3 rasters to the console.

esri.request({
 url: "https://[server]/arcgis/rest/services/[service]/MapServer/identify",
 content:{
   f: "pjson",
   geometry: "19,-33",
   geometryType:'esriGeometryPoint',
   imageDisplay:'600,550,96',
   layers:"visible:11,12,13",
   mapExtent:[16, -40, 21, -25].toString(),
   sr:4326,
   time:'',
   tolerance:0,
   returnGeometry:false,
   maxAllowableOffset:'' 
 },
 handleAs: "json",
 callbackParamName: "callback"
}).then(function(json){
 for (var r in json.results){
   res = json.results[r];
   var val = res.attributes['Pixel Value'];
   val = parseFloat(val).toFixed(1);
   console.log(val);
 }
});‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍
0 Kudos