No organisation defines the XYZ point format; it is a convention. This page
describes what the files contain in practice and how widely used open source readers
treat them: Open3D (FileXYZ.cpp, FileXYZN.cpp,
FileXYZRGB.cpp), which skips any line that does not start with three
numbers, and PDAL’s text reader. Anything beyond these rules is
a choice of the program that wrote the file.
Lines
- Plain text, usually ASCII; one point per line, ending with LF or CR LF.
- Values are decimal numbers in the C form: a full stop as decimal separator, an
optional sign and an optional exponent (
1.5e-3). Files from programs set to a European locale sometimes use commas instead, which then cannot also be the separator. - Values are separated by spaces, tabs, commas or semicolons. Runs of spaces count as one separator.
- There is no point count and no end marker; the file ends with the last line.
- Units and coordinate system are not recorded. Survey files usually hold projected coordinates in metres (easting, northing, height); scanner exports often hold local coordinates.
Header lines
Most files have none. Some begin with a line naming the columns, such as
X,Y,Z; some programs start it with // so that it reads
as a comment. The example below uses PDAL’s dimension names.
PDAL’s text reader
From PDAL io/TextReader.cpp, read as raw text:
- Extensions. It is registered as
readers.textfor.txtand.csvonly, not.xyz. To read an.xyzfile, name the reader explicitly. - Header. The reader takes its column names from one line, which can
come from the file or from an option. After skipping the lines given by the
skipoption (default none), it reads the next line as the header unless theheaderoption supplies one, in which case no line is read as a header. If the header line has no letter in it, it only logs a warning that the file does not appear to contain a header. So a header is needed either in the file or from theheaderoption, but the code does not stop for a header line without letters: it only warns. The line it reads there is always treated as the header. - Separator. If the header starts with a double quote, each name is
quoted and the separator is the text between a closing and the next opening quote (one
character, or a space if empty). Otherwise the first character in the header that is not
a letter or digit is the separator. The
separatoroption overrides both. A name may contain only characters allowed in a PDAL dimension name. - Data lines. Blank lines are skipped. With a separator other than a space, spaces are removed from the line before it is split; with a space as separator, runs of spaces count as one. A line whose number of fields differs from the header’s is ignored, with an error logged, and reading goes on.
- Values. Every field is read as a double-precision number. A field that is not a number is logged as an error and set to 0. A repeated column name in the header is an error.
Column layouts
The first three columns are always X, Y and Z. Readers recognise further columns by their count, by a header, or by asking the user.
| Columns | Layout | Notes |
|---|---|---|
| 3 | x y z | The basic form; Open3D’s .xyz |
| 4 | x y z i | With an intensity or a scalar value such as a classification |
| 6 | x y z r g b | Colour as integers 0–255, or as decimals 0–1 in Open3D’s .xyzrgb |
| 6 | x y z nx ny nz | With a unit normal; Open3D’s .xyzn |
| 7 | x y z i r g b | Intensity and colour, as in PTS |
| 9 | x y z r g b nx ny nz | Colour and normal; one common order, but not the only one |
A six-column file may hold either a colour or a normal; values all between −1
and 1 that form unit vectors suggest a normal, whole numbers up to 255 a colour.
Open3D settles it with the extension (.xyzn or
.xyzrgb), and writes each value with ten decimal places.
Gridded elevation
Elevation models exported as XYZ list one line per grid cell, in rows, with a constant spacing in X and Y. Nothing marks such a file as a grid; GIS programs detect the regular spacing when importing it as a raster.
Other formats with this extension
In chemistry, .xyz is a different format with its own page:
XYZ molecule geometry. It has a line with the number
of atoms, a comment line, then one line per atom, giving an element symbol or an atomic
number, followed by the coordinates in ångström. A first line holding a single whole
number, followed by a comment line, marks that format rather than a point cloud.
Worked example
X Y Z Red Green Blue
1.250 0.500 2.000 200 30 30
1.252 0.501 2.004 198 31 29