src.inout.simple_curve_writer
Classes
|
- 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. SeeSimpleCurveExtractorfor the upstream pipeline that producescurvesandmetadata.Note
The Shapefile dbase format truncates field names to 10 characters;
CURVE_LENGTH_3Detc. 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
Noneto 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.ndarrayor 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
Nonepaths cause the correspondingwrite_*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_stepspacing along its arc-length. The output LAS inherits the CRS from the input point cloud and always includesCURVE_ID,SEG_ID, andSLOPEas extra dimensions, plus up to four optional length columns gated by theoutput_curve_length_3d/_2d/output_seg_length_3d/_2dflags.SLOPEfollows the convention selected byself.slope_output_form:'sin'(default): emit the cached project- canonicaldZ/ds_3D = sin(theta)– bounded in [-1, 1] and stable at near-vertical.'tan': recomputetan(theta) = dZ/dxydirectly 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 asatan2(dZ, dxy) * 180/pi– unconditionally bounded in [-90, +90].
Length columns (each a
float32extra dim, broadcast to every resampled point of the corresponding feature):CURVE_LENGTH_3D(perCURVE_IDtotal 3D arc length, broadcast across every point of every feature in that curve).CURVE_LENGTH_2D(perCURVE_IDtotal planar XY length).SEG_LENGTH_3D(per-feature 3D arc length; replaces the legacyLENGTH_3Dcolumn).SEG_LENGTH_2D(per-feature planar XY length; replaces the legacyLENGTH_2Dcolumn).
- 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_2Dfrommetadatainto per-CURVE_IDtotals. 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_IDand the relevantLENGTH_*keys.want_3d (bool) – Compute the 3D total when
True. DefaultTrue.want_2d (bool) – Compute the 2D total when
True. DefaultTrue.
- 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 conversionstan = sin/sqrt(1-sin^2)andarcsin(sin) * 180/pinear 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-engineeringtan(theta) = dZ/dxy(withdxy_floorguard andtan_clipmagnitude clamp).'angle_deg'for inclination angle in degreesatan2(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. Default1e-9.tan_clip (float) – Output magnitude clip in
'tan'mode so LAS readers never seeinf. Default1e6(~89.99994 deg).
- Returns:
(M,)float64array 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 theout_prefixfrom the pipeline, following the VL3D convention used byWriter.- 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