Published
Edited
May 9, 2022
4 stars
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
lineSplitByClipArea = {

// Setup an empty array to collect line segmets clipped by clip area
let linesArray = []

turf.featureEach(lineJSON, line => {
// Check if the line feature is fully within the clip area. If it is, add it to linesArray.
if (turf.booleanWithin(line, clipAreaJSON.features[0])) {
linesArray.push(line)
} else {
// If the feature is not fully within the clip area, split the line by the clip area
let splitResults = turf.lineSplit(line, clipAreaJSON.features[0])
// Take the resulting features from the split, calculate a point on surface, and check if the point is within the clip area. If it is, add the line segment to linesArray.
turf.featureEach(splitResults, splitResult => {
let pof = turf.pointOnFeature(splitResult)
if (turf.booleanWithin(pof, clipAreaJSON.features[0])) {
linesArray.push(splitResult)
}
})
}
})
return turf.featureCollection(linesArray)
}
Insert cell
Insert cell
Insert cell
dissolvedLineSplitByClipArea = {
// Flatten all features into an aray to explode any MultiLinestring features to LineString feature
let flattenedLines = lineSplitByClipArea.features
.map(feature => turf.flatten(feature))
.map(fc => fc.features).flat()
// Create FeatureCollection of flattened LineString features
let flattenedLinesFC = turf.featureCollection(flattenedLines)
// Combine LineString features into a single MultiLineString
return turf.combine(flattenedLinesFC)
}
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell

Purpose-built for displays of data

Observable is your go-to platform for exploring data and creating expressive data visualizations. Use reactive JavaScript notebooks for prototyping and a collaborative canvas for visual data exploration and dashboard creation.
Learn more