-
Notifications
You must be signed in to change notification settings - Fork 11
[New] Apply hillshade renderer to raster #592
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from 27 commits
Commits
Show all changes
45 commits
Select commit
Hold shift + click to select a range
f6fba1a
add sample
rolson 2e0a633
fix offline data
rolson a32751c
apply renderer
rolson 990a524
update sample code
rolson ff25f16
add error handling
rolson 8f7409d
fix sample
rolson 42b7a56
simplify
rolson 32515f1
start adding settings view
rolson fefaa70
add snippet
rolson 4f52d21
add preview
rolson ee199fa
try not to use a model
rolson 953d63c
fixes
rolson f190a9d
make state private
rolson 6af7169
update screenshots
rolson b258fc9
update metadata
rolson 62b02c7
fix popover
rolson 7438313
comment
rolson 7038b36
Merge branch 'v.next' into ryan/ApplyHillshadeRendererToRaster
rolson f2ca3f6
reorder image names
rolson e98eb9c
update category
rolson f0cc049
update proj
rolson d2e93c9
Apply suggestions from code review
rolson e871741
remove comment
rolson dc1fa31
Merge branch 'ryan/ApplyHillshadeRendererToRaster' of https://github.…
rolson b5974c3
pr feedback
rolson 1b74a8e
remove preview
rolson 364b345
pr feedback
rolson 3b73cbe
Apply suggestions from code review
rolson fc48505
odr resource updates
rolson 12a59e4
Merge branch 'ryan/ApplyHillshadeRendererToRaster' of https://github.…
rolson 6ef72e4
odr fixes
rolson 3ff6bd2
fix compile error
rolson 198b8f3
fix odr resource
rolson 8832161
update link
rolson 02adeed
Merge branch 'v.next' into ryan/ApplyHillshadeRendererToRaster
rolson 0e91139
add settings view to copy files phase
rolson e0a607d
remove file
rolson 4079e83
Apply suggestions from code review
rolson 6252280
Update Samples.xcodeproj/project.pbxproj
rolson 941dd1e
re-sort
rolson c210c71
Merge branch 'ryan/ApplyHillshadeRendererToRaster' of https://github.…
rolson 0c16d27
sort portal data folder
rolson f7654a3
add dismiss button
rolson 6de6f71
update screen shot
rolson 3bab19c
Merge branch 'v.next' into ryan/ApplyHillshadeRendererToRaster
rolson File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
80 changes: 80 additions & 0 deletions
80
.../Apply hillshade renderer to raster/ApplyHillshadeRendererToRasterView.SettingsView.swift
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,80 @@ | ||
// Copyright 2025 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 | ||
|
||
extension ApplyHillshadeRendererToRasterView { | ||
struct SettingsView: View { | ||
/// The renderer that this view updates. | ||
@Binding var renderer: HillshadeRenderer | ||
/// The altitude angle of the renderer. | ||
@State private var altitude: Double = 0 | ||
/// The azimuth angle of the renderer. | ||
@State private var azimuth: Double = 0 | ||
/// The slope type of the renderer. | ||
@State private var slopeType: HillshadeRenderer.SlopeType? | ||
|
||
var body: some View { | ||
NavigationStack { | ||
Form { | ||
Section { | ||
LabeledContent("Altitude", value: altitude, format: .number) | ||
Slider(value: $altitude, in: 0...360, step: 1) | ||
} | ||
Section { | ||
LabeledContent("Azimuth", value: azimuth, format: .number) | ||
Slider(value: $azimuth, in: 0...360, step: 1) | ||
} | ||
Section { | ||
Picker("Slope Type", selection: $slopeType) { | ||
Text("None") | ||
.tag(nil as HillshadeRenderer.SlopeType?) | ||
Text("Degree") | ||
.tag(Optional(HillshadeRenderer.SlopeType.degree)) | ||
Text("Percent Rise") | ||
.tag(Optional(HillshadeRenderer.SlopeType.percentRise)) | ||
Text("Scaled") | ||
.tag(Optional(HillshadeRenderer.SlopeType.scaled)) | ||
} | ||
} | ||
} | ||
.onAppear { | ||
// Initialize the state when the view appears. | ||
altitude = renderer.altitude.converted(to: .degrees).value | ||
azimuth = renderer.azimuth.converted(to: .degrees).value | ||
slopeType = renderer.slopeType | ||
} | ||
.onChange(of: altitude) { updateRenderer(previousRenderer: renderer) } | ||
.onChange(of: azimuth) { updateRenderer(previousRenderer: renderer) } | ||
.onChange(of: slopeType) { updateRenderer(previousRenderer: renderer) } | ||
rolson marked this conversation as resolved.
Show resolved
Hide resolved
|
||
.navigationTitle("Hillshade Renderer Settings") | ||
.navigationBarTitleDisplayMode(.inline) | ||
rolson marked this conversation as resolved.
Show resolved
Hide resolved
|
||
} | ||
} | ||
|
||
/// Updates the renderer to the latest state. | ||
func updateRenderer(previousRenderer: HillshadeRenderer) { | ||
renderer = HillshadeRenderer( | ||
altitude: altitude, | ||
azimuth: azimuth, | ||
slopeType: slopeType, | ||
zFactor: previousRenderer.zFactor, | ||
pixelSizeFactor: previousRenderer.pixelSizeFactor, | ||
pixelSizePower: previousRenderer.pixelSizePower, | ||
outputBitDepth: previousRenderer.outputBitDepth | ||
) | ||
} | ||
} | ||
} |
93 changes: 93 additions & 0 deletions
93
Shared/Samples/Apply hillshade renderer to raster/ApplyHillshadeRendererToRasterView.swift
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,93 @@ | ||
// Copyright 2025 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 ApplyHillshadeRendererToRasterView: View { | ||
/// The model used to store the geo model and other expensive objects | ||
/// used in this view. | ||
class Model: ObservableObject { | ||
/// The map that will be shown. | ||
let map: Map | ||
|
||
/// The raster layer in the map. | ||
private let rasterLayer: RasterLayer | ||
|
||
/// The raster renderer. | ||
var renderer: HillshadeRenderer { | ||
didSet { | ||
// When the renderer is updated, update the layer accordingly. | ||
rasterLayer.renderer = renderer | ||
} | ||
} | ||
|
||
init() { | ||
// Gets the raster file URL. | ||
let rasterFileURL = Bundle.main.url(forResource: "srtm", withExtension: "tiff", subdirectory: "srtm")! | ||
rolson marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
// Creates a raster with the file URL. | ||
let raster = Raster(fileURL: rasterFileURL) | ||
|
||
// Creates a raster layer using the raster object. | ||
rasterLayer = RasterLayer(raster: raster) | ||
|
||
// Apply the hillshade renderer to the raster layer. | ||
renderer = HillshadeRenderer( | ||
altitude: 45, | ||
azimuth: 315, | ||
slopeType: nil, | ||
zFactor: 0.000016, | ||
pixelSizeFactor: 1, | ||
pixelSizePower: 1, | ||
outputBitDepth: 8 | ||
) | ||
rasterLayer.renderer = renderer | ||
|
||
// Create our map. | ||
map = Map(basemap: .init(baseLayer: rasterLayer)) | ||
} | ||
} | ||
|
||
/// The view model for the sample. | ||
@StateObject private var model = Model() | ||
rolson marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
/// A boolean value indicating if the settings panel is presented. | ||
rolson marked this conversation as resolved.
Show resolved
Hide resolved
|
||
@State private var isSettingsPanelPresented: Bool = false | ||
rolson marked this conversation as resolved.
Show resolved
Hide resolved
rolson marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
var body: some View { | ||
// Creates a map view to display the map. | ||
MapView(map: model.map) | ||
.toolbar { | ||
ToolbarItem(placement: .bottomBar) { | ||
Button { | ||
isSettingsPanelPresented = true | ||
} label: { | ||
Text("Settings") | ||
} | ||
rolson marked this conversation as resolved.
Show resolved
Hide resolved
|
||
.popover(isPresented: $isSettingsPanelPresented, arrowEdge: .bottom) { | ||
rolson marked this conversation as resolved.
Show resolved
Hide resolved
|
||
ApplyHillshadeRendererToRasterView.SettingsView( | ||
rolson marked this conversation as resolved.
Show resolved
Hide resolved
|
||
renderer: $model.renderer | ||
) | ||
.presentationDetents([.medium]) | ||
.frame(idealWidth: 320, idealHeight: 380) | ||
rolson marked this conversation as resolved.
Show resolved
Hide resolved
|
||
} | ||
} | ||
} | ||
} | ||
} | ||
|
||
#Preview { | ||
ApplyHillshadeRendererToRasterView() | ||
} | ||
rolson marked this conversation as resolved.
Show resolved
Hide resolved
|
32 changes: 32 additions & 0 deletions
32
Shared/Samples/Apply hillshade renderer to raster/README.md
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
# Apply hillshade renderer to raster | ||
|
||
Apply a hillshade renderer to a raster. | ||
|
||
 | ||
rolson marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
## Use case | ||
|
||
An environmental agency may track coastal erosion by comparing images of an area taken over a longer period of time with hillshade renderers applied. | ||
|
||
## How to use the sample | ||
|
||
Choose and adjust the settings to update the hillshade renderer on the raster layer. The sample allows you to change the Altitude, Azimuth, and Slope Type. | ||
|
||
## How it works | ||
|
||
1. Create a `Raster` from a grayscale raster file. | ||
2. Create a `RasterLayer` from the raster. | ||
3. Create a `Basemap` from the raster layer and set it to the map. | ||
4. Create a `HillshadeRenderer`, specifying the altitude, azimuth, slope type and other properties. | ||
5. Set the hillshade renderer to be used on the raster layer. | ||
|
||
## Relevant API | ||
|
||
* Basemap | ||
* HillshadeRenderer | ||
* Raster | ||
* RasterLayer | ||
|
||
## Tags | ||
|
||
altitude, angle, azimuth, raster, slope, visualization |
36 changes: 36 additions & 0 deletions
36
Shared/Samples/Apply hillshade renderer to raster/README.metadata.json
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
{ | ||
"category": "Visualization", | ||
"description": "Apply a hillshade renderer to a raster.", | ||
"ignore": false, | ||
"images": [ | ||
"apply-hillshade-renderer-to-raster-settings.png", | ||
"apply-hillshade-renderer-to-raster.png" | ||
], | ||
"keywords": [ | ||
"altitude", | ||
"angle", | ||
"azimuth", | ||
"raster", | ||
"slope", | ||
"visualization", | ||
"Basemap", | ||
"HillshadeRenderer", | ||
"Raster", | ||
"RasterLayer" | ||
], | ||
"offline_data": [ | ||
"ae9739163a76437ea02482e1a807b806" | ||
], | ||
"redirect_from": [], | ||
"relevant_apis": [ | ||
"Basemap", | ||
"HillshadeRenderer", | ||
"Raster", | ||
"RasterLayer" | ||
], | ||
"snippets": [ | ||
"ApplyHillshadeRendererToRasterView.swift", | ||
"ApplyHillshadeRendererToRasterView.SettingsView.swift" | ||
], | ||
"title": "Apply hillshade renderer to raster" | ||
} |
Binary file added
BIN
+60.4 KB
...ly hillshade renderer to raster/apply-hillshade-renderer-to-raster-settings.png
rolson marked this conversation as resolved.
Show resolved
Hide resolved
|
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+116 KB
...mples/Apply hillshade renderer to raster/apply-hillshade-renderer-to-raster.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.