![]() | r.proj: A Program to Cartographically Reproject Raster Maps For Use With the GRASS GIS
S.J.D. CoxAGCRC, CSIRO Exploration & Mining, Nedlands, WA |
Progressing further in this document and web constitutes acceptance of the terms of our copyright and disclaimer
This report describes the use and operation of the program r.proj, used with the GRASS GIS system. The report contains (i) a discussion of the problem which motivated the development of the program, (ii) a description of the method used, (iii) the manual page describing the usage of the program, (iv) a listing of the source-code.
Introduction
Map projections
Map projections are a method of representing information from a curved surface (usually a spheroid) in two dimensions, typically to allow indexing through cartesian coordinates. There are a wide variety of projections, with common ones divided into a number of classes, including cylindrical and pseudo-cylindrical, conic and pseudo-conic, and azimuthal methods, each of which may be conformal, equal-area, or neither.
The particular projection chosen depends on the purpose of the project, and the size, shape and location of the area of interest. For example, normal cylindrical projections are good for maps which are of greater extent east-west than north-south and in equatorial regions, while conic projections are better in mid-latitudes; transverse cylindrical projections are used for maps which are of greater extent north-south than east-west; azimuthal projections are used for polar regions. Oblique versions of any of these may also be used. Conformal projections preserve angular relationships, and better preserve arc-length, while equal-area projections are more appropriate for statistical studies and work in which the amount of material is important.
Projections are defined by precise mathematical relations, so the method of projecting coordinates from a geographic reference frame (latitude-longitude) into a projected cartesian reference frame (eg metres) is governed by these equations. Inverse projections can also be achieved. The public-domain Unix software package proj [1] has been designed to perform these transformations, and the user's manual contains a detailed description of over 100 useful projections. This also includes a programmers library of the projection methods to support other software development.
Thus, converting a "vector" map - in which objects are located with arbitrary spatial precision - from one projection into another is usually accomplished by a simple two-step process: first the location of all the points in the map are converted from the source through an inverse projection into latitude-longitude, and then through a forward projection into the target. (Of course the procedure will be one-step if either the source or target is in geographic coordinates.) Converting a raster map, or image, between different projections, however, involves additional considerations. A raster may be considered to represent a sampling of a process at a regular, ordered set of locations. The set of locations that lie at the intersections of a cartesian grid in one projection will not, in general, coincide with the sample points in another projection. Thus, the conversion of raster maps involves an interpolation step in which the values of points at intermediate locations relative to the source grid are estimated.
Projecting maps within the GRASS GIS
GIS data capture, import and transfer often requires a projection step, since the source or client will frequently be in a different projection to the working projection.
In some cases it is convenient to do the conversion outside the package, prior to import or after export, using software such as proj [1]. This is certainly the easiest method for site-lists, since there is no topology to be preserved, and proj can be used to process simple lists with a one-line command.
The format of files describing maps containing lines and arcs is generally more complex, as even in ascii parts of the files will describe topology, and not just locations. In the GRASS GIS package a program v.proj is provided to convert "vector" maps, transferring topology and attributes as well as node locations. This program uses the projection definition and parameters which are stored in the PROJ_INFO and PROJ_UNITS files in the PERMANENT mapset directory for every GRASS location.
However, although it is oriented mainly towards operations on raster maps, the standard GRASS distribution does not include an equivalent program to convert raster maps. That is the purpose of the program described here.
Design of r.proj
As discussed briefly above, the fundamental step in re-projecting a raster is resampling the source grid at locations corresponding to the intersections of a grid in the target projection. The basic procedure for accomplishing this, therefore, is as follows:
1. Generate a list of the grid-cell locations in the target;
2. Transform the coordinates of these into the source projection;
3. Resample the source grid, using an appropriate method, at these locations;
4. Copy these values into the correct grid-cells in the target.
Existing programs in either the GRASS distribution or contributed code, from other public-domain sources, or using standard Unix tools, are designed to accomplish all of these steps. In particular, r.stats [2] will generate a list of grid-cell locations (using the -1g flags), proj [1] will perform conversions into and out-of almost any projection, and s.sample [3] is designed to resample a grid at a list of arbitrary locations. For this reason, r.proj has been written as a Bourne-shell-script which essentially links these together, so that they are invoked automatically using a one-line command.
An alternative procedure might have converted the source grid cell values into a site-list in the target, and then resampled this on a grid in the target. Consider, however, that s.sample interpolates using a regular grid as its source, in which the indexing is implicit, whereas in the various tools for converting an irregularly located site-list into a grid (s.surf.tps, s.surf.idw, etc) the source data has to be explicitly sorted and indexed. As the two procedures will produce equivalent results, the intrinsic performance advantage of the chosen method is clear.
The usage is exemplified in the attached manual page. The source code is also attached, which may be examined for a detailed understanding of the method.
Note that, following normal GRASS conventions, the coverage and resolution of the resulting grid is set by the current region settings, which may be adjusted using g.region. The target raster will be relatively unbiased for all cases if its grid has a similar resolution to the source, so that the resampling/interpolation step is only a local operation. If the resolution is changed significantly, then the behaviour of the generalisation or refinement will depend on the model of the process being represented. This will be very different for categorical versus numerical data. Note that three methods for the local interpolation step are provided, corresponding to the three methods provided by s.sample.
Future enhancements
Since it is a script, the performance of r.proj depends on the performance of the components. The slowest step is in s.sample. While in this procedure there is very intensive disk access. Examination of s.sample (and advice from the author, Darrell McCauley) shows that there are three calls to get_row for each sample point in the case of bilinear interpolation, five for cubic, in order to retrieve the required section of the source grid. This is an expensive disk seek and (often) decompress operation which is clearly having a substantial effect, and appears to be negating the advantages expected from implicit indexing, discussed above. A substantial improvement might be expected if (a) the target points were sorted by northing before being passed to s.sample, and (b) s.sample held the rows in buffers, to be re-used as long as the points in the list fell within the same grid-row. The output would subsequently have to be "un-sorted" of course, in order to regain the original cell-order for the target grid.
Acknowledgments: This report is published with the permission of the Director of the Australian Geodynamics Cooperative Research Centre.
References
[1] Evenden, G.I. (1990) Cartographic projection procedures for the UNIX environment - a user's manual. USGS Open-File Report 90-284 (Also see Interim Report and 2nd Interim Report on Release 4, Evenden 1994).
[2] Shapiro, M. r.stats - Generates area statistics for raster map layers. GRASS 4.1 documentation (main section).
[3] McCauley, J.D., s.sample - Sample a raster file at site locations. GRASS 4.1 documentation (contrib section).
[95/96 Publication List]
[AGCRC Home]
[Feedback]
[Copyright and Disclaimer]
Copyright © 1997 AGCRC & CSIRO
Publications Contact
10/10/97 13:35