How to get terrain height from TerrainProvider

2,704 views
Skip to first unread message

tnkyou...@gmail.com

unread,
Jun 16, 2017, 2:12:48 PM6/16/17
to cesium-dev
Hi.

With Cesium 1.33,
I'd like to get terrain height of the point(longitude, latitude) from CesiumTerrainProvider.

I try to write a program but it does not work.
The program is as follows:
==============================================
var viewer = new Cesium.Viewer('cesiumContainer');

var terrainProvider = new Cesium.CesiumTerrainProvider({
url : 'https://assets.agi.com/stk-terrain/v1/tilesets/world/tiles'
});
viewer.terrainProvider = terrainProvider;

setTimeout(getHeight, 1000);
function getHeight() {
// As an example,
// longitude and latitude are set to 140.08531 and 36.103543.
var lon = 140.08531;
var lat = 36.103543;

var location = Cesium.Cartographic.fromDegrees(lon, lat, 0);
var maxLevel = terrainProvider.availability.computeMaximumLevelAtPosition(location);
var scheme = terrainProvider.tilingScheme;
var tileXY = scheme.positionToTileXY(location, maxLevel);
var tileRect = scheme.tileXYToRectangle(tileXY.x, tileXY.y, maxLevel);

var terrainPromise = terrainProvider.requestTileGeometry(tileXY.x, tileXY.y, maxLevel);

terrainPromise.then(function(dt) {
var height = dt.interpolateHeight(tileRect, location.longitude , location.latitude);

// ★ Correct value is about 25.3 meters.
// ★ However, console shows 68.71596342427405.
console.log("height :" + height);
});
}
==============================================

Please correct me if I'm wrong.

Thanks in advance

Rachel Hwang

unread,
Jun 16, 2017, 2:22:35 PM6/16/17
to cesium-dev, tnkyou...@gmail.com
Hi there,


That should be easier -- hope it helps!
- Rachel

tnkyou...@gmail.com

unread,
Jun 16, 2017, 2:52:18 PM6/16/17
to cesium-dev, tnkyou...@gmail.com
Thank you very much for your helps.

I revised my program.
However, The results do not change.
==============================================
var viewer = new Cesium.Viewer('cesiumContainer');

var terrainProvider = new Cesium.CesiumTerrainProvider({
url : 'https://assets.agi.com/stk-terrain/v1/tilesets/world/tiles'
});
viewer.terrainProvider = terrainProvider;

// As an example,
// longitude and latitude are set to 140.08531 and 36.103543.
var positions = [
Cesium.Cartographic.fromDegrees(140.08531, 36.103543),
];

var promise = Cesium.sampleTerrainMostDetailed(terrainProvider, positions);
Cesium.when(promise, function(updatedPositions) {
// ★ Correct value is about 25.3 meters.
// ★ However, console shows 68.71596342427405.
console.log(positions[0].height);
});
==============================================


2017年6月17日土曜日 3時22分35秒 UTC+9 Rachel Hwang:

Rachel Hwang

unread,
Jun 19, 2017, 3:21:43 PM6/19/17
to cesium-dev, tnkyou...@gmail.com


Hi there,


I don't see anything wrong with your code as posted when I tried it locally -- are you sure that your number is the expected result? If your reference data is from elsewhere, it's possible that the terrain datasets report different numbers because they're sampled at different resolutions, for instance.


If you're getting any errors, try running this and let us know what the console says: http://cesiumjs.org/Cesium/Apps/Sandcastle/?src=Hello%20World.html&label=Showcases&gist=6a089755741f3b8e5bfc4cb700d2aa3c


best,

- Rachel

Reply all
Reply to author
Forward
0 new messages