.TH SPHDISTANCE 1gmt "Feb 27 2014" "GMT 4.5.13 (SVN)" "Generic Mapping Tools" .SH NAME sphdistance \- Calculate nearest distances from Voronoi construction of spherical data .SH SYNOPSIS \fBsphdistance\fP \fIinfiles\fP \fB\-G\fP\fIgrdfile\fP [ \fB\-C\fP ] [ \fB\-D\fP ] [ \fB\-E\fP ] [ \fB\-F\fP ] [ \fB\-H\fP[\fBi\fP][\fInrec\fP] ] [ \fB\-I\fP\fIxinc\fP[\fIunit\fP][\fB=\fP|\fB+\fP][/\fIyinc\fP[\fIunit\fP][\fB=\fP|\fB+\fP]] ] [ \fB\-L\fP\fIunit\fP ] [ \fB\-Q\fP\fIvoronoi.d\fP ] [ \fB\-R\fP\fIwest\fP/\fIeast\fP/\fIsouth\fP/\fInorth\fP[\fBr\fP] ] [ \fB\-V\fP ] [ \fB\-:\fP[\fBi\fP|\fBo\fP] ] [ \fB\-b\fP[\fBi\fP|\fBo\fP][\fBs\fP|\fBS\fP|\fBd\fP|\fBD\fP[\fIncol\fP]|\fBc\fP[\fIvar1\fP\fB/\fP\fI...\fP]] ] [ \fB\-m\fP[\fBi\fP|\fBo\fP][\fIflag\fP] ] .SH DESCRIPTION \fBsphdistance\fP 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 \fBsphtriangulate\fP, thus bypassing the memory- and time-consuming triangularization. .TP \fIinfiles\fP Data files with the point coordinates in ASCII (or binary; see \fB\-b\fP). If no files are given the standard input is read. .TP .B \-G Name of the output grid to hold the computed distances. .SH OPTIONS .TP .B \-C 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 \fB\-Q\fP. .TP .B \-D Used with \fB\-m\fP to skip the last (repeated) input vertex at the end of a closed segment if it equals the first point in the segment. Requires \fB\-m\fP [Default uses all points]. .TP .B \-E Instead of computing distances, return the ID numbers of the Voronoi polygons that each grid node is inside [Default computes distances]. .TP \fB\-F\fP Force pixel node registration [Default is gridline registration]. (Node registrations are defined in \fBGMT\fP Cookbook Appendix B on grid file formats.) .TP \fB\-H\fP Input file(s) has header record(s). If used, the default number of header records is \fBN_HEADER_RECS\fP. Use \fB\-Hi\fP 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. .TP \fB\-I\fP \fIx_inc\fP [and optionally \fIy_inc\fP] is the grid spacing. Optionally, append a suffix modifier. \fBGeographical (degrees) coordinates\fP: Append \fBm\fP to indicate arc minutes or \fBc\fP to indicate arc seconds. If one of the units \fBe\fP, \fBk\fP, \fBi\fP, or \fBn\fP 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 \fBELLIPSOID\fP). If /\fIy_inc\fP is given but set to 0 it will be reset equal to \fIx_inc\fP; otherwise it will be converted to degrees latitude. \fBAll coordinates\fP: If \fB=\fP is appended then the corresponding max \fIx\fP (\fIeast\fP) or \fIy\fP (\fInorth\fP) 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 \fInumber of nodes\fP desired by appending \fB+\fP 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 \fB\-R\fP\fIgrdfile\fP is used then grid spacing has already been initialized; use \fB\-I\fP to override the values. .TP .B \-L Specify the unit used for distance calculations. Choose among \fBe\fP (m), \fBk\fP (km), \fBm\fP (mile), \fBn\fP (nautical mile), or \fBd\fP (spherical degree). A spherical approximation is used unless \fBELLIPSOID\fP is set to an actual ellipsoid. .B \-N Read the information pertaining to each Voronoi polygon (the unique node lon, lat and polygon area) from a separate file [Default acquires this information from the ASCII segment headers of the output file]. Required if binary input via \fB\-Q\fP is used. .TP .B \-Q Append the name of a file with pre-calculated Voronoi polygons [Default performs the Voronoi construction on input data]. For binary data \fB\-bi\fP you must specify the node information separately (via \fB\-N\fP). .TP \fB\-R\fP \fIwest, east, south,\fP and \fInorth\fP 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 \fBr\fP if lower left and upper right map coordinates are given instead of w/e/s/n. The two shorthands \fB\-Rg\fP and \fB\-Rd\fP 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 \fB\-R\fP settings (and grid spacing, if applicable) are copied from the grid. .TP \fB\-V\fP Selects verbose mode, which will send progress reports to stderr [Default runs "silently"]. .TP \fB\-:\fP Toggles between (longitude,latitude) and (latitude,longitude) input and/or output. [Default is (longitude,latitude)]. Append \fBi\fP to select input only or \fBo\fP to select output only. [Default affects both]. .TP \fB\-bi\fP Selects binary input. Append \fBs\fP for single precision [Default is \fBd\fP (double)]. Uppercase \fBS\fP or \fBD\fP will force byte-swapping. Optionally, append \fIncol\fP, the number of columns in your binary input file if it exceeds the columns needed by the program. Or append \fBc\fP if the input file is netCDF. Optionally, append \fIvar1\fP\fB/\fP\fIvar2\fP\fB/\fP\fI...\fP to specify the variables to be read. [Default is 2 input columns]. .TP \fB\-bo\fP Selects binary output. Append \fBs\fP for single precision [Default is \fBd\fP (double)]. Uppercase \fBS\fP or \fBD\fP will force byte-swapping. Optionally, append \fIncol\fP, the number of desired columns in your binary output file. [Default is same as input]. .TP \fB\-m\fP Multiple segment file(s). Segments are separated by a special record. For ASCII files the first character must be \fIflag\fP [Default is '>']. For binary files all fields must be NaN and \fB\-b\fP must set the number of output columns explicitly. By default the \fB\-m\fP setting applies to both input and output. Use \fB\-mi\fP and \fB\-mo\fP to give separate settings to input and output. .SH ASCII FORMAT PRECISION The ASCII output formats of numerical data are controlled by parameters in your \.gmtdefaults4 file. Longitude and latitude are formatted according to \fBOUTPUT_DEGREE_FORMAT\fP, whereas other values are formatted according to \fBD_FORMAT\fP. 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 (\fB\-bo\fP if available) or specify more decimals using the \fBD_FORMAT\fP setting. .SH GRID VALUES PRECISION 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. .SH EXAMPLES 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 .br .sp \fBsphdistance\fP testdata.txt \fB\-Rg \-I\fP1 \fB\-G\fPglobedist.grd .br .sp To generate the same grid in two steps using \fBsphtriangulate\fP separately, try .br .sp \fBsphtriangulate\fP testdata.txt \fB\-Qv\fP > voronoi.d .br \fBsphdistance\fP \fB\-Q\fPvoronoi.d \fB\-Rg \-I\fP1 \fB\-G\fPglobedist.grd .SH "SEE ALSO" .IR GMT (1), .IR sphinterpolate (1) .IR sphtriangulate (1) .IR triangulate (1) .SH REFERENCES Renka, R, J., 1997, Algorithm 772: STRIPACK: Delaunay Triangulation and Voronoi Diagram on the Surface of a Sphere, \fIAMC Trans. Math. Software, 23\fP (3), 416\-434.