iTowns / itowns

A Three.js-based framework written in Javascript/WebGL for visualizing 3D geospatial data
http://www.itowns-project.org
Other
1.11k stars 299 forks source link

Do Elevation layers support holes? #1366

Open rollastre opened 4 years ago

rollastre commented 4 years ago

Hello!

I think I have read the documentation completely and I couldn't find anything related to this, but still I'd say I saw once in the the code a setting for no-data value somewhere I am not able to find now. So, I wonder whether it is possible to have a planar view with Color and Elevation in which some part of the terrain don't exist. In other words, do elevation layers support holes?

A typical use case is that I want to be able to see objects that are bellow the terrain from above and I have solved this in another product by performing a cut in the terrain, or doing a shader trick that reads the value from a texture and if the fragment is for the area of the hole, it is discarded.

I can't find a way to solve this in iTowns. But I was rather convinced it was possible. Can anyone give me a hint, please?

Thanks in advance

gchoqueux commented 4 years ago

Hello Thanks, Effectively, there's no documentation on LayerElevation#noDataValue. I just add this documentation in new PR #1367.

You could add noDataValue (like -999999) in your elevation/terrain datas to add holes.

rollastre commented 4 years ago

Hello again. I don't know if I am doing it wrong, but I don't manage to get it working.

I have prepared an example to show what I am after here https://gis.iconiqlabs.com/wmts_test/view_wmts_with_elevation.html

It is a setting with 2 WMTS layers, one for the color and one for the elevation. They cover the whole world. But the elevation is flat everywhere except on the Eiffel Tower in Paris, France. (I am sure you can find it :-) ). If you zoom there close enough, you'll see that it lays in a plateau. What I am after is actually that such plateau was not displayed at all and make there a hole in the terrain so that the Eiffel Tower is not shown. I.e. a hole with an arbitrary shape that I define using a noDataValue in the tile. In this case 255. The tile for such thing at the level 16th can be found here

https://gis.iconiqlabs.com/wmtsproxy/elevation/Eiffel_Tower_EPSG_3785.obj?LAYER=elevation&FORMAT=image/jpeg&SERVICE=WMTS&VERSION=1.0.0&REQUEST=GetTile&STYLE=normal&TILEMATRIXSET=EPSG:3785&TILEMATRIX=16&TILEROW=22545&TILECOL=33185

as you can see it is either black or white. The white area is what I need to be a hole. The idea I had is to generate the elevation tiles in a self-made service with elevation values and a reserved value for a hole. So the question I have is: Is this possible and if so, could you please tell me what am I doing wrong?

Now, a second question is. If this is possible, I have the problem that I only have 255 values now. But I would expect I can encode the tiles in another format (e.g. float 32) per pixel so that I can get better precision on elevation. Am I right?

Thanks a lot!

zarov commented 4 years ago

There was some confusion from what you asked the first time: you can't display a hole in iTowns using noDataValue. If we find a noDataValue, we replace it with elevation data from the parent tile, if there is any.

In the same time, this check is only done on the four corner of the tile, because we can't allow a check on each point of the elevation data. So having only a hole in the middle will do nothing unfortunately, and it will be considered as correct data.

And then you have this part (the check of the four corner) where we consider that noDataValue is always the smallest value, so it won't work in you case of 0 for normal data and 255 for the ground.

What I suggest then, if you want something similar to a hole, is to invert your data. Keep in mind though that you will never get a "true" hole: we can't break the mesh of a tile, it needs to be consistent. So the best thing you can get is points placed on the center of the earth (for a GlobeView), or a deep valley for a PlanarView.

Concerning the float32, yeah you shouldn't have any problem with it (I'm not 100% sure, this needs to be tested).

jailln commented 2 years ago

In order to support this we should to display some tiles without terrain. One use case is to add other terrain sources or meshes instead.