[gdal-dev] converting AAIGrid to SRTM

Bryan Fields Bryan at bryanfields.net
Thu Oct 24 15:41:28 PDT 2019


On 10/23/19 3:43 PM, Even Rouault wrote:
>> Question 1:
>> Is there a way to have it auto name the output file?  I'd assume if it knows
>> what it's suppose to be named, there should be a flag to automatically name
>> it that.  I can't find that, and need it to convert several thousand of
>> these files.
> Such an option doesn't exist, but it shouldn't be hard to implement if you 
> want to submit a pull request for that. I'd suggest to trigger that mode if 
> the output filename provided is actually a directory name ("." being a valid 
> name).

I'd love to, but I'm not much of a programmer.  Typically I'll code up a
crappy script and then have one our my friends actually code up something that
works.

I made a script below that seems to work:

echo INPUT FILE: ${1}
gdal_translate -of SRTMHGT  $1 output.tmp 2>&1 |
while read line
        do
#       echo $line
        if [[ $line == "Warning 1: Expected output filename is"* ]]
                then
                while read -ra output
                do
                        OUTPUT=`echo ${output[6]} | cut -d "." -f 1,2`
                done <<< $line
        fi
done
echo GENERATING: $OUTPUT
mv output.tmp $OUTPUT

echo DONE WITH: $OUTPUT



>> Question 2:
>> Is my re-tiling correct and method correct to convert to SRTM 3 arc second
>> HGT files?
> Looks good

Well problem I ran into is this didn't split up the data right as it looks
like these ascii files have some overlap

bfields at Pythia:~/DEMv4/N00W090$ gdalinfo cut_n00w090.asc
Driver: AAIGrid/Arc/Info ASCII Grid
Files: cut_n00w090.asc
Size is 36023, 36023
Origin = (-90.009583333565004,30.009584035782641)
Pixel Size = (0.000833333353512,-0.000833333353512)
Corner Coordinates:
Upper Left  ( -90.0095833,  30.0095840)
Lower Left  ( -90.0095833,  -0.0095834)
Upper Right ( -59.9904159,  30.0095840)
Lower Right ( -59.9904159,  -0.0095834)
Center      ( -74.9999996,  15.0000003)
Band 1 Block=36023x1 Type=Int32, ColorInterp=Undefined
  NoData Value=-9999

This means the offset here not exactly aligned on -90, 0, but rather has an
overlap of 11 pixels on the left and 12 on the right.

Is there a way to trim this to 36001x36001 before converting it to the
1201x1201 tiles?

For example:
My understanding is the N00W90.HGT file lower left pixel is at 0, -90 lat/lon,
and will extend one pixel into N00W89.HGT.

When I run this conversion, I need an exact 1201x1201 image.  I'm also not
sure how to verify this is correct.  My concern is if I'm a pixel off that is
up to 90m, and now it would appear I'm 23 pixels off, or up to 2.07km.

Thank you,
-- 
Bryan Fields

727-409-1194 - Voice
http://bryanfields.net


More information about the gdal-dev mailing list