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

@turf/union

Package Overview
Dependencies
Maintainers
0
Versions
60
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@turf/union

turf union module

  • 7.2.0
  • latest
  • Source
  • npm
  • Socket score

Version published
Maintainers
0
Created

What is @turf/union?

@turf/union is a part of the Turf.js library, which is a powerful geospatial analysis library written in JavaScript. The @turf/union package specifically allows you to perform union operations on GeoJSON polygons, merging multiple polygons into a single polygon.

What are @turf/union's main functionalities?

Union of Two Polygons

This feature allows you to merge two GeoJSON polygons into a single polygon. The code sample demonstrates how to create two polygons and then merge them using the `turf.union` function.

const turf = require('@turf/turf');

const polygon1 = turf.polygon([[
  [-82.574787, 35.594087],
  [-82.574787, 35.615581],
  [-82.545261, 35.615581],
  [-82.545261, 35.594087],
  [-82.574787, 35.594087]
]]);

const polygon2 = turf.polygon([[
  [-82.560024, 35.585153],
  [-82.560024, 35.602602],
  [-82.52964, 35.602602],
  [-82.52964, 35.585153],
  [-82.560024, 35.585153]
]]);

const union = turf.union(polygon1, polygon2);
console.log(JSON.stringify(union));

Union of Multiple Polygons

This feature allows you to merge multiple GeoJSON polygons into a single polygon. The code sample demonstrates how to create three polygons and then merge them sequentially using the `turf.union` function.

const turf = require('@turf/turf');

const polygon1 = turf.polygon([[
  [-82.574787, 35.594087],
  [-82.574787, 35.615581],
  [-82.545261, 35.615581],
  [-82.545261, 35.594087],
  [-82.574787, 35.594087]
]]);

const polygon2 = turf.polygon([[
  [-82.560024, 35.585153],
  [-82.560024, 35.602602],
  [-82.52964, 35.602602],
  [-82.52964, 35.585153],
  [-82.560024, 35.585153]
]]);

const polygon3 = turf.polygon([[
  [-82.554024, 35.580153],
  [-82.554024, 35.595602],
  [-82.52464, 35.595602],
  [-82.52464, 35.580153],
  [-82.554024, 35.580153]
]]);

let union = turf.union(polygon1, polygon2);
union = turf.union(union, polygon3);
console.log(JSON.stringify(union));

Other packages similar to @turf/union

Keywords

FAQs

Package last updated on 29 Dec 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