Select to view content in your preferred language

GP Service problem

828
3
06-24-2011 09:24 PM
NadirHussain
Frequent Contributor
Dear All thanks in advance.
i am using buffer and clip Geoporcesing service.i have check this service works fine in arcmap.and i publish this service in arcgis server.here the service creats and runs.The problem is that i have no idea how to check this service is creating output or not.from flex client i try to get the result.but it is throwing error #1009.here it is my code.

<esri:Map id="myMap" width="100%" height="100%" logoVisible="false"  openHandCursorVisible="false"  mapClick="onMapClick(event)">
<esri:extent>
   <esri:Extent xmin="30" ymin="10" xmax="60" ymax="35"/>
</esri:extent>
<esri:ArcGISDynamicMapServiceLayer visible="true" url="http://home/ArcGIS/rest/services/myGPService/MapServer/"/>
<esri:GraphicsLayer id="graphicsLayer"/>
</esri:Map>
<esri:Geoprocessor id="gp" concurrency="last" executeComplete="onGPExecuteComplete(event)" fault="onGpError(event)"   outSpatialReference="{myMap.spatialReference}"  showBusyCursor="true"
url="http://home/ArcGIS/services/myGPService/GPServer" />

private function onGpError(event:FaultEvent):void
    {
     try
     {
      Alert.show("There was a problem","Error");
      Alert.show(event.message.toString());      
     }
     catch(errObj:Error)
     {Alert.show(errObj.message.toString());}
    }
private function onGPExecuteComplete(event:GeoprocessorEvent):void
{
  try
     {
      gpPending = false;
      Alert.show("In GP Execute")
      Alert.show(event.executeResult.results.length.toString());
     }
      catch(errObj:Error)
     {Alert.show(errObj.message.toString());}
  }
   
private function onMapClick(event:MapMouseEvent):void
{
  try
    {
     graphicsLayer.clear();
    var mapPoint:MapPoint = event.mapPoint;
    var graphic:Graphic = new Graphic(mapPoint);
    var featureSet:FeatureSet = new FeatureSet();
    featureSet.features = [ { geometry: mapPoint } ];
    var params:Object = new Object();
    params.Input_Features= featureSet;
    params.Distance = 100;
    //var params:Object = {"Input_Features": featureSet,"Distance": 300};
    gp.execute(params);
    gpPending = true;
    Alert.show("map click");
   }
   catch(errObj:Error)
   {Alert.show(errObj.message.toString());}
}
I am stuck here from last three days.
thanks one again.waiting for reply.
Thanks
Tags (2)
0 Kudos
3 Replies
KomanDiabate
Deactivated User
Hi Nader,
If you are just trying to click on map and buffer, it will be much easier to look into Geometry Services. There is a simple example on the Flex Sample on ESRI web page.
However if you are doing some complex processes, you will need to either code it in flex or stick to GP.
Hope this help.
<?xml version="1.0" encoding="utf-8"?>
<s:Application xmlns:fx="http://ns.adobe.com/mxml/2009"
               xmlns:s="library://ns.adobe.com/flex/spark"
               xmlns:esri="http://www.esri.com/2008/ags"
               pageTitle="Buffer using the Geometry Service">
    <!--
         This sample creates buffers around the center of the map. This example just draws the buffers,
         but the buffers could also be used to perform a task such as returning a list of addresses of
         people who live within the buffered area.
    -->

    <s:controlBarLayout>
        <s:HorizontalLayout horizontalAlign="center"
                            paddingBottom="7"
                            paddingTop="7"/>
    </s:controlBarLayout>
    <s:controlBarContent>
        <s:Button click="bufferCenterOfMap()" label="Buffer Center Of Map"/>
    </s:controlBarContent>

    <fx:Declarations>
        <esri:SimpleFillSymbol id="sfs" color="0xFF0000">
            <esri:SimpleLineSymbol color="0x000000"/>
        </esri:SimpleFillSymbol>
        <esri:GeometryService id="myGeometryService" url="http://sampleserver3.arcgisonline.com/ArcGIS/rest/services/Geometry/GeometryServer"/>
    </fx:Declarations>

    <fx:Script>
        <![CDATA[
            import com.esri.ags.Graphic;
            import com.esri.ags.SpatialReference;
            import com.esri.ags.events.GeometryServiceEvent;
            import com.esri.ags.geometry.MapPoint;
            import com.esri.ags.geometry.Polygon;
            import com.esri.ags.tasks.supportClasses.BufferParameters;

            private function bufferCenterOfMap():void
            {
                var myMapCenterPoint:MapPoint = MapPoint(myMap.extent.center);

                var bufferParameters:BufferParameters = new BufferParameters();
                // Note: As of version 2.0, the GeometryService input is geometries (instead of graphics).
                bufferParameters.geometries = [ myMapCenterPoint ];
                bufferParameters.distances = [ 50, 100 ];
                // Note: As of version 2.0, the buffer constants have been moved to GeometryService.
                bufferParameters.unit = GeometryService.UNIT_KILOMETER;
                bufferParameters.bufferSpatialReference = new SpatialReference(4326);
                bufferParameters.outSpatialReference = myMap.spatialReference;

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

                function bufferCompleteHandler(event:GeometryServiceEvent):void
                {
                    myGeometryService.removeEventListener(GeometryServiceEvent.BUFFER_COMPLETE, bufferCompleteHandler);
                    // Note: As of version 2.0, GeometryService returns geometries (instead of graphics)
                    for each (var geometry:Polygon in event.result)
                    {
                        var graphic:Graphic = new Graphic();
                        graphic.geometry = geometry;
                        graphic.symbol = sfs;
                        graphicsLayer.add(graphic);
                    }
                }
            }
        ]]>
    </fx:Script>

    <esri:Map id="myMap"
              crosshairVisible="true"
              level="3">
        <esri:ArcGISTiledMapServiceLayer url="http://server.arcgisonline.com/ArcGIS/rest/services/World_Topo_Map/MapServer"/>
        <esri:GraphicsLayer id="graphicsLayer"/>
    </esri:Map>

</s:Application>
0 Kudos
KomanDiabate
Deactivated User
Hi Nader,
If you are just trying to click on map and buffer, it will be much easier to look into Geometry Services. There is a simple example on the Flex Sample on ESRI web page.
However if you are doing some complex processes, you will need to either code it in flex or stick to GP.
Hope this help.

<!-- Flex 1.3 Code -->

<?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"
    layout="absolute" 
    pageTitle="Buffer using the Geometry Service"
    >
    <mx:Script>
        <![CDATA[
            import com.esri.ags.SpatialReference;
            import com.esri.ags.events.GeometryServiceEvent;
            import com.esri.ags.tasks.BufferParameters;
            import com.esri.ags.Graphic;
            import com.esri.ags.geometry.MapPoint;
            import com.esri.ags.events.PanEvent;
            
     
            //mousedown event
            private function mouseClickHandler(event:MouseEvent):void            
            {                
             if (!event.shiftKey)                
              {                    
              myMap.addEventListener(MouseEvent.MOUSE_DOWN, mouseDownHandler);                
              }            
            }
            
            private function mouseDownHandler(event:MouseEvent):void
            {
                myMap.removeEventListener(MouseEvent.MOUSE_UP, mouseDownHandler);
                var myMapCenterPoint:Graphic = new Graphic();
                myMapCenterPoint.geometry = myMap.toMapFromStage(event.stageX, event.stageY);

                var bufferParameters : BufferParameters = new BufferParameters();
                bufferParameters.features = [myMapCenterPoint];
                bufferParameters.distances = [100,200,600];
                bufferParameters.unit = BufferParameters.UNIT_FOOT
                bufferParameters.bufferSpatialReference = new SpatialReference(2230);
                
                myGeometryService.addEventListener(GeometryServiceEvent.BUFFER_COMPLETE, bufferCompleteHandler);
                myGeometryService.buffer( bufferParameters );

                function bufferCompleteHandler( event : GeometryServiceEvent ) : void
                {
                    myGeometryService.removeEventListener(GeometryServiceEvent.BUFFER_COMPLETE, bufferCompleteHandler);
                    for each ( var graphic : Graphic in event.graphics )
                    {
                        graphic.symbol = sfs;
                        myGraphicsLayer.add( graphic );
                    }
                }
            }
            public function deactivate():void
            {
             myMap.removeEventListener(MouseEvent.MOUSE_DOWN, mouseDownHandler);
            }
        ]]>
    </mx:Script>
    <esri:SimpleFillSymbol id="sfs" color="0xFF0000">
        <esri:SimpleLineSymbol color="0x000000"/>
    </esri:SimpleFillSymbol>
    <esri:GeometryService id="myGeometryService"
        url="http://sampleserver2.arcgisonline.com/ArcGIS/rest/services/Geometry/GeometryServer"/>
    <mx:Panel width="100%" height="100%">
        <mx:ControlBar>
            <mx:Button label="Buffer Center Of Map"  mouseUp="mouseClickHandler(event)" id="btnBuffer" toolTip="Draw a Polygon"/>
            <mx:Button label="Deactivate" width="103" id="btnDeactivate" click="deactivate()"/>
        </mx:ControlBar>
        <esri:Map id="myMap" >
            <esri:ArcGISDynamicMapServiceLayer
                url="http://.../ArcGIS/rest/services/....../MapServer"/>
            <esri:GraphicsLayer id="myGraphicsLayer"/>
        </esri:Map>
    </mx:Panel>
</mx:Application>

0 Kudos
NadirHussain
Frequent Contributor
thanks @kdiabate64
I have solved my issue with help of geometry service and spatial Query.but i am still wonder why it is not worked the geoprocessing service.Thanks Again
0 Kudos