Skip to content

turf.dissolve erroring with oddly shaped polygons #2420

@charlierudolph

Description

@charlierudolph

Currently hitting the following error when using turf.dissolve

Error: Unable to complete output ring starting at [54.52907798654607, -2.5983186383573154]. Last matching segment found ends at [54.61818656347785, -2.5731465650016876].
    at Function.factory (/Users/charlesrudolph/Code/test/node_modules/polygon-clipping/dist/polygon-clipping.cjs.js:1252:21)
    at Operation.run (/Users/charlesrudolph/Code/test/node_modules/polygon-clipping/dist/polygon-clipping.cjs.js:1776:30)
    at union (/Users/charlesrudolph/Code/test/node_modules/polygon-clipping/dist/polygon-clipping.cjs.js:1792:20)
    at Module.dissolve (file:///Users/charlesrudolph/Code/test/node_modules/@turf/dissolve/dist/es/index.js:42:31)
    at file:///Users/charlesrudolph/Code/test/index.js:9:18
    at ModuleJob.run (node:internal/modules/esm/module_job:194:25)

Code to reproduce:

import {cellToBoundary} from "h3-js"
import * as turf from "@turf/turf"

const h3Indexes = ['857bb583fffffff', '857bb58bfffffff']
const polygons = h3Indexes.map(x => cellToBoundary(x, true))
const turfPolygons = polygons.map(x => turf.polygon([x]))
turf.dissolve(turf.featureCollection(turfPolygons)) // <-- throws

With dependencies (Node 18.14):

  • @turf/turf: 6.5.0
  • h3-js: 4.1.0

For reference the turfPolygons value is:

[
  {
    "type": "Feature",
    "properties": {},
    "geometry": {
      "type": "Polygon",
      "coordinates": [
        [
          [54.674471560746106, -2.669669459403366],
          [54.66827243056676, -2.590808846502601]
          [54.61818656347785, -2.5731465650016876],
          [54.59479733372542, -2.5582148982951005],
          [54.52907798654607, -2.5983186383573154],
          [54.533564730328536, -2.68329182348515],
          [54.58040270977906, -2.713147336590615],
          [54.60545643615633, -2.7220126907386035],
          [54.674471560746106, -2.669669459403366]
        ]
      ]
    }
  },
  {
    "type": "Feature",
    "properties": {},
    "geometry": {
      "type": "Polygon",
      "coordinates": [
        [
          [54.59029423717366, -2.4733591205361],
          [54.59479733372542, -2.5582148982951005],
          [54.61818656347788, -2.573146565001703],
          [54.66827243056676, -2.590808846502601],
          [54.73723247700517, -2.538498282632361],
          [54.730995571183335, -2.4597687064449976],
          [54.655899262660675, -2.433377660227877],
          [54.59029423717366, -2.4733591205361]
        ]
      ]
    }
  }
]

And this is what the indicies look like in kepler.gl:

plotted

Metadata

Metadata

Assignees

Type

No type

Projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions