Visual Basic (Declaration) | |
---|---|
Public ReadOnly Property Fields As List(Of Field) |
C# | |
---|---|
public List<Field> Fields {get;} |
XAML | Copy Code |
---|---|
<UserControl.Resources> <DataTemplate x:Key="myCustomResources"> <StackPanel Orientation="Horizontal"> <TextBlock Text="{Binding Path=Name}"/> <TextBlock Text=" ("/> <TextBlock Text="{Binding Path=Type}"/> <TextBlock Text=")"/> </StackPanel> </DataTemplate> </UserControl.Resources> <Grid x:Name="LayoutRoot" Background="White"> <esri:Map Background="White" HorizontalAlignment="Left" Margin="12,63,0,0" Name="Map1" VerticalAlignment="Top" Height="525" Width="383" BorderThickness="5" BorderBrush="#FF30EBEB"> <!-- Add the ArcGISImageServiceLayer to the LayerCollection of the Map. --> <esri:ArcGISImageServiceLayer Url="http://sampleserver3.arcgisonline.com/ArcGIS/rest/services/Portland/CascadeLandsat/ImageServer" /> </esri:Map> <!-- This example shows two ways of displaying information obtained by the ArcGISImageServiceLayer.Fields. Both ways produce the same results. Change which method us being used by commenting one out and uncommmenting the other. Method #1: Uses a StaticResource in the UserControl to define a DataTemplate to format the way the Properties of the List of Fields is displayed in the ListBox Control. Method #2: Uses the DataTemplate directly in the ListBoxes XAML code to format the way the Properties of the List of Fields is displayed in the ListBox Control. --> <!-- Method #1: Review the <UserControl.Resources> tags above to see how the "myCustomResources" were made. --> <ListBox Height="525" HorizontalAlignment="Left" Margin="401,63,0,0" Name="ListBox_Fields" VerticalAlignment="Top" Width="187" ItemsSource="{Binding ElementName=Map1, Path=Layers[0].Fields}" ItemTemplate="{StaticResource myCustomResources}"/> <!-- Method #2 <ListBox Height="525" HorizontalAlignment="Left" Margin="401,63,0,0" Name="ListBox_Fields" VerticalAlignment="Top" Width="187" ItemsSource="{Binding ElementName=Map1, Path=Layers[0].Fields}"> <ListBox.ItemTemplate> <DataTemplate> <StackPanel Orientation="Horizontal"> <TextBlock Text="{Binding Path=Name}"/> <TextBlock Text=" ("/> <TextBlock Text="{Binding Path=Type}"/> <TextBlock Text=")"/> </StackPanel> </DataTemplate> </ListBox.ItemTemplate> </ListBox> --> </Grid> |
C# | Copy Code |
---|---|
private void MainPage_Loaded(object sender, System.Windows.RoutedEventArgs e) { // The Map1 object (a Map object) was defined previously in XAML. // Create an ArcGISImageServiceLayer. ESRI.ArcGIS.Client.ArcGISImageServiceLayer myArcGISImageServiceLayer = new ESRI.ArcGIS.Client.ArcGISImageServiceLayer(); myArcGISImageServiceLayer.Url = "http://sampleserver3.arcgisonline.com/ArcGIS/rest/services/Portland/CascadeLandsat/ImageServer"; // Create an Event Handler. // In this example there are two Event Handlers to demonstrate the same functionality but using two different // mechanisms. Change which Event Handler is being used by commenting one out and uncommenting the other. myArcGISImageServiceLayer.Initialized += new System.EventHandler<EventArgs>(ArcGISImageServiceLayer_Intialized1); //myArcGISImageServiceLayer.Initialized += new System.EventHandler<EventArgs>(ArcGISImageServiceLayer_Intialized2); // Add the ArcGISImageServiceLayer to the LayerCollection of the Map. Map1.Layers.Add(myArcGISImageServiceLayer); } private void ArcGISImageServiceLayer_Intialized1(object sender, EventArgs e) { // This example shows how to display the Fields that are available in the mosaic dataset by using // a DataTemplate that is defined in the Resources of the XAML file in a ListBox. The Field // Properties that are shown include: Name and Type. // // An example of the XAML code for the Static Resource is shown here: // <UserControl.Resources> // <DataTemplate x:Key="myCustomResources"> // <StackPanel Orientation="Horizontal"> // <TextBlock Text="{Binding Path=Name}"/> // <TextBlock Text=" ("/> // <TextBlock Text="{Binding Path=Type}"/> // <TextBlock Text=")"/> // </StackPanel> // </DataTemplate> // </UserControl.Resources> // // The Map1 object (a Map object) TextBlock_Fields (a TextBlock object) and ListBox_Fields (a // ListBox object) were defined previously in XAML. // Access a specific ArcGISImageServiceLayer. ESRI.ArcGIS.Client.ArcGISImageServiceLayer myArcGISImageServiceLayer = (ESRI.ArcGIS.Client.ArcGISImageServiceLayer)Map1.Layers[0]; // Fields Property (Read Only). Always returns a List object (even if empty). System.Collections.Generic.List<ESRI.ArcGIS.Client.Field> myFields = myArcGISImageServiceLayer.Fields; int myFieldsCount = myFields.Count; if (myFieldsCount > 0) { // One or more Field's present. Must be a mosaic dataset. // Display the number of Fields. TextBlock_Fields.Text = "Num Fields: " + myFieldsCount.ToString(); // Display the Field Propeties of Name and Type in a ListBox. ListBox_Fields.ItemsSource = myFields; DataTemplate myDataTemplate = new DataTemplate(); myDataTemplate = (DataTemplate)Resources["myCustomResources"]; ListBox_Fields.ItemTemplate = myDataTemplate; } else { // No Fields available. TextBlock_Fields.Text = "Num Fields: " + myFieldsCount.ToString(); } } private void ArcGISImageServiceLayer_Intialized2(object sender, EventArgs e) { // This example shows how to display the Fields that are available in the mosaic dataset by using // a DataTemplate that is constructed on the fly using the XamlReader Static Class in a // ListBox. The Field Properties that are shown include: Name and Type. // // The Map1 object (a Map object) TextBlock_Fields (a TextBlock object) and ListBox_Fields (a // ListBox object) were defined previously in XAML. // Access a specific ArcGISImageServiceLayer. ESRI.ArcGIS.Client.ArcGISImageServiceLayer myArcGISImageServiceLayer = (ESRI.ArcGIS.Client.ArcGISImageServiceLayer)Map1.Layers[0]; // Fields Property (Read Only). Always returns a List object (even if empty). System.Collections.Generic.List<ESRI.ArcGIS.Client.Field> myFields = myArcGISImageServiceLayer.Fields; int myFieldsCount = myFields.Count; if (myFieldsCount > 0) { // One or more Field's present. Must be a mosaic dataset. // Display the number of Fields. TextBlock_Fields.Text = "Num Fields: " + myFieldsCount.ToString(); // Construct a StringBuilder that will hold XAML text to define the DataTemplate. System.Text.StringBuilder stringBuilderDataTemplate = new System.Text.StringBuilder(); stringBuilderDataTemplate.Append("<DataTemplate "); stringBuilderDataTemplate.Append("xmlns='http://schemas.microsoft.com/winfx/"); stringBuilderDataTemplate.Append("2006/xaml/presentation' "); stringBuilderDataTemplate.Append("xmlns:x='http://schemas.microsoft.com/winfx/2006/xaml' "); // IMPORTANT: Provide the correct string for your applications Namespace. In the case of this // example, the Namespace is "ArcGISImageServiceLayer_Fields_CS". stringBuilderDataTemplate.Append("xmlns:local = 'clr-namespace:ArcGISImageServiceLayer_Fields_CS"); // IMPORTANT: Provide the correct string for your applications Assembly. In the case of this // example, the Assembly is "ArcGISImageServiceLayer_Fields_CS". stringBuilderDataTemplate.Append(";assembly=ArcGISImageServiceLayer_Fields_CS'>"); stringBuilderDataTemplate.Append("<StackPanel Orientation=\"Horizontal\">"); stringBuilderDataTemplate.Append("<TextBlock Text=\"{Binding Path=Name}\"/>"); stringBuilderDataTemplate.Append("<TextBlock Text=\" (\"/>"); stringBuilderDataTemplate.Append("<TextBlock Text=\"{Binding Path=Type}\"/>"); stringBuilderDataTemplate.Append("<TextBlock Text=\")\"/>"); stringBuilderDataTemplate.Append("</StackPanel>"); stringBuilderDataTemplate.Append("</DataTemplate>"); // Display the Field Propeties of Name and Type in a ListBox. ListBox_Fields.ItemsSource = myFields; DataTemplate myDataTemplate = new DataTemplate(); myDataTemplate = (DataTemplate)System.Windows.Markup.XamlReader.Load(stringBuilderDataTemplate.ToString()); ListBox_Fields.ItemTemplate = myDataTemplate; } else { // No Fields available. TextBlock_Fields.Text = "Num Fields: " + myFieldsCount.ToString(); } } |
VB.NET | Copy Code |
---|---|
Private Sub MainPage_Loaded(ByVal sender As Object, ByVal e As System.Windows.RoutedEventArgs) Handles Me.Loaded ' The Map1 object (a Map object) was defined previously in XAML. ' Create an ArcGISImageServiceLayer. Dim myArcGISImageServiceLayer As New ESRI.ArcGIS.Client.ArcGISImageServiceLayer myArcGISImageServiceLayer.Url = "http://sampleserver3.arcgisonline.com/ArcGIS/rest/services/Portland/CascadeLandsat/ImageServer" ' Create an Event Handler. ' In this example there are two Event Handlers to demonstrate the same functionality but using two different ' mechanisms. Change which Event Handler is being used by commenting one out and uncommenting the other. AddHandler myArcGISImageServiceLayer.Initialized, AddressOf ArcGISImageServiceLayer_Intialized1 'AddHandler myArcGISImageServiceLayer.Initialized, AddressOf ArcGISImageServiceLayer_Intialized2 ' Add the ArcGISImageServiceLayer to the LayerCollection of the Map. Map1.Layers.Add(myArcGISImageServiceLayer) End Sub Private Sub ArcGISImageServiceLayer_Intialized1(ByVal sender As Object, ByVal e As EventArgs) ' This example shows how to display the Fields that are available in the mosaic dataset by using ' a DataTemplate that is defined in the Resources of the XAML file in a ListBox. The Field ' Properties that are shown include: Name and Type. ' ' An example of the XAML code for the Static Resource is shown here: ' <UserControl.Resources> ' <DataTemplate x:Key="myCustomResources"> ' <StackPanel Orientation="Horizontal"> ' <TextBlock Text="{Binding Path=Name}"/> ' <TextBlock Text=" ("/> ' <TextBlock Text="{Binding Path=Type}"/> ' <TextBlock Text=")"/> ' </StackPanel> ' </DataTemplate> ' </UserControl.Resources> ' ' The Map1 object (a Map object) TextBlock_Fields (a TextBlock object) and ListBox_Fields (a ' ListBox object) were defined previously in XAML. ' Access a specific ArcGISImageServiceLayer. Dim myArcGISImageServiceLayer As ESRI.ArcGIS.Client.ArcGISImageServiceLayer = Map1.Layers.Item(0) ' Fields Property (Read Only). Always returns a List object (even if empty). Dim myFields As System.Collections.Generic.List(Of ESRI.ArcGIS.Client.Field) = myArcGISImageServiceLayer.Fields Dim myFieldsCount As Integer = myFields.Count If myFieldsCount > 0 Then ' One or more Field's present. Must be a mosaic dataset. ' Display the number of Fields. TextBlock_Fields.Text = "Num Fields: " + myFieldsCount.ToString ' Display the Field Propeties of Name and Type in a ListBox. ListBox_Fields.ItemsSource = myFields Dim myDataTemplate As New DataTemplate myDataTemplate = Resources("myCustomResources") ListBox_Fields.ItemTemplate = myDataTemplate Else ' No Fields available. TextBlock_Fields.Text = "Num Fields: " + myFieldsCount.ToString End If End Sub Private Sub ArcGISImageServiceLayer_Intialized2(ByVal sender As Object, ByVal e As EventArgs) ' This example shows how to display the Fields that are available in the mosaic dataset by using ' a DataTemplate that is constructed on the fly using the XamlReader Static Class in a ' ListBox. The Field Properties that are shown include: Name and Type. ' ' The Map1 object (a Map object) TextBlock_Fields (a TextBlock object) and ListBox_Fields (a ' ListBox object) were defined previously in XAML. ' Access a specific ArcGISImageServiceLayer. Dim myArcGISImageServiceLayer As ESRI.ArcGIS.Client.ArcGISImageServiceLayer = Map1.Layers.Item(0) ' Fields Property (Read Only). Always returns a List object (even if empty). Dim myFields As System.Collections.Generic.List(Of ESRI.ArcGIS.Client.Field) = myArcGISImageServiceLayer.Fields Dim myFieldsCount As Integer = myFields.Count If myFieldsCount > 0 Then ' One or more Field's present. Must be a mosaic dataset. ' Display the number of Fields. TextBlock_Fields.Text = "Num Fields: " + myFieldsCount.ToString ' Construct a StringBuilder that will hold XAML text to define the DataTemplate. Dim stringBuilderDataTemplate As New System.Text.StringBuilder stringBuilderDataTemplate.Append("<DataTemplate ") stringBuilderDataTemplate.Append("xmlns='http://schemas.microsoft.com/winfx/") stringBuilderDataTemplate.Append("2006/xaml/presentation' ") stringBuilderDataTemplate.Append("xmlns:x='http://schemas.microsoft.com/winfx/2006/xaml' ") ' IMPORTANT: Provide the correct string for your applications Namespace. In the case of this ' example, the Namespace is "ArcGISImageServiceLayer_Fields_VB". stringBuilderDataTemplate.Append("xmlns:local = 'clr-namespace:ArcGISImageServiceLayer_Fields_VB") ' IMPORTANT: Provide the correct string for your applications Assembly. In the case of this ' example, the Assembly is "ArcGISImageServiceLayer_Fields_VB". stringBuilderDataTemplate.Append(";assembly=ArcGISImageServiceLayer_Fields_VB'>") stringBuilderDataTemplate.Append("<StackPanel Orientation=""Horizontal"">") stringBuilderDataTemplate.Append("<TextBlock Text=""{Binding Path=Name}""/>") stringBuilderDataTemplate.Append("<TextBlock Text="" (""/>") stringBuilderDataTemplate.Append("<TextBlock Text=""{Binding Path=Type}""/>") stringBuilderDataTemplate.Append("<TextBlock Text="")""/>") stringBuilderDataTemplate.Append("</StackPanel>") stringBuilderDataTemplate.Append("</DataTemplate>") ' Display the Field Propeties of Name and Type in a ListBox. ListBox_Fields.ItemsSource = myFields Dim myDataTemplate As New DataTemplate myDataTemplate = System.Windows.Markup.XamlReader.Load(stringBuilderDataTemplate.ToString) ListBox_Fields.ItemTemplate = myDataTemplate Else ' No Fields available. TextBlock_Fields.Text = "Num Fields: " + myFieldsCount.ToString End If End Sub |
The Fields that are returned are metadata for each raster dataset (or band) that compose a mosaic dataset. Storing metadata as attributes enables parameters to be managed easily as well as enabling fast queries to enable selections. The table listing the raster items in the mosaic dataset can include information about such things as the pixel sizes, source name, the shape (outline) that the raster dataset covers, acquisition date, etc. Typically there is one record per raster dataset.
The List of Field objects that are returned from the Fields Property should not be confused with fields associated with raster dataset attribute tables. Images are made up of one or more bands. Each band has a single measurable characteristic (such as temperature, elevation, electromagnetic spectrum value, etc.) per pixel. Raster attribute tables enable the creation of classes, groups, categories, and memberships based upon pixel values.
If an ArcGISImageServiceLayer is not a mosaic dataset there will not be any Fields to be obtained.
The Fields property always returns a List object. Check to see if the List is empty (meaning the count will be 0) before iterating over the list for and individual Field.
Unfortunatley, the List(Of T)> Class is not an ObservableCollection and therefore does not raise any notification when its value changes. This means that it is not possible to bind the Fields Property in XAML and get an accurate Fields.Count. Therefore the following XAML will always return 0:
<TextBlock Name="TextBlock_Fields" Height="23" Width="50" Margin="0,0,0,0" HorizontalAlignment="Left" VerticalAlignment="Top" Text="{Binding ElementName=Map1, Path=Layers[0].Fields.Count}"/>Obtaining an accurate Fields.Count in the code-behind works as expected.
Theoretical information related to imagery can be found for the following topics:
- What is raster data?
- Essential raster data vocabulary
- What is a mosaic dataset?
- Raster dataset attribute tables
The following screenshot demonstrates an ArcGISImageServiceLayer that is based on Mosaic datasets which have a List of Field objects defined in the ArcGISImageServiceLayer.Fields Property. Using the technique of Binding it is possible to display Property values for each Field object in a ListBox. The screenshot corresonds with the code in this document.
Target Platforms: Windows XP Professional, Windows Server 2003 family, Windows Vista, Windows Server 2008 family