Geoscience Reference
In-Depth Information
453945 5828055
484665 5828055
515385 5828055
546105 5828055
576825 5828055
607545 5828055
...
The following code snippet iterates the text file, reading the locations line by line.
The loop is implemented using theBash commands
cat
,
while
and
read
. Here, we
opt for a simple three column output (X Y value). We prefer
gdallocationinfo
not to print the standard multi-line output for each location and use the option
-valonly
. The location has been read in the variables X and Y and can be printed
with the
echo
command from Bash. We want to print the pixel value on the same
line, so we omit a new line character after the location by using the option
-n
.
cat
locations.txt |
while read
XY;
do
echo
-n "$X $Y "
gdallocationinfo -b 1 -valonly -geoloc image.tif $X $Y
done
453945 5828055 10417
484665 5828055 10635
515385 5828055 10228
546105 5828055 10457
576825 5828055 10157
607545 5828055 10014
...
10.3 gdal2xyz.py
The Python script
gdal2xyz.py
converts a GDAL supported raster into ASCII
text. By default, all grid cell values are reported. You can restrict the output by
skipping a number of rows and columns (use the option
-skip
). You can also select
a spatial subset with the option
-scrwin
. The output is written to stdout (screen),
unless a destination (ASCII) file is provided as the last argument.
Usage: gdal2xyz.py [-skip factor] [-srcwin xoff yoff width
ₒ
height]') [-band b] [-csv] srcfile [dstfile]')
Search WWH ::
Custom Search