Take the 2-minute tour ×
Geographic Information Systems Stack Exchange is a question and answer site for cartographers, geographers and GIS professionals. It's 100% free, no registration required.

I need to import a climate map downloaded from WorldClim into Matlab for manipulation with the mapshow command. I am comfortable reading in ASCII grid data into matlab, but this format is not available from this website.

Available are the ESRI format with the file extension ".adf" and generic grid files with extension ".bil"

Anyone know how I can get these into matlab?

Thanks

share|improve this question

1 Answer 1

Assuming you're using ArcGIS 10, you can use the arcpy RasterToNumPyArray command to get a NumPy array, which if you read the NumPy Input and Output routines documentation you can see you can easily dump the raster data to disk as a text file with a format of your choice.

For example:

import arcpy
import numpy as np

arr = arcpy.RasterToNumPyArray('C:/some/raster.adf')
np.savetxt("output_array.txt", arr)

Better yet, download SciPy and from scipy.io there is the savemat function which can

Save a dictionary of names and arrays into a MATLAB-style .mat file

Again for example:

import arcpy
import numpy as np
import scipy.io as sio

arr = arcpy.RasterToNumPyArray('C:/some/raster.adf')
sio.savemat('out_vector.mat', {'vect':arr})

If you're not using ArcGIS, then you can use the GDAL library to convert the raster into a more usable format. Take a look at using the gdal_translate utility. For example:

gdal_translate -of AAIGrid source_dataset.adf output_dataset

Of course GDAL also has its own Python bindings which you can use to read the data into a NumPy Array and export as shown above.

share|improve this answer
    
Thanks for your response. Actually I do not have any arcgis program. I have been able to read ASCII Grid files directly into matlab without arcgis. I am looking for a way to do the same for ESRI files with ".adf" and ".bil" extensions. –  ben Apr 24 '12 at 4:39
    
No worries. Updated my answer to cover this. –  om_henners Apr 24 '12 at 6:35

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.