Display nautical charts per the ENC specification.
Use case
The ENC specification describes how hydrographic data should be displayed digitally.
An ENC exchange set is a catalog of data files which can be loaded as cells. The cells contain information on how symbols should be displayed in relation to one another, so as to represent information such as depth and obstacles accurately.
How to use the sample
When launched, the sample displays the ENC data. Take note of the high level of detail in the data and the smooth rendering of the layer.
How it works
Specify the path to a local CATALOG.031 file to create an AGSENCExchangeSet.
After loading the exchange set, get the AGSENCDataset objects in the exchange set from its datasets property.
Create an AGSENCCell for each dataset. Then create an AGSENCLayer for each cell.
Add the ENC layers to the map's operational layers collection to display it.
The latest hydrography package can be downloaded from ArcGIS for Developers (login is required). The S57DataDictionary.xml file is contained in it along with many others but a user does not need to know that in order to render ENC data.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
// Copyright 2020 Esri//// Licensed under the Apache License, Version 2.0 (the "License");// you may not use this file except in compliance with the License.// You may obtain a copy of the License at//// http://www.apache.org/licenses/LICENSE-2.0//// Unless required by applicable law or agreed to in writing, software// distributed under the License is distributed on an "AS IS" BASIS,// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.// See the License for the specific language governing permissions and// limitations under the License.import UIKit
import ArcGIS
classAddENCExchangeSetViewController: UIViewController{
/// The map view managed by the view controller.@IBOutletweakvar mapView: AGSMapView! {
didSet {
mapView.map =AGSMap(basemapStyle: .arcGISOceans)
}
}
/// A URL to the temporary folder for SENC data directory.let temporaryURL: URL= {
let directoryURL =FileManager.default.temporaryDirectory.appendingPathComponent(ProcessInfo().globallyUniqueString)
// Create and return the full, unique URL to the temporary folder.try?FileManager.default.createDirectory(at: directoryURL, withIntermediateDirectories: true)
return directoryURL
}()
/// Load the ENC dataset and add to the map view.////// - Parameter mapView: The map view managed by the view controller.funcaddENCExchangeSet(mapView: AGSMapView) {
guardlet map = mapView.map else { return }
// Load catalog file in ENC exchange set from bundle.let catalogURL =Bundle.main.url(
forResource: "CATALOG",
withExtension: "031",
subdirectory: "ExchangeSetWithoutUpdates/ENC_ROOT" )!let encExchangeSet =AGSENCExchangeSet(fileURLs: [catalogURL])
// URL to the "hydrography" data folder that contains the "S57DataDictionary.xml" file.let hydrographyDirectory =Bundle.main.url(
forResource: "S57DataDictionary",
withExtension: "xml",
subdirectory: "hydrography" )! .deletingLastPathComponent()
// Set environment settings for loading the dataset.let environmentSettings =AGSENCEnvironmentSettings.shared()
environmentSettings.resourceDirectory = hydrographyDirectory
// The SENC data directory is for temporarily storing generated files. environmentSettings.sencDataDirectory = temporaryURL
encExchangeSet.load { [weakself] error inguardletself=selfelse { return }
iflet error = error {
self.presentAlert(error: error)
} else {
// Create a list of ENC layers from datasets.let encLayers = encExchangeSet.datasets.map { AGSENCLayer(cell: AGSENCCell(dataset: $0)) }
// Add layers to the map. map.operationalLayers.addObjects(from: encLayers)
mapView.setViewpoint(AGSViewpoint(latitude: -32.5, longitude: 60.95, scale: 1e5), completion: nil)
}
}
}
overridefuncviewDidLoad() {
super.viewDidLoad()
// Add the source code button item to the right of navigation bar. (navigationItem.rightBarButtonItem as?SourceCodeBarButtonItem)?.filenames = ["AddENCExchangeSetViewController"]
addENCExchangeSet(mapView: mapView)
}
deinit {
// Recursively remove all files in the sample-specific// temporary folder and the folder itself.try?FileManager.default.removeItem(at: temporaryURL)
}
}