Mapping Toolbox    

Importing Other Data

With the huge quantities of geographic information available, it is impossible to provide interface functions for every file format. To help you read data in other formats, the Mapping Toolbox provides a set of high-level file import functions. These allow you to read data from binary or text files by simply describing the contents of the file. The files may contain matrices or fixed length records of geographic data. MATLAB also provides some file import functions. Type help iofun for more information on the MATLAB functions.

Much geographic data is provided as very large files containing matrices of values. You can read the part of the matrix of interest to you using the readmtx function.

To illustrate the use of readmtx, read in data giving the intensity of stable light sources collected from the Defense Meteorological Satellite program <http://www.ngdc.noaa.gov/dmsp/dmsp.html>. Download a recent data file (e.g., usa.bil) and header file (e.g., usa.hdr) from the DMSP FTP site. We will read and display data for the Cape Cod region. Take the following minimum information from the header file: the number of rows (NROWS) and columns (NCOLS) in the matrix, the location of the upper left corner (ULXMAP, ULYMAP), the grid spacing (XDIM, YDIM), and the storage format of the numbers (NBITS).

Most matrix files can be read using the same procedure. First you map your geographic limits into matrix row and column limits and construct vectors of row and column indices to be read. Then you read the submatrix using readmtx, and construct the maplegend.

Here is an example:

Boston appears to have grown since the data in the VMAP0 was compiled. The VMAP0 also missed the heavily populated part of Cape Cod.

Some data is stored on regular grids in projected coordinates. In that case, you need to define a map projection that matches the one used for the data. Because the grid is in projected coordinates rather than latitude and longitude, the map is a general matrix map and needs a graticule. To construct one, build a matrix of row and column indices, convert them to projected coordinates, and carry out the inverse projection. The resulting latitude, longitude, and map matrices can be displayed in any projection. Edit the avhrrlambert interface function to see an example.

Another common type of geographic data file format is fixed length records with fields of information. Examples of such data include geographic names, hydrographic soundings, ship track lines, and astronomical catalogs of stars. Use the readfields function to read selected fields or records from such files.

As an example, retrieve the U. S. Geological Survey Geographic Names Information System (GNIS) file containing a concise list of names and locations within the United States. The file can be found at
<http://mapping.usgs.gov/pub/gnis/US_concise.gz>.

The README file describes the file format and contents. To read this data, create a structure with this information.

You can identify records that match a search string using the grepfields function. With no output arguments, records matching the string are displayed onscreen. When an output argument is provided, the record numbers of matching records are returned.

Search for the locations of The MathWorks and Systems Planning and Analysis.

Use the readfields function to read the selected records into a structure.

If you are having trouble getting the file format right, you can check the record length of a file with line ending characters. Remember that DOS-based computers use two line ending characters.

If the file does not have line endings, you can use fread to read a few characters at a time.


  Astronomical Data Reference