.TH GMTSTITCH 1gmt "Feb 27 2014" "GMT 4.5.13 (SVN)" "Generic Mapping Tools" .SH NAME gmtstitch \- Join line segments whose end points match within tolerance .SH SYNOPSIS \fBgmtstitch\fP [ \fIinfiles\fP ] [ \fB\-C\fP[\fIclosed\fP] ] [ \fB\-D\fP[\fItemplate\fP] ] [ \fB\-H\fP[\fBi\fP][\fInrec\fP] ] [ \fB\-L\fP[\fIlinkfile\fP] ] [ \fB\-Q\fP[\fItemplate\fP] ] [ \fB\-T\fP\fIcutoff\fP[\fBm\fP|\fBc\fP|\fBe\fP|\fBE\fP|\fBk\fP|\fBK\fP][/\fInn_dist\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\-bo\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 \fBgmtstitch\fP reads one or more data files (which may be multisegment files; see \fB\-m\fP) and examines the coordinates of the end points of all line segments. If a pair of end points are identical or closer to each other than the specified separation tolerance then the two line segments are joined into a single segment. The process repeats until all the remaining endpoints no longer pass the tolerance test; the resulting segments are then written out to standard output. It it is not clear what the separation tolerance should be then use \fB\-L\fP to get a list of all separation distances and analyze them to determine a suitable cutoff. .TP \fIfile(s)\fP One of more data files. If none are supplied then we read standard input. .SH OPTIONS .TP \fB\-C\fP Write all the closed polygons to \fIclosed\fP [gmtstitch_closed.d] and all other segments as they are to stdout. No stitching takes place. Use \fB\-T\fP\fIcutoff\fP to set a minimum separation [0], and if \fIcutoff\fP is > 0 then we also close the polygons on output. .TP \fB\-D\fP For multiple segment data, dump each segment to a separate output file [Default writes a multiple segment file to stdout]. Append a format template for the individual file names; this template \fBmust\fP contain a C format specifier that can format an integer argument (the segment number); this is usually %d but could be %8.8d which gives leading zeros, etc. Optionally, it may also contain the format %c \fIbefore\fP the integer; this will then be replaced by C (closed) or O (open) to indicate segment type. [Default is gmtstitch_segment_%d.d]. Note that segment headers will be written in either case. For composite segments, a generic segment header will be written and the segment headers of individual pieces will be written out as comments to make it possible to identify where the stitched pieces came from. .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\-L\fP Writes the link information to the specified file [links.d]. For each segment we write the original segment id, and for the beginning and end point of the segment we report the id of the closest segment, whether it is the beginning (B) or end (E) point that is closest, and the distance between those points in units determined by \fB\-T\fP. .TP \fB\-Q\fP Used with \fB\-D\fP to a list file with the names of the individual output files. Optionally, append a filename template for the individual file names; this template \fBmay\fP contain a C format specifier that can format an character (C or O for closed or open, respectively). [Default is gmtstitch_list.d]. .TP \fB\-T\fP Specifies the separation tolerance in the data coordinate units [0]. Append \fBm\fP or \fBc\fP for minutes or seconds, or \fBe\fP or \fBk\fP for meters or km (implies \fB\-fg\fP using use flat Earth approximation. Use \fBE\fP or \fBK\fP for exact geodesic distances; however. if the current ELLIPSOID is Sphere then spherical great circle distances are used. If two lines has endpoints that are closer than this cutoff they will be joined. Optionally, append /\fInn_dist\fP which adds the requirement that a link will only be made if the second closest connection exceeds the \fInn_dist\fP. The latter distance is assumed to be in the same units as \fIcutoff\fP. .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\-f\fP Special formatting of input and/or output columns (time or geographical data). Specify \fBi\fP or \fBo\fP to make this apply only to input or output [Default applies to both]. Give one or more columns (or column ranges) separated by commas. Append \fBT\fP (absolute calendar time), \fBt\fP (relative time in chosen \fBTIME_UNIT\fP since \fBTIME_EPOCH\fP), \fBx\fP (longitude), \fBy\fP (latitude), or \fBf\fP (floating point) to each column or column range item. Shorthand \fB\-f\fP[\fBi\fP|\fBo\fP]\fBg\fP means \fB\-f\fP[\fBi\fP|\fBo\fP]0\fBx\fP,1\fBy\fP (geographic coordinates). .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 EXAMPLES .sp To combine the digitized multisegment lines segment_*.d (whose coordinates are in cm) into as few complete lines as possible, assuming the end points slop could be up to 0.1 mm, run .br .sp \fBgmtstitch\fP segment_*.d \fB\-Tf\fP 0.1 \fB\-m\fP > new_segments.d .br .sp To combine the digitized segments in the multisegment file my_lines.d (whose coordinates are in lon,lat) into as few complete lines as possible, assuming the end points slop could be up to 150 m, and write the complete segments to separate files called Map_segment_0001.dat, Map_segment_0002.dat, etc., run .sp \fBgmtstitch\fP my_lines.d \fB\-Tf\fP 0.15k \fB\-m\fP \fB\-D\fP Map_segment_%4.4d.dat .SH BUGS The line connection does not work if a line only has a single point. However, gmtstitch will correctly add the point to the nearest segment. Running gmtstitch again on the new set of lines will eventually connect all close lines. .SH "SEE ALSO" .IR GMT (1), .IR mapproject (1)