Visualize point cloud data using different renderers and filters.

Use case
Point clouds contain large collections of 3D points captured by sensors such as lidar. Each point can include attributes that describe its color, elevation, classification, return, and other properties. Applying renderers and filters to these attributes can reveal patterns in the data and isolate points of interest, such as buildings or vegetation.
How to use the sample
The sample initially displays a point cloud layer using its RGB values. Once the layer loads, open Settings and select a renderer to visualize the points by RGB color, elevation, or LAS classification code.
Use the Point Size Scale control to increase or decrease the size of the rendered points. The value is a multiplier that modifies the renderer’s splat algorithm scaleFactor, not a fixed size in pixels or map units.
Use the filter controls to include or exclude classification codes, select lidar return types, and require scan direction flag bit 6 to be set or clear. Multiple filters can be applied at the same time. To remove a filter without affecting the others, select Clear Classification Filter, turn off all return switches, or select Any scan direction.
With no classification filter, all Include switches are on and all Exclude switches are off. Switching modes inverts the selections to preserve which listed classification codes are allowed. Clearing the classification filter restores these unrestricted switch states for the current mode.
Once a classification filter is applied, Include with no selected codes hides all points, while Exclude with no selected codes allows all classifications. No selected return types allows all returns, and Any scan direction removes that restriction. Other active filters still apply.
The Last return type includes both Last of Many and Single. Selecting either alongside Last does not include additional points.
How it works
- Create a
PointCloudLayerwith the Sonoma Area 1 point cloud scene layer URL and add it to a scene’s operational layers. Create the scene withScene(viewingMode: .local, basemapStyle: .arcGISImagery)and display it in aLocalSceneView. Custom point cloud renderers and filters requireLocalSceneView, rather thanSceneView. - Create the following point cloud renderers:
- Create a
PointCloudRGBRendererusing theRGBattribute. - Create a
PointCloudStretchRendererusing theELEVATIONattribute and threePointCloudColorStopobjects with fixed example elevation values of 0, 30, and 90. - Create a
PointCloudClassBreaksRendererusing theELEVATIONattribute and threePointCloudColorClassBreakobjects with fixed example elevation ranges from-Double(Float.greatestFiniteMagnitude)to 20, 20 to 40, and 40 toDouble(Float.greatestFiniteMagnitude). The large finite outer bounds accommodate elevations outside the example thresholds, including negative elevations. - Create a
PointCloudUniqueValueRendererusing theCLASS_CODEattribute andPointCloudColorUniqueValueobjects for classification values 1 through 18. Although the attribute is numeric,PointCloudColorUniqueValueaccepts these values as strings.
- Create a
- Set a
PointCloudSplatAlgorithmon each renderer and set the renderer’spointsPerInchproperty to25. Modify the active renderer’s existing splat algorithm to update itsscaleFactor. - Set the selected renderer on the point cloud layer’s
rendererproperty. ThePointCloudRGBRendererwe constructed is applied initially. - Create the following point cloud filters:
- Create a
PointCloudValueFilterusing theCLASS_CODEattribute, the selected classification values asDoublevalues, and the selected include or exclude mode. - Create a
PointCloudReturnFilterusing theRETURNSattribute and the selected return types. - Create a
PointCloudBitfieldFilterusing theFLAGSattribute and require scan direction bit 6 to be either set or clear. The required-bit collections contain zero-based bit positions, not bit masks.
- Create a
- Add, update, or remove each filter independently in the point cloud layer’s
filterscollection as its selections change. The collection is initially empty. Remove the return filter when no return types are selected; an emptyPointCloudReturnFilterwould otherwise hide all points. Switching renderers leaves the filters unchanged.
Relevant API
- LocalSceneView
- PointCloudBitfieldFilter
- PointCloudClassBreaksRenderer
- PointCloudColorClassBreak
- PointCloudColorStop
- PointCloudColorUniqueValue
- PointCloudLayer
- PointCloudReturnFilter
- PointCloudRGBRenderer
- PointCloudSplatAlgorithm
- PointCloudStretchRenderer
- PointCloudUniqueValueRenderer
- PointCloudValueFilter
About the data
This sample uses the Sonoma Area 1 LiDAR RGB point cloud scene layer. The layer provides the RGB, ELEVATION, CLASS_CODE, RETURNS, and FLAGS attributes used by the renderers and filters.
Tags
3D, classification, filter, lidar, point cloud, renderer, scene layer, visualization
Sample code
// Copyright 2026 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//// https://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 ArcGISimport SwiftUI
struct ApplyPointCloudRendererAndFilterView: View { /// The model that stores the scene, layer, and renderers. @State private var model = Model()
/// A Boolean value indicating whether the settings are visible. @State private var settingsAreVisible = false
/// A Boolean value indicating whether the point cloud layer has not yet loaded. @State private var isLoading = true
/// An error encountered while loading or displaying the scene. @State private var error: (any Error)?
var body: some View { // Live point cloud filter changes require a local scene view. LocalSceneView(scene: model.scene) .onGeoModelErrorChanged { error in if let error { self.error = error } } .onLayerViewStateChanged { layer, viewState in if layer === model.pointCloudLayer, model.pointCloudLayer.loadStatus == .loaded, viewState.status.contains(.error), let error = viewState.error { self.error = error } } .overlay { if isLoading && model.pointCloudLayer.loadStatus != .failed { ProgressView("Loading point cloud") .padding() .background( .regularMaterial, in: .rect(cornerRadius: 10) ) } } .task { for await status in model.pointCloudLayer.$loadStatus { guard !Task.isCancelled else { return } isLoading = status != .loaded if status == .failed { error = model.pointCloudLayer.loadError } } } .errorAlert(presentingError: $error) .toolbar { ToolbarItem(placement: .bottomBar) { Button("Settings", systemImage: "gear") { settingsAreVisible = true } .disabled(isLoading) .popover(isPresented: $settingsAreVisible) { NavigationStack { SettingsView(model: model) } .frame(idealWidth: 400, idealHeight: 600) .presentationCompactAdaptation(.popover) } } } }}
private extension ApplyPointCloudRendererAndFilterView { /// The settings for rendering and independently filtering the point cloud. struct SettingsView: View { /// The action to dismiss the settings. @Environment(\.dismiss) private var dismiss
/// The model whose settings are edited by the controls. @Bindable var model: Model
var body: some View { Form { Section("Renderer") { Picker("Type", selection: $model.rendererKind) { ForEach(RendererKind.allCases, id: \.self) { kind in Text(LocalizedStringKey(kind.label)) } } LabeledContent("Point Size Scale") { Text("\(model.scaleFactor, format: .number.precision(.fractionLength(1)))") } Slider(value: $model.scaleFactor, in: 0.1...5, step: 0.1) { Text("Point Size Scale") } minimumValueLabel: { Text("0.1") } maximumValueLabel: { Text("5") } }
Section { Picker("Mode", selection: $model.classificationMode) { Text("Include").tag( PointCloudValueFilter.Mode.include ) Text("Exclude").tag( PointCloudValueFilter.Mode.exclude ) } ForEach( Classification.allCases, id: \.self ) { classification in Toggle(classification.label, isOn: Binding( get: { model.selectedClassifications .contains(classification) }, set: { model.setClassification( classification, isSelected: $0 ) } )) } Button( "Clear Classification Filter", action: model.clearClassificationFilter ) .disabled(!model.classificationFilterIsActive) } header: { Text("Classification Filter") } footer: { Text(""" With no classification filter, all Include switches \ are on and all Exclude switches are off. Changing \ modes inverts the selections for the listed codes. \ Once applied, Include with no selections hides all \ points; Exclude with no selections does not restrict \ classifications. Clear removes this filter. Other \ filters still apply. """) }
Section { ForEach(ReturnOptions.types, id: \.self) { returnType in Toggle( ReturnOptions.label(for: returnType), isOn: Binding( get: { model.selectedReturns.contains(returnType) }, set: { model.setReturnType( returnType, isSelected: $0 ) } ) ) } } header: { Text("Return Filter") } footer: { Text(""" With no return types selected, this filter is removed. \ Other filters still apply. Last includes both Last of \ Many and Single. Selecting either alongside Last does \ not include additional points. """) }
Section { Picker("Flag Bit 6", selection: $model.scanDirection) { ForEach( ScanDirection.allCases, id: \.self ) { direction in Text(LocalizedStringKey(direction.label)) } } } header: { Text("Scan Direction Filter") } footer: { Text(""" Scan direction records the lidar scanner's sweep \ direction when a point was captured. Required Set \ selects flag bit 6 = 1; Required Clear selects 0. Any \ removes this filter. Other filters still apply. """) } } .navigationTitle("Settings") .navigationBarTitleDisplayMode(.inline) .toolbar { ToolbarItem(placement: .confirmationAction) { Button("Done") { dismiss() } } } } }}
#Preview { NavigationStack { ApplyPointCloudRendererAndFilterView() }}// Copyright 2026 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//// https://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 ArcGISimport Observationimport UIKit
extension ApplyPointCloudRendererAndFilterView { /// The scene, point cloud layer, renderers, and filter settings for the sample. @MainActor @Observable final class Model { /// The scene containing the point cloud layer. let scene: ArcGIS.Scene
/// The Sonoma Area 1 LiDAR point cloud layer. let pointCloudLayer = PointCloudLayer(url: .sonomaPointCloud)
/// The renderers, retained to avoid replacements when switching. private let renderers: [RendererKind: PointCloudRenderer]
/// The selected renderer, initially RGB. var rendererKind = RendererKind.rgb { didSet { // Filters belong to the layer, so changing its renderer leaves // all active filters in place. pointCloudLayer.renderer = renderers[rendererKind] updatePointSize() } }
/// The scale factor applied to the active renderer's splat algorithm. var scaleFactor = 1.0 { didSet { updatePointSize() } }
/// Whether selected classification codes are included or excluded. var classificationMode = PointCloudValueFilter.Mode.include { didSet { guard classificationMode != oldValue else { return } selectedClassifications = Set(Classification.allCases) .subtracting(selectedClassifications) if classificationFilterIsActive { updateClassificationFilter() } } }
/// The classification codes selected by the user. private(set) var selectedClassifications = Set(Classification.allCases)
/// A Boolean value indicating whether a classification filter is applied, /// even when no codes are selected. private(set) var classificationFilterIsActive = false
/// The return types selected by the user. private(set) var selectedReturns: Set<PointCloudReturnFilter.ReturnType> = []
/// The mutually exclusive requirements for scan direction flag bit 6. var scanDirection = ScanDirection.any { didSet { updateScanDirectionFilter() } }
/// Creates the local scene and its persistent point cloud renderers. init() { let rendererPairs = RendererKind.allCases.map { kind in let renderer = kind.makeRenderer() renderer.pointsPerInch = 25 renderer.sizeAlgorithm = PointCloudSplatAlgorithm(scaleFactor: 1) return (kind, renderer) } renderers = Dictionary(uniqueKeysWithValues: rendererPairs) pointCloudLayer.renderer = renderers[.rgb] // Filters are added when the user interacts with their controls.
// Live point cloud filtering requires a local scene view. scene = Scene(viewingMode: .local, basemapStyle: .arcGISImagery) scene.baseSurface.addElevationSource( ArcGISTiledElevationSource(url: .worldElevationService) ) scene.addOperationalLayer(pointCloudLayer) scene.initialViewpoint = Viewpoint( latitude: .nan, longitude: .nan, scale: .nan, camera: Camera( latitude: 38.2324, longitude: -122.636, altitude: 350, heading: 0, pitch: 65, roll: 0 ) ) }
/// Updates the existing size algorithm without replacing the renderer. private func updatePointSize() { let algorithm = pointCloudLayer.renderer?.sizeAlgorithm as? PointCloudSplatAlgorithm algorithm?.scaleFactor = scaleFactor }
/// Updates a classification selection and applies its filter. func setClassification( _ classification: Classification, isSelected: Bool ) { if isSelected { selectedClassifications.insert(classification) } else { selectedClassifications.remove(classification) } updateClassificationFilter() }
/// Adds the classification filter on first use, then updates it. private func updateClassificationFilter() { let values = selectedClassifications .map { Double($0.rawValue) } .sorted() // Update the layer's existing classification filter when present, // or add one on first use. Other filters remain unchanged. if let filter = pointCloudLayer.filters.first(where: { $0 is PointCloudValueFilter }) as? PointCloudValueFilter { filter.removeAllValues() filter.addValues(values) filter.mode = classificationMode } else { pointCloudLayer.addFilter(PointCloudValueFilter( attributeName: "CLASS_CODE", values: values, mode: classificationMode )) } classificationFilterIsActive = true }
/// Removes the classification filter without affecting other filters. func clearClassificationFilter() { if let filter = pointCloudLayer.filters.first(where: { $0 is PointCloudValueFilter }) { pointCloudLayer.removeFilter(filter) } selectedClassifications = classificationMode == .include ? Set(Classification.allCases) : [] classificationFilterIsActive = false }
func setReturnType( _ returnType: PointCloudReturnFilter.ReturnType, isSelected: Bool ) { if isSelected { selectedReturns.insert(returnType) } else { selectedReturns.remove(returnType) } if selectedReturns.isEmpty { // An empty return filter hides all points, so remove it instead. clearReturnFilter() } else { let includedReturns = ReturnOptions.types.filter(selectedReturns.contains) if let filter = pointCloudLayer.filters.lazy.compactMap({ $0 as? PointCloudReturnFilter }).first { filter.removeAllIncludedReturns() filter.addIncludedReturns(includedReturns) } else { pointCloudLayer.addFilter(PointCloudReturnFilter( attributeName: "RETURNS", includedReturns: includedReturns )) } } }
/// Removes only the return filter and resets its selections. func clearReturnFilter() { if let filter = pointCloudLayer.filters.first(where: { $0 is PointCloudReturnFilter }) { pointCloudLayer.removeFilter(filter) } selectedReturns.removeAll() }
/// Updates the bitfield filter without requiring the same bit /// to be both set and clear. private func updateScanDirectionFilter() { let existingFilter = pointCloudLayer.filters.first(where: { $0 is PointCloudBitfieldFilter }) as? PointCloudBitfieldFilter if scanDirection == .any { if let existingFilter { pointCloudLayer.removeFilter(existingFilter) } } else { let filter: PointCloudBitfieldFilter if let existingFilter { filter = existingFilter filter.removeAllRequiredClearBits() filter.removeAllRequiredSetBits() } else { filter = PointCloudBitfieldFilter( attributeName: "FLAGS", requiredClearBits: [], requiredSetBits: [] ) pointCloudLayer.addFilter(filter) // The collections contain zero-based bit positions, not bit masks. if scanDirection == .set { filter.addRequiredSetBit(6) } else { filter.addRequiredClearBit(6) } } } } }
/// The available point cloud renderers. enum RendererKind: CaseIterable { case rgb case stretch case classBreaks case uniqueValue
/// The user-facing name of the renderer. var label: String { switch self { case .rgb: "RGB" case .stretch: "Elevation Stretch" case .classBreaks: "Elevation Class Breaks" case .uniqueValue: "Classification" } }
/// Creates a renderer with the appropriate attribute and colors. func makeRenderer() -> PointCloudRenderer { switch self { case .rgb: return PointCloudRGBRenderer(attributeName: "RGB") case .stretch: return makeStretchRenderer() case .classBreaks: return makeClassBreaksRenderer() case .uniqueValue: return makeUniqueValueRenderer() } }
/// Creates an elevation renderer that interpolates between color stops. private func makeStretchRenderer() -> PointCloudStretchRenderer { let stops = [ PointCloudColorStop( color: UIColor( red: 31 / 255, green: 79 / 255, blue: 1, alpha: 1 ), value: 0 ), PointCloudColorStop( color: UIColor( red: 33 / 255, green: 163 / 255, blue: 102 / 255, alpha: 1 ), value: 30 ), PointCloudColorStop( color: UIColor( red: 229 / 255, green: 57 / 255, blue: 53 / 255, alpha: 1 ), value: 90 ) ] return PointCloudStretchRenderer( attributeName: "ELEVATION", stops: stops ) }
/// Creates an elevation renderer with three discrete color ranges. private func makeClassBreaksRenderer() -> PointCloudClassBreaksRenderer { let classBreaks = [ PointCloudColorClassBreak( color: UIColor( red: 96 / 255, green: 67 / 255, blue: 151 / 255, alpha: 1 ), minValue: -Double(Float.greatestFiniteMagnitude), maxValue: 20 ), PointCloudColorClassBreak( color: UIColor( red: 65 / 255, green: 145 / 255, blue: 136 / 255, alpha: 1 ), minValue: 20, maxValue: 40 ), PointCloudColorClassBreak( color: UIColor( red: 216 / 255, green: 155 / 255, blue: 77 / 255, alpha: 1 ), minValue: 40, // Use Float's largest finite value as an effectively open-ended // upper bound; convert it to Double for the class-break API. maxValue: Double(Float.greatestFiniteMagnitude) ) ] return PointCloudClassBreaksRenderer( attributeName: "ELEVATION", classBreaks: classBreaks ) }
/// Creates a renderer with one color for each LAS classification code. private func makeUniqueValueRenderer() -> PointCloudUniqueValueRenderer { // Colors for LAS classification codes 1 through 18, in code order. let colors: [UIColor] = [ UIColor(red: 139 / 255, green: 178 / 255, blue: 194 / 255, alpha: 1), UIColor(red: 212 / 255, green: 223 / 255, blue: 160 / 255, alpha: 1), UIColor(red: 168 / 255, green: 208 / 255, blue: 141 / 255, alpha: 1), UIColor(red: 112 / 255, green: 173 / 255, blue: 71 / 255, alpha: 1), UIColor(red: 47 / 255, green: 107 / 255, blue: 47 / 255, alpha: 1), UIColor(red: 200 / 255, green: 62 / 255, blue: 62 / 255, alpha: 1), UIColor(red: 187 / 255, green: 185 / 255, blue: 220 / 255, alpha: 1), UIColor(red: 187 / 255, green: 225 / 255, blue: 228 / 255, alpha: 1), UIColor(red: 155 / 255, green: 191 / 255, blue: 177 / 255, alpha: 1), UIColor(red: 75 / 255, green: 85 / 255, blue: 99 / 255, alpha: 1), UIColor(red: 107 / 255, green: 114 / 255, blue: 128 / 255, alpha: 1), UIColor(red: 209 / 255, green: 213 / 255, blue: 219 / 255, alpha: 1), UIColor(red: 245 / 255, green: 158 / 255, blue: 11 / 255, alpha: 1), UIColor(red: 234 / 255, green: 179 / 255, blue: 8 / 255, alpha: 1), UIColor(red: 124 / 255, green: 58 / 255, blue: 237 / 255, alpha: 1), UIColor(red: 236 / 255, green: 72 / 255, blue: 153 / 255, alpha: 1), UIColor(red: 139 / 255, green: 90 / 255, blue: 43 / 255, alpha: 1), UIColor(red: 17 / 255, green: 24 / 255, blue: 39 / 255, alpha: 1) ]
// CLASS_CODE is numeric, but PointCloudColorUniqueValue accepts // strings, so convert each classification code to its string form. // PointCloudValueFilter instead accepts the codes as Double values. let uniqueValues = colors.enumerated().map { index, color in PointCloudColorUniqueValue( color: color, values: [String(index + 1)] ) }
return PointCloudUniqueValueRenderer( attributeName: "CLASS_CODE", uniqueValues: uniqueValues ) } }
/// The LAS classification codes offered by the classification filter. enum Classification: Int, CaseIterable { case ground = 2 case highVegetation = 5 case building = 6
/// The user-facing name of the classification. var label: String { switch self { case .ground: "Ground" case .highVegetation: "High Vegetation" case .building: "Building" } } }
/// The possible requirements for scan direction flag bit 6. enum ScanDirection: CaseIterable { case any case set case clear
/// The user-facing name of the scan direction requirement. var label: String { switch self { case .any: "Any" case .set: "Required Set" case .clear: "Required Clear" } } }
/// The return types and labels offered by this sample's settings. enum ReturnOptions { /// The return types in display order. static let types: [PointCloudReturnFilter.ReturnType] = [ .firstOfMany, .last, .lastOfMany, .single ]
/// The user-facing name of a return type. static func label( for returnType: PointCloudReturnFilter.ReturnType ) -> String { switch returnType { case .firstOfMany: "First of Many" case .last: "Last" case .lastOfMany: "Last of Many" case .single: "Single" @unknown default: "Unknown" } } }}
private extension URL { /// The URL of the Sonoma Area 1 LiDAR RGB scene layer. static var sonomaPointCloud: URL { URL(string: "https://tiles.arcgis.com/tiles/z2tnIkrLQ2BRzr6P/arcgis/rest/services/SONOMA_AREA1_LiDAR_RGB/SceneServer/layers/0")! }
/// The URL of the World Elevation 3D terrain service. static var worldElevationService: URL { URL(string: "https://elevation3d.arcgis.com/arcgis/rest/services/WorldElevation3D/Terrain3D/ImageServer")! }}