Select to view content in your preferred language

Determine if there are no features returned from a spatial relationship

610
6
01-18-2011 10:28 AM
MaryCreel
Deactivated User
I need to return the results of buffering several layers, (11 layers possible), around a point (an address). I am looping through the selected layers and executing the query tasks
utilizing the QueryEvent.EXECUTE_COMPLETE to determine when to start the next task. Everything works until
one of the layers does not have any features in the buffer area.
Is there any way to get that info...no features found?

onRelation is not called if there are no features found and I can not get to the next layer in the loop.

baseDisplay.myGeometryServiceWW.addEventListener(GeometryServiceEvent.RELATION_COMPLETE, onRelation);
baseDisplay.myGeometryServiceWW.relation(layerArrayWW, bufferLayerArray, GeometryService.SPATIAL_REL_WITHIN, null);

Here is part of the code. (2 of the 11 layers)
 
private function getBufferResultForFacLayer(layerID:int):void
{ // Start to find the locations/features that are located within the buffer.

[INDENT]bufferLayerArray = new Array();
[/INDENT]

[INDENT]setZoom();  
[/INDENT]

[INDENT]//reduce the candidates that can be within the buffer area
[/INDENT]
[INDENT]createLayerQuery(layerID); // create the query and set the outfields for the current layer to be checked
baseDisplay.queryTask.addEventListener(QueryEvent.EXECUTE_COMPLETE, fxnListener);
baseDisplay.queryTask.execute(baseDisplay.queryLayer, new AsyncResponder(onResult, onFault));
layersAdded++;
 
[/INDENT]
[INDENT]function fxnListener(event:QueryEvent):void
[/INDENT]
[INDENT]{ 
[/INDENT][INDENT]
[INDENT]bufferLayerArray.push(baseDisplay.bufferLayer.getChildAt(0) as Graphic); // layer contains the point at the center of the buffer area
[/INDENT]
[INDENT]switch (layerID)
{ 

[INDENT]case 0:
[/INDENT]
[INDENT]
[INDENT]baseDisplay.rhtVBox.lblWW.text = "CAO: 0 location(s) found"; // if no features of layer are found in buffer, onRelation is not called
[/INDENT]
[INDENT]layerArrayCAO = new Array();
for each (var gr0:Graphic in event.featureSet.features)

[INDENT]layerArrayCAO.push(gr0); 
[/INDENT]
 
baseDisplay.queryTask.removeEventListener(QueryEvent.EXECUTE_COMPLETE, fxnListener);
baseDisplay.myGeometryServiceCAO.addEventListener(GeometryServiceEvent.RELATION_COMPLETE, onRelation); 
baseDisplay.myGeometryServiceCAO.relation(layerArrayCAO, bufferLayerArray, GeometryService.SPATIAL_REL_WITHIN, null); 
break;
[/INDENT]case 1: 

[INDENT]baseDisplay.rhtVBox.lblWW.text = "WW: 0 location(s) found";
[/INDENT]
[INDENT]layerArrayWW = new Array();
 
for each (var gr1:Graphic in event.featureSet.features)

[INDENT]layerArrayWW.push(gr1); 
[/INDENT]
 
baseDisplay.queryTask.removeEventListener(QueryEvent.EXECUTE_COMPLETE, fxnListener);
baseDisplay.myGeometryServiceWW.addEventListener(GeometryServiceEvent.RELATION_COMPLETE, onRelation);
baseDisplay.myGeometryServiceWW.relation(layerArrayWW, bufferLayerArray, GeometryService.SPATIAL_REL_WITHIN, null); 
break;
[/INDENT]}
[/INDENT][/INDENT]}
[/INDENT]
[INDENT]function onResult(featureSet:FeatureSet, token:Object = null):void
[/INDENT]
[INDENT]{ 
}
 
[/INDENT]
[INDENT]function OnRelation(event:GeometryServiceEvent):void
[/INDENT]
[INDENT]{
[INDENT]// problem: if there are no locations found in the buffer, this function is not reached
[/INDENT]
[INDENT]var facObject:Object; 
var obj:Object;
var graphic:Graphic;
[/INDENT][INDENT]if (baseDisplay.provBufferLayer == null)

[INDENT][INDENT]baseDisplay.provBufferLayer = new GraphicsLayer();
[/INDENT][/INDENT]
[INDENT][/INDENT][/INDENT]
[INDENT]switch (layerID)
[/INDENT]
[INDENT]{ // each layer different outfields

[INDENT]case 0:
[/INDENT]
[INDENT]
[INDENT]baseDisplay.myGeometryServiceCAO.removeEventListener(GeometryServiceEvent.RELATION_COMPLETE, onRelation);
[/INDENT]
[/INDENT][INDENT][INDENT]baseDisplay.rhtVBox.lblCAO.text = "CAO: " + event.relations.length + " location(s) found"; 
 
for each (obj in event.relations)
{
[INDENT]graphic = new Graphic();
graphic = obj.graphic1; 
facObject = new Object(); 
facObject = {column1: ": ", column2: ": " , column3:??????, column4:"" };
bufferResults.addItem(facObject);
[/INDENT]} 
break;
case 1:
[INDENT]
[INDENT]baseDisplay.myGeometryServiceCAO.removeEventListener(GeometryServiceEvent.RELATION_COMPLETE, onRelation);
[/INDENT]
[/INDENT][INDENT]baseDisplay.rhtVBox.lblCAO.text = "CAO: " + event.relations.length + " location(s) found"; 
 
for each (obj in event.relations)
{
[INDENT]graphic = new Graphic();
graphic = obj.graphic1; 
facObject = new Object(); 
facObject = {column1: ": ", column2: ": " , column3:??????, column4:"" };
bufferResults.addItem(facObject);
[/INDENT]} 
break; 
[/INDENT]
[/INDENT][/INDENT][/INDENT][/INDENT]}}}
Tags (2)
0 Kudos
6 Replies
DasaPaddock
Esri Regular Contributor
Are you using ArcGIS Server 10 and leaving useAMF set to true on the QueryTask? If yes and you haven't upgraded to 10 SP 1, you may be running into a server bug where invalid AMF is returned when no features are found. In this case it should be calling your fault function. If this is the case, you can set useAMF to false on the QueryTask or upgrade to 10 SP 1.
0 Kudos
MaryCreel
Deactivated User
Thanks for the quick repsonse.  We are currently running  9.3.1.  I do not know if upgrading to 10 will happen soon.  The person who handles that is not here today.
0 Kudos
DasaPaddock
Esri Regular Contributor
You may want to check if the event.featureSet has any features in fxnListener() before calling the relation() function.
0 Kudos
MaryCreel
Deactivated User
Tried using that but the featureSet that is available in fxnListener contains the features that are in the current extent.  There may or may not be any features there.

A side question:  When running ArcGIS Server 10 do we need to upgrade to Flex4?
0 Kudos
DasaPaddock
Esri Regular Contributor
Is this what you tried?

if (layerArrayCAO.length > 0)
{
    baseDisplay.myGeometryServiceCAO.addEventListener(GeometryServiceEvent.RELATION_COMPLETE, onRelation); 
    baseDisplay.myGeometryServiceCAO.relation(layerArrayCAO, bufferLayerArray, GeometryService.SPATIAL_REL_WITHIN, null); 
}


You may also want to listen for faults on the GeometryService and/or use a tool like HttpFox to monitor the HTTP requests and responses to see if any errors are being returned from the server.

You can still use ArcGIS API for Flex 1.x with ArcGIS Server 10 since its REST services are backwards compatible. If you upgrade to ArcGIS API for Flex 2.x, then you'll need to upgrade to Flex SDK 4.x.
0 Kudos
MaryCreel
Deactivated User
Thanks Dasa.  I think I may have it working.  I still need to do more testing.  Thanks again.
0 Kudos