Raster Identify Flex Viewer

2936
7
11-15-2010 05:36 AM
PremRadhakrishnan
New Contributor III
Just what the title says, whats the easiest way to identify a pixel value for a Raster layer in the Flex Viewer. I looked through the REST API and couldnt find anything ....

Cheers
Tags (2)
0 Kudos
7 Replies
MattWilliams
New Contributor
This is exactly what I've been looking for, as well. Seems like using ArcGISImageServiceLayer is close, but I don't see anything about returning a pixel value in the API. I've had slight success using IdentifyTask on a dynamic service, but I'm not sure how to isolate just the pixel value. The identify task wants to return the entire table. And unfortunately, I'm not good enough yet to trying extending/modifying the IdentifyTask Class to any great degree.

To further complicate things, I'd like to click once and return 4 or 5 pixel values from layers of rasters. This, however, is step two. Step one is just getting Flex to return a pixel value from a mouse click.

Is this possible?
0 Kudos
DasaPaddock
Esri Regular Contributor
If you have a version 10 image service, you can use the ImageServiceIdentifyTask.html:
http://help.arcgis.com/en/webapi/flex/apiref/com/esri/ags/tasks/ImageServiceIdentifyTask.html
0 Kudos
MattWilliams
New Contributor
Well, I've tried but just am obviously missing something here. I still don't quite grasp how this is supposed to work. Do you obtain the pixel value by using the "value" property from IdentifyResult? I'm using a Raster Dataset Image Service, by the way, so I can't use the "properties" property which is only usable from a Mosaic Dataset. Anyways... here's my code. A little advice would be greatly appreciated. 🙂

<?xml version="1.0" encoding="utf-8"?>
<s:Application xmlns:fx="http://ns.adobe.com/mxml/2009"
      xmlns:s="library://ns.adobe.com/flex/spark"
      xmlns:esri="http://www.esri.com/2008/ags">
 
 <fx:Script>
  <![CDATA[
   
   import com.esri.ags.events.ImageServiceIdentifyEvent;
   import com.esri.ags.events.MapMouseEvent;
   import com.esri.ags.geometry.Geometry;
   import com.esri.ags.tasks.supportClasses.ImageServiceIdentifyParameters;
   import com.esri.ags.tasks.supportClasses.ImageServiceIdentifyResult;
   
   import mx.controls.Text;
   import mx.rpc.AsyncResponder;
   
   private function onMapClick(event:MapMouseEvent):void
   {
    imgIdentifyTask.url = "http://myservername/ArcGIS/rest/services/test4/ImageServer";
    
    var IDParams:ImageServiceIdentifyParameters = new ImageServiceIdentifyParameters();
    IDParams.geometry = event.mapPoint;
    
    imgIdentifyTask.execute(IDParams);
   }
   
   private function imgExecuteComplete(event:ImageServiceIdentifyEvent):void
   {
    var pixelValue:Label = event.identifyResult.value as Label
    idImageLabel.addChild(pixelValue); 
   }
  ]]>
 </fx:Script>
 
 <fx:Declarations>
    
  <esri:ImageServiceIdentifyTask id="imgIdentifyTask" executeComplete="imgExecuteComplete(event)"/>
  
 </fx:Declarations>
 
 <esri:Map id="myMap" extent="{new Extent(-10955781, 4374995, -8825382, 5549067)}"
     mapClick="onMapClick(event)"
     openHandCursorVisible="false">
  
  <esri:ArcGISTiledMapServiceLayer url="http://server.arcgisonline.com/ArcGIS/rest/services/World_Street_Map/MapServer"/>
  <esri:ArcGISImageServiceLayer url="http://myservername/ArcGIS/rest/services/test4/ImageServer"/>
  
 </esri:Map>
 
 <s:Label id="idImageLabel" text="{}" x="80" y="50" width="150"/>
 
</s:Application>
0 Kudos
DasaPaddock
Esri Regular Contributor
I believe so, but I'm not very familiar with this so your best bet may be to contact Esri Support.

From the REST docs at:
http://help.arcgis.com/en/arcgisserver/10.0/apis/rest/isidentify.html
"The result of this operation includes the pixel value of the mosaic for a given mosaic rule, a resolution (pixel size), and a set of catalog items that overlap the given geometry."
0 Kudos
MattWilliams
New Contributor
If anyone cares and for sake of posterity, I have this working on a rudimentary level. I still need to format the output, but I am getting pixels values. What I had to do is set up a Mosaic Dataset in a geodatabase. In my case I added two rasters that overlay each other. I then set up a Image Service in ArcGIS Server 10 that published the Mosaic Dataset. I used all the defaults, except the option of "Allowed compression methods", I unchecked JPEG. And used the code below.

DISCLAIMER: Don't use this for displaying overlaying rasters. I would stick with publishing individual Raster Datasets.

<?xml version="1.0" encoding="utf-8"?>
<s:Application xmlns:fx="http://ns.adobe.com/mxml/2009"
      xmlns:s="library://ns.adobe.com/flex/spark"
      xmlns:esri="http://www.esri.com/2008/ags" 
      xmlns:mx="library://ns.adobe.com/flex/mx">
 
 <fx:Script>
  <![CDATA[
   
   import com.esri.ags.events.ImageServiceIdentifyEvent;
   import com.esri.ags.events.MapMouseEvent;
   import com.esri.ags.geometry.Geometry;
   import com.esri.ags.tasks.supportClasses.ImageServiceIdentifyParameters;
   import com.esri.ags.tasks.supportClasses.ImageServiceIdentifyResult;
   
   import mx.controls.Label;
   import mx.controls.Text;
   import mx.core.IUIComponent;
   import mx.rpc.AsyncResponder;
      
   private function onMapClick(event:MapMouseEvent):void
   {
    imgIdentifyTask.url = "http://yourservername/ArcGIS/rest/services/FlexDev/lf_mosaic/ImageServer";
       
    var IDParams:ImageServiceIdentifyParameters = new ImageServiceIdentifyParameters();
    IDParams.geometry = event.mapPoint;
    imgIdentifyTask.execute(IDParams);
   
   }
   
   private function imgExecuteComplete(event:ImageServiceIdentifyEvent):void
   {
    var pixelValue:Array = event.identifyResult.properties.Values as Array;
    idImageLabel.text = pixelValue.toString();
   }
  ]]>
 </fx:Script>
 
 <fx:Declarations>
    
  <esri:ImageServiceIdentifyTask id="imgIdentifyTask" executeComplete="imgExecuteComplete(event)"/>
  
 </fx:Declarations>
 
 <esri:Map id="myMap" extent="{new Extent(-10955781, 4374995, -8825382, 5549067)}"
     openHandCursorVisible="false" mapClick="onMapClick(event)"> 
  
  <esri:ArcGISTiledMapServiceLayer url="http://server.arcgisonline.com/ArcGIS/rest/services/World_Street_Map/MapServer"/>
  
  <esri:ArcGISImageServiceLayer url="http://yourservername/ArcGIS/rest/services/FlexDev/lf_mosaic/ImageServer"/>
  
 </esri:Map>
 
 <s:HGroup  x="80" y="50" width="150" color="#245EEE">
 <s:Label id="idImageLabel" text="PIXEL VALUES FROM CLICK" fontWeight="bold" fontSize="24" color="#000000"/>
 </s:HGroup>
</s:Application>
0 Kudos
PremRadhakrishnan
New Contributor III
Cool Will have to wait till we switch over to 10 to test it out. Thanks
0 Kudos
haThach
New Contributor III
If anyone cares and for sake of posterity, I have this working on a rudimentary level. I still need to format the output, but I am getting pixels values. What I had to do is set up a Mosaic Dataset in a geodatabase. In my case I added two rasters that overlay each other. I then set up a Image Service in ArcGIS Server 10 that published the Mosaic Dataset. I used all the defaults, except the option of "Allowed compression methods", I unchecked JPEG. And used the code below.

DISCLAIMER: Don't use this for displaying overlaying rasters. I would stick with publishing individual Raster Datasets.

<?xml version="1.0" encoding="utf-8"?>
<s:Application xmlns:fx="http://ns.adobe.com/mxml/2009"
      xmlns:s="library://ns.adobe.com/flex/spark"
      xmlns:esri="http://www.esri.com/2008/ags" 
      xmlns:mx="library://ns.adobe.com/flex/mx">
 
 <fx:Script>
  <![CDATA[
   
   import com.esri.ags.events.ImageServiceIdentifyEvent;
   import com.esri.ags.events.MapMouseEvent;
   import com.esri.ags.geometry.Geometry;
   import com.esri.ags.tasks.supportClasses.ImageServiceIdentifyParameters;
   import com.esri.ags.tasks.supportClasses.ImageServiceIdentifyResult;
   
   import mx.controls.Label;
   import mx.controls.Text;
   import mx.core.IUIComponent;
   import mx.rpc.AsyncResponder;
      
   private function onMapClick(event:MapMouseEvent):void
   {
    imgIdentifyTask.url = "http://yourservername/ArcGIS/rest/services/FlexDev/lf_mosaic/ImageServer";
       
    var IDParams:ImageServiceIdentifyParameters = new ImageServiceIdentifyParameters();
    IDParams.geometry = event.mapPoint;
    imgIdentifyTask.execute(IDParams);
   
   }
   
   private function imgExecuteComplete(event:ImageServiceIdentifyEvent):void
   {
    var pixelValue:Array = event.identifyResult.properties.Values as Array;
    idImageLabel.text = pixelValue.toString();
   }
  ]]>
 </fx:Script>
 
 <fx:Declarations>
    
  <esri:ImageServiceIdentifyTask id="imgIdentifyTask" executeComplete="imgExecuteComplete(event)"/>
  
 </fx:Declarations>
 
 <esri:Map id="myMap" extent="{new Extent(-10955781, 4374995, -8825382, 5549067)}"
     openHandCursorVisible="false" mapClick="onMapClick(event)"> 
  
  <esri:ArcGISTiledMapServiceLayer url="http://server.arcgisonline.com/ArcGIS/rest/services/World_Street_Map/MapServer"/>
  
  <esri:ArcGISImageServiceLayer url="http://yourservername/ArcGIS/rest/services/FlexDev/lf_mosaic/ImageServer"/>
  
 </esri:Map>
 
 <s:HGroup  x="80" y="50" width="150" color="#245EEE">
 <s:Label id="idImageLabel" text="PIXEL VALUES FROM CLICK" fontWeight="bold" fontSize="24" color="#000000"/>
 </s:HGroup>
</s:Application>



Hi all,
Can somebody point me to the right direction of how to use the above code in Flexviewer 2.2.
Thanks.
0 Kudos