Farmsim Forensics: Real World Terrains (a.k.a. DEMs)
By: Kim Brandwijk
Tags: Terrain, Dem, Mapping, Fs19, Farming Simulator

It looks like we got lucky again. Our entire desired map area is covered by a single DEM tile. Go ahead and download that tile using the ‘Download TIF’ button. If you picked a location that needs two or more tiles, download all of them. If a one meter DEM is not available for your location, download the next best one (1/9 arc second is about 3.5 meter per pixel, 1/3 is about 10 meter pixel). If you try to open the files to view them, they will appear all white. Don’t worry, nothing’s wrong, the data is stored in a way that doesn’t translate well into visible colors. Think about these TIF files as large spreadsheets, where every pixel stores a lot of information about a little piece of the world.

Processing the DEM tiles

To recap, we picked a location, grabbed its coordinates, and downloaded one or more DEM tiles that cover our area. The last step is to crop these to the bouding box of our area, and convert them into the format that GIANTS expects. For all this, we use a single command line tool, called gdal . It’s an industry standard tool for working with geospatial data.

On Windows, the easiest way to get it installed properly is using Anaconda: https://anaconda.org/conda-forge/gdal. The website provides installation instructions. Either way, make sure to have it installed before continuing.

Stitching tiles together (optionally)

If you had to download more than one tile in the previous step, we will need to stitch these together first. From the Anaconda command prompt, in the folder where you downloaded the tiles, run:

> gdalwarp tile1.tif tile2.tif merged.tif

Cropping the tile

Next up, we are going to crop our tile (or merged tiles) to the area we need:

> gdal_translate -projwin -108.334368 39.126934 -108.311245 39.108917 -projwin_srs CRS:84 USGS_one_meter_x73y434_CO_MesaCo_QL2_UTM12_2016.tif cropped.tif

This command tells gdal to take a window with the coordinates that we specify (top left, bottom right) and put them in a new file. Because different sources use different coordinate systems and projections, we also explicitly specify that these coordinates are CRS:84 coordinates.

Elevation levels

Next up, we need to figure out what the minimum and maximum elevation is in the tile. We need this information, because we need to tell GE what the heightScale of our DEM is (in order words, how many meters of elevation does going from completely black to completely white in our heightmap represent). For this, we use gdalinfo :

> gdalinfo -mm cropped.tif Driver: GTiff/GeoTIFF

Files: cropped.tif

Size is 2058, 1941

Coordinate System is:

PROJCS["NAD83 / UTM zone 12N",

GEOGCS["NAD83",

DATUM["North_American_Datum_1983",

SPHEROID["GRS 1980",6378137,298.257222101,

AUTHORITY["EPSG","7019"]],

TOWGS84[0,0,0,0,0,0,0],

AUTHORITY["EPSG","6269"]],

PRIMEM["Greenwich",0,

AUTHORITY["EPSG","8901"]],

UNIT["degree",0.0174532925199433,

AUTHORITY["EPSG","9122"]],

AUTHORITY["EPSG","4269"]],

PROJECTION["Transverse_Mercator"],

PARAMETER["latitude_of_origin",0],

PARAMETER["central_meridian",-111],

PARAMETER["scale_factor",0.9996],

PARAMETER["false_easting",500000],

PARAMETER["false_northing",0],

UNIT["metre",1,

AUTHORITY["EPSG","9001"]],

AXIS["Easting",EAST],

AXIS["Northing",NORTH],

AUTHORITY["EPSG","26912"]]

Origin = (730425.000000000000000,4334247.000000000000000)

Pixel Size = (1.000000000000000,-1.000000000000000)

Metadata:

AREA_OR_POINT=Area

Image Structure Metadata:

INTERLEAVE=BAND

Corner Coordinates:

Upper Left ( 730425.000, 4334247.000) (108d20' 3.76"W, 39d 7'36.98"N)

Lower Left ( 730425.000, 4332306.000) (108d20' 6.13"W, 39d 6'34.08"N)

Upper Right ( 732483.000, 4334247.000) (108d18'38.14"W, 39d 7'35.01"N)

Lower Right ( 732483.000, 4332306.000) (108d18'40.53"W, 39d 6'32.11"N)

Center ( 731454.000, 4333276.500) (108d19'22.14"W, 39d 7' 4.55"N)

Band 1 Block=2058x1 Type=Float32, ColorInterp=Gray

Description = Layer_1

Computed Min/Max=1430.570,1687.457

NoData Value=-3.4028234663852886e+38

Metadata:

LAYER_TYPE=athematic

This command outputs a lot of information, but the bits we’re interested in are highlighted above, the minimum and maximum elevation values.

Creating the heightmap

The final command that we will use will create the actual PNG image

> gdal_translate -of PNG -ot UInt16 -scale 1400 1700 0 65535 -a_srs CRS:84 -outsize 2049 2049 cropped.tif DEM.png

We’re telling gdal that we need a PNG image, with 16-bit depth. We are also specifying that we would like an elevation range of 1400 to 1700 meters to take up the entire range from black (0) to white (65535). We also specify the projection, and the resolution of the file (2049x2049).

And there you have it, the heightmap for our terrain. You can clearly spot the low (dark) river, and the higher (lighter) mountains on the left and right of it. Let’s load it up in GE and see what it looks like. Don’t forget to set the heightScale to whatever range you picked (in our case: 300), and unitPerPixel to match the resolution of your image.