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.

New turf union returns a strange Polygon.

See original GitHub issue

I am trying to unite two polygons. First https://gist.github.com/ilijaz/e4fc41abb6e12fe9f346434a06d948db Second https://gist.github.com/ilijaz/c7fb49ad134173ce6b502dbcc449ffa9 Also first polygon created after union of some as second polygons.

const union = require('@turf/union').default;
const turf = require('@turf/turf');

const first = {"..."};
const second = {"..."};
const un1 = union(first, second);
console.log(turf.area(un1), turf.area(first), turf.area(second))

I’ve had https://gist.github.com/ilijaz/51b426f9131ab29141bf2a6660e6ad77 as result. You can see it’s wrong.

1334311.8920525517 20866.04727530979 268.7401291002204

Is it problem of tolerance? Is it normal that polygon has LinearRings that do not form a closed LlineString. They have only two coordinates.

Opposite of this case, union function from turf/turf works fine for me but it’s about 2 times slowly. Here result on same input data https://gist.github.com/ilijaz/78997225ea130a0a1db1b40990f90237

Issue Analytics

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

github_iconTop GitHub Comments

1reaction
rowanwinscommented, Aug 2, 2021

Resolved since v6.2.0

0reactions
EvertEtcommented, Jul 10, 2020

Indeed. The bug is that here the algorithm assumes multiple polygons are separate but in this case they should not be split up as the second one is a hole in the first one. https://github.com/Turfjs/turf/blob/a371807f78364820f15ab8f9ee3dc5aba51b7bac/packages/turf-union/index.ts#L47

Read more comments on GitHub >

github_iconTop Results From Across the Web

Turfjs/turf - Gitter
Hi, you may iterate your data, check boolean-point-in-polygon and returns polygon ... @benboughton1 Very strange, in source code dissolve using union .
Read more >
Advanced geospatial analysis - Turf.js
union. Takes two (Multi)Polygon(s) and returns a combined polygon. If the input polygons are not contiguous, this function returns a MultiPolygon feature.
Read more >
How to use the @turf/union function in @turf/union - Snyk
To help you get started, we've selected a few @turf/union examples, based on popular ways it is used in public projects. ; type:...
Read more >
Shared edge between two geojson polygons
Takes two polygons and finds their intersection. If they share a border, returns the border; if they don't intersect, returns undefined.
Read more >
Turf.js pointsWithinPolygon - creating a usable array
in the house loading function you say that you want to load a polygon but you create point feature, this will not working....
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