Select to view content in your preferred language

identify pixel value

4567
9
Jump to solution
12-05-2013 04:04 AM
EulàliaMonfort
Emerging Contributor
Hi,
I have a problem with identify pixel value. I publish  a raster in the Server and then, when I clik over the raster in the webmap I want to obtain the pixel value. Is it possible? What code in javascript I have to use? or what function/command? it's very easy to do with a shape file because I have an attribute table, but with raster I don't know how to do that because my raster is a float and I can't build an attribute table.

thanks in advance.

Eu
0 Kudos
1 Solution

Accepted Solutions
BenFousek
Deactivated User
Are you using firebug or some other development tools to debug in the browser? Using such allows you to view the actual request and the response from the server.

Instead of using alert(), try using console.log(idResults). Then you'll see the response in the console.

Here's the response from an identify of a raster layer:
[ATTACH=CONFIG]29726[/ATTACH]

Notice the raster values are returned in the attributes object just like a vector data identify of query. The reason your alert is undefined is because idResults[0]['pixel value'] is undefined. Try idResults[0].attributes['Pixel Value'].

You'll also notice there is a space in the attribute keys. This is unique in attributes returned from AGS. In a shp or gdb feature class attributes you can't have spaces. Normally you would be able to access a specific attribute like results[0].attributes.parcelId, but this is not possible with the space. results[0].attributes.Pixel Value will return an error so you do need to use results[0].attributes['Pixel Value'].

View solution in original post

0 Kudos
9 Replies
SteveCole
Honored Contributor
I hope someone else can prove me wrong but I believe that this cannot be done using just the API. I really would like to add this to one of my applications but have yet to accomplish this. There might be, however, one way to do this but it's likely to be slow and clunky: publish a geoprocessing (GP) service to perform this task.

In ArcToolbox, there is a "Get Cell Value" tool. You can find it under Data Management->Raster->Raster Properties. You could publish this tool as a GP and then pass it your coordinates (taken from the onClick event of the raster or more likely the map) and then present the results back to your user.

I played briefly with this but wasn't successful but this was because the raster I wanted to query was a geo-registered image which has no projection information (I added it to my map as a MapImageLayer). I got bogged down in a two step process of trying to project the image first and then sending that result (along with my x,y) to the Get Cell Value tool.

I've talked with the devs at the ESRI UC about this and they seemed surprised that raster layers didn't have an identify function. I'm hoping it gets added eventually but for now, I think the GP route may be your only option.

Steve
0 Kudos
MichaelJenkins
Frequent Contributor
If you are posting the service to your own ArcGIS Server, you can post the raster as an image service and the JavaScript API IdentifyTask should work to return the pixel value.  We have an application in development that is doing that.
GISP
0 Kudos
SteveCole
Honored Contributor
Good catch, Michael, thanks. Won't help you with MapImageLayers but I guess there is an option under the right circumstances.
0 Kudos
BenFousek
Deactivated User
You should be able to identify a raster simply by publishing it as map service, and identifying with a point. I do it with LiDAR data sets to get spot elevations, and to generate profiles by creating points along a line and using the results with dojox/charting to visualize it.

Identify returns pixel value and stretched value (0-255).
0 Kudos
EulàliaMonfort
Emerging Contributor
You should be able to identify a raster simply by publishing it as map service, and identifying with a point. I do it with LiDAR data sets to get spot elevations, and to generate profiles by creating points along a line and using the results with dojox/charting to visualize it.

Identify returns pixel value and stretched value (0-255).



Thanks btfou.

sorry but It's my first time programming in javascript and I'm a little lost. I published my raster as map service as you said. But I don't know how to identify a raster value using Identify Task. First I define Identifyparams, but then I don't know how to show the raster  value in a infoWindow. any ideas?
0 Kudos
EulàliaMonfort
Emerging Contributor
I wrote the following code, but the response is an "undefined" instead of the pixel value

function mapReady(map){
         dojo.connect(map,"onClick", executeIdentifyTask);
          //create identify tasks and setup parameters 
          identifyTask = new esri.tasks.IdentifyTask("http://.../rest/services/atlantic/Atlantic/MapServer");
       
       identifyParams = new esri.tasks.IdentifyParameters();
          identifyParams.tolerance = 1;
       identifyParams.returnGeometry = true;
       identifyParams.layerIds = [0];
       identifyParams.layerOption = esri.tasks.IdentifyParameters.LAYER_OPTION_TOP;
        }
             
   //fundio executeIdentifyTask
   function executeIdentifyTask(evt) {
          identifyParams.geometry = evt.mapPoint;
          identifyParams.mapExtent = map.extent; 
       
          identifyTask.execute(identifyParams,function(idResults) {
             alert(idResults[0]['pixel value']);
          });
            
         };
0 Kudos
BenFousek
Deactivated User
Are you using firebug or some other development tools to debug in the browser? Using such allows you to view the actual request and the response from the server.

Instead of using alert(), try using console.log(idResults). Then you'll see the response in the console.

Here's the response from an identify of a raster layer:
[ATTACH=CONFIG]29726[/ATTACH]

Notice the raster values are returned in the attributes object just like a vector data identify of query. The reason your alert is undefined is because idResults[0]['pixel value'] is undefined. Try idResults[0].attributes['Pixel Value'].

You'll also notice there is a space in the attribute keys. This is unique in attributes returned from AGS. In a shp or gdb feature class attributes you can't have spaces. Normally you would be able to access a specific attribute like results[0].attributes.parcelId, but this is not possible with the space. results[0].attributes.Pixel Value will return an error so you do need to use results[0].attributes['Pixel Value'].
0 Kudos
JillCress
Emerging Contributor
Hi,

Why is the layerName empty when you do an identify on a raster layer??  The layerId is populated correctly.
0 Kudos
BenFousek
Deactivated User
Why is the layerName empty when you do an identify on a raster layer??  The layerId is populated correctly.


Not 100% sure about this, but...I think it's because AGS is generating and returning a point independent of the raster for the result, unlike an identify on a point layer, which is returning an actual point. displayField is empty because it doesn't exist in a raster. layerName is empty because the point doesn't belong to the dataset so to speak. The layerId is populated simply to identify which layer the return point was generated from. The REST API could probably be enhanced to include layerName, but from my standpoint it's unnecessary.
0 Kudos