
Product
Introducing Webhook Events for Alert Changes
Add real-time Socket webhook events to your workflows to automatically receive software supply chain alert changes in real time.
polygon-splitter
Advanced tools
A small (<10kb minified) javascript library for splitting geojson polygons by a polyline.
Works with
npm install polygon-splitter
Accepts either a geojson Feature or Geometry (inc MultiPolygon and MultiLineString).
import polygonSplitter from 'polygon-splitter'
// or
const polygonSplitter = require('polygon-splitter')
const polygon = {
"type": "Polygon",
"coordinates": [[[0, 0],[10, -10], [20, 0], [10, 10], [0, 0]]]
}
const polyline = {
"type": "LineString",
"coordinates": [[20, 10], [5, 0], [20, -10]]
}
const output = polygonSplitter(polygon, polyline)
Splitting a polygon with a hole into 4 pieces. Compared with an approach outlined here, and also another one described here
polygon-splitter x 228,391 ops/sec ±0.63% (88 runs sampled)
alternate approach x 2,052 ops/sec ±3.60% (78 runs sampled)
alternate approach 2 x 900 ops/sec ±3.60% (78 runs sampled)
This is basically my own implementation of this algorithm. If you're interested in the details it's probably best to read to the source code. Some key points of understanding
Thanks to mourner for the most excellent robust-predicates library.
Thanks for my employer FrontierSI for freeing up some of my time to finish off this algorithm.
FAQs
Split a polygon using a polyline.
We found that polygon-splitter demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer 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
Add real-time Socket webhook events to your workflows to automatically receive software supply chain alert changes in real time.

Security News
ENISA has become a CVE Program Root, giving the EU a central authority for coordinating vulnerability reporting, disclosure, and cross-border response.

Product
Socket now scans OpenVSX extensions, giving teams early detection of risky behaviors, hidden capabilities, and supply chain threats in developer tools.