Langue: en

Version: 331696 (ubuntu - 24/10/10)

Section: 1 (Commandes utilisateur)


sphdistance - Calculate nearest distances from Voronoi construction of spherical data


sphdistance infiles -Ggrdfile [ -C ] [ -D ] [ -E ] [ -F ] [ -H[i][nrec] ] [ -Ixinc[unit][=|+][/yinc[unit][=|+]] ] [ -Lunit ] [ -Qvoronoi.d ] [ -Rwest/east/south/north[r] ] [ -V ] [ -:[i|o] ] [ -b[i|o][s|S|d|D[ncol]|c[var1/...]] ] [ -m[i|o][flag] ]


sphdistance reads one or more ASCII [or binary] files (or standard input) containing lon, lat and performs the construction of Voronoi polygons. These polygons are then processed to calculate the nearest distance to each node of the lattice and written to the specified grid. The Voronoi algorithm used is STRIPACK. As an option, you may provide pre-calculated Voronoi polygon file in the format written by sphtriangulate, thus bypassing the memory- and time-consuming triangularization.
Data files with the point coordinates in ASCII (or binary; see -b). If no files are given the standard input is read.


For large data set you can save some memory (at the expense of more processing) by only storing one form of location coordinates (geographic or Cartesian 3-D vectors) at any given time, translating from one form to the other when necessary [Default keeps both arrays in memory]. Not applicable with -Q.
Used with -m to skip the last (repeated) input vertex at the end of a closed segment if it equals the first point in the segment. Requires -m [Default uses all points].
Instead of computing distances, return the ID numbers of the Voronoi polygons that each grid node is inside [Default computes distances].
Input file(s) has header record(s). If used, the default number of header records is N_HEADER_RECS. Use -Hi if only input data should have header records [Default will write out header records if the input data have them]. Blank lines and lines starting with # are always skipped.
x_inc [and optionally y_inc] is the grid spacing. Optionally, append a suffix modifier. Geographical (degrees) coordinates: Append m to indicate arc minutes or c to indicate arc seconds. If one of the units e, k, i, or n is appended instead, the increment is assumed to be given in meter, km, miles, or nautical miles, respectively, and will be converted to the equivalent degrees longitude at the middle latitude of the region (the conversion depends on 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 = 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 + 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 Appendix B for details. Note: if -Rgrdfile is used then grid spacing has already been initialized; use -I to override the values.
Specify the unit used for distance calculations. Choose among e (m), k (km), m (mile), n (nautical mile), or d (spherical degree). A spherical approximation is used unless ELLIPSOID is set to an actual ellipsoid. -N Read the information pertaining to each Voronoi polygon (the unique node lon, lat and polygon area) from a separate file [Default aquires this information from the ASCII segment headers of the output file]. Required if binary input via -Q is used.
Append the name of a file with pre-calculated Voronoi polygons [Default performs the Voronoi construction on input data]. For binary data -bi you must specify the node information separately (via -N).
west, east, south, and north specify the Region of interest, and you may specify them in decimal degrees or in [+-]dd:mm[:ss.xxx][W|E|S|N] format. Append r if lower left and upper right map coordinates are given instead of w/e/s/n. The two shorthands -Rg and -Rd stand for global domain (0/360 and -180/+180 in longitude respectively, with -90/+90 in latitude). Alternatively, specify the name of an existing grid file and the -R settings (and grid spacing, if applicable) are copied from the grid.
Selects verbose mode, which will send progress reports to stderr [Default runs "silently"].
Toggles between (longitude,latitude) and (latitude,longitude) input and/or output. [Default is (longitude,latitude)]. Append i to select input only or o to select output only. [Default affects both].
Selects binary input. Append s for single precision [Default is d (double)]. Uppercase S or D will force byte-swapping. Optionally, append ncol, the number of columns in your binary input file if it exceeds the columns needed by the program. Or append c if the input file is netCDF. Optionally, append var1/var2/... to specify the variables to be read. [Default is 2 input columns].
Selects binary output. Append s for single precision [Default is d (double)]. Uppercase S or D will force byte-swapping. Optionally, append ncol, the number of desired columns in your binary output file. [Default is same as input].
Multiple segment file(s). Segments are separated by a special record. For ASCII files the first character must be flag [Default is '>']. For binary files all fields must be NaN and -b must set the number of output columns explicitly. By default the -m setting applies to both input and output. Use -mi and -mo to give separate settings to input and output.


The ASCII output formats of numerical data are controlled by parameters in your .gmtdefaults4 file. Longitude and latitude are formatted according to OUTPUT_DEGREE_FORMAT, whereas other values are formatted according to D_FORMAT. Be aware that the format in effect can lead to loss of precision in the output, which can lead to various problems downstream. If you find the output is not written with enough precision, consider switching to binary output (-bo if available) or specify more decimals using the D_FORMAT setting.


Regardless of the precision of the input data, GMT programs that create grid files will internally hold the grids in 4-byte floating point arrays. This is done to conserve memory and furthermore most if not all real data can be stored using 4-byte floating point values. Data with higher precision (i.e., double precision values) will lose that precision once GMT operates on the grid or writes out new grids. To limit loss of precision when processing data you should always consider normalizing the data prior to processing.


To construct Voronoi polygons from the points in the file testdata.txt and then calculate distances from the data to a global 1x1 degree grid, use

sphdistance testdata.txt -Rg -I1 -Gglobedist.grd

To generate the same grid in two steps using sphtriangulate separately, try

sphtriangulate testdata.txt -Qv > voronoi.d
sphdistance -Qvoronoi.d -Rg -I1 -Gglobedist.grd


GMT(1), sphinterpolate(1) sphtriangulate(1) triangulate(1)


Renka, R, J., 1997, Algorithm 772: STRIPACK: Delaunay Triangulation and Voronoi Diagram on the Surface of a Sphere, AMC Trans. Math. Software, 23 (3), 416-434.