Select to view content in your preferred language

Geometryutils, intersecting polygon, and query task error

2407
2
Jump to solution
07-20-2012 02:09 PM
ionarawilson1
Deactivated User
[ATTACH=CONFIG]16294[/ATTACH]

One of the tools in my app is to draw freehand polygons (counties) to show points (companies) in each county. Everything works great but if the user creates an intersecting polygon then I have a problem. To try to fix that I am working with the Geometryutils class to simplify the polygon and I am using this example on this link

http://help.arcgis.com/en/webapi/flex/samples/index.html#/Simplify_geometries/01nq00000063000000/

However the example is creating polygons to show polygons and I need to show points, howevert after I draw the polygon I get an error and the points appear on the map. I am attaching a picture of the print screen.  I have been trying everything to make it work for the past few hours and cant't find a solution.
Could anybody help me with what I need to change in my code? I really appreciate your help!


      // This is an event listener function added on the init function when the drawtool settings are set after the drawtool is created outside the function        import com.esri.ags.utils.GeometryUtil;    public var drawPolygon : Graphic = new Graphic();      private function onDrawEnd(event:DrawEvent):void    {     drawToolbar.deactivate();      myGraphicsLayer.clear();     freehandbutton.selectedIndex = -1;     multipointbutton.selectedIndex = -1;     myMap.panEnabled = false;          var geometry:Geometry = event.graphic.geometry;          if (geometry is Polygon && GeometryUtil.polygonSelfIntersecting(geometry as Polygon))     {      // Note: As of version 2.0, GeometryService returns geometries (instead of graphics).      myGeometryService.simplify([ geometry ]);     }          if (geometry is Polygon && !GeometryUtil.polygonSelfIntersecting(geometry as Polygon))     {                  drawPolygon.geometry = event.graphic.geometry;      drawPolygon.symbol = fillSymbolcounty;      drawPolygon.autoMoveToTop = false; //keep graphics from moving to top         //to not draw a polygon when I use the freehand polygon select tool I uncomment the next line, but right now I have this uncommented and on the zoomtorow function       // I have this  myPolygonGraphicsLayer.remove(drawPolygon) uncommented, so the polygon disappears when we zoom in and does not darken the view (it darkens the view      //if I dont have the drawpolygon.symbol as fillSymbolcounty which is transparent inside      myPolygonGraphicsLayer.add(drawPolygon);       runQueryTask(event.graphic.geometry);      // If using point draw tool then run querytask3     } else{      //Must be multipoint           runQueryTaskcounty(event.graphic.geometry);}              }                                import com.esri.ags.events.GeometryServiceEvent;    import com.esri.ags.geometry.Geometry;        import com.esri.ags.utils.GeometryUtil;        import mx.rpc.events.FaultEvent;        private function myGeometryService_simplifyCompleteHandler(event:GeometryServiceEvent):void    {     // Note: As of version 2.0, GeometryService returns geometries (instead of graphics)          doQuery(event.result[0] as Geometry);    }                    private function doQuery(geom:Geometry):void    {     try     {               queryTaskintersectingpolygon.showBusyCursor = true;      var queryintersectingpolygon:Query = new Query();      queryintersectingpolygon.spatialRelationship = "esriSpatialRelIntersects";      queryintersectingpolygon.returnGeometry = true;    //set to true because we want to place points on the map      queryintersectingpolygon.outSpatialReference = myMap.spatialReference;      queryintersectingpolygon.outFields = ['*'];             queryintersectingpolygon.geometry = geom;      queryintersectingpolygon.returnGeometry = true;      queryTaskintersectingpolygon.execute(queryintersectingpolygon, new AsyncResponder(onResult, onFault));            function onResult(featureSet:FeatureSet, token:Object = null):void      {       if (featureSet.features.length > 0)       {        for each (var myGraphic:Graphic in featureSet.features)        {                  //graphic.symbol = resultsSymbol;         //myGraphicslayerpolygon.add(graphic);            myGraphicsLayerintersectingpolygon.add(myGraphic);        }       }       else       {        Alert.show("No parcels were found", "Try something else");       }      }      function onFault(info:Object, token:Object = null):void      {       Alert.show(info.faultString + "\n\n" + info.faultDetail, "queryTask fault " + info.faultCode);      }     }     catch (error:Error)     {      Alert.show(error.toString(), "myGeometryService_simplifyCompleteHandler error");     }    }        protected function queryTask_faultHandler(event:FaultEvent):void    {     Alert.show(event.fault.faultString + "\n\n" + event.fault.faultDetail, "QueryTask Fault " + event.fault.faultCode);    }     


And this is geometry service and query task

    <esri:GeometryService id="myGeometryService"          simplifyComplete="myGeometryService_simplifyCompleteHandler(event)"          url="http://sampleserver3.arcgisonline.com/ArcGIS/rest/services/Geometry/GeometryServer"/>      <esri:QueryTask id="queryTaskintersectingpolygon"       fault="queryTask_faultHandler(event)"       url="http://tfs-24279/ArcGIS/rest/services/ForestProducts/dynamic_layer_forest_products/MapServer/0"       useAMF="false"/> 


And the graphics layer

<esri:GraphicsLayer id="myGraphicsLayerintersectingpolygon"/>
Tags (2)
0 Kudos
1 Solution

Accepted Solutions
ionarawilson1
Deactivated User
I just realized the problem was not in the query with the simplified polygon but with the else statement  on the onDrawEnd function that it was working before but once I added the if statements geometry is Polygon && GeometryUtil.polygonSelfIntersecting(geometry as Polygon)  and  (geometry is Polygon && !GeometryUtil.polygonSelfIntersecting(geometry as Polygon) I should not have
the else statement, so it should no be:

else  {
    
   
     runQueryTaskcounty(event.graphic.geometry);}
   
   
   }
  

   but

if (geometry is Multipoint){
     //Must be multipoint
   
     runQueryTaskcounty(event.graphic.geometry);}
   
   }

View solution in original post

0 Kudos
2 Replies
ionarawilson1
Deactivated User
Anybody could help me with this? I think it might be something really simple that I am missing but I am really stuck! Thanks!
0 Kudos
ionarawilson1
Deactivated User
I just realized the problem was not in the query with the simplified polygon but with the else statement  on the onDrawEnd function that it was working before but once I added the if statements geometry is Polygon && GeometryUtil.polygonSelfIntersecting(geometry as Polygon)  and  (geometry is Polygon && !GeometryUtil.polygonSelfIntersecting(geometry as Polygon) I should not have
the else statement, so it should no be:

else  {
    
   
     runQueryTaskcounty(event.graphic.geometry);}
   
   
   }
  

   but

if (geometry is Multipoint){
     //Must be multipoint
   
     runQueryTaskcounty(event.graphic.geometry);}
   
   }
0 Kudos