Giter Site home page Giter Site logo

polygonize's Introduction

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

polygonize's People

Contributors

nickcis avatar globetro avatar

Stargazers

 avatar Karl TAYOU avatar Thomas Gratier avatar Manuel Dugué avatar Liu Ji avatar Ohurtsov Oleksandr avatar wucan avatar Eddie Hsu avatar dev-guf avatar Sean Stone avatar Quang Van avatar Brian Burns avatar Fatih Yıldırım avatar Roberto Salas avatar Jannis R avatar Denis avatar matt wilkie avatar Max avatar

Watchers

 avatar matt wilkie avatar James Cloos avatar  avatar

polygonize's Issues

err Error: Each LinearRing of a Polygon must have 4 or more Positions.

Error: Each LinearRing of a Polygon must have 4 or more Positions.
    at polygon (C:\Users\GurumNyang\Documents\Github\PZ_seoul\node_modules\@turf\helpers\dist\js\index.js:233:19)
    at EdgeRing.toPolygon (C:\Users\GurumNyang\Documents\Github\PZ_seoul\node_modules\polygonize\cjs\EdgeRing.js:171:50)
    at EdgeRing.getEnvelope (C:\Users\GurumNyang\Documents\Github\PZ_seoul\node_modules\polygonize\cjs\EdgeRing.js:182:59)
    at C:\Users\GurumNyang\Documents\Github\PZ_seoul\node_modules\polygonize\cjs\EdgeRing.js:219:33
    at Array.forEach (<anonymous>)
    at Function.findEdgeRingContaining (C:\Users\GurumNyang\Documents\Github\PZ_seoul\node_modules\polygonize\cjs\EdgeRing.js:218:17)
    at C:\Users\GurumNyang\Documents\Github\PZ_seoul\node_modules\polygonize\cjs\index.js:58:28
    at Array.forEach (<anonymous>)
    at polygonize (C:\Users\GurumNyang\Documents\Github\PZ_seoul\node_modules\polygonize\cjs\index.js:57:9)
    at C:\Users\GurumNyang\Documents\Github\PZ_seoul\src\readOsm.js:314:36

Support for ES6 Modules?

Trying to convert TurfJS to ES modules, would it be possible to support ES modules in this library?

Also we're releasing v5.0, so might be a good idea to sync up the dependencies.

I can internalize this library into TurfJS for now until this library gets updated to ES modules.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.