Select to view content in your preferred language

GP SDK EXAMPLE - ENHANCEMENT

3273
12
12-02-2010 06:44 AM
ChristineZeller
Occasional Contributor
Good Morning,

I am working through getting a Geoprocess Task up and running.  Currently, I am working with SDK example: http://help.arcgis.com/en/webapi/silverlight/samples/start.htm#ClipFeatures

I noticed that the task http://serverapps.esri.com/ArcGIS/rest/services/SamplesNET/USA_Data_ClipTools/GPServer/ClipCounties
has the capabilities to generate an output parameter: output.zip file. 

Basically, I wanted to take the current example from the SDK and just enhance it to the point where the output.zip file is delivered to the client. 

I�??m having some trouble and I�??m wondering if someone has already taken this process/sdk example and enhanced it this way.  Could/would you share some pointers/suggestions/code?

Thanks
Christine.
0 Kudos
12 Replies
JMcNeil
Deactivated User
Christine,

The different projections should not matter...

Just add this to have a parameter for you HTML TITLE.

Code behind:

   parameters.Add(new GPLinearUnit("Linear_unit", esriUnits.esriMiles, Int32.Parse(DistanceTextBox.Text)));

Then Uncomment your text box for the html title in your xaml.

J
0 Kudos
ChristineZeller
Occasional Contributor
John,

Thanks for the reply.  I was able to get the html title paramater to start working and I was able to get the model to work when I am only returning one parameter (clipped buffered parcels) but when I add a 2nd parameter to add a zip file or the html file to be return I'm getting following message in fiddler...

First I see the model run successfully:

{"type":"esriJobMessageTypeInformative","description":"Zip file created successfully"},{"type":"esriJobMessageTypeInformative","description":"Completed script Zip..."},{"type":"esriJobMessageTypeInformative","description":"Executed (Zip) successfully."},{"type":"esriJobMessageTypeInformative","description":"End Time: Wed Dec 15 09:27:20 2010 (Elapsed Time: 2.00 seconds)"},{"type":"esriJobMessageTypeInformative","description":"Executed (Model) successfully."},{"type":"esriJobMessageTypeInformative","description":"End Time: Wed Dec 15 09:27:20 2010 (Elapsed Time: 1 minutes 33 seconds)"},{"type":"esriJobMessageTypeInformative","description":"Succeeded."}]}



2nd I get this message in Fiddler:

{"paramName":"Output_htm__2_","dataType":"GPDataFile","value":{"url":"http://gisserver/arcgisjobs/geoprocesstest_gpserver/j352194ced45c45e7884a0e813a1d965a/scratch/Output..."}}


Lastly I get this message in fiddler:

{"paramName":"BufferedParcels","dataType":"GPFeatureRecordSetLayer","value":{"geometryType":"esriGeometryPolygon","spatialReference":{"wkid":102100},"features":[{"geometry":{"rings":[[[-12998527.1723738,3900260.24040518],[-12998993.9301371,3900258.63318021],[-12998993.9780248,3900258.63688172],[-12998994.0247363,3900258.64806008],[-12998994.0691118,3900258.66643773],[-12998994.1100494,3900258.69155832],[-12998994.1465324,3900258.72279801],[-12998994.1776548,3900258.75938106],[-12998994.2026438,3900258.80039902],[-12998994.220879,3900258.84483331],[-12998994.2319074,3900258.89158049],[-12998994.2354551,3900258.93947975],[-12998991.2288367,3900564.43191656],[-12998987.4209855,3900951.32552332],[-12998986.748666,3901019.59856547],[-12998986.3288161,3901062.28360617],[-12998985.3118195,3901165.58476803],[-12998985.3067576,3901165.63716581],[-12998985.2927554,3901165.68791116],[-12998985.2702306,3901165.73549041],[-12998985.2398551,3901165.77848437],[-12998985.202535,3901165.8156106],[-12998985.1593833,3901165.84576169],[-12998985.1116874,3901165.86803827],[-12998985.0608698,3901165.88177589],[-12998985.0084464,3901165.88656476],[-12998861.1360073,3901166.46070732],[-12998049.2464839,3901170.18967775],[-12998049.1986119,3901170.18600655],[-12998049.1519104,3901170.17486335],[-12998049.1075382,3901170.15652467],[-12998049.0665962,3901170.13144555],[-12998049.0301005,3901170.10024828],[-12998048.9989567,3901170.06370701],[-12998048.9739375,3901170.02272845],[-12998048.9556637,3901169.97832943],[-12998048.9445888,3901169.93161165],[-12998048.9409876,3901169.88373435],[-12998052.2465168,3900729.69652288],[-12998052.2514778,3900729.64399579],[-12998052.2654228,3900729.59311116],[-12998052.2879339,3900729.54539371],[-12998052.3183366,3900729.50227316],[-12998052.35572,3900729.4650416],[-12998052.3989639,3900729.4348146],[-12998052.4467726,3900729.41249786],[-12998052.4977136,3900729.39876008],[-12998052.5502604,3900729.39401287],[-12998529.5404455,3900727.753392],[-12998528.6198704,3900566.74502357],[-12998526.8686252,3900260.5460756],[-12998526.8731007,3900260.49315398],[-12998526.8866947,3900260.44181266],[-12998526.9089944,3900260.39361046],[-12998526.9393228,3900260.35001095],[-12998526.976759,3900260.3123379],[-12998527.0201663,3900260.28173514],[-12998527.0682269,3900260.25913187],[-12998527.1194815,3900260.24521436],[-12998527.1723738,3900260.24040518]]]},"attributes":{"FID":1,"Id":0,"Shape_Length":3696.01622240368,"Shape_Area":629259.438384873}}],"exceededTransferLimit":"false"}}



I see the clipped buffered feature (1st output parameter returned) returned to the applicaiton but I don't see the second parameter (zip file).

I'm wondering if it has something to do with the last message - exceededTransferLimit":"false"}}

The application just runs and runs! 

Is there a way to increase the transferlimit?

I might just start a new post for this one problem.

Christine
0 Kudos
ChristineZeller
Occasional Contributor
Nakul, John, and Jay

I'm so sorry to post again and ask another question.  I thought I had this figured out:(

I have everything going and I'm trying to add my 3rd output parameter (the zip file).

My first two are returning fine (Clipped Buffered Parcels graphic and an HTML file) and I'm able to get the hyperlink button to appear for the zip file but it is linking to the HTML page so both the html button and the zip button are bring up the htlm output.  Would you mind looking at my code and letting me know what I'm doing wrong.

Thanks again for all the help!
Christine

using System;
using System.Collections.Generic;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Threading;
using ESRI.ArcGIS.Client;
using ESRI.ArcGIS.Client.Tasks;

namespace GeoProcessTest
{
    public partial class MainPage : UserControl
     {
        private DispatcherTimer _processingTimer;
  private Draw MyDrawObject;
  
       

        public MainPage()
        {
            InitializeComponent();

            _processingTimer = new System.Windows.Threading.DispatcherTimer();
            _processingTimer.Interval = new TimeSpan(0, 0, 0, 0, 800);
            _processingTimer.Tick += ProcessingTimer_Tick;

            MyDrawObject = new Draw(MyMap)
            {
                DrawMode = DrawMode.Polyline,
                IsEnabled = true,
                LineSymbol = LayoutRoot.Resources["ClipLineSymbol"] as ESRI.ArcGIS.Client.Symbols.LineSymbol
            };
            MyDrawObject.DrawComplete += MyDrawObject_DrawComplete;
        }

        private void MyDrawObject_DrawComplete(object sender, DrawEventArgs args)
        {
            MyDrawObject.IsEnabled = false;

            ProcessingTextBlock.Visibility = Visibility.Visible;
            _processingTimer.Start();

            GraphicsLayer graphicsLayer = MyMap.Layers["MyGraphicsLayer"] as GraphicsLayer;

            Graphic graphic = new Graphic()
            {
                Symbol = LayoutRoot.Resources["ClipLineSymbol"] as ESRI.ArcGIS.Client.Symbols.LineSymbol,
                Geometry = args.Geometry
            };
            graphicsLayer.Graphics.Add(graphic);

            Geoprocessor geoprocessorTask = new Geoprocessor("http://GisServer/ArcGIS/rest/services/GeoProcessTest/GPServer/Model");
            geoprocessorTask.UpdateDelay = 5000;
           
            geoprocessorTask.JobCompleted += GeoprocessorTask_JobCompleted;

           
            List<GPParameter> parameters = new List<GPParameter>();
            parameters.Add(new GPLinearUnit("Enter_Buffer_Distance", esriUnits.esriFeet, Int32.Parse(DistanceTextBox.Text)));
            parameters.Add(new GPFeatureRecordSetLayer("Draw_a_line_or_multiple_lines_to_select_parcels_", args.Geometry));
            parameters.Add(new GPString("HTML_TITLE", (TitleTextBox.Text)));

            geoprocessorTask.SubmitJobAsync(parameters);
        }

        private void GeoprocessorTask_JobCompleted(object sender, JobInfoEventArgs e)
        {
            Geoprocessor geoprocessorTask = sender as Geoprocessor;

            geoprocessorTask.GetResultDataCompleted += (s1, ev1) =>
            {
                
                GraphicsLayer graphicsLayer = MyMap.Layers["MyResultGraphicsLayer"] as GraphicsLayer;


                if (ev1.Parameter is GPFeatureRecordSetLayer)
                {
                    GPFeatureRecordSetLayer gpLayer = ev1.Parameter as GPFeatureRecordSetLayer;

                    if (gpLayer.FeatureSet.Features.Count == 0)
                    {
                        geoprocessorTask.GetResultImageLayerCompleted += (s2, ev2) =>
                        {
                            GPResultImageLayer gpImageLayer = ev2.GPResultImageLayer;
                            gpImageLayer.Opacity = 0.5;
                            MyMap.Layers.Add(gpImageLayer);

                            ProcessingTextBlock.Text = "Greater than 500 features returned.  Results drawn using map service.";
                            _processingTimer.Stop();
                        };


                        geoprocessorTask.GetResultImageLayerAsync(e.JobInfo.JobId, "BufferedParcels");
                        return;
                    }


                    foreach (Graphic graphic in gpLayer.FeatureSet.Features)
                    {
                        graphic.Symbol = LayoutRoot.Resources["ClipFeaturesFillSymbol"] as ESRI.ArcGIS.Client.Symbols.Symbol;
                        graphicsLayer.Graphics.Add(graphic);
                    }
                }


                //add code to add zip file


                 if (ev1.Parameter is GPDataFile)
                {
                    GPDataFile gpdata = ev1.Parameter as GPDataFile;
                    Uri uri = new Uri(gpdata.Url);
                    button1.TargetName = "_blank";
                    button1.NavigateUri = uri;
                    button1.Content = "HTML FILE";
                    button1.Visibility = System.Windows.Visibility.Visible;
                    //System.Windows.Browser.HtmlPage.Window.Navigate(uri);

                    //Uri uri2 = new Uri(gpdata.Url);
                    //button2.NavigateUri = uri2;
                    //button2.Content = "ZIP FILE";
                    //button2.Visibility = System.Windows.Visibility.Visible;

                     geoprocessorTask.GetResultDataAsync(e.JobInfo.JobId, "BufferedParcels");
                     
                    
                }

                 



                 //if (ev1.Parameter is GPDataFile)
                 //{
                 //    GPDataFile gpdata2 = ev1.Parameter as GPDataFile;
                     
                 //    Uri uri2 = new Uri(gpdata2.Url);
                 //    button2.NavigateUri = uri2;
                 //    button2.Content = "ZIP FILE";
                 //    button2.Visibility = System.Windows.Visibility.Visible;

                    
                 //}

                ProcessingTextBlock.Visibility = Visibility.Collapsed;
                _processingTimer.Stop();
            };



            geoprocessorTask.GetResultDataAsync(e.JobInfo.JobId, "Output_htm__2_");
            geoprocessorTask.GetResultDataAsync(e.JobInfo.JobId, "output_zip");
          //  geoprocessorTask.GetResultDataAsync(e.JobInfo.JobId, "BufferedParcels");
              
              

        }

        private void GeoprocessorTask_Failed(object sender, TaskFailedEventArgs e)
        {
            MessageBox.Show("Geoprocessor service failed: " + e.Error);
        }

        private void ClearButton_Click(object sender, RoutedEventArgs e)
        {
            List<Layer> gpResultImageLayers = new List<Layer>();

            foreach (Layer layer in MyMap.Layers)
                if (layer is GraphicsLayer)
                    (layer as GraphicsLayer).ClearGraphics();
                else if (layer is GPResultImageLayer)
                    gpResultImageLayers.Add(layer);
            for (int i = 0; i < gpResultImageLayers.Count; i++)
                MyMap.Layers.Remove(gpResultImageLayers);

            MyDrawObject.IsEnabled = true;

            ProcessingTextBlock.Text = "";
            ProcessingTextBlock.Visibility = Visibility.Collapsed;
        }

        void ProcessingTimer_Tick(object sender, EventArgs e)
        {
            if (ProcessingTextBlock.Text.Length > 20 || !ProcessingTextBlock.Text.StartsWith("Processing"))
                ProcessingTextBlock.Text = "Processing.";
            else
                ProcessingTextBlock.Text = ProcessingTextBlock.Text + ".";
        }
     }
}


0 Kudos