# Using external source to feed TerrainProvider

**URL:** <https://community.cesium.com/t/using-external-source-to-feed-terrainprovider/8125>\
**Category:** CesiumJS\
**Created:** [March 18, 2019, 5:52pm UTC](https://community.cesium.com/t/using-external-source-to-feed-terrainprovider/8125 "2019-03-18T17:52:39Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![nitay](https://sea2.discourse-cdn.com/cesium/user_avatar/community.cesium.com/nitay/32/4120_2.png) [@nitay](https://community.cesium.com/u/nitay)\
**Post date:** [March 18, 2019, 5:52pm UTC](https://community.cesium.com/t/using-external-source-to-feed-terrainprovider/8125/1 "2019-03-18T17:52:39Z")

</div>

Hi all,

1. A concise explanation of the problem you're experiencing.  
I'm trying to feed ArcGIS LERCs to TerrainProvider. I've followed the old ArcGisImageServerTerrainProvider logic as reference and this thread:  
[https://groups.google.com/forum/#!msg/cesium-dev/zhJgvO4U3Vk/A3yvKnQRMA8J](https://groups.google.com/forum/#!msg/cesium-dev/zhJgvO4U3Vk/A3yvKnQRMA8J)

The LERC part is easy; After decoding the LERC format I have a 257x257 terrain tile containing the altitudes in MSL (geoid, not ellipsoid).

Following ArcGisImageServerTerrainProvider logic, I've tried to feed a downscaled image to HeightmapTerrainData, but as far as I can see there's no terrain data at all in my scene.  
Cesium does call requestTileGeometry for the whole pyramid (from zoom 0 to the max zoom defined by childTileMask - I've put logging to verify this).

I'm not sure how to progress from here. Is this the right way to load terrain data to Cesium? Is there a better way?

Is there reference code for something like this?

2. A minimal code example. If you've found a bug, this helps us reproduce and repair it.  
This is the code that actually loads the terrain data:

&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;// Load LERC  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;let lerc = response.data;  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;let image = Lerc.decode(lerc);  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;let imageData = image.pixels[0];

&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;// Limit pyramid depth  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;let childrenAvailable = 15;  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;if (level \>= 13) {  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;childrenAvailable = 0;  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}

&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;// Load the LERC data into a heightmap buffer  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;let terrainBuffer = this.getImagePixels(imageData, image.width, image.height);  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;let result = new Cesium.HeightmapTerrainData({  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;buffer : terrainBuffer,  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;width : 65,  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;height : 65,  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;childTileMask : childrenAvailable, // all children present  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;structure : this.\_terrainDataStructure  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;});

&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;console.log('LERC Loaded [Level: ' + level + ' X: ' + x + ' Y: ' + y);

&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;return result;

4. The Cesium version you're using, your operating system and browser.  
Chrome Version 72.0.3626.121  
Windows 10  
Cesium 1.54

Thanks!  
Nitay

---

<div class="post-metadata">

**Author:** ![omar](https://sea2.discourse-cdn.com/cesium/user_avatar/community.cesium.com/omar/32/1999_2.png) [@omar](https://community.cesium.com/u/omar)\
**Post date:** [March 25, 2019, 4:20pm UTC](https://community.cesium.com/t/using-external-source-to-feed-terrainprovider/8125/2 "2019-03-25T16:20:51Z")

</div>

Yeah I think your best bet here is looking at the other terrain providers to see how they work. If you’re not already using it, you might find the inspector tool useful for debugging:

[https://cesiumjs.org/Cesium/Build/Apps/Sandcastle/?src=Cesium%20Inspector.html](https://cesiumjs.org/Cesium/Build/Apps/Sandcastle/?src=Cesium%20Inspector.html)

If you make progress on this please post what worked for you here! I can imagine it’ll be useful for other community members in the same situation.
