
Product
Socket for Jira Is Now Available
Socket for Jira lets teams turn alerts into Jira tickets with manual creation, automated ticketing rules, and two-way sync.
geojson-polygon-self-intersections
Advanced tools
Find self-intersections in geojson polygon (possibly with interior rings)
A very simple module to compute all self-intersections in coordinates of a polygon.
According to the Simple Features standard, polygons may not self-intersect. GeoJSON, however, doesn't care about this. This tool can be used to check for and/or retrieve self-intersections.
This package works in browsers and in Node.js as an ESM module.
Install Node.js or any compatible JavaScript runtime, then install this package with your favorite package manager.
npm install geojson-polygon-self-intersections
You can optionally build this package locally by running:
npm run build
import gpsi from 'geojson-polygon-self-intersections'
// feature = {type: "Feature", geometry: {type: "Polygon", coordinates: [[[1, 10], [11, 13], ...]]}}
const isects = gpsi(feature);
// isects = [[5, 8], [7, 3], ...]
Where feature is a GeoJSON Feature of Polygon geometry, who's coordinates are an Array of Array of Positions, where each position has at least two coordinates. Only the first two coordinates (typically X and Y or lon and lat) are taken into account.
The following options can be passed as a second argument to control the behaviour of the algorithm.
| Option | Description | Default |
|---|---|---|
useSpatialIndex | Whether a spatial index should be used to filter for possible intersections. | true |
reportVertexOnVertex | If the same vertex (or almost the same vertex) appears more than once in the input, should this be reported as an intersection? | false |
reportVertexOnEdge | If a vertex lies (almost) exactly on an edge segment, should this be reported as an intersection? | false |
epsilon | It is almost never a good idea to compare floating point numbers for identity. Therefor, if we say "the same vertex" or "exactly on an edge segment", we need to define how "close" is "close enough". Note that the value is not used as an euclidian distance but always relative to the length of some edge segment. | 0 |
callbackFunction | A callback function can be specified to process the output. See below. | ({ isect }) => isect |
For the callback function, the following data are available per intersection point:
isectring0edge0start0end0frac0ring1, edge1, start1, end1, frac1uniqueTogether, this may look like so:
const options = {
useSpatialIndex: false,
callbackFunction: ({ isect, frac0, frac1 }) => { return [isect, frac0, frac1] }
}
const isects = gpsi(feature, options);
// isects = [[[5, 8], 0.4856, 0.1865]], [[[7, 3], 0.3985, 0.9658]], ...]
This tool uses the rbush spatial index by default to speed up the detection of intersections. This is especially useful when are many edges but only few intersections. If you prefer, you can opt-out using an options parameter (see below) and it will perform a brute-force search for intersections instead. This might be preferable in case of few edges, as it allows you to avoid some overhead.
useSpatialIndex is no longer supportedFAQs
Find self-intersections in geojson polygon (possibly with interior rings)
The npm package geojson-polygon-self-intersections receives a total of 615,062 weekly downloads. As such, geojson-polygon-self-intersections popularity was classified as popular.
We found that geojson-polygon-self-intersections demonstrated a healthy version release cadence and project activity because the last version was released less than 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
Socket for Jira lets teams turn alerts into Jira tickets with manual creation, automated ticketing rules, and two-way sync.

Company News
Socket won two 2026 Reppy Awards from RepVue, ranking in the top 5% of all sales orgs. AE Alexandra Lister shares what it's like to grow a sales career here.

Security News
NIST will stop enriching most CVEs under a new risk-based model, narrowing the NVD's scope as vulnerability submissions continue to surge.