Previous Getting Started with IDL: Mapping Next

Warping Images to Maps

Image data can also be displayed on maps. The MAP_IMAGE function returns a warped version of an original image that can be displayed over a map projection. In this example, elevation data for the entire globe is displayed as an image with continent outlines and grid lines overlaid.

  1. Define the template for the file worldelv.dat. This file contains a 360 by 360 square array of byte values.
  2. WORLDTEMPLATE=BINARY_TEMPLATE(FILEPATH('worldelv.dat', $
       SUBDIR=['examples', 'data']))  
    

     

  3. When the binary template dialog box appears, name the template "WORLDTEMPLATE" and then click New Field.
  4.  

  5. In the New Field dialog, enter "W" for the Field Name, be sure to specify that you have two dimensions and that the field sizes are 360 and 360.
  6.  

  7. Also select Byte (unsigned) in the Type field. Now click OK in the New Field dialog. Click "OK" to close the binary template dialog as well. Next, read the file by entering:
  8. WORLDELV_BINARY=READ_BINARY(FILEPATH('worldelv.dat', $
       SUBDIR=['examples', 'data']),TEMPLATE=WORLDTEMPLATE)  
    

     

  9. Load a color table.
  10. loadct, 26  
    

     

  11. View the data as an image.
  12. TV, WORLDELV_BINARY.W  
    

     

    Figure 9-8: worldelv.dat Visualized with TV

    Figure 9-8: worldelv.dat Visualized with TV

     

    The first column of data in this image corresponds to 0 degrees longitude. Because MAP_IMAGE assumes that the first column of the image being warped corresponds to -180 degrees, we'll use the SHIFT function on the dataset before proceeding.

     

  13. Shift the array 180 elements in the row direction and 0 elements in the column direction to make -180 degrees the first column in the array.
  14. WORLDELV_BINARY.W=SHIFT(WORLDELV_BINARY.W, 180, 0)  
    

     

  15. View the data as an image.
  16. TV, WORLDELV_BINARY.W  
    

     

    Figure 9-9: Shifting the Array

    Figure 9-9: Shifting the Array

     

    From the image contained in the data, we can create a warped image to fit any of the available map projections. A map projection must be defined before using MAP_IMAGE, because MAP_IMAGE uses the currently defined map parameters.

     

  17. Create a Mollweide projection with continents and gridlines.
  18. MAP_SET,/MOLLWEIDE,/CONT,/GRID,COLOR=100  
    

     

  19. Warp the image using bilinear interpolation and save the result in the variable new.
  20. NEW=MAP_IMAGE(WORLDELV_BINARY.W,SX,SY,/BILIN)  
    

     

    The SX and SY in the command above are output variables that contain the X and Y position at which the image should be displayed. Setting the BILIN keyword causes bilinear interpolation to be used, resulting in a smoother warped image.

     

  21. Display the new image over the map:
  22. TV,NEW,SX,SY  
    

     

    Figure 9-10: Warping an Image to a Map

    Figure 9-10: Warping an Image to a Map

     

    The SX and SY variables provide TV with the proper starting coordinates for the warped image. TV usually displays images starting at position (0, 0). See the map in the previous figure. Note that the warped image gets displayed over the existing continent and grid lines.

     

  23. The continent outlines and thick grid lines can be displayed, as shown next, by entering:
  24. MAP_CONTINENTS  
    MAP_GRID,GLINETHICK=3  
    

     

    Figure 9-11: Showing gridlines and continents

    Figure 9-11: Showing gridlines and continents

  IDL Online Help (March 06, 2007)