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.

Union call fails with complex polygon and line string intersection attempt

See original GitHub issue

I have found what appears to be an issue with the union call crashing. The result is basically the node script I am running crashes and prints ‘debug’??. I have create a gist that replicates the issue https://gist.github.com/rheh/397308b280775ad70dedd140a27fd7ce.

The command and output I get follows:

ray@Pluto:~/badfir$ node bad.js 

/home/ray/badfir/node_modules/turf-intersect/node_modules/jsts/dist/jsts.min.js:14
this.resultGeom=this.computeGeometry(this.resultPointList,this.resultLineList,this.resultPolyList,t)},labelIncompleteNode:function(t,e){var n=this.ptLocator.locate(t.getCoordinate(),this.arg[e].getGeometry());t.getLabel().setLocation(e,n)},copyPoints:function(t){for(var e=this.arg[t].getNodeIterator();e.hasNext();){var n=e.next(),i=this.graph.addNode(n.getCoordinate());i.setLabel(t,n.getLabel().getLocation(t))}},findResultAreaEdges:function(t){for(var e=this.graph.getEdgeEnds().iterator();e.hasNext();){var n=e.next(),i=n.getLabel();i.isArea()&&!n.isInteriorAreaEdge()&&ii.isResultOfOp(i.getLocation(0,cn.RIGHT),i.getLocation(1,cn.RIGHT),t)&&n.setInResult(!0)}},computeLabelsFromDepths:function(){for(var t=this.edgeList.iterator();t.hasNext();){var e=t.next(),n=e.getLabel(),i=e.getDepth();if(!i.isNull()){i.normalize();for(var r=0;2>r;r++)n.isNull(r)||!n.isArea()||i.isNull(r)||(0===i.getDelta(r)?n.toLine(r):(f.isTrue(!i.isNull(r,c
[object Object]

A work around I’ve used is to call turf.simplify on the polygon before passing this to union. Although, I would like to understand what the issue is so I can avoid it. Is my data malformed? I suspect not as the sample plots the various geojson tools online, such as google-developers.appspot.com/maps/documentation/utils/geojson/. The disadvantage of the simplify call is that my intersection may miss as the shape become ‘flatter’

To see the script working with the simplify in switch the variables on line 4489.

My node version is v4.2.6. The version of turf is 3.0.14.

Issue Analytics

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

github_iconTop GitHub Comments

1reaction
rhehcommented, Apr 3, 2017

@DenisCarriere thanks, that works just fine with the complex polygon - even without the simplify,

1reaction
rowanwinscommented, Apr 1, 2017

Hi @rheh

Unfortuantly the union module is a little unstable sometimes depending on the input geometries, we’re currently trying to remove the dependency on jsts which is the source for the union operation.

Odds are if simpliying works then your vertices are too dense for jsts to work for some reason… It might also be worth checking if your polygons contain self-intersections using turf/kinks

Hope that helps.

Cheers Rowan

Read more comments on GitHub >

github_iconTop Results From Across the Web

problem with Union methode of GDAL - GIS Stack Exchange
I guess that intersection returns both polygons and linestrings and you can't save them into one shapefile. Either sort output geometries by ...
Read more >
python - Polygon intersection error in Shapely: "shapely.geos ...
Could anyone please explain why I am getting this exception? Edit: I printed p1.is_valid and it turns out to be False. There is...
Read more >
TopologyException unioning valid linestrings [JTS fails too]
The first union (LINESTRING EMPTY, collection of the two input geoms) is a no-op, ie: return the non-empty input untouched. =# select st_npoints(st_union( ......
Read more >
Geospatial functions in Athena engine version 2
Returns a LineString geometry type formed from an array of point geometry ... Starting in Athena engine version 2, only polygons are accepted...
Read more >
Given n line segments, find if any two segments intersect
That is why this algorithm is called Sweep Line Algorithm. The Sweep Line technique is useful in many other geometric algorithms like ...
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