Product
Introducing Java Support in Socket
We're excited to announce that Socket now supports the Java programming language.
@turf/simplify
Advanced tools
@turf/simplify is a module within the Turf.js library that provides functionality to simplify GeoJSON geometries. It uses the Ramer-Douglas-Peucker algorithm to reduce the number of points in a geometry while retaining its overall shape. This can be useful for reducing the complexity of geometries for faster processing and rendering.
Simplify a LineString
This feature allows you to simplify a LineString geometry. The `tolerance` parameter controls the level of simplification, and `highQuality` determines whether to use a slower, higher-quality algorithm.
const turf = require('@turf/turf');
const line = turf.lineString([[0, 0], [1, 1], [2, 2], [3, 3], [4, 4], [5, 5]]);
const simplified = turf.simplify(line, {tolerance: 0.01, highQuality: false});
console.log(simplified);
Simplify a Polygon
This feature allows you to simplify a Polygon geometry. Similar to the LineString example, you can control the simplification level with the `tolerance` parameter and choose between a faster or higher-quality algorithm with `highQuality`.
const turf = require('@turf/turf');
const polygon = turf.polygon([[[0, 0], [1, 1], [2, 2], [3, 3], [4, 4], [5, 5], [0, 0]]]);
const simplified = turf.simplify(polygon, {tolerance: 0.01, highQuality: false});
console.log(simplified);
simplify-js is a high-performance JavaScript library for simplifying 2D geometries. It also uses the Ramer-Douglas-Peucker algorithm and is highly efficient for client-side applications. Compared to @turf/simplify, simplify-js is more focused on 2D geometries and does not support GeoJSON directly.
topojson-simplify is a module within the TopoJSON library that provides tools for simplifying TopoJSON objects. It uses a different approach compared to @turf/simplify, focusing on converting GeoJSON to TopoJSON and then simplifying the topology. This can result in more efficient storage and transmission of geographic data.
Takes a GeoJSON object and returns a simplified version. Internally uses the 2d version of simplify-js to perform simplification using the Ramer-Douglas-Peucker algorithm.
geojson
GeoJSON object to be simplified
options
Object Optional parameters (optional, default {}
)
options.tolerance
number simplification tolerance (optional, default 1
)options.highQuality
boolean whether or not to spend more time to create a higher-quality simplification with a different algorithm (optional, default false
)options.mutate
boolean allows GeoJSON input to be mutated (significant performance increase if true) (optional, default false
)var geojson = turf.polygon([[
[-70.603637, -33.399918],
[-70.614624, -33.395332],
[-70.639343, -33.392466],
[-70.659942, -33.394759],
[-70.683975, -33.404504],
[-70.697021, -33.419406],
[-70.701141, -33.434306],
[-70.700454, -33.446339],
[-70.694274, -33.458369],
[-70.682601, -33.465816],
[-70.668869, -33.472117],
[-70.646209, -33.473835],
[-70.624923, -33.472117],
[-70.609817, -33.468107],
[-70.595397, -33.458369],
[-70.587158, -33.442901],
[-70.587158, -33.426283],
[-70.590591, -33.414248],
[-70.594711, -33.406224],
[-70.603637, -33.399918]
]]);
var options = {tolerance: 0.01, highQuality: false};
var simplified = turf.simplify(geojson, options);
//addToMap
var addToMap = [geojson, simplified]
Returns GeoJSON a simplified GeoJSON
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.
Install this single module individually:
$ npm install @turf/simplify
Or install the all-encompassing @turf/turf module that includes all modules as functions:
$ npm install @turf/turf
FAQs
turf simplify module
The npm package @turf/simplify receives a total of 512,543 weekly downloads. As such, @turf/simplify popularity was classified as popular.
We found that @turf/simplify demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 9 open source maintainers collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Product
We're excited to announce that Socket now supports the Java programming language.
Security News
Socket detected a malicious Python package impersonating a popular browser cookie library to steal passwords, screenshots, webcam images, and Discord tokens.
Security News
Deno 2.0 is now available with enhanced package management, full Node.js and npm compatibility, improved performance, and support for major JavaScript frameworks.