Coder Social home page Coder Social logo

Comments (2)

kbajori50 avatar kbajori50 commented on May 29, 2024

const h3 = require('h3-js');
const turf = require('@turf/turf');
const zeroAreaPolygon = [
[0, 0],
[0, 90],
[0, 90],
[0, 0],
];
const geojson = turf.polygon([zeroAreaPolygon]);
const area = turf.area(geojson);
if (area === 0) {
console.log('Zero area polygon, skipping');
// This is a weird case, why would you have a zero area polygon?
} else {
// Pass the polygon to h3.polygonToCells
const cells = h3.polygonToCells(zeroAreaPolygon, 1);
console.log(cells);
// This should give you an array of hexagonal cells that cover the polygon
}

from h3-js.

nrabinowitz avatar nrabinowitz commented on May 29, 2024

Technically this is expected behavior for h3-js - we are simply proxying the errors from the underlying C library. For this particular issue, the error is expected - the first step of the polygonToCells algorithm is to take the bounding box of the input polygon and estimate the number of cells it will contain. If the bounding box is zero-width or zero-height, we throw this error.

I do think it would make more sense to have the option to have h3-js throw fewer errors, however, and I plan to update the binding to offer a less strict option. It's been the subject of some debate whether it would be better to throw errors, which are generally clear and explicit, or return fallbacks like null and [] on failure, which are easier and more efficient for JS applications to handle.

from h3-js.

Related Issues (20)

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.