You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Now, we called the function intersect(BufferedLine, Polygon1). It should return the shape of BufferedLine as it is contained in Polygon1. However, it returns null.
We created a test with jest to show this: Bug.js.zip
/* @flow */import{lineString,interpolate,buffer,intersect}from"@turf/turf";exportconstLine1={type: "Feature",properties: {},geometry: {type: "LineString",coordinates: [[-1.520082950592041,47.28430930649756],[-1.5163064002990723,47.2820530712768]]}};constBufferedLine=buffer(Line1,10,{units: "meters",steps: 10});constPolygon1={type: "Feature",properties: {},geometry: {type: "Polygon",coordinates: [[[-1.520082950592041,47.28469504030638],[-1.5205228328704834,47.28418557996312],[-1.5160918235778809,47.281660039816714],[-1.5158557891845703,47.28214041120473],[-1.520082950592041,47.28469504030638]]]}};consthardcodedBufferedLine={geometry: {coordinates: [[[-1.5162470291855608,47.28209880486835],[-1.5162350179821558,47.28209006851059],[-1.5162257499611578,47.282079910368694],[-1.5162195812874169,47.28206872081364],[-1.5162167490196052,47.282056929853255],[-1.5162173620001864,47.28204499060729],[-1.5162213966726608,47.282033361894314],[-1.5162286979868271,47.28202249059961],[-1.5162389853572777,47.282012794501505],[-1.5162518634461344,47.28200464621637],[-1.516266837355665,47.281998358878994],[-1.5162833316469233,47.28199417410893],[-1.5163007124535464,47.28199225272506],[-1.5163183118408838,47.281992668565344],[-1.5163354534743494,47.281995405649184],[-1.5163514786105825,47.28200035879167],[-1.5163657714125842,47.28200733764573],[-1.520142321705553,47.28426357481694],[-1.520154332908958,47.28427231081577],[-1.5201636009299557,47.2842824685367],[-1.5201697696036964,47.284293657623515],[-1.5201726018715083,47.284305448085384],[-1.5201719888909269,47.28431738682121],[-1.5201679542184527,47.284329015032135],[-1.5201606529042861,47.284339885852866],[-1.520150365533836,47.28434958152446],[-1.5201374874449793,47.28435772944842],[-1.5201225135354488,47.28436401650539],[-1.52010601924419,47.284368201088],[-1.520088638437567,47.28437012238558],[-1.5200710390502294,47.284369706564],[-1.5200538974167639,47.284366969602985],[-1.520037872280531,47.284362016682074],[-1.520023579478529,47.28435503813864],[-1.5162470291855608,47.28209880486835]]],type: "Polygon"},properties: {},type: "Feature"};consthardcodedFixedBufferedLine={geometry: {coordinates: [[[-1.5162470291855608,47.28209880486835],[-1.5162350179821558,47.28209006851059],[-1.5162257499611578,47.282079910368694],[-1.5162195812874169,47.28206872081364],[-1.5162167490196052,47.282056929853255],[-1.5162173620001864,47.28204499060729],[-1.5162213966726608,47.282033361894314],[-1.5162286979868271,47.28202249059961],[-1.5162389853572777,47.282012794501505],[-1.5162518634461344,47.28200464621637],[-1.516266837355665,47.281998358878994],[-1.5162833316469233,47.28199417410893],[-1.5163007124535464,47.28199225272506],[-1.5163183118408838,47.281992668565344],[-1.5163354534743494,47.281995405649184],[-1.5163514786105825,47.28200035879167],[-1.5163657714125842,47.28200733764573],[-1.520142321705553,47.28426357481694],[-1.520154332908958,47.28427231081577],[-1.5201636009299557,47.2842824685367],[-1.5201697696036964,47.284293657623515],[-1.5201726018715083,47.284305448085384],[-1.5201719888909269,47.28431738682121],[-1.5201679542184527,47.284329015032135],[-1.5201606529042861,47.284339885852866],[-1.520150365533836,47.28434958152446],[-1.5201374874449793,47.28435772944842],[-1.5201225135354488,47.28436401650539],[-1.52010601924419,47.284368201088],[-1.520088638437567,47.28437012238558],[-1.5200710390502294,47.284369706564],[-1.5200538974167639,47.284366969602985],//[-1.520037872280531, 47.284362016682074], //This is the magic line :O[-1.520023579478529,47.28435503813864],[-1.5162470291855608,47.28209880486835]]],type: "Polygon"},properties: {},type: "Feature"};describe("Turf",()=>{// Testing if buffer of line is equal to my hardcoded BufferedLine ==> truetest("hardcoded buffered line equal buffer of line",()=>{expect(BufferedLine).toEqual(hardcodedBufferedLine);});//Testing if intersection of polygon1 and the BufferedLine is not null ==> false, it shouldn'ttest("intersect polygon with hardcoded buffered line",()=>{expect(intersect(hardcodedBufferedLine,Polygon1)).not.toBeFalsy();});//Testing if intersection of polygon1 and the fixed buffered line is not null ==> true, wtf ?!test("intersect polygon with hardcoded fixed buffered line work",()=>{expect(intersect(hardcodedFixedBufferedLine,Polygon1)).not.toBeFalsy();});});
We use some hard coded data to simplify the problem.
The first test show that the hard coded version of the BufferedLine was identical to the one generated with the buffer function. It succeeds.
The second test shows that intersect(hardcodedBufferedLine, Polygon1) returns null. It shouldn't
The third test is quite funny : we found that commenting one line of code solved the problem. In hardcodedFixedBufferedLine we commented the 3rd line from the end of the field coordinates in geometry. And now, intersect(hardcodedFixedBufferedLine, Polygon1) is correctly returning the shape of the BufferedLine. We have absolutely no idea why.
We had some fun while testing this, however, the "solution" we found is not very reproducible :P
If someone has a better solution, we are interested.
The text was updated successfully, but these errors were encountered:
@Hugosama Thanks for providing a very detailed test case.
At the moment @turf/intersect is using JSTS which we are going to be phasing out in favor of @w8r's martinez.
As a solution, could you attempt the same comparisons using martinez and see if you get the same expected results or null values.
We are not going to be providing a fix for jsts, so this will most likely not be resolved anytime soon in any of the 5.x releases. This will most likely be resolved in the next major release 6.x when we replace jsts with martinez.
CC: @rowanwins & @w8r has been working hard to improve martinez for us to import it in TurfJS.
Hi,
@crubier and I are trying to use your library but we encountered a very strange behavior from the function
intersect
.What we did :
Line1
. Here is the gist.buffer
function. We named thisBufferedLine
. Here is the gist.BufferedLine
. We called itPolygon1
. Here is the gist.intersect(BufferedLine, Polygon1)
. It should return the shape ofBufferedLine
as it is contained inPolygon1
. However, it returnsnull
.We created a test with
jest
to show this:Bug.js.zip
We use some hard coded data to simplify the problem.
BufferedLine
was identical to the one generated with thebuffer
function. It succeeds.intersect(hardcodedBufferedLine, Polygon1)
returnsnull
. It shouldn'thardcodedFixedBufferedLine
we commented the 3rd line from the end of the fieldcoordinates
ingeometry
. And now,intersect(hardcodedFixedBufferedLine, Polygon1)
is correctly returning the shape of theBufferedLine
. We have absolutely no idea why.We had some fun while testing this, however, the "solution" we found is not very reproducible :P
If someone has a better solution, we are interested.
The text was updated successfully, but these errors were encountered: