Skip To Content ArcGIS for Developers Sign In Dashboard

ArcGIS Runtime SDK for .NET

Image Service Raster Functions

Download Samples Repository

Description

Demonstrates applying raster functions to an image service layer.

"Desktop" "Store" "Phone" Available for Desktop, Store, Phone

Sample Code

<UserControl x:Class="ArcGISRuntime.Samples.Desktop.ImageServiceRasterFunctions"
             xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
             xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
             xmlns:esri="http://schemas.esri.com/arcgis/runtime/2013">
    <Grid>
		<esri:MapView x:Name="MyMapView" WrapAround="True" >
			<esri:Map InitialViewpoint="1445440,540657,1452348,544407,2264">
                <esri:ArcGISImageServiceLayer ID="ImageLayer"
                    ServiceUri="http://sampleserver6.arcgisonline.com/arcgis/rest/services/CharlotteLAS/ImageServer" />
            </esri:Map>
        </esri:MapView>

		<Border Background="White" BorderBrush="Black" BorderThickness="1"
				HorizontalAlignment="Right" VerticalAlignment="Top" 
				Margin="30" Padding="20"
				Width="300">
			<Border.Effect>
				<DropShadowEffect />
			</Border.Effect>
            <StackPanel>
				<TextBlock Text="Choose a raster function template"  TextAlignment="Center" FontWeight="Bold" FontSize="14" />
                <ComboBox x:Name="RasterFunctionsComboBox" Margin="5"
						  SelectionChanged="RasterFunctionsComboBox_SelectionChanged">
                    <ComboBox.ItemTemplate>
                        <DataTemplate>
                            <TextBlock Text="{Binding FunctionName}"/>
                        </DataTemplate>
                    </ComboBox.ItemTemplate>
                </ComboBox>
            </StackPanel>
        </Border>
    </Grid>
</UserControl>
using Esri.ArcGISRuntime.ArcGISServices;
using Esri.ArcGISRuntime.Geometry;
using Esri.ArcGISRuntime.Layers;
using System.Windows.Controls;

namespace ArcGISRuntime.Samples.Desktop
{
    /// <summary>
    /// Demonstrates applying raster functions to an image service layer.
    /// </summary>
    /// <title>Image Service Raster Functions</title>
	/// <category>Layers</category>
	/// <subcategory>Dynamic Service Layers</subcategory>
	public partial class ImageServiceRasterFunctions : UserControl
    {
        public ImageServiceRasterFunctions()
        {
            InitializeComponent();

			MyMapView.Map.SpatialReference = SpatialReference.Create(2264);
			MyMapView.LayerLoaded += MyMapView_LayerLoaded;
        }

        private void RasterFunctionsComboBox_SelectionChanged(object sender, SelectionChangedEventArgs e)
        {
			ArcGISImageServiceLayer imageLayer = MyMapView.Map.Layers["ImageLayer"] as ArcGISImageServiceLayer;
            var rasterFunction = (sender as ComboBox).SelectedItem as RasterFunctionInfo;
            if (rasterFunction != null)
            {
                RenderingRule renderingRule = new RenderingRule() { RasterFunctionName = rasterFunction.FunctionName };
                imageLayer.RenderingRule = renderingRule;
            }
        }

        private void MyMapView_LayerLoaded(object sender, Esri.ArcGISRuntime.Controls.LayerLoadedEventArgs e)
        {
            if (e.Layer.ID == "ImageLayer")
            {
                ArcGISImageServiceLayer imageLayer = e.Layer as ArcGISImageServiceLayer;
                if (e.LoadError == null)
                {
                    RasterFunctionsComboBox.ItemsSource = imageLayer.ServiceInfo.RasterFunctionInfos;
                    RasterFunctionsComboBox.SelectedIndex = 0;
                }
            }
        }
    }
}
Feedback on this topic?