New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

geojson-polygon-self-intersections

Package Overview
Dependencies
Maintainers
1
Versions
7
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

geojson-polygon-self-intersections

A very simple script to compute all self-intersections in a GeoJSON polygon.

  • 1.1.0
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
193K
increased by4.92%
Maintainers
1
Weekly downloads
 
Created
Source

geojson-polygon-self-intersections

A very simple script to compute all self-intersections in a GeoJSON polygon.

According to the Simple Features standard, polygons may not self-intersect. GeoJSON, however, doesn't care about this. You can use this tool to check for self-intersections, list them or use them in some way.

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 input 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.

Usage

Get Node.js, then

npm install geojson-polygon-self-intersections

and use it like so:

var gpsi = require('geojson-polygon-self-intersections');

// poly = ...

var isects = gpsi(poly);

// isects = [[5, 8], [7, 3], ...]

Where poly is a GeoJSON Polygon, and isects is a GeoJSON MultiPoint.

Alternatively, you can use a filter function to specify the output. You have access to the following data per point:

  • [x,y] intersection coordinates: isect
  • ring index of the first edge: ring0
  • edge index of the first edge: edge0
  • [x,y] of the start point of the first edge: start0
  • [x,y] of the end point of the first edge: end0
  • fractional distance of the intersection on the first edge: frac0
  • idem for the second edge: ring1, edge1, start1, end1, frac1
  • boolean indicating if the intersection is unique: unique

Finally, you can set a boolean variable to specify if a spatial index should be used to filter for possible intersections.

Together, this may look like so:

var useSpatialIndex = 0;
var isects = gpsi(poly, function filterFn(isect, ring0, edge0, start0, end0, frac0, ring1, edge1, start1, end1, frac1, unique){return [isect, frac0, frac1];}, useSpatialIndex);

// isects = [[[5, 8], 0.4856, 0.1865]], [[[7, 3], 0.3985, 0.9658]], ...]

Keywords

FAQs

Package last updated on 09 Aug 2016

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