grdproject

Forward and inverse map transformation of grids

Synopsis

gmt grdproject ingrid -Goutgrid -Jparameters [ -C[dx/dy] ] [ -Dxinc[+e|n][/yinc[+e|n]] ] [ -Edpi ] [ -F[c|i|p|e|f|k|M|n|u] ] [ -I ] [ -Mc|i|p ] [ -Rregion ] [ -V[level] ] [ -jflags ] [ -nflags ] [ -rreg ] [ --PAR=value ]

Note: No space is allowed between the option flag and the associated arguments.

Description

grdproject will do one of two things depending whether -I has been set. If set, it will transform a gridded data set from a rectangular coordinate system onto a geographical system by resampling the surface at the new nodes. If not set, it will project a geographical gridded data set onto a rectangular grid. To obtain the value at each new node, its location is inversely projected back onto the input grid after which a value is interpolated between the surrounding input grid values. By default bi-cubic interpolation is used. Aliasing is avoided by also forward projecting the input grid nodes. If two or more nodes are projected onto the same new node, their average will dominate in the calculation of the new node value. Interpolation and aliasing is controlled with the -n option. The new node spacing may be determined in one of several ways by specifying the grid spacing, number of nodes, or resolution. Nodes not constrained by input data are set to NaN.

The -R option can be used to select a map region larger or smaller than that implied by the extent of the grid file.

Required Arguments

ingrid[=ID|?varname][+bband][+ddivisor][+ninvalid][+ooffset][+sscale]

Optionally, append =ID for reading a specific file format [Default is =nf] or ?varname for a specific netCDF variable [Default is the first 2-D grid found by GMT]. The following modifiers are supported:

  • +b - Select a band [Default is 0].

  • +d - Divide data values by the given divisor [Default is 1].

  • +n - Replace data values matching invalid with NaN.

  • +o - Offset data values by the given offset [Default is 0].

  • +s - Scale data values by the given scale [Default is 1].

Note: Any offset is added after any scaling.

-Goutgrid[=ID][+ddivisor][+ninvalid][+ooffset|a][+sscale|a][:driver[dataType][+coptions]]

Optionally, append =ID for writing a specific file format. The following modifiers are supported:

  • +d - Divide data values by given divisor [Default is 1].

  • +n - Replace data values matching invalid with a NaN.

  • +o - Offset data values by the given offset, or append a for automatic range offset to preserve precision for integer grids [Default is 0].

  • +s - Scale data values by the given scale, or append a for automatic scaling to preserve precision for integer grids [Default is 1].

Note: Any offset is added before any scaling. +sa also sets +oa (unless overridden). To write specific formats via GDAL, use =gd and supply driver (and optionally dataType) and/or one or more concatenated GDAL -co options using +c. See the “Writing grids and images” cookbook section for more details.

-Jparameters

Specify the projection. (See full description) (See cookbook summary) (See projections table).

Optional Arguments

-C[dx/dy]

Let projected coordinates be relative to projection center [Default is relative to lower left corner]. Optionally, add offsets in the projected units to be added (or subtracted when -I is set) to (from) the projected coordinates, such as false eastings and northings for particular projection zones [0/0].

-Dxinc[+e|n][/yinc[+e|n]]

Set the grid spacing for the new grid. If neither -D nor -E are set then we select the same number of output nodes as there are input nodes. Optionally append a suffix modifier. Geographical (degrees) coordinates: Append m to indicate arc minutes or s to indicate arc seconds. If one of the units e, f, k, M, n or u is appended instead, the increment is assumed to be given in meter, foot, km, Mile, nautical mile or US survey foot, respectively, and will be converted to the equivalent degrees longitude at the middle latitude of the region (the conversion depends on PROJ_ELLIPSOID). If y_inc is given but set to 0 it will be reset equal to x_inc; otherwise it will be converted to degrees latitude. All coordinates: If +e is appended then the corresponding max x (east) or y (north) may be slightly adjusted to fit exactly the given increment [by default the increment may be adjusted slightly to fit the given domain]. Finally, instead of giving an increment you may specify the number of nodes desired by appending +n to the supplied integer argument; the increment is then recalculated from the number of nodes and the domain. The resulting increment value depends on whether you have selected a gridline-registered or pixel-registered grid; see GMT File Formats for details. Note: If -Rgrdfile is used then the grid spacing (and registration) have already been initialized; use -D (and -r) to override the values.

-Edpi

Set the resolution for the new grid in dots per inch.

-F[c|i|p|e|f|k|M|n|u]

Force 1:1 scaling, i.e., output (or input, see -I) data are in actual projected meters [e]. To specify other units, append f (foot), k (km), M (statute mile), n (nautical mile), u (US survey foot), i (inch), c (cm), or p (point). Without -F, the output (or input, see -I) are in the units specified by PROJ_LENGTH_UNIT (but see -M).

-I

Do the Inverse transformation, from rectangular to geographical.

-Mc|i|p

Append c, i, or p to indicate that cm, inch, or point should be the projected measure unit [Default is set by PROJ_LENGTH_UNIT in gmt.conf]. Cannot be used with -F.

-Rxmin/xmax/ymin/ymax[+r][+uunit]

Specify the region of interest. You may ask to project only a subset of the grid by specifying a smaller input w/e/s/n region [Default is the region given by the grid file]. (See full description) (See cookbook information).

-V[level]

Select verbosity level [w]. (See full description) (See cookbook information).

-je|f|g (more …)

Determine how spherical distances or coordinate transformations are calculated.

-n[b|c|l|n][+a][+bBC][+c][+tthreshold] (more …)

Select interpolation mode for grids.

-r[g|p] (more …)

Set node registration [gridline].

-^ or just -

Print a short message about the syntax of the command, then exit (Note: on Windows just use -).

-+ or just +

Print an extensive usage (help) message, including the explanation of any module-specific option (but not the GMT common options), then exit.

-? or no arguments

Print a complete usage (help) message, including the explanation of all options, then exit.

--PAR=value

Temporarily override a GMT default setting; repeatable. See gmt.conf for parameters.

Examples

Note: Below are some examples of valid syntax for this module. The examples that use remote files (file names starting with @) can be cut and pasted into your terminal for testing. Other commands requiring input files are just dummy examples of the types of uses that are common but cannot be run verbatim as written.

To transform a chunk of the geographical remote grid earth_relief_05m onto a pixel Mercator grid at 300 dpi given a scale of 0.25 inches per degree, run

gmt grdproject @earth_relief_05m -R20/50/12/25 -Jm0.25i -E300 -r -Getopo5_merc.nc -Mi

To inversely transform the file topo_tm.nc back onto a geographical grid, use

gmt grdproject topo_tm.nc -R-80/-70/20/40 -Jt-75/1:500000 -I -D5m -V -Gtopo.nc

This assumes, of course, that the coordinates in topo_tm.nc were created with the same projection parameters.

To inversely transform the file topo_utm.nc (which is in UTM meters) back to a geographical grid we specify a one-to-one mapping with meter as the measure unit:

gmt grdproject topo_utm.nc -R203/205/60/65 -Ju5/1:1 -I -Gtopo.nc -V

To inversely transform the file data.nc (which is in Mercator meters with Greenwich as the central longitude and a false easting of -4 and produced on the ellipse WGS-72) back to a geographical grid we specify a one-to-one mapping with meter as the measure unit:

gmt grdproject data.nc -Jm/1:1 -I -F -C-4/0 -Gdata_geo.nc -V --PROJ_ELLIPSOID=WGS-72

Output Region Issues

The boundaries of a projected (rectangular) data set will not necessarily give rectangular geographical boundaries (Mercator is one exception). In those cases some nodes may be unconstrained (set to NaN). To get a full grid back, your input grid may have to cover a larger area than you are interested in.

Select Ellipsoidal versus Spherical Solution

GMT will use ellipsoidal formulae if they are implemented and the user have selected an ellipsoid as the reference shape (see PROJ_ELLIPSOID). The user needs to be aware of a few potential pitfalls: (1) For some projections, such as Transverse Mercator, Albers, and Lambert’s conformal conic we use the ellipsoidal expressions when the areas mapped are small, and switch to the spherical expressions (and substituting the appropriate auxiliary latitudes) for larger maps. The ellipsoidal formulae are used as follows: (a) Transverse Mercator: When all points are within 10 degrees of central meridian, (b) Conic projections when longitudinal range is less than 90 degrees, (c) Cassini projection when all points are within 4 degrees of central meridian. (2) When you are trying to match some historical data (e.g., coordinates obtained with a certain projection and a certain reference ellipsoid) you may find that GMT gives results that are slightly different. One likely source of this mismatch is that older calculations often used less significant digits. For instance, Snyder’s examples often use the Clarke 1866 ellipsoid (defined by him as having a flattening f = 1/294.98). From f we get the eccentricity squared to be 0.00676862818 (this is what GMT uses), while Snyder rounds off and uses 0.00676866. This difference can give discrepancies of several tens of cm. If you need to reproduce coordinates projected with this slightly different eccentricity, you should specify your own ellipsoid with the same parameters as Clarke 1866, but with f = 1/294.97861076. Also, be aware that older data may be referenced to different datums, and unless you know which datum was used and convert all data to a common datum you may experience mismatches of tens to hundreds of meters. (3) Finally, be aware that PROJ_SCALE_FACTOR have certain default values for some projections so you may have to override the setting in order to match results produced with other settings. The decision of ellipsoidal (if available) versus spherical is taken in this order:

  • The user specifies -je which forces the ellipsoidal solution.

  • The user specifies -jg which forces the spherical solution.

  • A specific region is set via -R which implies that portions of that region will be more than stated limit of longitude from the specific (or implied if not set) central meridian.

When a spherical solution is requested or implied, we consider the currently selected ellipsoid and substitute the relevant auxiliary latitude as latitude in the exact equation. Finally, coordinate conversion may also be affected by the selected PROJ_SCALE_FACTOR which is typically 0.9996 but is 1 for a sphere. Note: For some projection, a spherical solution may be used despite the user having selected an ellipsoid. This occurs when the user’s -R setting implies a region that exceeds the domain in which the ellipsoidal series expansions are valid. These are the conditions: (1) Lambert Conformal Conic (-JL)and Albers Equal-Area (-JB) will use the spherical solution when the map scale exceeds 1.0E7. (2) Transverse Mercator (-JT) and UTM (-JU) will will use the spherical solution when either the west or east boundary given in -R is more than 10 degrees from the central meridian, and (3) same for Cassini (-JC) but with a limit of only 4 degrees.

See Also

gmt, gmt.conf, mapproject