本文整理汇总了C#中Geoprocessor.GetResultImageLayerAsync方法的典型用法代码示例。如果您正苦于以下问题:C# Geoprocessor.GetResultImageLayerAsync方法的具体用法?C# Geoprocessor.GetResultImageLayerAsync怎么用?C# Geoprocessor.GetResultImageLayerAsync使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Geoprocessor
的用法示例。
在下文中一共展示了Geoprocessor.GetResultImageLayerAsync方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: StartGP_Click
private async void StartGP_Click(object sender, RoutedEventArgs e)
{
StartGP.IsEnabled = false;
ClearGraphics();
ClearButton.Visibility = Windows.UI.Xaml.Visibility.Collapsed;
ProcessingTextBlock.Visibility = Visibility.Collapsed;
var inputPolyline = await mapView1.Editor.RequestShapeAsync(DrawShape.Polyline);
var inputGraphic = new Graphic { Geometry = inputPolyline };
GraphicsLayer inputLayer = mapView1.Map.Layers["InputLayer"] as GraphicsLayer;
inputLayer.Graphics.Add(inputGraphic);
MyProgressRing.Visibility = Visibility.Visible;
MyProgressRing.IsActive = true;
string message = null;
Geoprocessor task = new Geoprocessor(new Uri(ServiceUri));
var inputParameter = new GPInputParameter();
inputParameter.GPParameters.Add(new GPFeatureRecordSetLayer("Input_Features", inputPolyline));
inputParameter.GPParameters.Add(new GPLinearUnit("Linear_unit", LinearUnits.Miles, Int32.Parse(DistanceTextBox.Text)));
try
{
//Submit the job and await the results
var gpJobInfo = await task.SubmitJobAsync(inputParameter);
//Poll the server every 5 seconds for the status of the job.
//Cancelled, Cancelling, Deleted, Deleting, Executing, Failed, New, Submitted, Succeeded, TimedOut, Waiting
while (gpJobInfo.JobStatus != GPJobStatus.Cancelled &&
gpJobInfo.JobStatus != GPJobStatus.Deleted &&
gpJobInfo.JobStatus != GPJobStatus.Failed &&
gpJobInfo.JobStatus != GPJobStatus.Succeeded &&
gpJobInfo.JobStatus != GPJobStatus.TimedOut)
{
gpJobInfo = await task.CheckJobStatusAsync(gpJobInfo.JobID);
await Task.Delay(5000);
}
//Now that the job is completed, check whether the service returned the results as Features or as a GPResultImageLayer.
//This can happen if the number of features to return exceeds the limit set on the service
if (gpJobInfo.JobStatus == GPJobStatus.Succeeded)
{
var resultData = await task.GetResultDataAsync(gpJobInfo.JobID, "Clipped_Counties");
if (resultData is GPFeatureRecordSetLayer)
{
GPFeatureRecordSetLayer gpLayer = resultData as GPFeatureRecordSetLayer;
if (gpLayer.FeatureSet.Features.Count == 0)
{
var resultImageLayer = await task.GetResultImageLayerAsync(gpJobInfo.JobID, "Clipped_Counties");
GPResultImageLayer gpImageLayer = resultImageLayer;
gpImageLayer.Opacity = 0.5;
mapView1.Map.Layers.Add(gpImageLayer);
ProcessingTextBlock.Visibility = Visibility.Visible;
ProcessingTextBlock.Text = "Greater than 500 features returned. Results drawn using map service.";
return;
}
GraphicsLayer resultLayer = mapView1.Map.Layers["MyResultGraphicsLayer"] as GraphicsLayer;
foreach (Graphic g in gpLayer.FeatureSet.Features)
{
resultLayer.Graphics.Add(g);
}
}
}
MyProgressRing.Visibility = Visibility.Collapsed;
MyProgressRing.IsActive = false;
ClearButton.Visibility = Visibility.Visible;
StartGP.IsEnabled = true;
}
catch (Exception ex)
{
message = ex.Message;
}
if (message != null)
await new MessageDialog(message, "GP Failed").ShowAsync();
}
示例2: BuildUI
private void BuildUI()
{
if (ParamContainer == null || ParameterConfigs == null ||
ParameterConfigs.Count < 1) return;
if ((Results == null || Results.Count < 1) && (Errors == null || Errors.Count < 1))
return;
if (!inputLayerInfoAvailable())
return;
ParamContainer.Children.Clear();
ParamContainer.ColumnDefinitions.Clear();
ParamContainer.RowDefinitions.Clear();
ParamContainer.ColumnDefinitions.Add(new ColumnDefinition() { Width = GridLength.Auto });
ParamContainer.ColumnDefinitions.Add(new ColumnDefinition() );// { Width = new GridLength(0, GridUnitType.Star) });
HasSimpleResults = false;
layerParamNameIDLookup = InputLayers != null ?
new Dictionary<string, string>(InputLayers) : new Dictionary<string, string>();
int pendingGPResultImageLayers = 0;
#region Results
if (Results != null && Results.Count > 0)
{
#region GP mapserver result
MapServiceLayerParameterConfig mapServiceLayerParameterConfig = ParameterConfigs.FirstOrDefault(p => p.Type == GPParameterType.MapServiceLayer) as MapServiceLayerParameterConfig;
if (mapServiceLayerParameterConfig != null && mapServiceLayerParameterConfig.SupportsJobResource)
{
string t = "/rest/services/";
string url = string.Format("{0}/{1}/MapServer/jobs/{2}", TaskUrl.Substring(0, TaskUrl.IndexOf(t, StringComparison.OrdinalIgnoreCase) + t.Length - 1), mapServiceLayerParameterConfig.Name, JobID);
ArcGISDynamicMapServiceLayer layer = new ArcGISDynamicMapServiceLayer { Url = url, };
layer.SetValue(ESRI.ArcGIS.Mapping.Core.LayerExtensions.ExcludeSerializationProperty, true);
addToMap(mapServiceLayerParameterConfig, layer);
}
#endregion
#region display each result
foreach (ParameterConfig config in ParameterConfigs)
{
MapServiceLayerParameterConfig cfg;
if (config.Type == GPParameterType.MapServiceLayer && (cfg = config as MapServiceLayerParameterConfig) != null && !cfg.SupportsJobResource)
{
pendingGPResultImageLayers++;
Geoprocessor gp = new Geoprocessor(TaskUrl);
gp.OutputSpatialReference = Map.SpatialReference.Clone();
gp.GetResultImageLayerCompleted += (s, e) =>
{
GPResultImageLayer gpImageLayer = e.GPResultImageLayer;
setLayerProps(cfg, gpImageLayer);
Map.Layers.Add(gpImageLayer);
layerParamNameIDLookup.Add(cfg.Name, gpImageLayer.ID);
pendingGPResultImageLayers--;
if (layerParamNameIDLookup.Count > 1 && pendingGPResultImageLayers == 0)
LayerOrderer.OrderLayers(Map, LayerOrder, layerParamNameIDLookup);
};
gp.GetResultImageLayerAsync(JobID, cfg.Name);
continue;
}
GPParameter param = getParameter(config.Name);
if (param == null) continue;
string value = ParameterBase.ParameterToDisplayString(config.Type, param);
switch (config.Type)
{
case GPParameterType.Boolean:
case GPParameterType.Double:
case GPParameterType.Long:
case GPParameterType.String:
case GPParameterType.Date:
case GPParameterType.LinearUnit:
if (value == null)
value = string.Empty;
addparamUI(config.Label, value, false);
break;
case GPParameterType.FeatureLayer:
addToMap(param as GPFeatureRecordSetLayer, config);
break;
case GPParameterType.RecordSet:
if (string.IsNullOrEmpty(value) && param is GPRecordSet)
{
GPRecordSet rs = param as GPRecordSet;
if (string.IsNullOrEmpty(rs.Url) && rs.FeatureSet != null)
value = ESRI.ArcGIS.Mapping.GP.Resources.Strings.OnlyUrlOutputIsSupportedForRecordsets;
else
value = string.Empty;
addparamUI(config.Label, value, false);
}
else
addparamUI(config.Label, value, true);
break;
case GPParameterType.DataFile:
case GPParameterType.RasterData:
case GPParameterType.RasterDataLayer:
if (value == null)
value = string.Empty;
addparamUI(config.Label, value, true);
break;
}
}
#endregion
if (layerParamNameIDLookup.Count > 1 && pendingGPResultImageLayers ==0)
//.........这里部分代码省略.........
示例3: getInputLineAndClip
// Waits for the user to draw a line, then performs the buffer and clip operation
private async void getInputLineAndClip()
{
if (m_firstPointAdded)
return;
// Get line from user
var clipLine = await Editor.RequestShapeAsync(DrawShape.Polyline,
new SimpleLineSymbol() { Color = Colors.Red, Width = 2, Style = SimpleLineStyle.Dash });
ClipLines.Add(new Graphic() { Geometry = clipLine });
// Show busy UI
BusyVisibility = Visibility.Visible;
StatusText = "Executing...";
string error = null;
// Initialize the Geoprocessing task with the buffer and clip service endpoint
Geoprocessor task = new Geoprocessor(new Uri("http://serverapps10.esri.com/ArcGIS/rest/services/SamplesNET/" +
"USA_Data_ClipTools/GPServer/ClipCounties"));
// Initialize input parameters
var parameter = new GPInputParameter()
{
OutSpatialReference = SpatialReferences.WebMercator
};
parameter.GPParameters.Add(new GPFeatureRecordSetLayer("Input_Features", clipLine)); // input geometry
parameter.GPParameters.Add(new GPLinearUnit("Linear_unit", LinearUnits.Miles, BufferDistance)); // buffer distance
try
{
// Submit the job and await the results
var result = await task.SubmitJobAsync(parameter);
// Poll the server every two seconds for the status of the job.
while (result.JobStatus != GPJobStatus.Cancelled
&& result.JobStatus != GPJobStatus.Deleted
&& result.JobStatus != GPJobStatus.Failed
&& result.JobStatus != GPJobStatus.Succeeded
&& result.JobStatus != GPJobStatus.TimedOut)
{
result = await task.CheckJobStatusAsync(result.JobID);
// show the status
var descriptions = result.Messages.Select(msg => msg.Description);
var status = string.Join(Environment.NewLine, descriptions);
if (!string.IsNullOrEmpty(status))
StatusText = status;
await Task.Delay(2000);
}
if (result.JobStatus == GPJobStatus.Succeeded)
{
// Get the results
var resultData = await task.GetResultDataAsync(result.JobID, "Clipped_Counties");
if (resultData is GPFeatureRecordSetLayer)
{
GPFeatureRecordSetLayer resultsLayer = resultData as GPFeatureRecordSetLayer;
if (resultsLayer.FeatureSet != null
&& resultsLayer.FeatureSet.Features != null
&& resultsLayer.FeatureSet.Features.Count != 0)
{
// Results were returned as graphics. Add them to the ClippedCounties collection
ClippedCounties = new ObservableCollection<Graphic>(resultsLayer.FeatureSet.Features);
}
else // Try to get results as a GPResultImageLayer
{
StatusText = "Clip operation complete. Retrieving results...";
m_clippedCountiesLayer = await task.GetResultImageLayerAsync(result.JobID, "Clipped_Counties");
// If successful, add the layer to the layers collection
if (m_clippedCountiesLayer != null)
{
m_clippedCountiesLayer.Opacity = 0.5;
// Insert the layer below the input layer
Layers.Insert(Layers.IndexOf(m_clipLinesLayer), m_clippedCountiesLayer);
// Wait until the result layer is initialized
await m_clippedCountiesLayer.InitializeAsync();
}
else
{
error = "No results found";
}
}
}
else
{
error = "Clip operation failed";
}
}
else
{
error = "Clip operation failed";
}
}
catch (Exception ex)
{
//.........这里部分代码省略.........
示例4: Clip
public async void Clip()
{
// get the local GP server's URL
this.gpUrl = this.localGPService.UrlGeoprocessingService;
// start the GP
this.gpTask = new Geoprocessor(new Uri(this.gpUrl + "/ClipFeatures"));
//get the user's input line
var inputLine = await this.mapView.Editor.RequestShapeAsync(DrawShape.Polyline) as Polyline;
// clear the graphics layers
this.resultGraphicsLayer.Graphics.Clear();
this.inputGraphicsLayer.Graphics.Clear();
// add new graphic to layer
this.inputGraphicsLayer.Graphics.Add(new Graphic { Geometry = inputLine, Symbol = this.simpleInputLineSymbol });
// add the parameters
var parameter = new GPInputParameter();
parameter.GPParameters.Add(new GPFeatureRecordSetLayer("Input", inputLine));
parameter.GPParameters.Add(new GPLinearUnit("Linear_Unit", LinearUnits.Miles, this.Distance));
// poll the task
var result = await SubmitAndPollStatusAsync(parameter);
// add successful results to the map
if (result.JobStatus == GPJobStatus.Succeeded)
{
this.Status = "Finished processing. Retrieving results...";
var resultData = await gpTask.GetResultDataAsync(result.JobID, "Clipped_Counties");
if (resultData is GPFeatureRecordSetLayer)
{
GPFeatureRecordSetLayer gpLayer = resultData as GPFeatureRecordSetLayer;
if (gpLayer.FeatureSet.Features.Count == 0)
{
// the the map service results
var resultImageLayer = await gpTask.GetResultImageLayerAsync(result.JobID, "Clipped_Counties");
// make the result image layer opaque
GPResultImageLayer gpImageLayer = resultImageLayer;
gpImageLayer.Opacity = 0.5;
this.mapView.Map.Layers.Add(gpImageLayer);
this.Status = "Greater than 500 features returned. Results drawn using map service.";
return;
}
// get the result features and add them to the GraphicsLayer
var features = gpLayer.FeatureSet.Features;
foreach (Feature feature in features)
{
this.resultGraphicsLayer.Graphics.Add(feature as Graphic);
}
}
this.Status = "Success!!!";
}
}