What is @turf/isolines?
@turf/isolines is a module within the Turf.js library that allows you to generate isolines (contour lines) from a grid of points with z-values. This is useful for visualizing elevation, temperature, or other continuous data over a geographic area.
What are @turf/isolines's main functionalities?
Generate Isolines
This feature allows you to generate isolines from a grid of points with z-values. The code sample demonstrates creating a grid of points, assigning random z-values, and generating isolines based on specified breaks.
const turf = require('@turf/turf');
// Create a grid of points with z-values
const points = turf.pointGrid([-95, 30, -85, 40], 100, { units: 'miles' });
points.features.forEach((point, i) => {
point.properties.z = Math.random() * 10;
});
// Generate isolines
const breaks = [0, 2, 4, 6, 8, 10];
const isolines = turf.isolines(points, breaks, { zProperty: 'z' });
console.log(JSON.stringify(isolines));
Other packages similar to @turf/isolines
d3-contour
d3-contour is a module in the D3.js library that provides tools for generating contour plots. It is similar to @turf/isolines in that it can generate contour lines from a set of data points. However, d3-contour is more focused on data visualization and is part of the broader D3.js ecosystem, which is widely used for creating complex and interactive visualizations.
marching-squares
marching-squares is a JavaScript library for generating contour lines using the Marching Squares algorithm. It is similar to @turf/isolines in that it can generate contour lines from a grid of data points. However, marching-squares is a more specialized library focused solely on the contour generation algorithm, whereas @turf/isolines is part of the larger Turf.js library for geospatial analysis.
@turf/isolines
isolines
Takes points with z-values and an array of
value breaks and generates isolines.
Parameters
Examples
var points = turf.random('point', 100, {
bbox: [0, 30, 20, 50]
});
for (var i = 0; i < points.features.length; i++) {
points.features[i].properties.z = Math.random() * 10;
}
var breaks = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10];
var isolined = turf.isolines(points, 'z', 15, breaks);
Returns FeatureCollection<LineString> isolines
This module is part of the Turfjs project, an open source
module collection dedicated to geographic algorithms. It is maintained in the
Turfjs/turf repository, where you can create
PRs and issues.
Installation
Install this module individually:
$ npm install @turf/isolines
Or install the Turf module that includes it as a function:
$ npm install @turf/turf