sortCont

Overview

sortCont sorts unorganized 2-point contour line segments (bin_vect records generated by contgrid) into continuous, end-to-end connected polylines grouped by contour level, minimizing plotter pen-ups and optionally exporting clean ASCII polylines with custom line-break markers and separate label files.


Syntax & CLI Options

sortCont [-v] [-ascii] [-keep_labels] [-low <val>] [-high <val>] [-break_string "<str>"] <rawcontfile> <sortcontfile>
Flag Description
-v Verbose progress output during segment chaining.
-ascii Output sorted contours as 3-column ASCII (lat/y lon/x value) instead of binary bin_vect records.
-keep_labels When -ascii is enabled, write embedded contour label records (x1 == -999999.0) to <sortcontfile>.labels.
-break_string "<str>" When -ascii is enabled, print <str> (e.g., "999 999") at every polyline break (pen-up).
-low <val> Minimum depth filter parameter (default: -10000.0).
-high <val> Maximum depth filter parameter (default: 10000.0).
<rawcontfile> Input unsorted binary bin_vect contour file.
<sortcontfile> Output sorted binary or ASCII contour file.

How It Works

  1. Contour Level Inventory:
    • Scans <rawcontfile> (sizeof(bin_vect) per record) to catalog every distinct contour elevation (vector.value) and count the number of segments at each level.
    • Records with vector.x1 == -999999.0 are treated as contour labels: in binary mode they are copied directly to <sortcontfile>, whereas in -ascii -keep_labels mode they are written to <sortcontfile>.labels.
  2. End-to-End Segment Chaining:
    • For each contour level levels[i], loads all segments at that level into memory.
    • Starts a new polyline at the first unused segment and searches remaining unused segments for one whose start point (x1, y1) or end point (x2, y2) matches the current tail (thevect->x2, thevect->y2) (reversing segment orientation when matched on (x2, y2)).
    • When no matching continuation segment exists, marks a pen-up break (penup[location] = 1) and begins the next polyline until all segments for that level are chained.
  3. Output:
    • Writes either binary bin_vect records or ASCII y1 x1 value vertices (inserting <break_string> whenever penup[k] == 1).

Examples

Sort a binary contour file into connected binary polylines

sortCont harbor.cont harbor_sorted.cont

Convert binary contours to ASCII polylines with "999 999" line breaks and a label file

sortCont -ascii -keep_labels -break_string "999 999" harbor.cont harbor_contours.txt

Workflow Context

  • Upstream: contgrid (extracts raw binary bin_vect contour segments from an .r4 grid).
  • Downstream: embedCont, getdxf, jview.