Code Monkey home page Code Monkey logo

tin-terrain's Introduction

NOTE: This repository has been archived as it is no longer maintained. HERE thanks the community for their contributions so far and encourages any interested party to come forward and discuss taking over maintenance.

TIN Terrain

Build Status

TIN Terrain is a command-line tool for converting heightmaps presented in GeoTIFF format into tiled optimized meshes (Triangulated Irregular Network) with different levels of details.

Check out heremaps/quantized-mesh-viewer for examples of rendering output in Cesium.js and Three.js.

Note: This is experimental code, expect changes.

dem2tin GeoTIFF to mesh on USGS craterlake DEM

Features

  • Takes GeoTIFF with heightmap as an input
  • Transforms heightmap into a TIN mesh with a given max-error parameter and outputs into .obj format
  • Transforms heightmap into tiled TIN mesh for a given zoom range and outputs tiled pyramid into quantized-mesh-1.0 terrain format

Let us know what you think!

You can help us a lot to prioritize issues in tin-terrain if you submit a short anonymous survey

Installation

You can build and run this tool either with Docker or directly on your system. Building with Docker is easier and works on macOS, Linux, and Windows.

Detailed instructions for each platform are provided below.

Building with Docker

The provided Dockerfile builds the TIN Terrain executable on Ubuntu Linux.

To build the container, execute:

./build-docker.sh

To run TIN Terrain from Docker, type e.g.

docker run -v [local data directory]:/data:cached --name tin-terrain --rm -i -t tin-terrain tin-terrain ...

where [local data directory] is the folder that contains your DEM files and will receive the output files. This will be mapped to /data in the Docker instance, so you should use:

docker run -v [local data directory]:/data:cached --name tin-terrain --rm -i -t tin-terrain tin-terrain dem2tin --input /data/... --output /data/... 

Alternatively, use

docker run -v [local data directory]:/data:cached --name tin-terrain --rm -i -t tin-terrain bash 

to open an interactive shell which lets you execute tin-terrain and access /data. Any files not stored in /data will be lost when closing the session.

Prerequisites & Dependencies

If you choose to compile and run "TIN Terrain" directly on your system, please note that the following packages must be installed on your system:

  • The C++ standard library from the compiler (tested with clang 9.1.0 and gcc 7.3.0)
  • Boost (BSL-1.0) program_options, filesystem, system (tested with version 1.67)
  • GDAL (MIT) gdal, gdal_priv, cpl_conv (tested with version 2.3)

TIN Terrain also downloads some source code of 3rd party libraries during the CMake configure phase:

You can disable this behaviour by passing the -DTNTN_DOWNLOAD_DEPS=OFF option to CMake when generating the project/makefiles. If you do so, you have to download dependencies yourself and also pass the TNTN_LIBGLM_SOURCE_DIR and TNTN_LIBFMT_SOURCE_DIR variables to CMake as well as TNTN_CATCH2_SOURCE_DIR if you want to run the tests.

See download-deps.cmake for detailed version info.

Building on macOS

  1. Install dependencies, preferably with homebrew:
    brew install boost
    brew install cmake
    brew install gdal
    
  2. Create an XCode project:
    mkdir build-cmake-xcode
    cd build-cmake-xcode
    cmake -GXcode path/to/sourcecode/
    open tin-terrain.xcodeproj
    
  3. Build the TIN Terrain target.

The resulting binaries will be in the Debug/Release subdirectory.

To run the tests, build and run the tntn-tests target.

Possible linking issues with GDAL

If another version of GDAL is present on your machine, the FindGDAL.cmake provided with cmake might not be able to properly detect the newest version of GDAL you installed through homebrew (or any other prefered method).

Whether this is the case, can be easily detected, if the linking step in the compilation errors on linking GDAL.

Therefore you might need to guide cmake to the right location of the GDAL:

cmake -GXcode -DGDAL_LIBRARY=PATH/TO/GDAL/LIB path/to/sourcecode/

e.g

cmake -GXcode -DGDAL_LIBRARY=/usr/local/Cellar/gdal/2.3.1_2/lib/libgdal.dylib path/to/sourcecode/

Building on Linux

  1. Install dependencies, e.g. on Ubuntu:
    apt-get install build-essential cmake libboost-all-dev libgdal-dev
    
  2. Create Makefile:
    mkdir build-cmake-release
    cd build-cmake-release
    cmake -DCMAKE_BUILD_TYPE=Release path/to/sourcecode/
    
  3. Build the tin-terrain target
    VERBOSE=1 make tin-terrain
    

The resulting binary should then be ready. To run the tests, build and run the tntn-tests target:

  1. Recreate Makefile (and set TNTN_TEST=ON):
    cd build-cmake-release
    cmake -DTNTN_TEST=ON -DCMAKE_BUILD_TYPE=Debug path/to/sourcecode/
    
  2. Build the tntn-tests target
    VERBOSE=1 make tntn-tests
    

Usage

The tin-terrain command-line tool has a few subcommands. You can run tin-terrain --help to see all available subcommands.

$ tin-terrain --help
usage:
  tin-terrain [OPTION]... <subcommand> ...

Global Options:
  -h [ --help ]               print this help message
  --log arg (=stdout)         diagnostics output/log target, can be stdout,
                              stderr, or none
  -v [ --verbose ] [=arg(=1)] be more verbose
  --subcommand arg            command to execute
  --subargs arg               arguments for command

available subcommands:
  dem2tin - convert a DEM into a mesh/tin
  dem2tintiles - convert a DEM into mesh/tin tiles
  benchmark - run all available meshing methods on a given set of input files and produce statistics (performance, error rate)
  version - print version information

Projections

The tin-terrain tool requires your datasets to be in the Web Mercator projection (EPSG:3857). If your datasets are not in this projection, you can quite easily reproject your datasets with gdalwarp, e.g.:

gdalwarp -t_srs EPSG:3857 ned19_n37x75_w122x50_ca_goldengate_2010.img ned19_n37x75_w122x50_ca_goldengate_2010_mercator.tif

Creating a single mesh/TIN

You can use the dem2tin subcommand to convert a raster heightmap into a single big mesh/TIN in the OBJ format.

You can see all available options by running tin-terrain dem2tin --help.

$ tin-terrain dem2tin --help
usage:
  tin-terrain dem2tin [OPTIONS]...

dem2tin options:
  --input arg                 input filename
  --input-format arg (=auto)  input file format, can be any of: auto, asc, xyz,
                              tiff
  --output arg                output filename
  --output-format arg (=auto) output file format, can be any of: auto, obj,
                              off, terrain (quantized mesh), json/geojson
  --method arg (=terra)       meshing method, valid values are: terra, zemlya and dense
  --max-error arg             (terra & zemlya) maximum geometric error
  --step arg (=1)		      (dense) grid spacing in pixels


methods:
  terra     - implements a delaunay based triangulation with point selection using a fast greedy insert mechnism
    reference: Garland, Michael, and Paul S. Heckbert. "Fast polygonal approximation of terrains and height fields." (1995).
    paper: https://mgarland.org/papers/scape.pdf
    and http://mgarland.org/archive/cmu/scape/terra.html
  zemlya    - hierarchical greedy insertion
    reference: Zheng, Xianwei, et al. "A VIRTUAL GLOBE-BASED MULTI-RESOLUTION TIN SURFACE MODELING AND VISUALIZETION METHOD." International Archives of the Photogrammetry, Remote Sensing & Spatial Information Sciences 41 (2016).
    paper: https://www.int-arch-photogramm-remote-sens-spatial-inf-sci.net/XLI-B2/459/2016/isprs-archives-XLI-B2-459-2016.pdf
  dense     - generates a simple mesh grid from the raster input by placing one vertex per pixel

For example, you can run the following command to convert "ned19_n37x75_w122x50_ca_goldengate_2010_mercator.tif" to a single big mesh, using a max-error parameter of 2.0 meters:

tin-terrain dem2tin --input /data/ned19_n37x75_w122x50_ca_goldengate_2010_mercator.tif --output /data/terrain.obj --max-error 2.0

After running this command, you should see a "terrain.obj" output file in the same directory. This OBJ file contains the generated mesh.

The max-error parameter specifies the vertical error allowance in meters, so a smaller max-error parameter results in more triangles in the output mesh, better mesh quality, and longer running time.

Creating a pyramid of mesh/TIN tiles

The dem2tintiles subcommand takes a raster heightmap as the input, and creates tiled TIN mesh for a given zoom range. The output tiles can be either in the OBJ format or in the quantized-mesh-1.0 terrain format.

You can see all available options by running tin-terrain dem2tintiles --help.

$ tin-terrain dem2tintiles --help
usage:
  tin-terrain dem2tintiles [OPTION]...

dem2tintiles options:
  --input arg                    input filename
  --output-dir arg (=./output)
  --max-zoom arg (=-1)           maximum zoom level to generate tiles for. will
                                 guesstimate from resolution if not provided.
  --min-zoom arg (=-1)           minimum zoom level to generate tiles for will
                                 guesstimate from resolution if not provided.
  --max-error arg                (terra or zemlya) max error when using
  --step arg (=1)            	 (dense) grid spacing in pixels
  --output-format arg (=terrain) output tiles in terrain (quantized mesh) or
                                 obj
  --method arg (=terra)          meshing algorithm. one of: terra, zemlya or dense

For example, you can run the following command to convert "ned19_n37x75_w122x50_ca_goldengate_2010_mercator.tif" to a pyramid of mesh tiles.

tin-terrain dem2tintiles --input /data/ned19_n37x75_w122x50_ca_goldengate_2010_mercator.tif --output-dir /data/output --min-zoom 5 --max-zoom 14 --output-format=terrain --max-error 2.0

When this command finishes running, you should see an output folder containing all the mesh tiles, organized into a pyramid of subfolders.

├── 10
│   ├── 163
│   │   ├── 627.terrain
│   │   └── 628.terrain
│   └── 164
│       ├── 627.terrain
│       └── 628.terrain
...

The folder structure follows the map tile convention: Z/X/Y.terrain.

These mesh tiles can then be easily served from a webserver and be consumed by frontend applications for purposes such as terrain visualization.

Sample Datasets

When you enable the TNTN_TEST and TNTN_DOWNLOAD_DEPS options in the CMake configuration, a few sample datasets will be downloaded into the ${CMAKE_SOURCE_DIR}/3rdparty/ folder.

For example, you will find the crater lake dataset in the ${CMAKE_SOURCE_DIR}/3rdparty/craterlake folder. This dataset is created and maintained by the U.S. Geological Survey (USGS) and can be downloaded from http://oe.oregonexplorer.info/craterlake/.

To generate a mesh from this dataset, you need to reproject it to the Web Mercator projection first, using the gdalwarp command-line tool which comes with your GDAL installation:

gdalwarp -t_srs EPSG:3857 -r cubic -of GTiff -ot Float32 dems_10m.dem dems_10m.tif

Then you can run tin-terrain on this reprojected GeoTIFF file to create a mesh:

./tin-terrain dem2tin --input dems_10m.tif --output terrain.obj --max-error 2.0 --method terra

License

Copyright (C) 2018 HERE Europe B.V.

See the LICENSE file in the root of this project for license details.

Papers

Some algorithms are based on ideas from:

tin-terrain's People

Contributors

adrpar avatar apoluektov avatar cleeus avatar delfrrr avatar fester avatar heremaps-bot avatar morishuz avatar nicolasneubauer avatar sschuberth avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

tin-terrain's Issues

dem2tintiles layer.json missing

AFAIK, when it comes to tiles, there is a file with the metadata. For example, while we tile a raster, there is always a layer.json file that gets used by OL or Cesium initially. But the dem2tintiles does not create that file. Is that intended or am I missing something?

Mesh2Raster::rasterise does costly calculations for a DEBUG message

#if true
// count empty pixels
// i.e. where rendere hasn't been able to add height
int countempty = 0;
double ndv = raster.get_no_data_value();
for(int r = 2; r < raster.get_height() - 2; r++)
{
double* pH = raster.get_ptr(r);
for(int c = 2; c < raster.get_width() - 2; c++)
{
if(pH[c] == ndv)
{
countempty++;
}
}
}
if(countempty > 0)
{
TNTN_LOG_WARN("{} empty pixel ", countempty);
}
#endif

This #if true block looks like debug code and it seems to serve no other purpose than creating a debug message. I think we can do without it.

Terrain shadow

Unless I'm wrong. The Cesium.SceneMode.SCENE3D is not supported because the normal are not included in the tiles? Do you plan to add normal / allow shadow / SCENE3D?

Tiling issues

There are some issues with tile boundaries:

  1. in certain circumstances border vertices are not shared with neighbouring tiles - causing discontinuities between tiles.
    screen shot 2018-09-04 at 18 52 29

  2. tiling code can produce extra vertices with spacings much less than original terrain raster (amongst other things causing severe issues when save with quantised mesh methods). To understand the scale: in this image the grey square regions are pixels!
    screen shot 2018-09-04 at 19 00 07

please note: some of these issues may be fixed now, but either way we should have a test to measure tile boundary continuity and multiple polygons per pixel problems.

also, to visualise this i had to write specialised code (export geojson meshes in correct coordinates) but we should eventually add this as a debug option to the tiling "dem2tiles" subcommand.

create quantized-mesh of obj-mesh

is it possible to create a quantized-mesh from obj geometry?
does not work((
tin-terrain dem2tin --input E:/test_terrain/Tin-Terrain/data/my3857.xyz --input-format xyz --output E:/test_terrain/Tin-Terrain/data/ttt.terrain --output-format terrain --max-error 2.0

ERROR 4: `E:/test_terrain/Tin-Terrain/data/my3857.xyz' not recognized as a supported file format.

image

meshing should have a --max-faces parameter

Renderers are facing practical limitations for the number of triangles they can render per scene. Instead of tuning the --max-error parameter until that limit is met, we should add a --max-faces parameter that guarantees a maximum number of faces per tile/dem.

Both terra and zemlya can trivially be extended to stop increasing the number of faces when a certain number is reached.

tiling zoom lvl -1 fails

Creating tile: 0,1
after clipping: 167 triangles in tile
writer log: {
        "QuantizedMeshHeader_start": 0
        "VertexData_vertexCount_start": 88
        "VertexData_vertexCount": 123
        "VertexData_u_start": 92
        "VertexData_v_start": 338
        "VertexData_height_start": 584
        "IndexData_bits": 16
        "IndexData_triangleCount_start": 830
        "IndexData_triangleCount": 167
        "IndexData_indices_start": 834
}

Processing zoom level -1, raster size 113x150
ERROR cmd.cpp:211 zero partitions in zoom level, skipping

with the given dataset

PS C:\dev\tin-terrain> docker run --rm -v c:/geoids:/data geodata/gdal gdalinfo egm2008-1-wgs84.tif
Driver: GTiff/GeoTIFF
Files: egm2008-1-wgs84.tif
Size is 14558, 19269
Coordinate System is:
PROJCS["WGS 84 / Pseudo-Mercator",
    GEOGCS["WGS 84",
        DATUM["WGS_1984",
            SPHEROID["WGS 84",6378137,298.257223563,
                AUTHORITY["EPSG","7030"]],
            AUTHORITY["EPSG","6326"]],
        PRIMEM["Greenwich",0,
            AUTHORITY["EPSG","8901"]],
        UNIT["degree",0.0174532925199433,
            AUTHORITY["EPSG","9122"]],
        AUTHORITY["EPSG","4326"]],
    PROJECTION["Mercator_1SP"],
    PARAMETER["central_meridian",0],
    PARAMETER["scale_factor",1],
    PARAMETER["false_easting",0],
    PARAMETER["false_northing",0],
    UNIT["metre",1,
        AUTHORITY["EPSG","9001"]],
    AXIS["X",EAST],
    AXIS["Y",NORTH],
    EXTENSION["PROJ4","+proj=merc +a=6378137 +b=6378137 +lat_ts=0.0 +lon_0=0.0 +x_0=0.0 +y_0=0 +k=1.0 +units=m +nadgrids=@null +wktext +no_defs"],
    AUTHORITY["EPSG","3857"]]
Origin = (-20037504.039667639881372,26520631.129502959549427)
Pixel Size = (2752.732241633115791,-2752.732241633115791)
Metadata:
  AREA_OR_POINT=Area
  TIFFTAG_IMAGEDESCRIPTION=VERT_DATUM["EGM2008 geoid",2005,AUTHORITY["EPSG","1027"]]
Image Structure Metadata:
  INTERLEAVE=BAND
Corner Coordinates:
Upper Left  (-20037504.040,26520631.130) (179d59'59.86"W, 88d12'29.40"N)
Lower Left  (-20037504.040,-26521766.435) (179d59'59.86"W, 88d12'30.55"S)
Upper Right (20036771.934,26520631.130) (179d59'36.19"E, 88d12'29.40"N)
Lower Right (20036771.934,-26521766.435) (179d59'36.19"E, 88d12'30.55"S)
Center      (    -366.053,    -567.653) (  0d 0'11.84"W,  0d 0'18.36"S)
Band 1 Block=14558x1 Type=Float32, ColorInterp=Gray
  NoData Value=-32767
  Unit Type: metre

using the following command

docker run --rm -v c:/geoids:/data earthml/tin-terrain tin-terrain dem2tintiles --input /data/egm2008-1-wgs84.tif --output-dir /data/egm2008-1-tiles --max-error 2.0 --output-format terrain

Support edges input as constraints

It would be great if the triangulation could support user-supplied vector lines as constraints for the triangulation. These are sometimes available as high quality lines gathered in surveying.

For example for Hamburg, Germany there is a DEM as regular raster: http://suche.transparenz.hamburg.de/dataset/digitales-hohenmodell-hamburg-dgm-15

And an accompanying "Bruchkanten" file where specific known "hard" edges in the terrain were drawn: http://suche.transparenz.hamburg.de/dataset/bruchkanten-hamburg8?forceWeb=true (eww, dxf and lots of layers, I mean the B_Boeschungen_curve_ here).

Those edges are more realistic than what any algorithm could ever dream of from a regular raster.

Candidate error wnat to push a solution

I ported this project to c# and found a small error that makes the code skip candidates i some cases. I tried to make a brach and push suggested changes but it seems I dont have permission. How do I get to push suggested changes?

Got the following error while installing

I'm running it on a Linux.

$ cmake -DCMAKE_BUILD_TYPE=Release path/to/sourcecode/
CMake Error: The source directory "/home/xxxxx/projects/tin-terrain/build-cmake-release/path/to/sourcecode" does not appear to contain CMakeLists.txt.
Specify --help for usage, or press the help button on the CMake GUI.

Changed the cmake path then got the following error:

$ cmake -DCMAKE_BUILD_TYPE=Release ..
-- file /home/xxxxx/projects/tin-terrain/3rdparty/libfmt-5.1.0.tar.gz already downloaded and unpacked, not doing anything
-- file /home/xxxxx/projects/tin-terrain/3rdparty/libglm-0.9.9.0.tar.gz already downloaded and unpacked, not doing anything
-- file /home/xxxxx/projects/tin-terrain/3rdparty/Catch2-2.3.0/catch.hpp already downloaded and unpacked, not doing anything
-- CMake version: 3.22.1
-- Version: 5.1.0
-- Build type: Release
-- CXX_STANDARD: 14
-- Configuring done
CMake Error in CMakeLists.txt:
  Imported target "Boost::program_options" includes non-existent path

    "/include"

  in its INTERFACE_INCLUDE_DIRECTORIES.  Possible reasons include:

  * The path was deleted, renamed, or moved to another location.

  * An install or uninstall procedure did not complete successfully.

  * The installation package was faulty and references files it does not
  provide.



CMake Error in CMakeLists.txt:
  Imported target "Boost::program_options" includes non-existent path

    "/include"

  in its INTERFACE_INCLUDE_DIRECTORIES.  Possible reasons include:

  * The path was deleted, renamed, or moved to another location.

  * An install or uninstall procedure did not complete successfully.

  * The installation package was faulty and references files it does not
  provide.

Proposal for fixing tile boundary continuity issues

I propose a new way to generate mesh tiles. Rather than having overlapping regions and cropping them to size, we should generate meshes from raster tiles that do not overlap (faster, simpler). then in a second step we insert points between the two tiles, at regular intervals at a sub pixel position, and add them to both of the adjacent meshes. These would be overlapping vertices, with identical height and position in both adjacent tiles. This guarantees continuity of the mesh and is simple to implement. The only slight drawback would be the need to update the edges in the mesh in a second step.

  1. generate TIN mesh for each raster tile separately and independently
    screen shot 2018-09-28 at 13 36 54

  2. place vertices on midpoint between tiles. the height for each vertex is computed directly from the raster values (average between two cells etc). the vertices shown here in red are for the boundary between blue and green tiles. obviously this needs to be repeated for all boundaries between all tiles
    screen shot 2018-09-28 at 13 37 01

  3. update edges for each mesh to accommodate new vertices.
    screen shot 2018-09-28 at 13 37 11

Error while building and installing

error: parameter declared ‘auto’
std::for_each(begin, end, [this](const auto& v) { add(v); });
error: ‘v’ was not declared in this scope
std::for_each(begin, end, [this](const auto& v) { add(v); });
error: ‘make_unique’ is not a member of ‘std’
TileMaker() : m_mesh(std::make_unique()) {}
error: expected primary-expression before ‘>’ token
TileMaker() : m_mesh(std::make_unique()) {}
error: expected primary-expression before ‘)’ token
TileMaker() : m_mesh(std::make_unique()) {}

Tin-terrain running from cmd

Hi!
I want to run tin terrain directly from cmd without docker installation. Is it possible? dem2tin, how do I run it? Like cmd c: dem2tin...whats the code line?
Best regards, Tobias

Valid Quantized Mesh Header?

I'm new to this stuff so apologies if this is user error or misunderstanding...

The coordinate values in the quantized mesh header seem off. The quantized-mesh spec says coordinate values should be in earth-centered fixed coordinates. Given that, I'd expect the magnitude of the center point to be a value close to the radius of the earth, but that doesn't seem to be the case.

As an example I ran dem2tintiles on the craterlake dem dataset.

The resulting header for tile 6/10/40.terrain looks like:

{
  "centerX": -13462700.917811524,
  "centerY": 5322463.153553393,
  "centerZ": 1331.456658194813,
  "minHeight": 1130.3309326171875,
  "maxHeight": 1532.5823974609375,
  "boundingSphereCenterX": -13462700.917811524,
  "boundingSphereCenterY": 5322463.153553393,
  "boundingSphereCenterZ": 1331.456658194813,
  "boundingSphereRadius": 885541.1267042665,
  "horizonOcclusionPointX": -13462700.917811524,
  "horizonOcclusionPointY": 5322463.153553393,
  "horizonOcclusionPointZ": 1532.5824073771364
}

which means the resulting magnitude for the center point is 14476633.994 which seems way off from the earth radius of 6378137

CMake might find wrong GDAL library

There is an issue with the cmake provided FindGDAL.cmake script (see https://gitlab.kitware.com/cmake/cmake/issues/17771, even though they claim things are fixed, they are not).

The issue mainly is, that FindGDAL determines the right location of the GDAL library though gdal-config, however fails to use the insights gained from that procedure. It is then using find_library to search for gdal again, and then obviously derails...

The best would be to fix the FindGDAL.cmake file or provide our own in the repository. However for the moment, I propose to just update the README file accordingly (see my PR).

single quantized mesh from tiff

Is it possible to use dem2tin to create a single quantized mesh file using a tiff input?

Whenever I run dem2tin with the option --output-format terrain it fails:

./tin-terrain dem2tin --input baty.tif --output bathy.terrain
  --input-format tiff --output-format terrain --method terra
subcommand_dem2tin
Opening raster file baty.tif with GDAL...
reading raster data...
done
performing terra meshing...
starting greedy insertion with raster width: 1386, height: 1421
initialize the mesh with four corner points
finished greedy insertion
done
time for meshing step: 0.365798 sec = 0.00609663 minutes
number of triangles: 41894
number of vertices: 20950
writing mesh... (bathy.terrain)
ERROR QuantizedMeshIO.cpp:327 Mesh has to be triangulated in order to be written as QM
ERROR cmd.cpp:453 error writing output file

When I choose to output an .obj file instead it works fine and if I manually inspect the resulting mesh it looks perfectly triangulated. The error message is confusing since the meshing process seem to work. I tried all methods and multiple inputs including the example files from your readme. I also ran gdalwarp to transform my data into the correct projection.

dem2tintiles is producing valid quantized meshes on the same .tiff files.

Any help would be appreciated!

static linking with cmake (MacOS)

Hi,
is it possible to build the binary tin-terrain with static linking? I would like to easily share this program between machines. Currently this requires installing all the dependencies. It would be very helpful if one could just copy the executable. I work in MacOS but I guess this is not OS dependent. Can this be done with some tweakings of cmake flags?

Note If others run into the same issue: There is a workaround possible which I currently use:
copy all dependencies to some new dir on the build machine:

mkdir <somedir>
cd <somedir>
cp /usr/local/opt/gdal/lib/libgdal.20.dylib .
cp /usr/local/opt/[email protected]/lib/libcrypto.1.1.dylib .
cp /usr/local/opt/proj/lib/libproj.15.dylib .
cp /usr/local/opt/json-c/lib/libjson-c.4.dylib .
cp /usr/local/opt/freexl/lib/libfreexl.1.dylib .
cp /usr/local/opt/geos/lib/libgeos_c.1.dylib .
cp /usr/local/opt/webp/lib/libwebp.7.dylib .
cp /usr/local/opt/epsilon/lib/libepsilon.1.dylib .
cp /usr/local/opt/sqlite/lib/libsqlite3.0.dylib .
cp /usr/local/opt/unixodbc/lib/libodbc.2.dylib .
cp /usr/local/opt/unixodbc/lib/libodbcinst.2.dylib .
cp /usr/local/opt/expat/lib/libexpat.1.dylib .
cp /usr/local/opt/xerces-c/lib/libxerces-c-3.2.dylib .
cp /usr/local/opt/jasper/lib/libjasper.4.dylib .
cp /usr/local/opt/netcdf/lib/libnetcdf.15.dylib .
cp /usr/local/opt/hdf5/lib/libhdf5.103.dylib .
cp /usr/local/opt/giflib/lib/libgif.dylib .
cp /usr/local/opt/jpeg/lib/libjpeg.9.dylib .
cp /usr/local/opt/libgeotiff/lib/libgeotiff.5.dylib .
cp /usr/local/opt/libtiff/lib/libtiff.5.dylib .
cp /usr/local/opt/libpng/lib/libpng16.16.dylib .
cp /usr/local/opt/cfitsio/lib/libcfitsio.8.dylib .
cp /usr/local/opt/libpq/lib/libpq.5.dylib .
cp /usr/local/opt/zstd/lib/libzstd.1.dylib .
cp /usr/local/opt/xz/lib/liblzma.5.dylib .
cp /usr/local/opt/libdap/lib/libdap.25.dylib .
cp /usr/local/opt/libdap/lib/libdapserver.7.dylib .
cp /usr/local/opt/libdap/lib/libdapclient.6.dylib .
cp /usr/local/opt/libspatialite/lib/libspatialite.7.dylib .
cp /usr/local/opt/pcre/lib/libpcre.1.dylib .
cp /usr/local/opt/libxml2/lib/libxml2.2.dylib .

Transfer somedir to the new machine. And then use the following the script:

export DYLD_FALLBACK_LIBRARY_PATH=<somedir>
./tin-terrain $*

This is only for Mac and of course it is really ugly. It will break with any change in the dependency chain.

P.S. This is really a great tool! Thanks for sharing it.

dem2tin failure w/o actionable error msg

I downloaded tin-terrain today and built the Docker image on my Mac.

When I run dem2tin, I see the following failure:

root@f481e479e8a9:/home# tin-terrain dem2tin --input /data/LMI_Haedarlikan_DEM_16bit/LMI_Haedarlikan_DEM_16bit-Mercator.tif --output /data/LMI_Haedarlikan_DEM_16bit/test.obj
subcommand_dem2tin
Opening raster file /data/LMI_Haedarlikan_DEM_16bit/LMI_Haedarlikan_DEM_16bit-Mercator.tif with GDAL...
reading raster data...
Killed
root@f481e479e8a9:/home#

My dataset:

root@f481e479e8a9:/home# gdalinfo /data/LMI_Haedarlikan_DEM_16bit/LMI_Haedarlikan_DEM_16bit-Mercator.tif
Driver: GTiff/GeoTIFF
Files: /data/LMI_Haedarlikan_DEM_16bit/LMI_Haedarlikan_DEM_16bit-Mercator.tif
Size is 56541, 39914
Coordinate System is:
PROJCS["WGS 84 / Pseudo-Mercator",
GEOGCS["WGS 84",
DATUM["WGS_1984",
SPHEROID["WGS 84",6378137,298.257223563,
AUTHORITY["EPSG","7030"]],
AUTHORITY["EPSG","6326"]],
PRIMEM["Greenwich",0,
AUTHORITY["EPSG","8901"]],
UNIT["degree",0.0174532925199433,
AUTHORITY["EPSG","9122"]],
AUTHORITY["EPSG","4326"]],
PROJECTION["Mercator_1SP"],
PARAMETER["central_meridian",0],
PARAMETER["scale_factor",1],
PARAMETER["false_easting",0],
PARAMETER["false_northing",0],
UNIT["metre",1,
AUTHORITY["EPSG","9001"]],
AXIS["X",EAST],
AXIS["Y",NORTH],
EXTENSION["PROJ4","+proj=merc +a=6378137 +b=6378137 +lat_ts=0.0 +lon_0=0.0 +x_0=0.0 +y_0=0 +k=1.0 +units=m +nadgrids=@null +wktext +no_defs"],
AUTHORITY["EPSG","3857"]]
Origin = (-2764161.621573575772345,10052026.112180622294545)
Pixel Size = (23.488512876275621,-23.488512876275621)
Metadata:
AREA_OR_POINT=Area
DataType=Generic
Image Structure Metadata:
INTERLEAVE=BAND
Corner Coordinates:
Upper Left (-2764161.622,10052026.112) ( 24d49'51.19"W, 66d37'55.54"N)
Lower Left (-2764161.622, 9114505.609) ( 24d49'51.19"W, 63d 3'29.08"N)
Upper Right (-1436097.615,10052026.112) ( 12d54' 2.46"W, 66d37'55.54"N)
Lower Right (-1436097.615, 9114505.609) ( 12d54' 2.46"W, 63d 3'29.08"N)
Center (-2100129.618, 9583265.861) ( 18d51'56.83"W, 64d54'16.26"N)
Band 1 Block=56541x1 Type=Int16, ColorInterp=Gray
NoData Value=-10000
Metadata:
BandName=Band_1
SourceBandIndex=0
root@f481e479e8a9:/home#

Since I downloaded rather than cloned, not much here. But I did this today:

root@f481e479e8a9:/home# tin-terrain version
name: tin-terrain
copyright_notice: Copyright (C) 2018 HERE Europe B.V.
git_description:
git_hash:
build_timestamp: 20181130T2116Z
root@f481e479e8a9:/home#

I've tried the verbose switch and the log option, but there is no additional information to help me decide what to try next. Any suggestions would be much appreciated.

Setup CI with Travis

  • build a docker image
  • check formatting (clang-format)
  • build with clang (release/debug)
  • build with gcc (release/debug)
  • build with fsanitize

Tile coordinate scheme

Hi thanks for the great work with tin-terrain! I am just a bit confused as to how the tile indices are calculated. The X and Z coordinates seem to match up with with the OSM spec but the Y coord does not align. Is it possible that I have just done something wrong in the generation of my tiles? I reprojected my DEM raster to 3857, and then ran the tin-terrain tool as instructed in the README. Thanks in advance for any guidance!

If it helps, I am trying to load terrain mesh tiles and render them with deck.gl.

Corners are inserted in the output mesh even if they are no data values

I tried to transform a DEM from HiRise data which is distributed as GTiff format. The input DEM is available here.
This file includes several no-data value points which include the four corners of the raster DEM and dem2tin seems to add to the output obj the four corners even if these are no-data values.

The following is the output of the program after processing the DEM:
image

"Killed" ... Memory usage?

I'm trying to run dem2tintiles via docker and see the message "Killed" very quickly when I run dem2tintiles on a fairly normal (16GB RAM) Windows PC:

`

docker run -v e::/data:cached --name tin-terrain --rm -m 8g --memory-swap 128g --oom-kill-disable -i -t tin-terrain bash
`

root@364d9c5d1d3a:/home# /usr/local/bin/tin-terrain dem2tintiles --input /data/merit.tif --output-dir /data/output --min-zoom 5 --max-zoom 14 --output-format=terrain --max-error 2.0 Opening raster file /data/merit.tif with GDAL... reading raster data... Killed

My image is large (500gB):
`

gdalinfo merit.tif
Driver: GTiff/GeoTIFF
Files: merit.tif
merit.tif.ovr
Size is 432000, 305835
Coordinate System is:
PROJCS["WGS 84 / Pseudo-Mercator",
...
Band 1 Block=256x256 Type=Float32, ColorInterp=Gray
NoData Value=-9999
Overviews: 108000x76459, 27000x19115, 6750x4779, 1688x1195
`

I believe that I'm running out of memory, but what sort of memory usage should I expect? Is there any sort of DEM 'windowing' to limit memory usage? Is there another way to organize my data differently to not require absurd amounts of memory?

Obj file not viewable in blender

The obj file that is created from dem2tin is not view able in blender. Is there some reason that this would be the case? The original tif file depth map imports just fine as a DEM in BlenderGIS.

Can this program run on the ubuntu16.04?

When i run this project on ubuntu18.04,it can finish.But when i run it on ubuntu16.04 will occur this error:
IMG_20191120_150830
I am so grateful if someone can tell me how to handle.

Compilation problem

Hello:

I am trying to compile the sources following the instructions on a 18.04 linux server machine with gdal 2.2.3 installed. This is the error:

[ 52%] Building CXX object CMakeFiles/tntn.dir/src/RasterIO.cpp.o
/usr/bin/c++ -DGLM_ENABLE_EXPERIMENTAL -DGLM_FORCE_SWIZZLE -I/mnt/data1/srtm30/tin-terrain-master/3rdparty/glm-0.9.9.0 -I/mnt/data1/srtm30/tin-terrain-master/include -I/usr/include/gdal -I/mnt/data1/srtm30/tin-terrain-master/3rdparty/fmt-5.1.0/include -O3 -DNDEBUG -std=gnu++14 -o CMakeFiles/tntn.dir/src/RasterIO.cpp.o -c /mnt/data1/srtm30/tin-terrain-master/src/RasterIO.cpp
/mnt/data1/srtm30/tin-terrain-master/src/RasterIO.cpp: In function ‘bool tntn::is_valid_projection(GDALDataset*)’:
/mnt/data1/srtm30/tin-terrain-master/src/RasterIO.cpp:290:44: error: no matching function for call to ‘OGRSpatialReference::importFromWkt(const char*&)’
raster_srs.importFromWkt(projection_wkt);
^
In file included from /mnt/data1/srtm30/tin-terrain-master/src/RasterIO.cpp:14:0:
/usr/include/gdal/ogr_spatialref.h:185:17: note: candidate: OGRErr OGRSpatialReference::importFromWkt(char**)
OGRErr importFromWkt( char ** );
^~~~~~~~~~~~~
/usr/include/gdal/ogr_spatialref.h:185:17: note: no known conversion for argument 1 from ‘const char*’ to ‘char**’
/mnt/data1/srtm30/tin-terrain-master/src/RasterIO.cpp:316:24: error: ‘class OGRSpatialReference’ has no member named ‘FindMatches’
raster_srs.FindMatches(NULL, &matches_number, NULL);
^~~~~~~~~~~
/mnt/data1/srtm30/tin-terrain-master/src/RasterIO.cpp:335:9: error: ‘OSRFreeSRSArray’ was not declared in this scope
OSRFreeSRSArray(matched_projections);
^~~~~~~~~~~~~~~
CMakeFiles/tntn.dir/build.make:470: recipe for target 'CMakeFiles/tntn.dir/src/RasterIO.cpp.o' failed
make[3]: *** [CMakeFiles/tntn.dir/src/RasterIO.cpp.o] Error 1
make[3]: Leaving directory '/mnt/data1/srtm30/tin-terrain-master/build'
CMakeFiles/Makefile2:67: recipe for target 'CMakeFiles/tntn.dir/all' failed
make[2]: *** [CMakeFiles/tntn.dir/all] Error 2
make[2]: Leaving directory '/mnt/data1/srtm30/tin-terrain-master/build'
CMakeFiles/Makefile2:117: recipe for target 'CMakeFiles/tin-terrain.dir/rule' failed
make[1]: *** [CMakeFiles/tin-terrain.dir/rule] Error 2
make[1]: Leaving directory '/mnt/data1/srtm30/tin-terrain-master/build'
Makefile:131: recipe for target 'tin-terrain' failed
make: *** [tin-terrain] Error 2

No idea what is the problem... please help
Thanks

Build Error - caused by 'no release file' error

Running build-docker.sh results in the following output:

Sending build context to Docker daemon 10.44 MB
Step 1/18 : FROM ubuntu:18.10
 ---> 9dc19675e327
Step 2/18 : RUN apt-get update
 ---> Running in 17c69c3ada81

Ign:1 http://archive.ubuntu.com/ubuntu cosmic InRelease
Ign:2 http://security.ubuntu.com/ubuntu cosmic-security InRelease
Ign:3 http://archive.ubuntu.com/ubuntu cosmic-updates InRelease
Err:4 http://security.ubuntu.com/ubuntu cosmic-security Release
  404  Not Found [IP: 91.189.88.142 80]
Ign:5 http://archive.ubuntu.com/ubuntu cosmic-backports InRelease
Err:6 http://archive.ubuntu.com/ubuntu cosmic Release
  404  Not Found [IP: 91.189.88.142 80]
Err:7 http://archive.ubuntu.com/ubuntu cosmic-updates Release
  404  Not Found [IP: 91.189.88.142 80]
Err:8 http://archive.ubuntu.com/ubuntu cosmic-backports Release
  404  Not Found [IP: 91.189.88.142 80]
Reading package lists...
E: The repository 'http://security.ubuntu.com/ubuntu cosmic-security Release' does not have a Release file.
E: The repository 'http://archive.ubuntu.com/ubuntu cosmic Release' does not have a Release file.
E: The repository 'http://archive.ubuntu.com/ubuntu cosmic-updates Release' does not have a Release file.
E: The repository 'http://archive.ubuntu.com/ubuntu cosmic-backports Release' does not have a Release file.
The command '/bin/sh -c apt-get update' returned a non-zero code: 100

I was able to build the image successfully by replacing line 1 in Dockerfile with "FROM ubuntu" (just removed the versioning). Is this an error from my end, or is this something that needs to be updated in the repository?

Segfault in GDALCopyWord on big GeoTIFF

On a 68036x65743 GeoTIFF I got the following error:

$ gdb --args ./tin-terrain dem2tin --method terra --max-error 10 --input /tmp//DGM1_2x2KM_XYZ_HH_2018_01_17_3857_p2deflate.tif --output /tmp/test.obj
GNU gdb (GDB) 8.2
Copyright (C) 2018 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.
Type "show copying" and "show warranty" for details.
This GDB was configured as "x86_64-pc-linux-gnu".
Type "show configuration" for configuration details.
For bug reporting instructions, please see:
<http://www.gnu.org/software/gdb/bugs/>.
Find the GDB manual and other documentation resources online at:
    <http://www.gnu.org/software/gdb/documentation/>.

For help, type "help".
Type "apropos word" to search for commands related to "word"...
Reading symbols from ./tin-terrain...done.
(gdb) run
Starting program: /tmp/tools/tin-terrain/build-cmake-release/tin-terrain dem2tin --method terra --max-error 10 --input /tmp//DGM1_2x2KM_XYZ_HH_2018_01_17_3857_p2deflate.tif --output /tmp/test.obj
[Thread debugging using libthread_db enabled]
Using host libthread_db library "/usr/lib/libthread_db.so.1".
subcommand_dem2tin
DEBUG gdal_init.cpp:14 calling GDALAllRegister...
Opening raster file /tmp//DGM1_2x2KM_XYZ_HH_2018_01_17_3857_p2deflate.tif with GDAL...
reading raster data...

Program received signal SIGSEGV, Segmentation fault.
0x00007ffff760ba9f in GDALCopyWord (dfValueOut=@0x7fffec731710: 6.68388536893727e-265, fValueIn=<optimized out>) at gdal_priv_templates.hpp:173
173	gdal_priv_templates.hpp: No such file or directory.
(gdb) bt
#0  0x00007ffff760ba9f in GDALCopyWord (dfValueOut=@0x7fffec731710: 6.68388536893727e-265, fValueIn=<optimized out>) at gdal_priv_templates.hpp:173
#1  (anonymous namespace)::GDALCopyWordsGenericT<float, double> (nWordCount=<optimized out>, nDstPixelStride=<optimized out>, pDstData=<optimized out>, 
    nSrcPixelStride=<optimized out>, pSrcData=<optimized out>) at rasterio.cpp:1960
#2  (anonymous namespace)::GDALCopyWordsT<float, double> (nWordCount=<optimized out>, nDstPixelStride=<optimized out>, pDstData=<optimized out>, 
    nSrcPixelStride=<optimized out>, pSrcData=<optimized out>) at rasterio.cpp:1973
#3  (anonymous namespace)::GDALCopyWordsFromT<float> (pSrcData=<optimized out>, nSrcPixelStride=4, bInComplex=<optimized out>, pDstData=<optimized out>, 
    eDstType=<optimized out>, nDstPixelStride=8, nWordCount=256) at rasterio.cpp:2607
#4  0x00007ffff76138b0 in GDALRasterBand::IRasterIO (this=this@entry=0x555555851f70, eRWFlag=eRWFlag@entry=GF_Read, nXOff=<optimized out>, nXOff@entry=0, 
    nYOff=<optimized out>, nYOff@entry=0, nXSize=<optimized out>, nXSize@entry=68036, nYSize=<optimized out>, nYSize@entry=65743, pData=0x7fff9794c010, 
    nBufXSize=68036, nBufYSize=65743, eBufType=GDT_Float64, nPixelSpace=8, nLineSpace=544288, psExtraArg=0x7fffffffd5b0) at rasterio.cpp:416
#5  0x00007ffff727daec in GTiffRasterBand::IRasterIO (this=0x555555851f70, eRWFlag=GF_Read, nXOff=0, nYOff=0, nXSize=68036, nYSize=65743, pData=0x7fff9794c010, 
    nBufXSize=68036, nBufYSize=65743, eBufType=GDT_Float64, nPixelSpace=8, nLineSpace=544288, psExtraArg=0x7fffffffd5b0) at geotiff.cpp:4222
#6  0x00007ffff75f591d in GDALRasterBand::RasterIO (this=0x555555851f70, eRWFlag=GF_Read, nXOff=0, nYOff=0, nXSize=68036, nYSize=<optimized out>, 
    pData=0x7fff9794c010, nBufXSize=68036, nBufYSize=65743, eBufType=GDT_Float64, nPixelSpace=8, nLineSpace=544288, psExtraArg=0x7fffffffd5b0)
    at gdalrasterband.cpp:361
#7  0x00005555557102f4 in tntn::load_raster_file (
    file_name="/tmp/DGM1_2x2KM_XYZ_HH_2018_01_17_3857_p2deflate.tif", target_raster=..., validate_projection=false) at /tmp/tools/tin-terrain/src/RasterIO.cpp:384
#8  0x0000555555676b10 in tntn::subcommand_dem2tin (need_help=false, global_varmap=..., unrecognized=std::vector of length 8, capacity 16 = {...})
    at /tmp/tools/tin-terrain/src/cmd.cpp:351
#9  0x0000555555679e01 in tntn::tin_terrain_commandline_action (args=std::vector of length 9, capacity 16 = {...})
    at /tmp/tools/tin-terrain/src/cmd.cpp:763
#10 0x000055555567a6f0 in main (argc=10, argv=0x7fffffffe078) at /tmp/tools/tin-terrain/src/cmd.cpp:799
(gdb) 

If I scale it to 10% (6804x6574) it works fine.

Tiling Issue - No Zoom Level 1 or 0

Using a freely available height DEM from Earth Explorer (ASTGTM2_S37E148_dem) - dem2tintiles results in a truncated set of zoom levels. Level 1 results in the message below, no level 0 is generated.

after clipping: 0 triangles in tile
WARN cmd.cpp:206 raster on zoom level 0 empty, cannot create tiles, proceeding...

Zoom levels 2-6 are only generated if I force them by setting "max-zoom".
ASTGTM2_S37E148_dem.tif.zip

Maintenance

Hi there, we are planning on making production use of this library as a core component in our stack for a new project. We have a few small patches ready to go and submitted a first PR a month ago which has confirmation from another user that it solves an issue they raised earlier.

Since we think this is a high-quality library but appears to not be a priority for you guys at heremaps with the last commit coming a year ago, we would like to suggest taking over its maintenance. Would you be interested in transferring ownership of the repo to us or a new org with shared ownership?

In the meantime we will be maintaining a fork at https://github.com/cognitive-earth/tin-terrain and will start looking at the PRs and Issues from this repo soon. Anyone else is encouraged to create PRs and Issues over at our repo for the moment :)

No layers.json

In order for CesiumJS to work, I've found it needs a layers.json file to know what tiles are available, their details, projection, etc. This is not produced by dem2tintiles.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.