Code covered by the BSD License  

Highlights from
ARCGRIDWRITE

4.5

4.5 | 2 ratings Rate this file 23 Downloads (last 30 days) File Size: 2.68 KB File ID: #16176

ARCGRIDWRITE

by Andrew Stevens

 

30 Aug 2007 (Updated 31 Mar 2009)

Write gridded data set in Arc ASCII Grid Format

| Watch this File

File Information
Description

ARCGRIDWRITE converts data in a matlab grid (as produced by eg. meshgrid and griddata) into a text file in Arc ASCII Grid Format. The file can also be automatically converted to raster on PC's with ARCINFO installed.
 
EXAMPLE - create a raster grid of the peaks function
[X,Y,Z]=peaks(100);
arcgridwrite('peaksArc.asc',X,Y,Z,'precision',3, 'convert')
 
NOTES
Because the Arc ASCII format has only one parameter for cell size, both X and Y must have the same, non-varying grid spacing.

MATLAB release MATLAB 7.8 (R2009a)
Tags for This File  
Everyone's Tags
Tags I've Applied
Add New Tags Please login to tag files.
Comments and Ratings (8)
13 Mar 2009 Colin Lazauski

This is a nice file and works well. Modification of the header section write format will allow the file to be read directly by ESRI Arc-GIS. My modification is:

%write header
fprintf(fid,'%s','ncols ');
fprintf(fid,' %d\n',nz);
fprintf(fid,'%s','nrows ');
fprintf(fid,' %d\n',mz);
fprintf(fid,'%s','xllcorner ');
fprintf(fid,[dc,'\n'],minX);
fprintf(fid,'%s','yllcorner ');
fprintf(fid,[dc,'\n'],minY);
fprintf(fid,'%s','cellsize ');
fprintf(fid,'%-6.0d\n',dx);
fprintf(fid,'%s','NODATA_value ');
fprintf(fid,'%-5.0d\n',-9999);

This place the numeric values starting in column 15 and removes the trailing zeros from the last two values.

31 Mar 2009 Andrew Stevens

Colin,

Thanks for your comments. I found after playing with a couple examples, I determined that if I simply change the output filename from .txt to .asc that the file can be read directly into arc without doing the raster conversion.

I would also be careful with your modification of the way the header is written in the output file. Your modification forces the cell-size to be an integer which would produce a large error in many of my datasets.

Andrew

09 Sep 2009 Daniya  
08 Sep 2010 Edward Bair

Thanks for the util. It may be the way I'm building the grid, but ARCGRIDWRITE creates rasters that are flipped vertically for me. If Z is my raster, I need to do the following to have it written correctly:

[iv,jv]=ndgrid(1:size(Z,1),1:size(Z,2));
arcgridwrite('VegGrid_small.asc',jv,iv,flipud(Z));

31 Mar 2011 Edgar

Andrew,

Thanks for the script. However, I found the script is not able to write high resolution cellsizes. My grid has a resolution of 0.075. However, the scripts writes: "0.000". How can I solve this?? Thanks.

EM

31 Mar 2011 Andrew Stevens

Edgar,

The default precision for the function is %0.3f, so you should get 0.075 as the cell spacing. I tried the following code to verify:

%generate synthetic data with desired %cell spacing
xi=0:0.075:1;
yi=0:0.075:1;
[xm,ym]=meshgrid(xi,yi);
zm=peaks(numel(xi));

%call arcgridwrite
arcgridwrite('test.asc',xm,ym,zm);

%look at output
type('test.asc')

The results look correct to me. Let me know (by email) if you have further questions.

25 Jan 2012 A Westergaard

Andrew,
Thank you for sharing your work. As I am new to MatLab, I hope you or others have time for some guidance: In Matlab I have a matrix with values [-1:1]. I want to export this matrix to ArcMap. What would the syntax be for this? Thank you in advance.

26 Jan 2012 A Westergaard

The above mentioned matrix has 350 rows and 300 columns. Values are double.

Please login to add a comment or rating.
Updates
31 Aug 2007

bug fixed in conversion to raster portion of program

21 Oct 2008

change keyword in header from corner to center.

31 Mar 2009

changed description, help and example

Tag Activity for this File
Tag Applied By Date/Time
data import Andrew Stevens 22 Oct 2008 09:24:56
data export Andrew Stevens 22 Oct 2008 09:24:56
esri Andrew Stevens 22 Oct 2008 09:24:56
arc Andrew Stevens 22 Oct 2008 09:24:56
grid Andrew Stevens 22 Oct 2008 09:24:56
raster Andrew Stevens 22 Oct 2008 09:24:56
utilities Andrew Stevens 22 Oct 2008 09:24:56
export Andrew Stevens 22 Oct 2008 09:24:56
arc Daniya 09 Sep 2009 05:39:13
esri Daniya 09 Sep 2009 05:40:26
grid Daniya 09 Sep 2009 05:40:29
raster Daniya 09 Sep 2009 05:40:35
data import Daniya 09 Sep 2009 05:40:37
data export Daniya 09 Sep 2009 05:40:39

Contact us at files@mathworks.com