View on GitHub Sample viewer app

Visualize point cloud data using different renderers and filters.

Apply point cloud renderer and filter

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

  1. Create a PointCloudLayer with the Sonoma Area 1 point cloud scene layer URL and add it to a scene’s operational layers. Create the scene with Scene(viewingMode: .local, basemapStyle: .arcGISImagery) and display it in a LocalSceneView. Custom point cloud renderers and filters require LocalSceneView, rather than SceneView.
  2. Create the following point cloud renderers:
    • Create a PointCloudRGBRenderer using the RGB attribute.
    • Create a PointCloudStretchRenderer using the ELEVATION attribute and three PointCloudColorStop objects with fixed example elevation values of 0, 30, and 90.
    • Create a PointCloudClassBreaksRenderer using the ELEVATION attribute and three PointCloudColorClassBreak objects with fixed example elevation ranges from -Double(Float.greatestFiniteMagnitude) to 20, 20 to 40, and 40 to Double(Float.greatestFiniteMagnitude). The large finite outer bounds accommodate elevations outside the example thresholds, including negative elevations.
    • Create a PointCloudUniqueValueRenderer using the CLASS_CODE attribute and PointCloudColorUniqueValue objects for classification values 1 through 18. Although the attribute is numeric, PointCloudColorUniqueValue accepts these values as strings.
  3. Set a PointCloudSplatAlgorithm on each renderer and set the renderer’s pointsPerInch property to 25. Modify the active renderer’s existing splat algorithm to update its scaleFactor.
  4. Set the selected renderer on the point cloud layer’s renderer property. The PointCloudRGBRenderer we constructed is applied initially.
  5. Create the following point cloud filters:
    • Create a PointCloudValueFilter using the CLASS_CODE attribute, the selected classification values as Double values, and the selected include or exclude mode.
    • Create a PointCloudReturnFilter using the RETURNS attribute and the selected return types.
    • Create a PointCloudBitfieldFilter using the FLAGS attribute and require scan direction bit 6 to be either set or clear. The required-bit collections contain zero-based bit positions, not bit masks.
  6. Add, update, or remove each filter independently in the point cloud layer’s filters collection as its selections change. The collection is initially empty. Remove the return filter when no return types are selected; an empty PointCloudReturnFilter would 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

ApplyPointCloudRendererAndFilterView.swiftApplyPointCloudRendererAndFilterView.swiftApplyPointCloudRendererAndFilterView.Model.swift
// 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 ArcGIS
import 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()
}
}