[GIS] Geometryutil, simplify polygon, querytask and query fault error

arcgis-flex-apipointpolygonquerysimplify

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 Geometryutil class to simplify the polygon and I am using this example on this link

http://help.arcgis.com/en/webapi/fle…0000063000000/

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. The error says RPC Fault Faultstring="Unable to complete query operation" faultCode="400" faultDetail="Unable to perform query operation. 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!
Here is the code snippet

// 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);
        }

Best Answer

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);}

}

Related Question