1

I have a GeoTIFF file that QGIS has produced from merging multiple DEM TIFFs together. The gdalinfo for this file is:

Driver: GTiff/GeoTIFF
Files: ca_heightmap.tif
Size is 39601, 39601
Coordinate System is:
GEOGCRS["WGS 84",
    DATUM["World Geodetic System 1984",
        ELLIPSOID["WGS 84",6378137,298.257223563,
            LENGTHUNIT["metre",1]]],
    PRIMEM["Greenwich",0,
        ANGLEUNIT["degree",0.0174532925199433]],
    CS[ellipsoidal,2],
        AXIS["geodetic latitude (Lat)",north,
            ORDER[1],
            ANGLEUNIT["degree",0.0174532925199433]],
        AXIS["geodetic longitude (Lon)",east,
            ORDER[2],
            ANGLEUNIT["degree",0.0174532925199433]],
    ID["EPSG",4326]]
Data axis to CRS axis mapping: 2,1
Origin = (-125.000138888888998,43.000138888888898)
Pixel Size = (0.000277777777778,-0.000277777777778)
Metadata:
  AREA_OR_POINT=Area
Image Structure Metadata:
  INTERLEAVE=BAND
Corner Coordinates:
Upper Left  (-125.0001389,  43.0001389) (125d 0' 0.50"W, 43d 0' 0.50"N)
Lower Left  (-125.0001389,  31.9998611) (125d 0' 0.50"W, 31d59'59.50"N)
Upper Right (-113.9998611,  43.0001389) (113d59'59.50"W, 43d 0' 0.50"N)
Lower Right (-113.9998611,  31.9998611) (113d59'59.50"W, 31d59'59.50"N)
Center      (-119.5000000,  37.5000000) (119d30' 0.00"W, 37d30' 0.00"N)
Band 1 Block=39601x1 Type=Float32, ColorInterp=Gray

enter image description here

How can I convert this to a raw file that I am able to import as a terrain in Unity? When I open this TIFF in GIMP, I just get a black/white image that loses the height map aspect (I'm not really sure what happens to it, but it looks like this in GIMP)

enter image description here

6
  • 1
    GIMP is an image processing program, while your TIFF is a dataset. GIMP won't be able to render a Float32 visually. Have you tried importing it in Unity at all? Commented Oct 24, 2020 at 10:34
  • It seems that unity can only accept a raw file for a terrain
    – Hdot
    Commented Oct 24, 2020 at 10:37
  • 2
    And what is a "raw file" to Unity? Please link to some specification if possible. Commented Oct 24, 2020 at 10:46
  • I'm new to Unity and QGIS, so i'm just going off of what im seeing people say over the forums etc. But when importing a file to be used as a terrain in unity, it expects a .raw file
    – Hdot
    Commented Oct 24, 2020 at 10:50
  • ah, I managed to get the correct format using gdal_translate –of ENVI –ot UInt16 –scale –outsize 1025 1025 ca_heightmap.tif heightmap.raw
    – Hdot
    Commented Oct 24, 2020 at 11:24

2 Answers 2

3

Using the command gdal_translate –of ENVI –ot UInt16 –scale –outsize 1024 1024 ca_heightmap.tif heightmap.raw to get the correct format for Unity

3

Gimp 2.10.24 insisted on producing an 8-bit raw file from a 16-bit TIFF height map. Looked terrible...

After fiddling for hours trying to get GDAL to work on windows, ended up using numpy on Python directly, instead ...

Here are 5 lines of code to do the job:

from PIL import Image
import numpy

im = Image.open('image.tif')
imarray = numpy.array(im)
imarray.astype('int16').tofile("image.raw")

enter image description here

enter image description here

enter image description here

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.