Turf: TopologyException: found non-noded intersection between LINESTRING

Created on 1 Feb 2019  路  3Comments  路  Source: Turfjs/turf

How to reproduce:

https://jsfiddle.net/mnvx/6tfcan1b/

image

I has built union of 3 polygons. And I try to intersect them with 4th. As you can see on screenshot, problem caused by very small triangle (looks like point) in center of image. Coordinates of triangle:

[41.71762030205352, 45.327609463396044]
[41.71762049999992, 45.32760549993015]
[41.71762039674412, 45.327609678130536]
[41.71762030205352, 45.327609463396044]

Will be grateful for help!

bug wontfix

Most helpful comment

I was able to render the first polygon you posted in QGIS:

screen shot 2019-02-01 at 1 55 17 pm

This geometry is about 1/3 of an inch wide at its widest point, which I suspect is what is causing the problem. My best guess is that the top two vertices are being quantized into a single vertex, causing the triangle to collapse into a straight line. Ideally this would be handled, but this is powered by a downstream dependency, and precision issues of this scale can be extremely difficult to fix. The solution you posted is pretty reasonable, and I might also suggest wrapping any topology code like this in a try catch, just in case.

All 3 comments

This error message is reported when a polygon edge crosses itself in a self-intersection. This is not considered a valid feature in Turf world; only geometries compliant with OGS simple features are supported. I'm having a little trouble viewing this feature in geojson.io since it is so small, but I suspect it either crosses itself or is so small that precision fuzziness is coming into play.

As you can see my polygons are simple rectangles and they are not crosses itself:


var poly1 = turf.polygon([[
  [41.717473611309515, 45.32769037664998],
  [41.71748258868331, 45.32751062335003],
  [41.717624988683724, 45.32751562335002],
  [41.71761601130913, 45.32769537664997],
  [41.717473611309515, 45.32769037664998],
]]);
var poly2 = turf.polygon([[
  [41.71761827784451, 45.327695418465375],
  [41.71762272215187, 45.32751558153461],
  [41.717726322151975, 45.327517381534626],
  [41.7177218778445, 45.32769721846538],
  [41.71761827784451, 45.327695418465375],
]]);
var poly3 = turf.polygon([[
  [41.717650442543345, 45.327677814459825],
  [41.71741635738158, 45.32775038554018],
  [41.7173797575532, 45.327667385540174],
  [41.71761384237186, 45.32759481445982],
  [41.717650442543345, 45.327677814459825],
]]);

var polyField = turf.polygon([[
  [41.7170, 45.3280],
  [41.7180, 45.3280],
  [41.7180, 45.3273],
  [41.7170, 45.3273],
  [41.7170, 45.3280],
]]);

var union = turf.union(poly1, poly2, poly3);
L.geoJson(union).addTo(map);
L.geoJson(polyField).addTo(map);

var intersection = turf.intersect(union, polyField); // error at this line

But hole inside of union is really very small. Is it good way just to delete small polygons from union before build of intersection?

Something like this:

    let newCoords = [];
    for (let i = 0; i < union.geometry.coordinates.length; i++) {
      const currentCoords = union.geometry.coordinates[i];
      const poly = turf.polygon([currentCoords]);
      if (turf.area(poly) > 0.01) {
        newCoords.push(currentCoords);
      }
    }
    union.geometry.coordinates = newCoords;

I was able to render the first polygon you posted in QGIS:

screen shot 2019-02-01 at 1 55 17 pm

This geometry is about 1/3 of an inch wide at its widest point, which I suspect is what is causing the problem. My best guess is that the top two vertices are being quantized into a single vertex, causing the triangle to collapse into a straight line. Ideally this would be handled, but this is powered by a downstream dependency, and precision issues of this scale can be extremely difficult to fix. The solution you posted is pretty reasonable, and I might also suggest wrapping any topology code like this in a try catch, just in case.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

MichelBahl picture MichelBahl  路  4Comments

robhawkes picture robhawkes  路  3Comments

andrewharvey picture andrewharvey  路  3Comments

morganherlocker picture morganherlocker  路  5Comments

psi-gh picture psi-gh  路  4Comments