Raster2Xyz

Converts a raster into a text file of XYZ triplets, one line for each cell, with the easting and the northing of its center and its value, separated by tabs:

1637215.0	5114435.0	1207.594970703125
1637225.0	5114435.0	1217.385986328125
...

These are the first lines for the sample elevation model of the example below: the cells are written row by row, from the north west corner, and the novalues are left out, as the first cells of this raster. The values of rasters of floating point numbers are written with all the digits of their conversion. It is the plain format to pass a raster to programs that don’t read the raster formats, or to look at its values. Xyz2Raster reads it back.

Details

The cells are written row by row, from the north west corner. The novalues are left out, unless they are asked for, in which case they are written as -9999. The file can be read back into a raster with Xyz2Raster.

Parameters

Converts a raster to a text file of XYZ triplets: a line for each cell, with the easting and the northing of its center and its value, separated by tabs.

Toolbox folder: Raster Processing
Status: Certified
Keywords: Raster, Conversion
Authors: Andrea Antonello
Class: org.hortonmachine.modules.Raster2Xyz

Inputs

Parameter

Type

Unit

Default

Description

inRaster

raster file

The raster to convert.

doRemovenv

boolean

true

If true, the cells with novalue are left out.

Outputs

Parameter

Type

Unit

Description

outFile

output file

The output text file of the triplets.

Example

The example converts the sample elevation model of the manual, dtm_flanginec.tif in docs/manual/modules/maps/data, into triplets and back into a raster:

import org.hortonmachine.modules.Raster2Xyz
import org.hortonmachine.modules.Xyz2Raster

// the folder with the elevation model: change it to yours
var folder = "/data/flanginec/"

// the elevation model as a text file of triplets: easting, northing and elevation
var raster2xyz = new Raster2Xyz()
raster2xyz.inRaster = folder + "dtm_flanginec.tif"
raster2xyz.outFile = folder + "dtm_flanginec.xyz"
raster2xyz.process()

// and back to a raster, with the resolution and the CRS of the points
var xyz2raster = new Xyz2Raster()
xyz2raster.inFile = folder + "dtm_flanginec.xyz"
xyz2raster.pRes = 10.0
xyz2raster.pCode = "EPSG:3003"
xyz2raster.outRaster = folder + "dtm_from_xyz.tif"
xyz2raster.process()