Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@turf/flatten

Package Overview
Dependencies
Maintainers
9
Versions
46
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@turf/flatten

turf flatten module

  • 7.1.0
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
649K
decreased by-0.38%
Maintainers
9
Weekly downloads
 
Created

What is @turf/flatten?

@turf/flatten is a module in the Turf.js library that is used to flatten any GeoJSON object into a FeatureCollection. This is particularly useful when dealing with complex nested geometries and you need to simplify them into a flat structure.

What are @turf/flatten's main functionalities?

Flattening a MultiPolygon

This code demonstrates how to flatten a MultiPolygon into a FeatureCollection of Polygons. The input is a MultiPolygon, and the output is a FeatureCollection with each Polygon as a separate feature.

const turf = require('@turf/turf');
const multiPolygon = turf.multiPolygon([[[[0, 0], [10, 0], [10, 10], [0, 10], [0, 0]]], [[[20, 20], [30, 20], [30, 30], [20, 30], [20, 20]]]]);
const flattened = turf.flatten(multiPolygon);
console.log(flattened);

Flattening a MultiLineString

This code demonstrates how to flatten a MultiLineString into a FeatureCollection of LineStrings. The input is a MultiLineString, and the output is a FeatureCollection with each LineString as a separate feature.

const turf = require('@turf/turf');
const multiLineString = turf.multiLineString([[[0, 0], [10, 10]], [[20, 20], [30, 30]]]);
const flattened = turf.flatten(multiLineString);
console.log(flattened);

Flattening a GeometryCollection

This code demonstrates how to flatten a GeometryCollection into a FeatureCollection of individual geometries. The input is a GeometryCollection, and the output is a FeatureCollection with each geometry as a separate feature.

const turf = require('@turf/turf');
const geometryCollection = turf.geometryCollection([
  turf.point([0, 0]),
  turf.lineString([[10, 10], [20, 20]]),
  turf.polygon([[[30, 30], [40, 40], [50, 50], [30, 30]]])
]);
const flattened = turf.flatten(geometryCollection);
console.log(flattened);

Other packages similar to @turf/flatten

Keywords

FAQs

Package last updated on 09 Aug 2024

Did you know?

Socket

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.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc