Centerline Extraction
About 2 min
Centerline Extraction
Automatically extract centerlines from double-line features such as road outlines or tunnel edges.
Online Example
Online Demo{target="_blank"}
Overview
The centerline extraction algorithm automatically identifies paired parallel lines and computes their centerline. Typical application scenarios:
- Road outline lines -> road centerlines
- Mine tunnel edge lines -> tunnel centerlines
- Double-line pipelines -> pipeline centerlines
- Riverbank lines -> river centerlines
Usage
Method 1: Command Panel
In the menu bar, choose Tools -> Extract Centerline, or click Extract Centerline in the Ribbon Tools tab to open the parameter panel.
Method 2: Call in Code
const { Engine, Layer, PolylineEnt, BulgePoints, BulgePoint, getWebCadCoreService } = vjcad;
// 1. Collect line data (format: [[[x,y],[x,y],...], ...])
const lines = [
[[0, 2.5], [100, 2.5]], // Upper edge
[[0, -2.5], [100, -2.5]], // Lower edge
];
// 2. Configure parameters and call WASM
const wasmService = getWebCadCoreService();
const result = wasmService.extractCenterlineSync({
lines,
config: {
minSpaceDistance: [4], // Minimum spacing between paired lines
maxSpaceDistance: [6], // Maximum spacing between paired lines
maxGapDistance: 15, // Allowed break distance
collinearTolerance: 1.0, // Collinearity tolerance
}
});
// 3. Create centerline entities
if (result.centerlines && result.centerlines.length > 0) {
const layer = new Layer("Centerline");
layer.color = 1;
Engine.currentDoc.layers.add(layer);
for (const polyline of result.centerlines) {
const bp = new BulgePoints();
for (const pt of polyline) {
bp.add(new BulgePoint([pt[0], pt[1]], 0));
}
const pline = new PolylineEnt(bp, false);
pline.setDefaults();
pline.layer = "Centerline";
Engine.pcanvas.addEntity(pline);
}
Engine.pcanvas.redraw();
}Algorithm Workflow
Input double-line data
↓
1. Split into segments + merge collinear segments
↓
2. Identify parallel line pairs
(similar slope + spacing within range)
↓
3. Compute centerline
(use midpoints of perpendicular feet)
↓
4. Merge disconnected centerline segments
↓
5. Merge endpoints to nearby segments
↓
6. Final merge of connected centerlines
↓
Output centerlinesParameter Description
Parallel-Line Distance
| Parameter | Default | Description |
|---|---|---|
minSpaceDistance | [2.5] | Array of minimum double-line spacings, supports multiple groups |
maxSpaceDistance | [7.5] | Array of maximum double-line spacings, corresponding one-to-one with the minimum-spacing array |
Tips
Multiple spacing groups are supported to handle double lines of different widths. For example, extract both 5 m and 10 m roads at the same time:
minSpaceDistance: [4, 9],
maxSpaceDistance: [6, 11],Numeric Parameters
| Parameter | Default | Description |
|---|---|---|
collinearTolerance | 1.0 | Tolerance for collinearity checks |
duplicateTolerance | 0.2 | Tolerance for removing duplicate points |
maxGapDistance | 15 | Maximum allowed distance for segment breaks |
numDecimalDigits | 3 | Decimal precision for coordinates |
minDlMinRatio | 0.01 | Minimum overlap ratio of the double lines |
paralleSlopeAngleTolerance | 1.5 | Slope-angle tolerance for detecting parallel lines, in degrees |
mergeSlopeAngleTolerance | 20 | Angle tolerance for merging centerlines, in degrees |
maxCenterMergeDistance | 15 | Maximum distance for centerline endpoint merging |
minCenterDistance | 5.1 | Minimum centerline length; shorter segments are filtered out |
Processing Options
| Parameter | Default | Description |
|---|---|---|
connectGapLine | true | Whether to connect lines within the allowed gap range |
mergeNode | true | Whether to merge endpoints |
filterShortLine | true | Whether to filter lines shorter than the minimum distance |
mergeLine | true | Whether to merge connected lines into a single line |
Input / Output Format
Input
{
"lines": [
[[x1,y1], [x2,y2], ...],
[[x1,y1], [x2,y2], ...]
],
"config": { ... }
}lines supports two formats:
- Simple array:
[[[x,y],[x,y],...], ...] - GeoJSON FeatureCollection: standard GeoJSON format, supporting
LineStringandMultiLineString
Output
[
[[x1,y1], [x2,y2], ...],
[[x1,y1], [x2,y2], ...]
]