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

polygonize

Package Overview
Dependencies
Maintainers
1
Versions
6
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

polygonize

Javascript implementation of GEOS's Polygonize function

  • 1.1.0
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
230
decreased by-21.5%
Maintainers
1
Weekly downloads
 
Created
Source

Polygonize

Build Status

Polygonizes a set of Geometrys which contain linework that represents the edges of a planar graph. It's basically an implementation of GEOS's Polygonizer.

Although, the algorithm is the same as GEOS, it isn't a literal transcription of the C++ source code. It was rewriten in order to get a more javascript like code.

JSDoc

/**
 * Polygonizes {@link LineString|(Multi)LineString(s)} into {@link Polygons}.
 *
 * Implementation of GEOSPolygonize function (`geos::operation::polygonize::Polygonizer`).
 *
 * Polygonizes a set of lines that represents edges in a planar graph. Edges must be correctly
 * noded, i.e., they must only meet at their endpoints.
 *
 * The implementation correctly handles:
 *
 * - Dangles: edges which have one or both ends which are not incident on another edge endpoint.
 * - Cut Edges (bridges): edges that are connected at both ends but which do not form part of a polygon.
 *
 * @name polygonize
 * @param {FeatureCollection|Geometry|Feature<LineString|MultiLineString>} geoJson Lines in order to polygonize
 * @returns {FeatureCollection<Polygon>} Polygons created
 * @throws {Error} if geoJson is invalid.
 */

Example

This example is the test found in test/in/complex.geojson.

const polygonize = require('polygonize'),
    fs = require('fs'),
    input = JSON.parse(fs.readFileSync('./test/in/complex.geojson'));

console.log(JSON.stringify(polygonize(input)));

The input as GeoJson LineString:

Turned into polygons:

Documentation

Polygonizes (Multi)LineString(s) into Polygons.

Implementation of GEOSPolygonize function (geos::operation::polygonize::Polygonizer).

Polygonizes a set of lines that represents edges in a planar graph. Edges must be correctly noded, i.e., they must only meet at their endpoints.

The implementation correctly handles:

  • Dangles: edges which have one or both ends which are not incident on another edge endpoint.
  • Cut Edges (bridges): edges that are connected at both ends but which do not form part of a polygon.

Parameters

Returns FeatureCollection<Polygon> Polygons created

Installation

Install this module individually:

$ npm install polygonize

Keywords

FAQs

Package last updated on 18 Oct 2017

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