Public
Edited
Sep 22, 2023
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
sample_line = lines[6]
Insert cell
sample_simplified = turf.simplify(sample_line, {
tolerance: 0.00025,
highQuality: false,
mutate: false
})
Insert cell
single_segments = turf.lineSegment(sample_simplified)
Insert cell
data_density_extent = d3.extent(
geojson_with_line_weights.features.map(d => d.properties.density)
)
Insert cell
data_mean = d3.mean(
geojson_with_line_weights.features.map(d => d.properties.density)
)
Insert cell
density_normalized = d3
.scaleLinear()
.domain([0, data_mean, data_density_extent[1]])
.range([0, 0.8, 1])
Insert cell
density_scale = d3
.scaleLinear()
.range([1, 5])
.domain(data_density_extent)
Insert cell
color_scale = n => {
var s = d3.scaleLinear().domain([0, data_density_extent[1]]);
return d3.interpolateRgb("#FFA500", "#cb4154")(s(n));
}
Insert cell
segment_with_weights = segment_with_weights_fn(
single_segments,
all_points_by_cluster["1"]
)
Insert cell
segment_with_weights_fn = (segments, points) => {
var tmp = JSON.parse(JSON.stringify(segments));
tmp.features = tmp.features.map(d => {
var distances = [];
points.map(pt => {
var dis = turf.pointToLineDistance(pt, d, { units: 'kilometers' });
distances.push(dis);
});

d.properties.length = turf.length(d, { units: 'kilometers' });
d.properties.close_points_count = distances.filter(di => di < 0.02).length;
d.properties.density =
d.properties.close_points_count / d.properties.length;
return d;
});
return tmp;
}
Insert cell
Insert cell
all_activity = FileAttachment("file_07312021.json").json()
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