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?

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.

  • 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
    Commented Apr 24, 2012 at 4:39
  • No worries. Updated my answer to cover this.
    – om_henners
    Commented Apr 24, 2012 at 6:35

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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