Wednesday, 13 July 2016

geotiff tiff - GDAL - Specify span of elevation values for conversion to Terragen format?


I'm attempting to use the tools to convert some files I have to the Terragen format. I was hoping to use either gdal_translate or gdalwarp in a similar fashion to this post. (though I should admit I am not sure which tool may be more appropriate for my task)


However, when I issue either command it exits with an error, in fact, the same error:


$ gdal_translate -of Terragen src.tif dest.ter
Input file size is 8743, 6159
0ERROR 1: Inverted, flat, or unspecified span for Terragen file.

$ gdalwarp -of Terragen src.tif dest.ter

Creating output file that is 8743P x 6159L.
ERROR 1: Inverted, flat, or unspecified span for Terragen file.

I quickly stumbled upon a post (which also points to gdal documentation) stating that I need to specify the span of elevation values:



Use the Create call. Set the MINUSERPIXELVALUE option (a float) to the lowest elevation of your elevation data, and MAXUSERPIXELVALUE to the highest. The units must match the elevation units you will give to band::SetUnitType().



Were I developing my own utility that used libgdal, this information would be applicable. However, instead of developing a new utility to achieve the conversion - I'd rather use the existing gdal tools if possible ( , ).


Is it possible to specify the min/max elevation values using any existing tools?



Answer




For merely converting a raster from one format to another, many of the GDAL tools will do that along with their specialized functions so either GDALWARP or GDAL_TRANSALTE will do fine for your purposes (which also explains why they give you the same error).


The information you mention in the documentation in your links is applicable to using GDAL. Most of the GDAL tools have a "-co" switch (Creation Options). Scroll down in the tool's documentation and you'll see the explanation of each switch listed in the synopsis at the top of the page. The Creation Options are towards the bottom in this case. This is where you set the MINUSERPIXELVALUE and MAXUSERPIXELVALUE.


So, for instance I have a DTM file called 'HP.asc'. gdalinfo tells me it has a min of 20m and a max of 1347m. So I would issue the following command:


C:\OSGeo4W64\bin>gdalwarp -of TERRAGEN -co MINUSERPIXELVALUE=20 -co MAXUSERPIXELVALUE=1347 "c:\someSrcPath\HP40.asc" "c:\someDestination\HP40.ter"

No comments:

Post a Comment

arcpy - Changing output name when exporting data driven pages to JPG?

Is there a way to save the output JPG, changing the output file name to the page name, instead of page number? I mean changing the script fo...