Outputting Features in Flex from geoprocess

671
6
11-22-2010 10:01 AM
BryanGunter
New Contributor
Been trying to output features from a geoprocess i am running in flex.  I am new to the flex api so i have been following examples but i seem to be having trouble with the output.  The model i am using works fine in arcgis 10 but i seem to have trouble getting the output from the model to display on the screen. 

This is part of the code i am using:

private function georesult(featureSet:FeatureSet):void
   {
   
    this.cursorManager.setBusyCursor();
   
    if (featureSet.features.length < 2)
    {
     Alert.show("Input not valid")
     return;
    }
   
   
    var sfs_default:SimpleFillSymbol = new SimpleFillSymbol(SimpleFillSymbol.STYLE_SOLID, 0x0000FF, 1.4);
    var N:Number;
    N= 0;
   
   

    for each(var graphic:Graphic in featureSet.features)
    {
    
     N=N+1;
    
    }
   
   
    Alert.show("The number of features input = "+myNumberFormatter.format(N));
   
    var outSR:SpatialReference = new SpatialReference(2254);
    var processSR:SpatialReference = new SpatialReference(2254);
    var params:Object = new Object();
    params.Input = featureSet;
    gp.outSpatialReference = outSR;
    gp.processSpatialReference= processSR;
   
    gp.url = "http://chlorite.ge.olemiss.edu/ArcGIS/rest/services/AGSParkingTools/GPServer/Handicap%20Selection%20...";

    gp.submitJob( params) ;
    gp.addEventListener(GeoprocessorEvent.JOB_COMPLETE, executeCompleteHandler);
    gp.addEventListener(FaultEvent.FAULT, faultHandler);
  

   
       
   
   }
   private function executeCompleteHandler(event:GeoprocessorEvent):void          
   {              
   gp.addEventListener(GeoprocessorEvent.GET_RESULT_DATA_COMPLETE, onGetResult);
    gp.getResultData(event.jobInfo.jobId, "Handicap_Selection");


}          
  
   private function onGetResult(event:GeoprocessorEvent):void
   {
    var pv:ParameterValue = event.parameterValue;
    //Alert.show(pv.value.toString());
   
    var fs:FeatureSet = pv.value as FeatureSet;
    if (fs != null)
    {
     var N:Number;
     N=0;
     var myGraphicsLayer:GraphicsLayer = new GraphicsLayer();
     var sfs_default:SimpleFillSymbol = new SimpleFillSymbol(SimpleFillSymbol.STYLE_SOLID, 0x0000FF, 1.4);
    
     for each(var graphic:Graphic in fs.features)
     {
      graphic.symbol = sfs_default;
      myGraphicsLayer.add(graphic);
      myGraphicsLayer.visible=true;
      //map.addLayer(myGraphicsLayer);
      N=N+1;
     }
     Alert.show("The number of features output = "+myNumberFormatter.format(N));
    }
    else
    {
     Alert.show("nothing to return");
    }
    this.cursorManager.removeBusyCursor();
   }

   private function faultHandler(f:FaultEvent):void         
   {              
    this.cursorManager.removeBusyCursor();              
    if (f.type == "fault" && f.fault.name == 'Error' && f.fault.faultCode == '500' && f.fault.faultString == 'Error Executing Task')         
    {                  
     Alert.show("Oops - no results.  Try clicking in an ocean...");            
    }              
    else               
    {                   
     Alert.show("Unexpected fault:\n" + f.toString());            
    }          
   }


at first i thought that perhaps the input was not being sent correctly so i added the alerts and counter to track my inputs and outputs.  Any help would be appreciated. i have included the url to the geoprocess in case anyone can  identify the problem.

Thanks for any help at all,
Bryan
Tags (2)
0 Kudos
6 Replies
DasaPaddock
Esri Regular Contributor
This code looks OK. Is it getting to this line?
    Alert.show("The number of features output = "+myNumberFormatter.format(N));

If you set a break point on this line, does the graphic have non-null geometry?
    graphic.symbol = sfs_default;
0 Kudos
BryanGunter
New Contributor
This code looks OK. Is it getting to this line?
    Alert.show("The number of features output = "+myNumberFormatter.format(N));

If you set a break point on this line, does the graphic have non-null geometry?
    graphic.symbol = sfs_default;


I really appreciate you pointing that out, i was wondering how to look at the properties to see if the values werent null etc. 

So the features may be null but they dont look completely null to me.  Here is what i mean:

I ran with a breakline in at that point and looked at the variable gemometry. 

while the extent is flagged as null the correct type along with x,y locations are given back as output.

An example:

geometry com.esri.ags.geometry.MapPoint (@fc689c1)
[inherited]
defaultSymbol com.esri.ags.symbols.SimpleMarkerSymbol (@cc69ad9)
extent null
type "esriGeometryPoint"
x 772572.2031795047
y 1770431.6414705142


I see the extent is null but those are valid x,y coordinates

i suppose i could just convert those x, y coordinates to map coordinates if all else fails?

Thanks a lot
0 Kudos
DasaPaddock
Esri Regular Contributor
It's normal for extent to be null on a MapPoint.

Are those x/y values valid for SR 2254? Is the Map in SR 2254?
0 Kudos
BryanGunter
New Contributor
SR 2254 is:

PROJCS["NAD_1983_StatePlane_Mississippi_East_FIPS_2301_Feet",GEOGCS["GCS_North_American_1983",DATUM["D_North_American_1983",SPHEROID["GRS_1980",6378137.0,298.257222101]],PRIMEM["Greenwich",0.0],UNIT["Degree",0.0174532925199433]],PROJECTION["Transverse_Mercator"],PARAMETER["False_Easting",984250.0],PARAMETER["False_Northing",0.0],PARAMETER["Central_Meridian",-88.83333333333333],PARAMETER["Scale_Factor",0.99995],PARAMETER["Latitude_Of_Origin",29.5],UNIT["Foot_US",0.3048006096012192]]

The data i am using is defined as:
PROJCS["NAD_1983_StatePlane_Mississippi_East_FIPS_2301",GEOGCS["GCS_North_American_1983",DATUM["D_North_American_1983",SPHEROID["GRS_1980",6378137.0,298.257222101]],PRIMEM["Greenwich",0.0],UNIT["Degree",0.0174532925199433]],PROJECTION["Transverse_Mercator"],PARAMETER["False_Easting",984250.0],PARAMETER["False_Northing",0.0],PARAMETER["Central_Meridian",-88.83333333333333],PARAMETER["Scale_Factor",0.99995],PARAMETER["Latitude_Of_Origin",29.5],UNIT["Foot_US",0.3048006096012192]]


However after looking at your response and testing the xy extents of my map i am thinking that the SR might be in conflict? i am using the default WKID:102100 esri basemaps as well at the moment in the flex viewer.  Does the viewer automatically adjust for different systems  ( i am guessing no) or do i need to convert my data to another SR?
0 Kudos
DasaPaddock
Esri Regular Contributor
The Viewer doesn't auto-adjust. Try setting gp.outSpatialReference to the map's spatialReference. In the widget code, you could just use:
gp.outSpatialReference = map.spatialReference;
0 Kudos
BryanGunter
New Contributor
Thank you very much for helping me Dasa.  The line of code you mentioned fixed the problem.

Tyvm,
Bryan
0 Kudos