Select to view content in your preferred language

Near Query Question

1225
1
11-26-2012 04:57 AM
by Anonymous User
Not applicable
I would like to enhance a flood zone widget to find the distance to the nearest flood zone.  It would be a single polygon to polygon near query(buffer ???).  That would return the distance in feet from a parcel of property to nearest 100 year flood zone.  The result would be like:  This parcel is 2,314 feet from the nearest flood zone.

Can anyone get me started - as to something in the api I could use to query this near distance?
If all else fails, I was thinking of mutiple buffer queries at incrementing distances until it found a hit.
But, this seems too taxing to do so many queries.  Maybe there is a sample some where.  thanks
Tags (2)
0 Kudos
1 Reply
by Anonymous User
Not applicable
Well, I went with buffering.  See code below.  But, I used the PROGRAMATIC_LAYER_VISIBILITY_CHANGED event to turn on the flood zone layer in the TOC and I don't see how to listen for when this layer has actually been drawn.  Any help with this?  thanks

problem line:  ViewerContainer.addEventListener(AppEvent.LAYER_LOADED, layerloadComplete);


My show flood function:
   private function showFlood(event:MouseEvent):void
   {
    msg = "Loading Flood Zone layer . . . ";
    PopUpManager.addPopUp(tWindow2, hostComponent.map, true);
    PopUpManager.centerPopUp(tWindow2);
    event.stopImmediatePropagation();   

    ViewerContainer.addEventListener(AppEvent.LAYER_LOADED, layerloadComplete);     
    ViewerContainer.dispatchEvent(new AppEvent(AppEvent.PROGRAMATIC_LAYER_VISIBILITY_CHANGED, "Flood Zones"));  
    var resultEvent:Polygon = new Polygon;
    geomArr = [];
    var graphic:Graphic = hostComponent.graphic;
    geomArr.push(graphic.geometry);
    var bufferParameters:BufferParameters = new BufferParameters();
    bufferParameters.bufferSpatialReference= new SpatialReference(102003);
    bufferParameters.geometries = geomArr;
    bufferParameters.unit = GeometryService.UNIT_FOOT;
    bufferParameters.distances = [ 1 ];
    
    function layerloadComplete(event:AppEvent):void
    {
     ViewerContainer.removeEventListener(AppEvent.LAYER_LOADED, layerloadComplete);
     msg = "Searching for nearest Flood Zone . . . ";
     beginBuffer();
    }    
    
    function beginBuffer():void
    {        
     myGeometryService.addEventListener(GeometryServiceEvent.BUFFER_COMPLETE, bufferCompleteHandler);
     myGeometryService.buffer(bufferParameters);         
    }
    function bufferCompleteHandler(event:GeometryServiceEvent):void
    {    
     myGeometryService.removeEventListener(GeometryServiceEvent.BUFFER_COMPLETE, bufferCompleteHandler);
     resultEvent = event.result[0];
     try
     {
      var graphic:Graphic = new Graphic();
      graphic.geometry = resultEvent;
      queryFeaturesGraphical(graphic.geometry);
     }
     catch (error:Error)
     {
      Alert.show(error.message);
     }
    }    
    function queryFeaturesGraphical(geom:Geometry):void
    {
     var queryParams:Query = new Query();
     queryParams.returnGeometry = false;
     var queryFields:String = "*";
     queryParams.outFields = queryFields.split(",");      
     queryParams.geometry = geom;
     
     queryParams.where = "FLD_ZONE IN ('A','AE')";
     queryParams.spatialRelationship = "esriSpatialRelIntersects";
     var url:String = "http://[myserver]/ArcGIS/rest/services/Feature_Natural/MapServer/8";
     var queryTask:QueryTask = new QueryTask(url);  
     queryTask.execute(queryParams, new AsyncResponder(onResult, onFault)); 
    }    
    function onResult(featureSet:FeatureSet, token:XMLList = null):void
    {    
     try
     {
      if (featureSet.features.length < 1)
      {       
       if (bufferParameters.distances[0].toString() == "5280")
       {
        msg = "The nearest Flood Zone is more than a mile away.";
       }         
       if (bufferParameters.distances[0].toString() == "2640")
       {
        msg = "The nearest Flood Zone is more than a half mile away.";
        bufferParameters.distances = [ 5280 ];
        beginBuffer();
       }  
       if (bufferParameters.distances[0].toString() == "1000")
       {
        msg = "The nearest Flood Zone is more than 1000 feet away.";
        bufferParameters.distances = [ 2640 ];
        beginBuffer();
       } 
       if (bufferParameters.distances[0].toString() == "500")
       {
        msg = "The nearest Flood Zone is more than 500 feet away.";
        bufferParameters.distances = [ 1000 ];
        beginBuffer();
       }
       if (bufferParameters.distances[0].toString() == "200")
       {
        msg = "The nearest Flood Zone is more than 200 feet away.";
        bufferParameters.distances = [ 500 ];
        beginBuffer();
       }       
       if (bufferParameters.distances[0].toString() == "1")
       {
        msg = "This property is touching or inside a Flood Zone.";
        bufferParameters.distances = [ 200 ];
        beginBuffer();
       }   
      }
      else
      {
       for each(var obj:Object in featureSet.attributes){
        Alert.show("done");
        break;
       }            
      }
     }
     catch (error:Error)
     {
      Alert.show(error.message);
     }
    }   
    function onFault(info:Object, token:Object = null):void
    {
     Alert.show(info.toString());
    }        
   }
0 Kudos