How To: Convert a grid to a text file of x-, y- and z-values of the center of each cell with the SAMPLE function
While the ArcToolbox Conversion tool 'Grid to ASCII' produces an ASCII file that stores the z-values of each cell of a grid, there is no x and y coordinate for the center of each cell. Intstructions provided produce a text file that contains the x coordinate, the y coordinate, and the z-value of the center of every cell in a grid. Spatial Analyst is required to perform this operation.
The following steps require the Spatial Analyst extension to be active and the Spatial Analyst toolbar to be turned on.
- Add the grid to ArcMap.
- Select the Raster Calculator option from the Spatial Analyst menu.
- Use the following expression in the Raster Calculator where [ingrid] is the name of the grid layer:
outfile.txt = SAMPLE([ingrid],[ingrid])
- The text file called outfile.txt is written to the working directory. The working directory can be determined or set from the Spatial Analyst > Options > General tab.
The format of the output text file may have to be modified to be compatible with specific needs. The first and last columns in the text file are the z-values.
ESRI does not provide the VBA code for the above procedure. The necessary code must be developed by the user.
- Convert a grid to a text file of x-, y- and z-values of the center of each cell with the Grid to Features function in the Spatial Analyst toolbar
- Convert a raster dataset to an XYZ table