Select to view content in your preferred language

Query not returning all features when using a graphic. Sample doesn't work either.

557
4
05-26-2010 12:34 PM
BrendanLee
Emerging Contributor
The code below works...most of the time. I want the user to draw a polygon, then use the graphic to select all the parcels it intersects. The selected set of parcels will then be buffered.

If a graphic is drawn that covers a large amount of parcels or has several vertices, the query only returns a portion of the parcels covered by the graphic. It's pretty random too in what it misses. I am simplyfing the polygon. The sample for selecting parcels does the same thing if a large area is defined.

I'm trying to build a notification program and there are many times when a large area needs to be defined. Any suggestions??

<?xml version="1.0" encoding="utf-8"?>
<mx:Application
    xmlns:mx="http://www.adobe.com/2006/mxml"
    xmlns:esri="http://www.esri.com/2008/ags"
    styleName="plain"
>

<mx:Script>
 <![CDATA[
  import com.esri.ags.tasks.Query;
  import com.esri.ags.tasks.QueryTask;
  import com.esri.ags.events.QueryEvent;
  import com.esri.ags.events.GeoprocessorEvent;
  import com.esri.ags.events.GeometryServiceEvent;       
  import com.esri.ags.toolbars.Draw;
  import com.esri.ags.toolbars.Navigation;            
  import com.esri.ags.tasks.FeatureSet;
  import com.esri.ags.geometry.Geometry;
  import com.esri.ags.geometry.Polygon;
  import com.esri.ags.geometry.Extent;
  import com.esri.ags.SpatialReference;                     
  import com.esri.ags.Graphic;
  import com.esri.ags.events.DrawEvent;            
  import com.esri.ags.layers.GraphicsLayer;
  import com.esri.ags.tasks.BufferParameters;          
  import mx.rpc.events.FaultEvent;
  import mx.rpc.AsyncResponder;
  import mx.collections.ArrayCollection;
  import mx.controls.Alert;
  import mx.events.ItemClickEvent;
            
 private var graphicParcels:Array;

 private function itemClickHandler(event:ItemClickEvent):void
 {
  tbb.selectedIndex = -1;
  myGraphicsLayer.clear();
  parcelGraphicsLayer.clear();
  
  switch (event.index)
  {                 
   case 0:
   {
    drawToolbar.activate(Draw.POLYGON);
    break;
   }
   case 1:
   {
    drawToolbar.activate(Draw.FREEHAND_POLYGON);
    break;
   }
  }
 }
 
 /* Required with a DrawEnd event.*/
    private function onDrawEnd(event:DrawEvent):void
    {
  var graphic:Graphic = event.graphic;
  drawToolbar.deactivate();

  // Add graphic to the graphics layer
  myGraphicsLayer.add(graphic);
    
  var geometryPolygon:Polygon = graphic.geometry as Polygon;
  myMap.centerAt(geometryPolygon.extent.center);
  
  // Simplify the graphic so selection will work properly
  myGeometryService.simplify([graphic]);                    
 }
    
 private function simplifyCompleteHandler(event:GeometryServiceEvent):void            
 {     
  findParcels(event.graphics[0]); 
 }
 
 private function findParcels(graphic:Graphic):void
 {          
  // clear the graphics layer
  //myGraphicsLayer.clear();
                
  // Create query to select parcels that intersect drawn shape                      
  var parcelQuery : Query = new Query();
  parcelQuery.returnGeometry = true;
  parcelQuery.geometry = graphic.geometry;
  parcelQuery.outFields = ["PARCEL", "STRNO", "STRDIR", "STRNAME", "STRTYPE"];
  parcelQuery.spatialRelationship = Query.SPATIAL_REL_INTERSECTS;
  parcelQuery.outSpatialReference = myMap.spatialReference;
  parcelQueryTask.showBusyCursor = true;                     
  parcelQueryTask.execute(parcelQuery, new AsyncResponder(onParcelResult, onParcelFault));;
 }
  
 private function onParcelResult(featureSet:FeatureSet, token:Object = null) : void
 {   
  if (featureSet.features.length != 0)                    
  {
   myGraphicsLayer.clear();
   // Create an extent rectangle that will cover all the parcels selected
   var unionExtent : Extent;
   var myFirstGraphic : Graphic = featureSet.features[0];
   unionExtent = Polygon(myFirstGraphic.geometry).extent;

   for each (var myGraphic : Graphic in featureSet.features)
   {
                myGraphic.symbol = (parsym);

    // Adds parcel number and address as tool tip
    myGraphic.toolTip = "Parcel: " + myGraphic.attributes.PARCEL.toString()
     + "\nAddress: " + myGraphic.attributes.STRNO + " " 
     + myGraphic.attributes.STRDIR.toString() + " "
     + myGraphic.attributes.STRNAME + " "
     + myGraphic.attributes.STRTYPE;
    
    parcelGraphicsLayer.add(myGraphic);
     
    // Expand map extent to all selected parcels                       
    unionExtent = unionExtent.union(Polygon(myGraphic.geometry).extent );
   }

   // Zoom map out a bit
   //myMap.extent = unionExtent.expand(2); 
   myMap.extent = unionExtent.extent; 
    
   // Pass all selected parcels to array to be used by buffer function
   graphicParcels = ArrayCollection(parcelGraphicsLayer.graphicProvider).toArray();            
  }
  else
  {
   Alert.show("Error selecting parcels");
  } 
 } 
 
 private function onParcelFault( info : Object, token : Object = null ) : void
 {
  Alert.show( info.toString() );
 }

 private function bufferFeature():void
 {
  var bufferParameters:BufferParameters = new BufferParameters();
        bufferParameters.features = graphicParcels;
  bufferParameters.distances = [ 500 ];
  bufferParameters.unionResults = true;
  bufferParameters.unit = BufferParameters.UNIT_FOOT;
  bufferParameters.bufferSpatialReference = new SpatialReference(32007); 

  myGeometryService.addEventListener(GeometryServiceEvent.BUFFER_COMPLETE, bufferCompleteHandler1);
  myGeometryService.buffer(bufferParameters);

  function bufferCompleteHandler1(event:GeometryServiceEvent):void
  {
   for each (var graphic:Graphic in event.graphics)
   {
    graphic.symbol = sfs;
    
    var buffExtent : Extent;
    buffExtent = Polygon(graphic.geometry).extent;
    // Zoom map out a bit
    myMap.extent = buffExtent.expand(2);
    myGraphicsLayer.add(graphic);
   }
            myGeometryService.removeEventListener(GeometryServiceEvent.BUFFER_COMPLETE, bufferCompleteHandler1);
  }
 }
 
 private function onGeomFault(fe:FaultEvent):void            
 {          
  Alert.show("Unexpected fault:\n" + fe.toString());
 }                            
     ]]>
    </mx:Script>
  <!-- Parcel query -->
    <esri:QueryTask id="parcelQueryTask"
        url="http://cohntfs82/ArcGIS/rest/services/public/Parcels/MapServer/0" />
 
  <!-- Geometry Service used to project point for Google Street View -->
    <esri:GeometryService
            id="myGeometryService"
            simplifyComplete="simplifyCompleteHandler(event)"
            fault="onGeomFault(event)"
            showBusyCursor="true"
            url="http://cohntfs82/ArcGIS/rest/services/Tools/Geometry/GeometryServer"/>

 
    <!-- Symbol for Polygon -->
    <esri:SimpleFillSymbol id="sfs" alpha="0.4">
        <esri:SimpleLineSymbol color="#FF0000" width="2" alpha=".6" style="solid"/>
    </esri:SimpleFillSymbol>
    
    <esri:SimpleFillSymbol id="parsym" alpha="0.6" color="#f1f57c">
     <esri:SimpleLineSymbol color="#FF0000" width="2" alpha=".6" style="solid"/>
    </esri:SimpleFillSymbol>

    <esri:Draw id="drawToolbar"
        map="{myMap}"
        fillSymbol="{sfs}"
        drawEnd="onDrawEnd(event)" />
      
    <mx:ControlBar width="100%" horizontalAlign="center">
        <mx:VBox borderStyle="solid" horizontalAlign="center" width="172">
            <mx:ToggleButtonBar id="tbb"
                creationComplete="tbb.selectedIndex = -1"
                itemClick="itemClickHandler(event)"
                toggleOnClick="true">
                <mx:dataProvider>
                    <mx:Object id="p0" label="Polygon"/>
                    <mx:Object id="p1" label="FreeHand"/>
                </mx:dataProvider>
            </mx:ToggleButtonBar>         
        </mx:VBox>          
        <mx:Button label="Buffer" id="buttonBuffer" click="bufferFeature()"/>
    </mx:ControlBar>
    
    <esri:Map id="myMap" logoVisible="false">     
        <esri:ArcGISTiledMapServiceLayer
            url="http://cohntfs82/ArcGIS/rest/services/public/basemap/MapServer" />
        <esri:GraphicsLayer id="myGraphicsLayer"/>
        <esri:GraphicsLayer id="parcelGraphicsLayer"/>
    </esri:Map>
    
</mx:Application>
Tags (2)
0 Kudos
4 Replies
DasaPaddock
Esri Regular Contributor
0 Kudos
BrendanLee
Emerging Contributor
Dasa,

Thanks for the reply. I followed the directions for increasing the max records and set it to 5000. I'm still getting the same results.
0 Kudos
DasaPaddock
Esri Regular Contributor
If you go to your query page, like this one:
http://sampleserver1.arcgisonline.com/ArcGIS/rest/services/Portland/ESRI_LandBase_WebMercator/MapSer...
and in the Where field, enter "1=1" and set Return Geometry to No, do you get more than 500 results? If not, you may need to contact ESRI support at http://support.esri.com
0 Kudos
BrendanLee
Emerging Contributor
Dasa,

I did the query and it still returns only 500. I stopped and restarted the service several times. I also did an iisreset. Still no luck.

Is this a bug or is something not set up correctly on my server?
0 Kudos