That was a quite difficult task, but now I have 2 working solutions, as described here.
First of all I had to export the binary Esri Grid file to an ASCII grid file format using the ArcToolbox > Conversion tools > From Raster > To ASCII. The result was a 2.6GB text file with a elevation data displayed in a plain text matrix with around 20k x 20k elevation values.
Now I have two different scripts I can use to access the data:
1 Single data
If I only need one single elevation data value on a certain X/Y- or LAT/LON- position I can use the following bash script:
#!/bin/bash
INPUT=$1
# Parses starting coordinates.
x11=$(awk '$1 == "xllcorner" { print $2 }' $INPUT)
y11=$(awk '$1 == "yllcorner" { print $2 }' $INPUT)
# Gets requested coordinates from args.
X=$2
Y=$3
# Calculates the line number and column.
LINE=$(bc <<< "scale=0;($Y-$y11+7)/1")
COLN=$(bc <<< "scale=0;($X-$x11+1)/1")
# Prints the Z Coordinates at X=COLN and Y=LINE
awk -v line=$LINE 'NR == line { print $0 }' $INPUT | cut -f $COLN -d " "
Usage:
$ ./elevation.sh dem.txt 3356387.137 5800803.818
29.58562
It takes around 7 seconds for a single elevation data to be extracted. Time consumption with this script is linear, if I call it for 100 data values, this will take around 700 seconds.
2 Multiple data
The other approach is perl script:
#!/usr/bin/perl
use strict;
use warnings;
use v5.10;
use autodie;
use List::MoreUtils qw(any);
my $data_file = shift;
my %metadata;
my @data;
open my $fh, '<', $data_file;
while (<$fh>) {
chomp;
my @F = split;
if (any {$F[0] eq $_} qw(ncols nrows xllcorner yllcorner cellsize NODATA_value)) {
$metadata{$F[0]} = $F[1];
}
else {
push @data, \@F;
}
}
close $fh;
while (@ARGV) {
my $x = shift;
my $y = shift;
my $x_delta = int(($x - $metadata{xllcorner}) / $metadata{cellsize});
my $y_delta = int(($y - $metadata{yllcorner}) / $metadata{cellsize});
if ($x_delta < 0 or $y_delta < 0 or not defined $data[$y_delta][$x_delta]) {
say $metadata{NODATA_value};
}
else {
say $data[$y_delta][$x_delta];
}
}
Usage with multiple coordinates:
$ ./elevation.pl dem.txt 0 0 3356385.137 5800799.818 3356387.137 5800803.818
-9999
31.11266
29.58562
It takes around 2 minutes to compute which is much longer than the bash script. But the time consumption of this script is not connected to the number of arguments. To access 100 elevation values it still takes only 2 minutes.
Downside of this script it needs alot of main memory, around 10x of the DEM file size, in my case: 26GB.