Import XYZ
Import XYZ DEM data
There are a couple of ways to import regular DEM (elevation) data in XYZ ASCII format:
- use v.in.ascii, then r.to.vect
- use r.in.xyz along with g.region
Hint if there are multiple white spaces as separator
Often one comes across ASCII tables formatted in unfortunate ways, e.g. like this:
617000.0 148000.0 157.92 617025.0 148000.0 157.82 617050.0 148000.0 157.70 617075.0 148000.0 157.60 ...
Above mentioned GRASS commands refuse to import directly from that since they require single (and not replicated) field separators.
Solution: On Unix-based systems, you can get rid of this on the fly and import the XYZ ASCII file to a raster map combining some text tools and GRASS commands.
Example: We assume to import the XYZ ASCII file VTL2733.XYZ which shows above mentioned structure (which also indicates a 25m raster size):
# first scan the map extent in human readable way (reduce white space on the fly, read from standard-input): cat VTL2733.XYZ | tr -s ' ' ' ' | r.in.xyz -s in=- fs=space out=test Range: min max x: 617000.000000 619250.000000 y: 148000.000000 151000.000000 z: 149.160000 162.150000 # set region, get from scanning the file again, now in machine-readable form (eval and -g flag): eval `cat VTL2733.XYZ | tr -s ' ' ' ' | r.in.xyz -s -g in=- fs=space out=test` g.region n=$n s=$s w=$w e=$e res=25 -p # enlarge region by half raster cell resolution to store values in cell-center: g.region n=n+12.5 s=s-12.5 w=w-12.5 e=e+12.5 -p # verify that the number of rows in the ASCII file corresponds to the number of cells in enlarged region wc -l VTL2733.XYZ # finally import as raster map: cat VTL2733.XYZ | tr -s ' ' ' ' | r.in.xyz in=- fs=space out=vtl2733
Now you can analyse the map or export into a reasonable raster format (e.g., GeoTIFF) with r.out.gdal.