Code covered by the BSD License  

Highlights from
ascii2xyz

Be the first to rate this file! 5 Downloads (last 30 days) File Size: 2.63 KB File ID: #21785

ascii2xyz

by Andrew Stevens

 

16 Oct 2008 (Updated 27 Oct 2008)

convert ARC ASCII text file to xyz

| Watch this File

File Information
Description

ASCII2XYZ reads in a raster text file in ARC ASCII format and converts values to a m x 3 matrix of x, y, a z values.

This code is mostly vectorized and performs well with reasonably large files (see example below).

%read in a 25 MB file
a=dir('foo.txt')

a =

       name: 'foo.txt'
       date: '17-Oct-2008 08:53:34'
      bytes: 25437683
      isdir: 0
    datenum: 7.3370e+005

tic
xyz=ascii2xyz('foo.txt');
toc
Elapsed time is 8.110956 seconds.

Acknowledgements

The author wishes to acknowledge the following in the creation of this submission:
Raster to XYZ

MATLAB release MATLAB 7.6 (R2008a)
Other requirements Will likely only run on Matlab Version 7.1 (R14SP3) or later
Tags for This File  
Everyone's Tags
Tags I've Applied
Add New Tags Please login to tag files.
Comments and Ratings (5)
17 Oct 2008 Joaquim Luis

What if the ARC file uses xllcenter/yllcenter instead of xllcorner/yllcorner?

20 Oct 2008 Andrew Stevens

Joaquim, Thanks for the comments. This file assumes that the coordinates are relative to the pixel center. I had no idea that "xllcorner" actually referred to absolute corner of the grid. I will post a modified file in the next few days that will account for the different coordinate reference systems.

26 Jan 2010 fran anwar

sir....
I has an ascii file (.asc) but when l try to get the x,y and z, there is some error. it say " 'Error reading header information"..why sir?

27 Jan 2010 Andrew Stevens

Fran,

This file is intended to read in an ASCII file produced by ARC GIS containing raster data. A properly formatted ARC ASCII file has header information which your file does not apparently have. Type 'help ascii2xyz' to see the required header format.

Andrew

26 Jul 2011 Ric

Hey,
i'm trying to use this script, but it just outputs values of 0.051 instead of 51.(and about 10-17 numbers (depending on the coordinates) following) - it also would be just great to have an option of getting the script to output a .txt file, containing longitute, latitude, altitude (seperated by anything) - as my coal is to get ascii-data into a sql database. do you have any ideas?
as i'm not experienced in matlab in any way so it's not possible to improve the script myself though it's doing exactly what i need (exept for the output-prescision and output-file).
thank you very very much for writing the script in the first place, and even more for helping me!

best regards, ricardo

Please login to add a comment or rating.
Updates
17 Oct 2008

update description

21 Oct 2008

Added support for ASCII files that specify either the corner of the grid or the center of the lower left pixel in the header.

27 Oct 2008

fixed error in how y-values are allocated

Tag Activity for this File
Tag Applied By Date/Time
data import Andrew Stevens 22 Oct 2008 10:24:55
data export Andrew Stevens 22 Oct 2008 10:24:55
ascii Andrew Stevens 22 Oct 2008 10:24:55
raster Andrew Stevens 22 Oct 2008 10:24:55
vector Andrew Stevens 22 Oct 2008 10:24:55
dem Andrew Stevens 22 Oct 2008 10:24:55
import Andrew Stevens 22 Oct 2008 10:24:55
data Andrew Stevens 22 Oct 2008 10:24:55
utilties Andrew Stevens 22 Oct 2008 10:24:55
data export Cristina McIntire 10 Nov 2008 11:03:36
data import Cristina McIntire 10 Nov 2008 11:03:40
import Cristina McIntire 10 Nov 2008 11:03:42

Contact us at files@mathworks.com