Vertically exaggerate terrain in a scene.
Use case
Vertical exaggeration can be used to emphasize subtle changes in a surface. This can be useful in creating visualizations of terrain where the horizontal extent of the surface is significantly greater than the amount of vertical change in the surface. A fractional vertical exaggeration can be used to flatten surfaces or features that have extreme vertical variation.
How to use the sample
Use the slider to update terrain exaggeration.
How it works
- Create an elevation surface from a URL with
Surface.getElevationSources().add("elevationURL")
. An elevation source defines the terrain based on a digital elevation model (DEM) or digital terrain model (DTM). - Add the surface to the scene with
scene.setBaseSurface(Surface)
. The surface visualizes the elevation source. - Configure the surface's elevation exaggeration using
surface.setElevationExaggeration(exaggeration)
.
Relevant API
- Scene
- Surface
- Surface.setElevationExaggeration
Tags
3D, DEM, DTM, elevation, scene, surface, terrain
Sample Code
/* Copyright 2018 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.
*
*/
package com.esri.arcgisruntime.sample.terrainexaggeration;
import androidx.appcompat.app.AppCompatActivity;
import android.os.Bundle;
import android.widget.SeekBar;
import android.widget.TextView;
import com.esri.arcgisruntime.geometry.Point;
import com.esri.arcgisruntime.mapping.ArcGISScene;
import com.esri.arcgisruntime.mapping.ArcGISTiledElevationSource;
import com.esri.arcgisruntime.mapping.Basemap;
import com.esri.arcgisruntime.mapping.BasemapStyle;
import com.esri.arcgisruntime.mapping.Surface;
import com.esri.arcgisruntime.mapping.view.Camera;
import com.esri.arcgisruntime.mapping.view.SceneView;
public class MainActivity extends AppCompatActivity {
private SceneView mSceneView;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
// get a reference to the scene view
mSceneView = findViewById(R.id.sceneView);
// create a scene and add it to the scene view
ArcGISScene scene = new ArcGISScene(BasemapStyle.ARCGIS_TOPOGRAPHIC);
mSceneView.setScene(scene);
// add base surface for elevation data
final Surface surface = new Surface();
ArcGISTiledElevationSource elevationSource = new ArcGISTiledElevationSource(getString(R.string.elevation_image_service_url));
surface.getElevationSources().add(elevationSource);
scene.setBaseSurface(surface);
// add a camera and initial camera position
Point initialLocation = new Point(-119.94891542688772, 46.75792111605992, 3183, mSceneView.getSpatialReference());
Camera camera = new Camera(initialLocation, 0, 7, 70, 0);
mSceneView.setViewpointCamera(camera);
// create TextView to show SeekBar value
final TextView exaggerationTextView = findViewById(R.id.exaggerationValueTextView);
// create SeekBar
final SeekBar exaggerationSeekBar = findViewById(R.id.exaggerationSeekBar);
exaggerationSeekBar.setOnSeekBarChangeListener(new SeekBar.OnSeekBarChangeListener() {
@Override public void onProgressChanged(SeekBar seekBar, int progress, boolean b) {
// disallow any progress value below 1
progress = Math.max(1, progress);
// set the text to SeekBar value
exaggerationTextView.setText(String.valueOf(progress));
// set exaggeration of surface to the value the user selected
surface.setElevationExaggeration(progress);
}
@Override public void onStartTrackingTouch(SeekBar seekBar) {
}
@Override public void onStopTrackingTouch(SeekBar seekBar) {
// disallow any progress value below 1
seekBar.setProgress(Math.max(1, seekBar.getProgress()));
}
});
}
@Override
protected void onPause() {
mSceneView.pause();
super.onPause();
}
@Override
protected void onResume() {
super.onResume();
mSceneView.resume();
}
@Override
protected void onDestroy() {
mSceneView.dispose();
super.onDestroy();
}
}