Skip To Content ArcGIS for Developers Sign In Dashboard

S57 Cell Information

Download Samples Repository

Description

This sample demonstrates adding and removing S-57 cells from an HydrographicS57Layer in the Map and accessing the Dataset Identification (DSID) metadata of those S-57 cells. The DSID metadata Provides information regarding the dataset's source and the product specification it is part of.

"Desktop" "Store" Available for Desktop, Store

Sample Code

<UserControl x:Class="ArcGISRuntime.Samples.Desktop.Symbology.Hydrographic.S57CellInfoSample"
      	 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"
             xmlns:hydro="clr-namespace:Esri.ArcGISRuntime.Hydrographic;assembly=Esri.ArcGISRuntime"
             xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" 
             xmlns:d="http://schemas.microsoft.com/expression/blend/2008" 
			 xmlns:local="clr-namespace:ArcGISRuntime.Samples.Desktop.Symbology.Hydrographic"
             mc:Ignorable="d" 
             d:DesignHeight="1200" d:DesignWidth="1600">
	<Grid>
		<esri:MapView x:Name="MyMapView" 
					  LayerLoaded="MyMapView_LayerLoaded">
			<esri:Map>
				<esri:ArcGISTiledMapServiceLayer ID="Ocean_BaseMap"
                        ServiceUri="http://services.arcgisonline.com/arcgis/rest/services/Ocean/World_Ocean_Base/MapServer" />

				<!-- Using group layer to group all Hydrographic layers -->
				<esri:GroupLayer ID="Hydrographic">
					<hydro:HydrographicS57Layer ID="US1WCO1M" 
						Path="..\..\..\samples-data\symbology\s57-electronic-navigational-charts\us1wc01m\US1WC01M.000">
					</hydro:HydrographicS57Layer>
				</esri:GroupLayer>
			</esri:Map>
		</esri:MapView>
		<Border Background="White" BorderBrush="Black" BorderThickness="1" Margin="30" Padding="20"
                HorizontalAlignment="Right" VerticalAlignment="Top">
			<Border.Effect>
				<DropShadowEffect />
			</Border.Effect>
			<StackPanel>
				<StackPanel Orientation="Horizontal" HorizontalAlignment="Center">
					<Button Margin="10" x:Name="addCellButton" Content="Add Cell(s)" 
							Click="AddCellButton_Click" 
							Height="30" Width="100" 
							IsEnabled="False"/>
					<Button Margin="10" x:Name="removeSelectedCellsButton" Content="Remove Selected" 
							Click="RemoveSelectedCellsButton_Click" 
							Height="30" Width="100"
							IsEnabled="False"/>
					<Button Margin="10" x:Name="zoomToSelectedButton" Content="Zoom to Selected"
							Click="ZoomToSelectedButtom_Click" 
							Height="30" Width="100" 
							IsEnabled="False"/>
				</StackPanel>

				<!-- Cells -->
				<ScrollViewer Margin="5" 
							  HorizontalScrollBarVisibility="Hidden" VerticalScrollBarVisibility="Auto"  
							  Height="140">
					<ListBox x:Name="s57CellList" 
							 SelectionChanged="s57CellList_SelectionChanged">
						<ListBox.ItemTemplate>
							<DataTemplate>
								<StackPanel Orientation="Horizontal" Margin="2">
									<TextBlock Text="{Binding ID, Mode=OneWay}" Margin="5,0,2,0" > 
									<TextBlock Text=" - "></TextBlock>
									<TextBlock Text="{Binding Status, Mode=OneWay}"  />
                                <ToolTipService.ToolTip>
                                    <StackPanel MaxWidth="400">
                                        <TextBlock FontWeight="Bold" Text="{Binding Path}" TextWrapping="Wrap" />
                                    </StackPanel>
                                </ToolTipService.ToolTip>
                            </TextBlock>
								</StackPanel>
							</DataTemplate>
						</ListBox.ItemTemplate>
					</ListBox>
				</ScrollViewer>

				<!--  Cell info -->
				<GroupBox x:Name="cellInfoDisplay">
					<GroupBox.Header>
						<Label>Cell information</Label>
					</GroupBox.Header>
					<StackPanel>
						<StackPanel Orientation="Horizontal">
							<TextBlock>Name:</TextBlock>
							<TextBlock Text="{Binding Name}" Margin="5,0,0,0"/>
						</StackPanel>
						<StackPanel Orientation="Horizontal">
							<TextBlock>Path:</TextBlock>
							<TextBlock Text="{Binding Path}" Margin="5,0,0,0" MaxWidth="380" TextWrapping="Wrap"/>
						</StackPanel>
						<StackPanel Orientation="Horizontal">
							<TextBlock>Agency:</TextBlock>
							<TextBlock Text="{Binding Agency}" Margin="5,0,0,0"/>
						</StackPanel>
						<StackPanel Orientation="Horizontal">
							<TextBlock>ExchangePurpose:</TextBlock>
							<TextBlock Text="{Binding ExchangePurpose}" Margin="5,0,0,0"/>
						</StackPanel>
						<StackPanel Orientation="Horizontal">
							<TextBlock>Intended Usage:</TextBlock>
							<TextBlock Text="{Binding IntendedUsage}" Margin="5,0,0,0"/>
						</StackPanel>
						<StackPanel Orientation="Horizontal">
							<TextBlock>Edition Number:</TextBlock>
							<TextBlock Text="{Binding EditionNumber}" Margin="5,0,0,0"/>
						</StackPanel>
						<StackPanel Orientation="Horizontal">
							<TextBlock>Update Number:</TextBlock>
							<TextBlock Text="{Binding UpdateNumber}" Margin="5,0,0,0"/>
						</StackPanel>
						<StackPanel Orientation="Horizontal">
							<TextBlock>Update Application Date:</TextBlock>
							<TextBlock Text="{Binding UpdateApplicationDate}" Margin="5,0,0,0"/>
						</StackPanel>
						<StackPanel Orientation="Horizontal">
							<TextBlock>Issue Date:</TextBlock>
							<TextBlock Text="{Binding IssueDate}" Margin="5,0,0,0"/>
						</StackPanel>
						<StackPanel Orientation="Horizontal">
							<TextBlock>Compilation Scale:</TextBlock>
							<TextBlock Text="{Binding CompilationScale}" Margin="5,0,0,0"/>
						</StackPanel>
					</StackPanel>
				</GroupBox>
			</StackPanel>
		</Border>
	</Grid>
</UserControl>
using Esri.ArcGISRuntime.Controls;
using Esri.ArcGISRuntime.Geometry;
using Esri.ArcGISRuntime.Hydrographic;
using Esri.ArcGISRuntime.Layers;
using Microsoft.Win32;
using System;
using System.IO;
using System.Linq;
using System.Windows;
using System.Windows.Controls;

namespace ArcGISRuntime.Samples.Desktop.Symbology.Hydrographic
{
	/// <summary>
	/// This sample demonstrates adding and removing S-57 cells from an HydrographicS57Layer in the Map and accessing the Dataset Identification (DSID) metadata of those S-57 cells. The DSID metadata Provides information regarding the dataset's source and the product specification it is part of.
	/// </summary>
	/// <title>S57 Cell Information</title>
	/// <category>Symbology</category>
	/// <subcategory>Hydrographic</subcategory>
	/// <requiresSymbols>true</requiresSymbols>
	public partial class S57CellInfoSample : UserControl 
	{
		GroupLayer _hydrographicGroupLayer;

		public S57CellInfoSample()
		{
			InitializeComponent();

			// Create default instance of display properties and set that to DataContext for binding
			ZoomToHydrographicLayers();
		}

		// Zoom to combined extent of the group layer that contains all hydrographic layers
		private async void ZoomToHydrographicLayers()
		{
			try
			{
				// wait until all layers are loaded
				await MyMapView.LayersLoadedAsync();
				
				// Get group layer from Map and set list items source
				_hydrographicGroupLayer = MyMapView.Map.Layers.OfType<GroupLayer>().First();
				s57CellList.ItemsSource = _hydrographicGroupLayer.ChildLayers;
				s57CellList.SelectedIndex = 0;

				Envelope extent = _hydrographicGroupLayer.ChildLayers.First().FullExtent;

				// Create combined extent from child hydrographic layers
				foreach (var layer in _hydrographicGroupLayer.ChildLayers)
					extent = extent.Union(layer.FullExtent);

				// Zoom to full extent
				await MyMapView.SetViewAsync(extent);

				// Enable controls
				addCellButton.IsEnabled = true;
				zoomToSelectedButton.IsEnabled = true;
				removeSelectedCellsButton.IsEnabled = true;
			}
			catch (Exception ex)
			{
				MessageBox.Show("Error occurred : " + ex.Message, "Sample error");
			}
		}

		// Show error if loading layers fail
		private void MyMapView_LayerLoaded(object sender, LayerLoadedEventArgs e)
		{
			if (e.LoadError == null)
				return;

			MessageBox.Show(
					string.Format("Error when loading layer. {0}", e.LoadError.ToString()),
					"Error loading layer");
		}

		private void AddCellButton_Click(object sender, System.Windows.RoutedEventArgs e)
		{
			// Create an instance of the open file dialog box.
			OpenFileDialog openFileDialog1 = new OpenFileDialog();

			// Set filter options and filter index.
			openFileDialog1.DefaultExt = ".000";
			openFileDialog1.Filter = "S57 Cells (.000)|*.000";
			openFileDialog1.Multiselect = true;

			// Call the ShowDialog method to show the dialog box.
			bool? userClickedOK = openFileDialog1.ShowDialog();

			// Process input if the user clicked OK.
			if (userClickedOK == true)
			{
				foreach (string fileName in openFileDialog1.FileNames)
				{
					var hydroLayer = new HydrographicS57Layer() 
					{ 
						Path = fileName,
						ID = Path.GetFileNameWithoutExtension(fileName)
					};
					_hydrographicGroupLayer.ChildLayers.Add(hydroLayer);
					s57CellList.SelectedItem = hydroLayer;
				}
			}
		}

		private async void ZoomToSelectedButtom_Click(object sender, RoutedEventArgs e)
		{
			var selectedLayer = s57CellList.SelectedItem as HydrographicS57Layer;
			if (selectedLayer == null)
				return;

			ZoomToCell(await selectedLayer.GetCellAsync(MyMapView));
		}

		private void ZoomToCell(S57Cell currentCell)
		{
			if (currentCell == null)
				return;

			if (currentCell.Extent != null)
			{
				MyMapView.SetView(currentCell.Extent);
			}
		}

		private async void s57CellList_SelectionChanged(object sender, SelectionChangedEventArgs e)
		{
			var selectedLayer = s57CellList.SelectedItem as HydrographicS57Layer;
			if (selectedLayer == null)
				return;

			cellInfoDisplay.DataContext = await selectedLayer.GetCellAsync(MyMapView);
		}

		private void RemoveSelectedCellsButton_Click(object sender, System.Windows.RoutedEventArgs e)
		{
			var selectedLayer = s57CellList.SelectedItem as HydrographicS57Layer;
			if (selectedLayer == null)
				return;

			_hydrographicGroupLayer.ChildLayers.Remove(selectedLayer);
			cellInfoDisplay.DataContext = null;
		}
	}
}
Feedback on this topic?