Supercomputing Institute Technical User Support

 

IDL: Mapping

  1. Drawing Map Projections
  2. Drawing an Orthographic Projection
  3. Plotting a Portion of the Globe
  4. Plotting Data on Maps
  5. Reading Latitudes and Longitudes
  6. Plotting Contours Over Maps
  7. Warping Images to Maps

Drawing Map Projections

Drawing continental outlines and plotting data in different projections is easy using IDL's mapping routines. The MAP_SET routine is the heart of the mapping package.  It controls the type of projection and the limits of the global region to be mapped.
1. Reset the graphics window to default size:
window
2. Display a cylindrical projection map of the world:
map_set,/cylindrical,/grid,/continents,/label


The CYLINDRICAL keyword tells MAP_SET to use the cylindrical projection. The GRID keyword causes the latitude and longitude lines to be drawn. The LABEL keyword adds the latitude and longitude labels. The CONTINENTS keyword tells MAP_SET to draw continental outlines.  A similar map could be created by entering a series of separate commands to set up the type of projection, draw the continent outlines, and then draw the grid lines.

Although the single-line MAP_SET command is quicker to enter, by using the separate MAP_SET, MAP_GRID, and MAP_CONTINENTS commands, you exercise more control over the map colors, fills, and so on.

3. Load a new color table.
loadct,39
4. Display a Miller cylindrical projection of the world.
map_set,/miller
5. Draw the continent outlines. The FILL keyword fills in the continents using the color specified by the COLOR keyword.
map_continents,color=220,/fill
6. Draw the grid lines. The COLOR keyword specifies the color of the grid lines.  The LABEL keyword labels the lines.
map_grid,color=160,/label
The order of MAP_GRID and MAP_CONTINENTS depends on how you wish to display your map. In the above example, if you call MAP_GRID before MAP_CONTINENTS, the filled continents are drawn over the labeled grid lines.
7. Dismiss the graphics window:
wdelete

Drawing an Orthographic Projection

To draw a map that looks more like a globe, use the orthographic projection.
1. Open a graphics window for viewing:
window
2. Enter the following at the Command Line:
map_set,30,-100,0,/orthographic,/isotropic,/grid, $
/continents,/label,/horizon

The numbers following the MAP_SET command (30, -100, and 0) are the latitude and longitude to be centered and the angle of rotation for the North direction. The ISOTROPIC keyword creates a map that has the same scale in the vertical and horizontal directions, so we get a circular map in a rectangular window. IDL keywords (but not function and procedure names) can always be abbreviated to their minimum unique length. The GRID, COLOR, and LABEL keywords work the same as before. The HORIZON keyword draws the line at which the horizon exists. Without the HORIZON keyword, MAP_SET only draws the grid and the continents.

3. Dismiss the graphics window:
wdelete

Plotting a Portion of the Globe

You do not always have to plot the entire globe, you can plot a section of the globe by using the LIMIT keyword which specifies a region of the globe to plot.
1. Open a graphics window for viewing:
window
2. Enter the following at the Command Line:
map_set,32,-100,/azim,limit=[10, -130, 55, -70], $
/grid,/cont,/label

The azimuthal equidistant projection shows the United States and Mexico. The AZIM keyword selects the azimuthal equidistant projection. The keyword LIMIT is set equal to a four-element vector containing the minimum latitude, minimum longitude, maximum latitude, and maximum longitude.

3. Dismiss the graphics window:
wdelete

Plotting Data on Maps

You can annotate plots easily in IDL. To plot the location of selected cities in North America, as shown in the following figure, you need to create three arrays: one to hold latitudes, one to hold longitudes, and one to hold the names of the cities being plotted.
1. Open a graphics window for viewing:
window
2. Create a 5-element array of floating-point values representing latitudes in degrees North of zero.
lats=[40.02,34.00,38.55,48.25,17.29]
3. The values in LONS are negative because they represent degrees West of zero longitude.
lons=[-105.16,-119.40,-77.00,-114.21,-88.10]
4. Create a five-element array of string values. Text strings can be enclosed in either single quotes ('text') or double quotes ("text").
cities=['Boulder, CO','Santa Cruz, CA',$
'Washington, DC','Whitefish, MT','Belize, Belize']
5. Draw a Mercator projection featuring the United States and Mexico.
map_set,/mercator,/grid,/continent,limit=[10,-130,60,-70]
6. Place a plotting symbol at the location of each city.
plots,lons,lats,psym=4,symsize=1.4,color=220
7. Place the names of the cities near their respective symbols.
xyouts,lons,lats,cities,color=80, $
charthick=2,charsize=1.25,align=0.5

The PSYM keyword makes PLOTS use diamond-shaped plotting symbols instead of connecting lines. The SYMSIZE keyword controls the size of the plotting symbols. XYOUTS draws the characters for each element of the array CITIES at the corresponding location specified by the array elements of LONS and LATS. The CHARTHICK keyword controls the thickness of the text characters and the CHARSIZE keyword controls their size (1.0 is the default size). Setting the ALIGN keyword to 0.5 centers the city names over their corresponding data points.

Reading Latitudes and Longitudes

f a map projection is displayed, IDL can return the position of the cursor over the map in latitude and longitude coordinates.
1. Enter the command:
cursor, lon, lat & print, lat, lon
The CURSOR command reads the X and Y positions of the cursor when the mouse button is pressed and returns those values in the LON and LAT variables. Use the mouse to move the cursor over the map window and click on any point. The latitude and longitude of that point on the map are printed in the Output Log.
2. When you are finished with your map, dismiss the graphics window:
wdelete

Plotting Contours Over Maps

Contour plots can easily be drawn over map projections by using the OVERPLOT keyword to the CONTOUR routine. See the map in the figure below. Enter the following at the Command Line:
1. Open a graphics window for viewing:
window
2. Create a dataset to plot:
a=dist(91)
3. Create an lat value vector containing 91 values that range from -90 to 90 in 2 degree increments:
lat=findgen(91)*2-90
4. Create a lon value vector containing 91 values that range from -180 to 180 in 4 degree increments:
lon=findgen(91)*4-180
5. Create a new sinusoidal map projection over which to plot the data:
map_set,/grid,/continents,/sinusoidal,/horizon
6. Draw a twelve-level contour plot of array a over the map:
contour,a,lon,lat,/overplot,nlevels=12

Since latitudes range from -90 to 90 degrees and longitudes range from -180 to 180 degrees, you created two vectors containing the X and Y values for CONTOUR to use in displaying the array A. If the X and Y values are not explicitly specified, CONTOUR will plot the array A over only a small portion of the globe.

7. When you are finished with the map, dismiss the graphics window:
wdelete

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. Raed the binary file worldelv.dat.
elv=read_binary('/usr/local/rsi/idl_5.4/idl_5.4/examples/data/worldelv.dat',$ data_dims=[360,360],data_type=1)
2. Load a color table.
loadct, 26
3. View the data as an image.
tv,elv

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, well use the SHIFT function on the dataset before proceeding.

4. 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.
elv=shift(elv, 180, 0)
5. View the data as an image.
tv,elv

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.

6. Create a Mollweide projection with continents and gridlines.
map_set,/mollweide,/cont,/grid,color=100
7. Warp the image using bilinear interpolation and save the result in the variable new.
new=map_image(elv,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.
8. Display the new image over the map:
tv,new,sx,sy

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.

9. The continent outlines and thick grid lines can be displayed, as shown next, by entering:
map_continents
map_grid,glinethick=3


 
This information is available in alternative formats upon request by individuals with disabilities. Please send email to alt-format@msi.umn.edu or call 612-624-0528.

HOME | QUESTIONS | FEEDBACK
Employment | Events | Links | People | Programs | Publications | Support | Welcome
 


URL: http://www.msi.umn.edu/software/fast/tutorial/fast-starting.html
This page last modified on Friday, 03 November, 2000,  09:10:02 CDT  
Please direct questions or problems to help@msi.umn.edu  
Website related questions or problems should be dirrected to webmaster@msi.umn.edu