While the ArcToolbox Conversion tool 'Grid to ASCII' will produce 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. This article describes a method that will produce a text file that contains the x coordinate, the y coordinate, and the z-value of the center of every cell a grid. Spatial Analyst is required to perform this operation.
The advantages of using this method are that it provides control over the precision of the values returned for the x and y coordinates and the format of the txt file generated. The disadvantages to this method are that only integer grids can be used, because floating-point grids do not have a VAT, and it can be time consuming.
These 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 Convert option under the Spatial Analyst menu.
- Select the Raster to features option.
- Select the field for the z-values in the text file. Typically, this is the Value field.
- Set the Output Geometry type to points.
- Select an output shapefile or feature class.
- Click OK. This generates a layer with a point at the center of each cell. The value in the field GRID_CODE is the z-value of the cell.
Populate the table of the new layer
- Add x and y fields to the table of the layer.
- Populate the x and y fields with the values from the point. Refer to the following technical article for further details: How To: Calculate X, Y, and Z values in an attribute table using Field Calculator.
- Close the table.
Configure layer properties
- Right-click the layer, select Properties, and click the Fields tab.
- If necessary, turn off fields that shouldn’t be in the final text file by selecting them one at a time from the list and removing the checkmark next to 'visible'.
- Click OK in the layer Properties dialog to accept the changes to the table.
- Right-click the layer, and select the Open Attribute Table option.
- Click Options and select the Export option.
- Click the Browse button.
- In the Saving data dialog box, select Text file from the Save as type drop-down list.
- Navigate to a directory to save the file and select an appropriate name.
- Click Save and OK.