question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Bug: turf/difference fails on a shared edge

See original GitHub issue

It appears difference is failing due to a bug in a supporting library: https://github.com/w8r/martinez/issues/35

Here is a runnable test that exhibits the behavior

const difference = require('@turf/difference');
tape('Difference failure', (t) => {
  const polygon1 = {
    'type': 'Polygon',
    'coordinates': [
      [[ 10, 10 ], [ 80, 10 ], [ 80, 80 ], [ 10, 80 ], [ 10, 10 ]]
    ]
  };

  const polygon2 = {
    'type': 'Polygon',
    'coordinates': [
      [[ 20, 10 ], [ 30, 10 ], [ 30, 80 ], [ 20, 80 ], [ 20, 10 ]]
    ]
  };

  const result = difference(polygon1, polygon2);
});
// Expected result to be a multi-polygon
// Actual fails with exception `Each LinearRing of a Polygon must have 4 or more Positions.`

This failure happens since martinez returns a malformed polygon when two edges overlap. It returns a “good” difference and as well as a two- or three-point polygon. Could this be detected and handled prior to handing off to helper.polygon, which is where the exception occurs?

(Hoping creating a tracking issue between the two libraries helps find a common solution faster.)

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Comments:5 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
w8rcommented, May 27, 2018

linking the issue here w8r/martinez#81

0reactions
rowanwinscommented, Jul 30, 2021

Resolved in v6.2.0 onwards

Read more comments on GitHub >

github_iconTop Results From Across the Web

TopologyException error when finding difference from polygon ...
I'm trying to use the turf.js 'difference' tool on a polygon and a multipolygon - the multipolygon areas are to be subtracted from...
Read more >
Turf difference function and coincident polygon boundaries
I've been wrestling with this issue for a few days. The tool I'm creating takes one polygon and essentially minuses/subtracts another from ...
Read more >
Advanced geospatial analysis - Turf.js
May result in degenerate edges when clipping Polygons. ... npm install @turf/difference ... Error - if it encounters an unknown geometry type.
Read more >
Cache Bug in Edge Version 95.0.1020.53
1. Open a InPrivate Window and visit the problematic website, now Edge performs as expected. 2. Clear the cache, go into Developer Mode...
Read more >
Edge 106.0.1370.37 with bug fixes; failed start issue not fixed
[German]Short addendum: Microsoft has updated the Edge browser in the stable channel to version 106.0.1370.37 on October 6, 2022. Is a bug ......
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found