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 a grid FeatureCollection of Point features with z-values and an array of
value breaks and generates isolines.
Parameters
-
pointGrid
FeatureCollection<Point> input points
-
breaks
Array<number> values of zProperty
where to draw isolines
-
options
Object Optional parameters (optional, default {}
)
options.zProperty
string the property name in points
from which z-values will be pulled (optional, default 'elevation'
)options.commonProperties
Object GeoJSON properties passed to ALL isolines (optional, default {}
)options.breaksProperties
Array<Object> GeoJSON properties passed, in order, to the correspondent isoline;
the breaks array will define the order in which the isolines are created (optional, default []
)
Examples
var extent = [0, 30, 20, 50];
var cellWidth = 100;
var pointGrid = turf.pointGrid(extent, cellWidth, {units: 'miles'});
for (var i = 0; i < pointGrid.features.length; i++) {
pointGrid.features[i].properties.temperature = Math.random() * 10;
}
var breaks = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10];
var lines = turf.isolines(pointGrid, breaks, {zProperty: 'temperature'});
var addToMap = [lines];
Returns FeatureCollection<MultiLineString> a FeatureCollection of MultiLineString features representing 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 single module individually:
$ npm install @turf/isolines
Or install the all-encompassing @turf/turf module that includes all modules as functions:
$ npm install @turf/turf