Extrusion is the process of stretching a flat, 2D shape vertically to create a 3D object in a scene. For example, you can extrude building polygons by a height value to create three-dimensional building shapes.
How to use the sample
Tap the bottom buttons to switch between using population density and total population for extrusion. Higher extrusion directly corresponds to higher attribute values.
How it works
Create an AGSServiceFeatureTable from a URL.
Create an AGSFeatureLayer from the service feature table.
Make sure to set the renderingMode property to dynamic.
Apply an AGSSimpleRenderer to the feature layer.
Set the renderer's extrusionMode property to absoluteHeight.
Set the renderer's extrusionExpression property to "[POP2007]/ 10".
Relevant API
AGSExtrusionMode
AGSFeatureLayer
AGSRendererSceneProperties
AGSServiceFeatureTable
AGSSimpleRenderer
Tags
3D, extrude, extrusion, extrusion expression, height, renderer, scene
Sample Code
FeatureLayerExtrusionViewController.swift
Use dark colors for code blocksCopy
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
87
88
89
90
91
92
93
94
95
96
// Copyright 2017 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
/// A view controller that manages the interface of the Feature Layer Extrusion/// sample.classFeatureLayerExtrusionViewController: UIViewController{
/// The scene displayed in the scene view.let scene: AGSScene/// The renderer of the feature layer.let renderer: AGSRendererrequiredinit?(coder: NSCoder) {
scene =AGSScene(basemapStyle: .arcGISTopographic)
/// The url of the States layer of the Census Map Service.let censusMapServiceStatesLayerURL =URL(string: "https://sampleserver6.arcgisonline.com/arcgis/rest/services/Census/MapServer/3")!// Create service feature table from US census feature service.let table =AGSServiceFeatureTable(url: censusMapServiceStatesLayerURL)
// Create feature layer from service feature table.let layer =AGSFeatureLayer(featureTable: table)
// Feature layer must be rendered dynamically for extrusion to work. layer.renderingMode = .dynamic
// Setup the symbols used to display the features (US states) from the table.let lineSymbol =AGSSimpleLineSymbol(style: .solid, color: .blue, width: 1.0)
let fillSymbol =AGSSimpleFillSymbol(style: .solid, color: .blue, outline: lineSymbol)
renderer =AGSSimpleRenderer(symbol: fillSymbol)
iflet sceneProperties = renderer.sceneProperties {
sceneProperties.extrusionMode = .absoluteHeight
sceneProperties.extrusionExpression =Statistic.totalPopulation.extrusionExpression
}
// Set the renderer on the layer and add the layer to the scene. layer.renderer = renderer
scene.operationalLayers.add(layer)
super.init(coder: coder)
}
/// The scene view managed by the view controller.@IBOutletweakvar sceneView: AGSSceneView!
overridefuncviewDidLoad() {
super.viewDidLoad()
// Adds the source code button item to the right of navigation bar. (self.navigationItem.rightBarButtonItem as!SourceCodeBarButtonItem).filenames = ["FeatureLayerExtrusionViewController"]
sceneView.scene = scene
// Set the scene view's viewpoint.let distance =12_940_924.0let point =AGSPoint(x: -99.659448, y: 20.513652, z: distance, spatialReference: .wgs84())
let camera =AGSCamera(lookAt: point, distance: 0, heading: 0, pitch: 15, roll: 0)
let viewpoint =AGSViewpoint(center: point, scale: distance, camera: camera)
sceneView.setViewpoint(viewpoint)
}
enumStatistic: Int{
case totalPopulation
case populationDensity
/// The extrusion expression for the statistic.var extrusionExpression: String {
switchself {
case .totalPopulation:
return"[POP2007]/ 10"case .populationDensity:
// The offset makes the extrusion look better over Alaska.let offset =100_000return"([POP07_SQMI] * 5000) + \(offset)" }
}
}
@IBActionfuncextrusionAction(_sender: UISegmentedControl) {
iflet statistic =Statistic(rawValue: sender.selectedSegmentIndex) {
renderer.sceneProperties?.extrusionExpression = statistic.extrusionExpression
} else {
assertionFailure("Selected segment does not correspond to a statistic")
}
}
}