How to smooth terrain from DEM files.

regg001

New member
Is there a tool that could smooth the terrain from a DEM file.

I have a DEM file with ''lines'' of elevation at one meter (each line goes up or down by a meter). The resolution of the file is sufficient for my needs, still at each and every line of elevation the terrain is jumping a meter (that's 3 feet +). Quite a jump for a track and the engine :D

So am looking for a tool that would smooth the terrain by progressively linking each ''step'' of elevation to the other.

Or is it already available in one of the tool i'm already using (global mapper, microdem, hog... Or can this be done when migrating the file to a TGA image ?

Here's a sample of my file - as you can see i need to smooth the terrain otherwise it's like driving on a wild horse

http://pages.infinit.net/vlnvopok/testview.gif
 
Last edited by a moderator:
regg001

Not sure if your original DEM has stepped terrain or if this is happening during the processing of it into Trainz. I had a similar problem recently - in my case the DEM (as viewed in MicroDEM) was smooth but the Trainz terrain turned out to be terraced after processing it through HOG.

The solution was to work the DEM into an ASCII-xyz file format and process that using HOG's "piglet" function. The terrace effect completely disappeared and there was no need to smooth anything in Trainz. It was a beautiful moment. Bob Pearson of this forum put me on to that.

I think I made a copy of the exact method. If I can find this in my archives again, I'll post it here if you think it would help you.

Cheers

- Deane

Edit: Here's the text from that old thread I was refering to;

1. Using MicroDEM 8.0, open the DEM file.

2. Click menu item "Info" and note the min. and max. elevations.

3. File - Save DEM - ASCII XYZ (choose a name and location to save to).

4. Ascii Export Options [choose XY Format = "UTM" and Z format = "Meters (float)". Click OK and wait while it writes the XYZ file].

5. Now using HOG, choose Tools - Convert - "ASCII XYZ to 24-bit height map".....wait while Piglet does it's thing.

6. Open the resulting psychedelic 24-bit TGA using a graphics utility (I used IrfanView).

7. Crop the image to dimensions fitting this equation;
Width (or height) in pixels = (N x 72) + 4 (where N = number of trainz baseboards).
Before cropping, you can apparently resize the TGA without damaging the data. I resized the image keeping the width to height ratio constant. I did this without resampling the image. At this stage, I don't know if resampling or changing the aspect ratio does any harm to a 24-bit height coded map.

8. Put the image in the HOG folder.

9. Open HOG again, feed in the 24-bit TGA as the elevation map and enter the min. and max. elevations noted in MicroDEM. For the record, I did not click "interpolate" at this stage. This method doesn't seem to need it.

10. Create the trainz gnd file as per normal in HOG.

One odd thing I did notice was that max and min elevations used as input via HOG were not reflected numerically in the Trainz terrain. I had to re-do steps 8 - 9, trying different elevation ranges until it came out how I wanted. Not sure what's going on with that. However the main thing is there are no "rice paddies" up the hillsides! Thanks to all contributors to this thread, I would never have figured it out without your help.

- Deane
____________________________
Deane,

You don't need to enter the elevation range as the actual height data is taken directly from the ascii dem and encoded into the 24-bit tga. AFAIK just accept what HOG displays unless you need to scale the heights for some reason.
Grey and chroma scales don't encode the actual height only a scaled value so you have to tell HOG what range to use.

Bob Pearson

PS. Image looks good. Note resizing will change the horizontal scale as the tga piglet makes is sized at 1 pixel = 10 m. I would just crop it to get the area and aspect ratio you want. Tiger or other type of vector overlays can be created in MD the same way as previous using the DEM you made the ascii xyz from. Layer them over the 24-bit height encoded tga in the paint program of choice and crop to size when you do the height file so they will align in HOG.

PPS. Interpolation option will give a smoother look to the terrain even if you start with 10m DEM. May or may not be what you're trying to achieve. For DEMS with less resolution I think I'd perfer to let MD do the interpolation by resampling on a 10m x 10m utm grid 1st since the data has to be interpolated anyhow. Personal preference to some extent but my 2 cents worth.
___________________________________
Ah, well that explains it, thanks again Bob.

It seems to me that this "Ascii-XYZ-Piglet" method is actually simpler, less error-prone and gives superior results to the Chroma color method. I like it. Less chance of getting "illegal" colored pixels (even if you resize the image) and the elevation range takes care of itself if you don't want to change from it's original value.

For those who have never seen one before, the 24-bit height coded TGA made by Piglet is very different from Chroma and Greyscale images. Here is a sample, so you'll recognize it;
xyzqm0.jpg

I did actually try the "interpolation" option at the HOG stage, but found the final terrain lost some of it's sharpness. On the other hand, it didn't do any real damage, so it seems to be a choice rather than a mandatory yes or no.

Thanks also for mentioning how to include vector data Bob. I skipped it because in this case, I intend to totally change the look of the land (imagine Oregon after 200 years of global warming has transformed it into a desert!).

Regarding resizing, yes, you would normally only need to crop. In my case, I wanted to capture all the nice topology but not end up with too big a Trainz map. I reduced the X-Y dimensions of the image by half (reduces area and filesize to one-quarter). Having done that, I also needed to reduce the Z (elevation) range by a similar factor to keep gradients the same. This seems to require some trial and error. If you are not changing elevation range, leave HOG at its default values (-1000m and +9000m) before making the gnd file.
OK, now I only have 1254 baseboards to texture.
 
Last edited:
I guess these are two different effects.

Many DEMs have an internal vertical resolution of 1 m. Even the Canadian CDED 0.75 arc sec do. Normally this is not a big issue, as all the Trainz terrain creation tools HOG, MapMaker or TransDEM apply interpolation (bilinear filtering). The kind of terracing shown in the image will not appear in Trainz terrain. There might be another noticeable effect but I'll come to this later.

The more important aspect is terracing produced by HOG, caused by limited input data value range as provided by MicroDEM. That's what Deane is talking about. HOG takes the height values form a tga file. A tga file represents a colour image, and a colour value represents a height. The MicroDEM/HOG process uses colour models with a predefined number of colours and this number is limited. Depending on the colour model chosen it can reach a maximum of 255, IIRC. It means that there are only 255 different height values at most. Hence, any terrain exceeding the height range of 255 meters is subject to a lossy conversion.

HOG offers an alternate format, its private 24bit tga interpretation. The "piglet" is HOG's own tool for creating this format but requires xyz data as input. In earlier versions of TransDEM, I also created this format. The 24bit format has a vertical resolution of 1 mm which explains why there will be no terracing any more.

You may still notice a different effect particularly in flat terrain, a certain unevenness. Assume you have a flat area at the elevation of 33.5 metres. The 1 m resolution DEM data here can only take values of either 33.0 or 34.0 m and in practice it will toggle between them. For a 20 m horizontal resolution like CDED jumps of 1 m are quite unpleasant. This noticeable effect is called "quantisation noise". It can be treated with low pass filtering, i.e. smoothing. HOG has an option here (which I never tested). MapMaker does it quite extensively - Norbert talked about it about a year ago in the old forum - and I offer a rather conservative smoothing filter in TransDEM. If anyone is interested I can upload a few screenshots of its effect.

USGS NED DEMs offer GeoTiff as a download format. This format stores elevation as floating point values, which allows for millimetre resolution. Use this format with NEDs for best accuracy, either with MicroDEM/xyz/HOG-piglet/HOG or with TransDEM. You can never add detail by applying filters later.

geophil
 
Hey thanks alot guys.... Few i did not expect so much detailed informations. I will surely try your ''recipe'' :D . I'l let you know the outcome.

Currently i'm using Microdem to transform (migrate) my DEM files from their real value to 1 pixels = 10 meters. From there i save it to a BMP image and then goes to Photoshop to migrate it to a TGA. It is that last TGA that i use in Hog.

I'm not yet at the level of combining layers (dem, map, image, etc.). Once i get a smooth terrain, i will go to that other level of combining layers.

I'm learning a ollllllllle bunch of stuff here while playing with that. Thanks again.
 
G'day Regg001,

You mentioned in your initial post that you were using Global Mapper and in the last that you had changed to MicroDEM. Although I have nothing against MicroDEM, if you are already comfortable with Global Mapper, it is quite capable of exporting in the "XYZ" format, as good as, (if not better than), MicroDEM. I use basically the same method as indicated above with Global Mapper doing the 'conversion' to "xyz" instead of MicroDEM, with usurpassed results in all cases.

Jerker {:)}
 
Actually, i'm trying many tools at the same time but basically doing the same thing.

I have no preference ''yet'' toward one tool or the other. I mentionned Microdem in my previous post because it is easier in Microdem to resize to 1 pix. = 10m .

I have an old Global mapper version (V6) running - some of the newest options on that tool are not available on that version. I used that program several years ago when i did some work with MS Flight Simulator.
 
G'day regg001,

Version 6 of Global Mapper will still export to "XYZ" format, despite its age (as far as I know the current version is only 7)! Unless 'compatibility' between 'routes' is important, I have found that the need to be 'accurate' with one's dimensions is not all that important. I usually leave the images at the size they are created by Global Mapper (based on the selected "Export Bounds"), although for reasons I have yet to explain, it is necessary to resize the canvas (note, I said the canvas - NOT the image) of the overlays (TIGER/Vector/Maps) produced by Global Mapper, to match the XYZ.tga produced by Piglet, which creates an image 1 pixel wider by 1 pixel higher than those by GM (so that they are all the same size when sent to HOG for processing). This doesn't appear to effect the end result in any way.

Jerker {:)}
 
Back
Top