sogelink-research / ctod

Cesium Terrain On Demand: Generate Cesium terrain tiles on demand from a Cloud Optimized GeoTIFF
MIT License
38 stars 7 forks source link

Generated cache cannot be loaded by Cesium while served from webserver #11

Closed Sgambe33 closed 4 months ago

Sgambe33 commented 4 months ago

I tried using this tool to generate offline tiles to then serve with a webserver because I do not have the possibility of running a server 24/7 with the necessary computing power to generate tiles on the go. I noticed that some tiles are missing since CesiumJS throws some errors about being "unable to load terrain tile": Failed to obtain terrain tile X: 541 Y: 123 Level: 9. Error message: "Request has failed. Status Code: 404" Keep in mind that when seeding the cache I specifically choose all zoom layers from 0 to 17. Is this problem related to this program or some kind of misconfiguration on my end?

Furthermore, just a curiosity, why are tiles generated by this progam way smaller than the ones created by CesiumIon? Like for the same dataset cotd's are about 30mb while Ion's are 400mb.

tebben commented 4 months ago

Did you use the seed-cache script to generate the cache? If so did it gave you any error or is there a file /9/541/123.terrain in the directory?

If the COG you are using is available somewhere I could have a look later this week.

I'm not sure why it's 30MB vs ION's 400MB, maybe there were errors/problems and not all tiles are generated or maybe ION tiles further than level 17 which can increase the size by a lot.

Sgambe33 commented 4 months ago

I looked again and that tile is present but now I get another error for level 0: Failed to obtain terrain tile X: 1 Y: 0 Level: 0. Error message: "TypeError: Cannot read properties of undefined (reading 'computeChildMaskForTile')" If you need the COG I can send it to you.

tebben commented 4 months ago

Cesium requests a terrain tile with an inverted y compared to the TMS, the cache in CTOD stores and loads tiles according to the TMS schema. In the latest update the cache now follows the inverted y structure so the cache can be served directly without CTOD in between.

the seed_cache script now also contains a new option --export-layer-json {max_zoom} to create a layer.json in the root directory of the tiles layer_code/meshing_method/layer.json. Add an integer to --export-layer-json to define the max zoom level Cesium will request.

I didn't get the same error you described above with the old cache but I hope this update solves your problem.

I tested the following:

Generate cache

poetry run seed_cache --port 5001 -m grid -i ./ctod/files/test_cog.tif -o ./cache-test -r 20 -z 0-1-2-3-4-5-6-7-8-9-10-11-12-13-14-15-16-17 --export-layer-json 17

Serve cache

cd cache-test/{layer_id}/grid
http-server -p 3000 -g --cors

View

Within a simple self hosted html file with Cesium I set the terrain provider to http://localhost:3000 and it showed me the terrain from hosted cache directory correctly without warnings in the developer console.

Sgambe33 commented 4 months ago

Thanks for the quick fix! Everything seems to be working fine now. Still thinking about the size difference, could it be the method used for generating the tiles?

tebben commented 4 months ago

No problem.

Yes, there can be a size difference because of the method used and thus the amount of vertices in a tile. ION probably uses something similar to delatin which is likely smaller in size compared to the grid method unless there is a huge hight difference. Maybe i'll have a look later creating terrain tiles using ION and compare them to tile generated with CTOD.

Closing the issue since it's fixed.