Skip to content

Commit 33818b7

Browse files
authored
Adds sample "Apply stretch renderer" (#436)
1 parent 5ff0aff commit 33818b7

File tree

10 files changed

+722
-0
lines changed

10 files changed

+722
-0
lines changed
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
# Apply stretch renderer
2+
3+
Use a stretch renderer to enhance the visual contrast of raster data for analysis.
4+
5+
![Image of apply stretch renderer](apply-stretch-renderer.png)
6+
7+
## Use case
8+
9+
An appropriate stretch renderer can enhance the contrast of raster imagery, allowing the user to control how their data is displayed for efficient imagery analysis.
10+
11+
## How to use the sample
12+
13+
Choose one of the stretch parameter types:
14+
15+
* Standard deviation - a linear stretch defined by the standard deviation of the pixel values
16+
* Min-max - a linear stretch based on minimum and maximum pixel values
17+
* Percent clip - a linear stretch between the defined percent clip minimum and percent clip maximum pixel values
18+
19+
Then configure the parameters.
20+
21+
## How it works
22+
23+
1. Create a `Raster` from a raster file using `Raster.createWithPath`.
24+
2. Create a `RasterLayer` from the `Raster`.
25+
3. Add the layer to the map's operational layers.
26+
4. Create a `StretchRenderer`, specifying the stretch parameters and other properties.
27+
5. Set the renderer on the layer using `rasterLayer.renderer(...)`.
28+
29+
## Relevant API
30+
31+
* ColorRamp
32+
* MinMaxStretchParameters
33+
* PercentClipStretchParameters
34+
* Raster
35+
* RasterLayer
36+
* StandardDeviationStretchParameters
37+
* StretchParameters
38+
* StretchRenderer
39+
40+
## Offline data
41+
42+
This sample uses the [Shasta](https://www.arcgis.com/home/item.html?id=7c4c679ab06a4df19dc497f577f111bd) raster file.
43+
44+
## About the data
45+
46+
This sample uses a raster imagery tile of an area of forested mountainous terrain and rivers.
47+
48+
## Additional information
49+
50+
See [Stretch function](https://pro.arcgis.com/en/pro-app/latest/help/analysis/raster-functions/stretch-function.htm) in the *ArcGIS Pro* documentation for more information about the types of stretches that can be performed.
51+
52+
## Tags
53+
54+
analysis, deviation, histogram, imagery, interpretation, min-max, percent clip, pixel, raster, stretch, symbology, visualization
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
{
2+
"category": "Visualization",
3+
"description": "Use a stretch renderer to enhance the visual contrast of raster data for analysis.",
4+
"formal_name": "ApplyStretchRenderer",
5+
"ignore": false,
6+
"images": [
7+
"apply-stretch-renderer.png"
8+
],
9+
"keywords": [
10+
"analysis",
11+
"deviation",
12+
"histogram",
13+
"imagery",
14+
"interpretation",
15+
"min-max",
16+
"percent clip",
17+
"pixel",
18+
"raster",
19+
"stretch",
20+
"symbology",
21+
"visualization",
22+
"ColorRamp",
23+
"MinMaxStretchParameters",
24+
"PercentClipStretchParameters",
25+
"Raster",
26+
"RasterLayer",
27+
"StandardDeviationStretchParameters",
28+
"StretchParameters",
29+
"StretchRenderer"
30+
],
31+
"language": "kotlin",
32+
"provision_from": [
33+
"https://www.arcgis.com/home/item.html?id=7c4c679ab06a4df19dc497f577f111bd"
34+
],
35+
"provision_to": [],
36+
"redirect_from": "",
37+
"relevant_apis": [
38+
"ColorRamp",
39+
"MinMaxStretchParameters",
40+
"PercentClipStretchParameters",
41+
"Raster",
42+
"RasterLayer",
43+
"StandardDeviationStretchParameters",
44+
"StretchParameters",
45+
"StretchRenderer"
46+
],
47+
"snippets": [
48+
"src/main/java/com/esri/arcgismaps/sample/applystretchrenderer/components/ApplyStretchRendererViewModel.kt",
49+
"src/main/java/com/esri/arcgismaps/sample/applystretchrenderer/MainActivity.kt",
50+
"src/main/java/com/esri/arcgismaps/sample/applystretchrenderer/DownloadActivity.kt",
51+
"src/main/java/com/esri/arcgismaps/sample/applystretchrenderer/screens/ApplyStretchRendererScreen.kt"
52+
],
53+
"title": "Apply stretch renderer"
54+
}
661 KB
Loading
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
plugins {
2+
alias(libs.plugins.arcgismaps.android.library)
3+
alias(libs.plugins.arcgismaps.android.library.compose)
4+
alias(libs.plugins.arcgismaps.kotlin.sample)
5+
alias(libs.plugins.gradle.secrets)
6+
}
7+
8+
secrets {
9+
// this file doesn't contain secrets, it just provides defaults which can be committed into git.
10+
defaultPropertiesFileName = "secrets.defaults.properties"
11+
}
12+
13+
android {
14+
namespace = "com.esri.arcgismaps.sample.applystretchrenderer"
15+
buildFeatures {
16+
buildConfig = true
17+
}
18+
}
19+
20+
dependencies {
21+
// Only module specific dependencies needed here
22+
}
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<manifest xmlns:android="http://schemas.android.com/apk/res/android">
3+
4+
<uses-permission android:name="android.permission.INTERNET" />
5+
6+
<application><activity
7+
android:exported="true"
8+
android:name=".MainActivity"
9+
android:label="@string/apply_stretch_renderer_app_name">
10+
11+
</activity>
12+
<activity
13+
android:name=".DownloadActivity"
14+
android:exported="true"
15+
android:label="@string/apply_stretch_renderer_app_name" />
16+
</application>
17+
18+
</manifest>
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
/* Copyright 2025 Esri
2+
*
3+
* Licensed under the Apache License, Version 2.0 (the "License");
4+
* you may not use this file except in compliance with the License.
5+
* You may obtain a copy of the License at
6+
*
7+
* http://www.apache.org/licenses/LICENSE-2.0
8+
*
9+
* Unless required by applicable law or agreed to in writing, software
10+
* distributed under the License is distributed on an "AS IS" BASIS,
11+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
* See the License for the specific language governing permissions and
13+
* limitations under the License.
14+
*
15+
*/
16+
package com.esri.arcgismaps.sample.applystretchrenderer
17+
18+
import android.content.Intent
19+
import android.os.Bundle
20+
import com.esri.arcgismaps.sample.sampleslib.DownloaderActivity
21+
22+
class DownloadActivity : DownloaderActivity() {
23+
override fun onCreate(savedInstanceState: Bundle?) {
24+
super.onCreate(savedInstanceState)
25+
downloadAndStartSample(
26+
Intent(this, MainActivity::class.java),
27+
getString(R.string.apply_stretch_renderer_app_name),
28+
listOf(
29+
"https://www.arcgis.com/home/item.html?id=7c4c679ab06a4df19dc497f577f111bd"
30+
)
31+
)
32+
}
33+
}
Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
/* Copyright 2025 Esri
2+
*
3+
* Licensed under the Apache License, Version 2.0 (the "License");
4+
* you may not use this file except in compliance with the License.
5+
* You may obtain a copy of the License at
6+
*
7+
* http://www.apache.org/licenses/LICENSE-2.0
8+
*
9+
* Unless required by applicable law or agreed to in writing, software
10+
* distributed under the License is distributed on an "AS IS" BASIS,
11+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
* See the License for the specific language governing permissions and
13+
* limitations under the License.
14+
*
15+
*/
16+
17+
package com.esri.arcgismaps.sample.applystretchrenderer
18+
19+
import android.os.Bundle
20+
import androidx.activity.ComponentActivity
21+
import androidx.activity.compose.setContent
22+
import androidx.compose.material3.MaterialTheme
23+
import androidx.compose.material3.Surface
24+
import androidx.compose.runtime.Composable
25+
import com.arcgismaps.ApiKey
26+
import com.arcgismaps.ArcGISEnvironment
27+
import com.esri.arcgismaps.sample.sampleslib.theme.SampleAppTheme
28+
import com.esri.arcgismaps.sample.applystretchrenderer.screens.ApplyStretchRendererScreen
29+
30+
class MainActivity : ComponentActivity() {
31+
32+
override fun onCreate(savedInstanceState: Bundle?) {
33+
super.onCreate(savedInstanceState)
34+
// authentication with an API key or named user is
35+
// required to access basemaps and other location services
36+
ArcGISEnvironment.apiKey = ApiKey.create(BuildConfig.ACCESS_TOKEN)
37+
38+
setContent {
39+
SampleAppTheme {
40+
ApplyStretchRendererApp()
41+
}
42+
}
43+
}
44+
45+
@Composable
46+
private fun ApplyStretchRendererApp() {
47+
Surface(color = MaterialTheme.colorScheme.background) {
48+
ApplyStretchRendererScreen(
49+
sampleName = getString(R.string.apply_stretch_renderer_app_name)
50+
)
51+
}
52+
}
53+
}

0 commit comments

Comments
 (0)