How to Optimize Your Mapping Application
This section describes several methods for improving the performance of your mapping application. These methods will help you to design a mapping application that performs well at an acceptable resolution.
In general, map data is processed and displayed in four stages in PV‑WAVE. When considering how to improve the performance of a mapping application, it is helpful to keep in mind these four stages, illustrated in
Figure 12-8: Stages to Generate Map.
This section focuses on performance improvements that can be gained in stages 1 and 2. Stage 3 cannot be substantially improved because it depends on array operations, which are already optimized by PV‑WAVE.
The performance of stage 4, plotting the data, depends largely on the size of the dataset being plotted. Reducing the size of the dataset is the primary focus of this section.
A summary of methods for improving the speed at which PV‑WAVE reads and displays map data is shown in
Table 12-2: Methods for Optimizing Mapping Applications. More details are provided in this section.
Subsetting Data with MAP Procedure Keywords
Perhaps the easiest way to improve the performance of a mapping application is to subset the map dataset using keywords provided with the MAP procedure. These keywords are passed directly to the procedure that reads the map dataset, so that the data is subsetted before it is read into memory.
For additional information on the keywords described below, see the description of the MAP procedure in the PV‑WAVE
Reference. See also
"Subsetting the Map Dataset".
Subsetting with the Select Keyword
The Select keyword reduces the amount of data returned to the MAP procedure. It lets you specify only the map features that you want to plot from the dataset. Selecting a subset of the available map features can improve performance significantly.
The Select keyword can be used to subset the world_db and usgs_db datasets.
Subsetting with Range, Zoom, and Center Keywords
These keywords let you subset a map dataset by specifying a range of data to plot. In other words, only the data that falls within a selected area is returned by the MAP procedure. With the Range keyword, you specify an area to plot within a range of longitude and latitude values. The Zoom and Center keywords allow you display an area surrounding a specified point.
Subsetting with the Resolution Keyword
The Resolution keyword reduces (samples) the number of data points that are plotted, thereby reducing the map resolution. This keyword can be useful when plotting a wide area map where the full resolution of the database might not be discernible given the resolution of the output device.
This keyword can only be used with the world_db dataset.
Use File_Path and Read_Path Keywords to Avoid Re-reading Data
As noted previously, the procedure that reads the dataset (e.g., world_db or usgs_db) is responsible for performing most of the subsetting. However, each time the MAP procedure is called, the map-reading procedure is called, and the process of subsetting the data is repeated.
This ensures that the full resolution of these datasets can be accessed when needed, but can slow down performance when the same data subset must be plotted repeatedly.
The File_Path and Read_Path keywords to the MAP procedure store a subsetted dataset in a binary file and then read it for subsequent calls to MAP. The Read_Path keyword restores the data quickly without calling the dataset-reading procedure.
Thus the mapping process is reduced to reading a small dataset, projecting it, and plotting it. This method provides the optimal performance and the best resolution for large datasets. The demonstration routines for mapping use this technique to optimize their speed of execution, and the same technique can be used in your own applications. The demonstration routines are in:
(UNIX) $RW_DIR/mapping-2_0/demo
(WIN) %RW_DIR\mapping-2_0\demo
Where RW_DIR is the main Rogue Wave installation directory.
Creating a Basemap Image
There are other techniques, not strictly related to mapping, which can be used in some circumstances to further increase the performance of drawing a basemap. For instance, if a basemap needs to be redrawn quickly many times in an X Window System environment, the command:
DEVICE, Copy
can be used to rapidly update a window from a copy held in another window. The following example demonstrates this, and can be used to update a map in a fraction of a second, but with the limitation that the resolution is limited to that of the window in which the map is created.
; Create an invisible pixmap window.
WINDOW, 1, Xsize = 600, Ysize = 400, /Pixmap
; Draw a map of Europe.
MAP, Center = [10, 50], Zoom = 7
; Create a visible window of the same size.
WINDOW, 0, Xsize = 600, Ysize = 400
; Copy the contents of the pixmap window to the visible window.
; (This can be repeated indefinitely.)
DEVICE, Copy = [0, 0, 600, 400, 0, 0, 1]
It is also possible to use the TVRD command to copy the contents of a window containing a basemap into a byte array variable. Saving this variable in a file allows the basemap to be restored by simply reading the variable and redisplaying the image, as in this example:
; Create a window.
WINDOW, Xsize = 600, Ysize = 400
; Draw a map of Europe.
MAP, Center = [10, 50], Zoom = 7
; Copy the contents of the window to the basemap variable.
basemap = TVRD(0,0, 600, 400)
; Save the basemap variable.
SAVE, basemap, File = 'mybasemap.dat'
Then to restore the basemap later:
; Restore the basemap image.
RESTORE, File = 'mybasemap.dat'
; Create a window.
WINDOW, 1, Xsize = 600, Ysize = 400
; Redisplay the basemap image.
TV, basemap
Optimized Data Reading
Two procedures designed to read map datasets are provided with PV‑WAVE. These procedures, world_db and usgs_db, read map data directly into memory whenever they are called.
If you supply your own dataset (that is, a dataset other than the World Databank II or USGS datasets) and write a procedure to read it, it is possible that it will be too large to read the entire dataset into memory at once.
In this case, a C or FORTRAN program can be written to read and subset the data prior to placing it in memory. Using connectivity features, such as LINKNLOAD, a PV‑WAVE procedure can be written to call the C or FORTRAN program in a mapping application. This method can provide the best access speed for large datasets, and can be useful when you need to perform a lot of testing to determine how to subset the data correctly.
See
"Accessing Other Map Datasets" for information on writing a procedure to read a dataset.