Reply To: Terrian model?

Home Forums AR Sandbox Forum Terrian model? Reply To: Terrian model?


Hi, all!

I’ve been working with the AR Sandbox version 2.3 and having some fun with DEM files.
It’s time to share what I’ve been doing and let you all have some fun too.

I’ve been able to use topography files from aerial LiDar surveys and create grid files from them.
The grid files are in the format that the AR Sandbox will read. It has worked well so far, but I have not tested it exhaustively.
You are welcome to try this too, with the caveat that it’s not perfect and may not always work.

First, below is the text of a simple C++ program to create a “grid” file from real DEM data.
Copy the lines below to a text file and save it with the name “tin2grid.cpp”.

/* Start copying here */
/* This code is freely released to the public domain. */
#include <iostream>
#include <fstream>
#include <sstream>
#include <string>

using namespace std;

int main(int argc, char *argv[])
	if(argc < 3) {
		cout << "tin2grid <inputfile> <outputfile>" << endl;
		return 0;

	std::string line;
	std::string val;
 	float fval;

	std::ifstream infile(argv[1]);
	std::ofstream outfile(argv[2], ios::binary);

	//first 4 lines need to be handled carefully
	int h, w;
	getline(infile, val);
	w = stoi(val.substr(6,6));
	getline(infile, val);
	h = stoi(val.substr(6,6));

	outfile.write(reinterpret_cast<char*>(&w), sizeof(int));
	outfile.write(reinterpret_cast<char*>(&h), sizeof(int));

	float xmin, ymin, xmax, ymax;
	getline(infile, val);
	xmin = stof(val.substr(10, 40));
	getline(infile, val);
    ymin = stof(val.substr(10, 40));
    xmax = xmin + w;
    ymax = ymin + h;

    outfile.write(reinterpret_cast<char*>(&xmin), sizeof(float));
    outfile.write(reinterpret_cast<char*>(&ymin), sizeof(float));
	outfile.write(reinterpret_cast<char*>(&xmax), sizeof(float));
	outfile.write(reinterpret_cast<char*>(&ymax), sizeof(float));

	//next two lines are not needed, but we need to read them to skip them
	getline(infile, val);
    getline(infile, val);

		//skip empty lines
		stringstream ss(line);
		while(getline(ss, val, ' '))
			fval = stof(val);
			outfile.write(reinterpret_cast<char*>(&fval), sizeof(float));


	return 0;

/* Stop copying here */

After you have saved that you will need to compile it into an executable file.
You can do that at the command line, using the following:

$ g++ -std=c++11 tin2grid.cpp -o tin2grid

That will create an executable named “tin2grid”

Now to explain what it does.

You need to start with an Arc ASCII TIN file. This utility will convert it to the Sandbox “grid” format.
Here’s how to get a file to work with:

To get an Arc ASCII Grid format TIN file:
1) Open a browser and go to
2) Click “Data” in the menus at the top and choose “Lidar Point Cloud”.
3) Select a dataset from the list. The Airborne Lidar sets work nicely.
4) Use the map to zoom in on a relatively small area.
a. The area where the LiDAR data is available will be highlighted in red.
b. Zoom in on a small set of features.
5) Click the “Select a Region” button, then drag a rectangle to select an area.
6) When your rectangle is complete, look in the green highlighted area of the web page below the map. It will show you how many points are in the data for the area you selected. (If you’re using the site as a “guest” you will be limited to 50 million points of data per request. Aim for about 5 million points or less at first.)
7) In the “Choose Return Classification” section, turn off “Unclassified”. This will reduce the points somewhat.
8) In the “Point Cloud Data Download” section, select “Point cloud data in ASCII format”. (This selection is not really important, but one of the selections must be chosen. Only the TIN data will be used.)
9) In the “DEM Generation (Streaming TIN) section, leave “Calculate TIN” on, and select “Arc ASCII Grid” format in the “Grid Format” menu.
10) Enter a name for the “Job Title” (it only has to be meaningful to you), a description, and your email address.
a. These things are required so that you can get an email with links to download the data if it takes a long time to process. Turning off the “Calculate TIN” feature makes it pretty quick though, like a couple minutes in my tests.
11) Click the Submit button and wait for the process to finish.
12) You need to download the “DEM Results” that will a file named “output.tin.tar.gz”.
a. If you download on a Windows machine, you will need 7-Zip or something equivalent to open GZIP archive, and the TAR file within.
b. Copy the file to your Linux machine where you run the AR Sandbox.
c. Extract the file named “output.tin.asc” and rename it to something meaningful to you.
d. Run the tin2Grid utility to convert this to a “grid” file that the AR Sandbox software can read.
e. Invocation is: tin2grid <inputfile> <outputfile>

Hope this is helpful to you.
S. Harned

  • This reply was modified 4 years, 7 months ago by sharned.

Comments are closed.