Network Analyst : Apply a spatial filter to a Datalayer

761
3
02-27-2012 01:02 AM
CharlesMILLOT1
New Contributor II
hello

I want to improve a closest facility task in a flex web application.

I have a datalayer for my facilities with thousand's of rows.
I want to compute the facilities which are in my current map extent, In order to improve the performance of the task.
Without spatial filter, the task works slow (because of my thousand's of facilities) but works fine.

I try to filter my datalayer with its geometry property but without any result.

"
facilities.geometry=map.extent;
facilities.spatialRelationship="esriSpatialRelWithin";
m_naClosestFacilityParams.facilities=facilities;
"
When I solve my closest facility tasks, I have the error that there is no valid facility whereas I have tens of "localizable" facilities in my map extent.

event.fault.faultDetail = "0 Facilities localisés. Au moins 1 localisés nécessaires.  Nombre insuffisant d???emplacements valides dans "Facilities" ou "Incidents"."

Does anyone know how to apply a spatial filter on a datalayer with its geometry property? Any example?

Thank for your help.

Charles
Tags (2)
0 Kudos
3 Replies
RuiShen
New Contributor III
Basically, I created an application that loads a featurelayer and when mouseclick on the map. The features within the map extent are used as facilities and the mouse click point is used as the incident point.
Below is what included in the mapClickHandler:
private function myMap_mapClickHandler(event:MapMouseEvent):void
   {

    var facilitiesSet:FeatureSet = new FeatureSet([]);
                                var incidents:FeatureSet = new FeatureSet([]);
    var queryTask:QueryTask = new QueryTask();
    queryTask.url = "http://sampleserver3.arcgisonline.com/ArcGIS/rest/services/Network/USA/MapServer/3";
    queryTask.useAMF = false;
    var query:Query = new Query();
    query.outSpatialReference = myMap.spatialReference;
   
    query.returnGeometry = true;
    query.geometry=myMap.extent;
    queryTask.execute(query, new AsyncResponder(onResult, onFault));
   
   
    function onResult(featureSet:FeatureSet, token:Object = null):void
    {
     for each (var myGraphic:Graphic in featureSet.features)
     {
     
      // creating an arraycollection from the graphic attriobutes
      var facility:Graphic=new Graphic();
      facility.geometry=myGraphic.geometry;
      facilitiesSet.features.push(facility);
     }
    
    
    
    
     var incident:Graphic = new Graphic(event.mapPoint);
     incidentsGraphicsLayer.add(incident);
    
     incidents.features.push(incident);
     cfParams.facilities = facilitiesSet;
     cfParams.outSpatialReference = myMap.spatialReference;
                                        cfParams.incidents= incidents;
     cfTask.solve(cfParams);
    }
    function onFault(info:Object, token:Object = null):void
    {
     Alert.show(info.toString());
    }
   
   }

This works for me on my side, let me know if this helps.
Thanks!
0 Kudos
CharlesMILLOT1
New Contributor II
hello,

your solution works but i want to use Datalayer instead of feature set.

I fixed my problem. It was a spatial reference problem.

When I specify a spatialreference (ie wkid=27582 (which is the wkid for the lambert 2 projection frequently used in France)) the rest service doesn't work.
I had just to remove this wkid and now it works.

Thank you for your reply.

Charles
0 Kudos
RuiShen
New Contributor III
Hi Charles,
What do you mean by datalayer? Do you mean a featurelayer you used in your map application?

If that is the case, my code sample should work for you. Basically, it conduct a query on the featurelayer based on your map's current extent and use the result featureset as the facilities parameter for the Closest facilities task.

Rui
0 Kudos