src.inout.simple_curve_writer

Classes

SimpleCurveWriter([output_gpkg, output_shp, ...])

class src.inout.simple_curve_writer.SimpleCurveWriter(output_gpkg=None, output_shp=None, output_csv=None, curve_pcloud=None, curve_pcloud_step=None, slope_output_form='sin', epsg=None, out_prefix=None, coord_center=None)
Author:

Alberto M. Esmoris Pena

Multi-format output sink for the polylines produced by SimpleCurveExtractor. Emits up to four artefacts in a single dispatch:

  • GeoPackage (output_gpkg) – one feature per chained polyline, with per-feature metadata columns.

  • Shapefile (output_shp) – equivalent surface with the dbase-name truncation rules described below.

  • CSV (output_csv) – per-vertex flat table.

  • LAS curve point cloud (curve_pcloud) – resampled polylines with per-vertex slope and segment fields.

Instances are constructed once per pipeline run from the private SCE pipeline phase _step_output_writers; they take a snapshot of the relevant SCE configuration plus the centring offset and emit the polyline outputs without further coupling to the orchestrator. See SimpleCurveExtractor for the upstream pipeline that produces curves and metadata.

Note

The Shapefile dbase format truncates field names to 10 characters; CURVE_LENGTH_3D etc. are preserved by writing them under the same logical names because Shapefile clients tolerate the truncation deterministically.

Variables:
  • output_gpkg (str or None) – GeoPackage output path or None.

  • output_shp (str or None) – Shapefile output path or None.

  • output_csv (str or None) – CSV output path or None.

  • curve_pcloud (str or None) – LAS curve-pcloud output path or None.

  • curve_pcloud_step (float) – Resampling step (m) for the curve-pcloud writer.

  • slope_output_form (str) – Slope column convention emitted by write_curve_pcloud ('sin', 'tan', or 'angle_deg').

  • epsg (int or None) – Output EPSG code, or None to inherit the source point cloud’s CRS.

  • out_prefix (str or None) – Pipeline-level path prefix used by the * substitution in output paths.

  • coord_center (numpy.ndarray or None) – 3-vector centring offset added to polyline points before writing world-space output.

__init__(output_gpkg=None, output_shp=None, output_csv=None, curve_pcloud=None, curve_pcloud_step=None, slope_output_form='sin', epsg=None, out_prefix=None, coord_center=None)

Store the writer configuration verbatim. No validation or derivation is performed; empty or None paths cause the corresponding write_* method to be skipped at the SCE call site.

write_gpkg(curves, metadata, pcloud)

Write curves to a GeoPackage file.

Parameters:
  • curves (list of dict) – Refined curve segments.

  • metadata (list of dict) – Per-segment metadata.

  • pcloud (PointCloud) – The source point cloud (for CRS).

write_shp(curves, metadata, pcloud)

Write curves to a Shapefile.

Parameters:
  • curves (list of dict) – Refined curve segments.

  • metadata (list of dict) – Per-segment metadata.

  • pcloud (PointCloud) – The source point cloud (for CRS).

write_csv(curves, metadata)

Write curves to a CSV file with columns: CurveID, SegmentID, SequenceID, X, Y, Z, Slope.

Parameters:
  • curves (list of dict) – Refined curve segments.

  • metadata (list of dict) – Per-segment metadata.

write_curve_pcloud(curves, metadata, pcloud)

Write curve points to a LAS point cloud.

Each curve is resampled at curve_pcloud_step spacing along its arc-length. The output LAS inherits the CRS from the input point cloud and always includes CURVE_ID, SEG_ID, and SLOPE as extra dimensions, plus up to four optional length columns gated by the output_curve_length_3d / _2d / output_seg_length_3d / _2d flags.

SLOPE follows the convention selected by self.slope_output_form:

  • 'sin' (default): emit the cached project- canonical dZ/ds_3D = sin(theta) – bounded in [-1, 1] and stable at near-vertical.

  • 'tan': recompute tan(theta) = dZ/dxy directly from the resampled output coordinates with a planar guard and a magnitude clip – civil-engineering grade; can blow up on near- vertical sub-polylines.

  • 'angle_deg': recompute the inclination angle in degrees as atan2(dZ, dxy) * 180/pi – unconditionally bounded in [-90, +90].

Length columns (each a float32 extra dim, broadcast to every resampled point of the corresponding feature):

  • CURVE_LENGTH_3D (per CURVE_ID total 3D arc length, broadcast across every point of every feature in that curve).

  • CURVE_LENGTH_2D (per CURVE_ID total planar XY length).

  • SEG_LENGTH_3D (per-feature 3D arc length; replaces the legacy LENGTH_3D column).

  • SEG_LENGTH_2D (per-feature planar XY length; replaces the legacy LENGTH_2D column).

Parameters:
  • curves (list of dict) – Refined curve segments.

  • metadata (list of dict) – Per-segment metadata dicts.

  • pcloud (PointCloud) – The source point cloud (for CRS and LAS header reference).

static per_cid_length_totals(metadata, want_3d=True, want_2d=True)

Aggregate per-feature LENGTH_3D / LENGTH_2D from metadata into per- CURVE_ID totals. The flags let callers skip the computation entirely when the corresponding output column is disabled, so no memory is allocated for unused per-CID values.

Parameters:
  • metadata (list of dict) – Per-feature metadata list. Each entry must carry CURVE_ID and the relevant LENGTH_* keys.

  • want_3d (bool) – Compute the 3D total when True. Default True.

  • want_2d (bool) – Compute the 2D total when True. Default True.

Returns:

Dict {cid: {'len_3d': float, 'len_2d': float}} with only the requested keys populated.

Return type:

dict

static slope_from_blocks(xyz_blocks, form, dxy_floor=1e-09, tan_clip=1000000.0)

Recompute the per-vertex slope from the resampled XYZ blocks emitted by write_curve_pcloud, in either 'tan' or 'angle_deg' convention. Direct recomputation from the output coordinates avoids the catastrophic-cancellation precision loss of the analytical conversions tan = sin/sqrt(1-sin^2) and arcsin(sin) * 180/pi near vertical.

Per-vertex aggregation follows the same boundary convention as the C++ computeGrade: forward difference at the first vertex, backward at the last, central (averaged-segment) at interior vertices.

Parameters:
  • xyz_blocks (list of np.ndarray) – List of per-curve (n_out, 3) arrays (resampled XYZ).

  • form (str) – 'tan' for civil-engineering tan(theta) = dZ/dxy (with dxy_floor guard and tan_clip magnitude clamp). 'angle_deg' for inclination angle in degrees atan2(dZ, dxy) * 180/pi (unconditionally bounded in [-90, +90]).

  • dxy_floor (float) – Minimum planar step (m) used to guard the divide on near-vertical segments in 'tan' mode. Default 1e-9.

  • tan_clip (float) – Output magnitude clip in 'tan' mode so LAS readers never see inf. Default 1e6 (~89.99994 deg).

Returns:

(M,) float64 array of per- vertex slope values, concatenated over the input blocks in the same order.

Return type:

np.ndarray

resolve_output_path(path)

Resolve output path by replacing the leading * wildcard with the out_prefix from the pipeline, following the VL3D convention used by Writer.

Parameters:

path (str) – The output path, possibly starting with *.

Returns:

Resolved path.

Return type:

str

get_crs(pcloud)

Obtain the coordinate reference system (CRS) for the output files. Tries the configured EPSG code first, then attempts to read CRS from the LAS file VLRs.

Parameters:

pcloud (PointCloud) – The source point cloud.

Returns:

CRS string or None.

Return type:

str or None