Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

intersect throws an exception for simple geometries #1346

Closed
chupacabra007 opened this issue Apr 2, 2018 · 10 comments
Closed

intersect throws an exception for simple geometries #1346

chupacabra007 opened this issue Apr 2, 2018 · 10 comments

Comments

@chupacabra007
Copy link

chupacabra007 commented Apr 2, 2018

Below is a code, which reproduces the error

var feature1 = {"type": "Feature", "geometry":{"type":"Polygon","coordinates":[[[12.73841711412891,5.276491276933854],[12.73841711412891,5.26433809314591],[12.77575346361622,5.26433809314591],[12.77575346361622,5.276491276933854],[12.73841711412891,5.276491276933854]]]}}; 

var feature2 = {"type": "Feature", "geometry":{"type":"Polygon","coordinates": [[[12.742005555922084,5.26494850208533],[12.74208332332084,5.26638756290103],[12.74264933958395,5.26712821207218],[12.74420687153181,5.26916645824258],[12.744261007136885,5.26923759369981],[12.744252343996095,5.26928114350116],[12.74426162247027,5.26928143869088],[12.74429517026287,5.26928249624277],[12.744383549648106,5.26939863311202],[12.74582834012948,5.271287852901594],[12.74584985686319,5.2713014704035],[12.75072736717303,5.274369911893245],[12.75070125832354,5.274371293946444],[12.751585341441405,5.27432448331302],[12.751718241645,5.27430907144344],[12.75219166052623,5.274397469582624],[12.753741972519926,5.2750107914778],[12.75475210020897,5.27505130749768],[12.75797915371775,5.275187581339765],[12.75824737144762,5.27521653246188],[12.75847733903942,5.27412984256864],[12.75964016567839,5.274202629539474],[12.759947088047205,5.272327604053885],[12.76079686056724,5.27238547483233],[12.76040458945803,5.274242801880206],[12.761632845393684,5.27431255469227],[12.76147153241675,5.27534037987445],[12.76168522377035,5.275348792347955],[12.76248041477553,5.27532741347707],[12.76311140083349,5.27531043644339],[12.763113164183366,5.27530066834558],[12.76328083923683,5.27436675389123],[12.76371754322724,5.27238127326871],[12.76377730946703,5.272112605948195],[12.76388393844301,5.271642748991866],[12.765548228667214,5.271478551582845],[12.76568938563844,5.271464620029434],[12.76591999077935,5.27144186279679],[12.76591338498566,5.27148243588837],[12.76590231316839,5.2715465401549],[12.765902926832446,5.27154647829286],[12.76641018721594,5.27149770584464],[12.766768720545414,5.27145661932795],[12.76682282772052,5.27144961260515],[12.76682724454327,5.2714291886457],[12.76685084958441,5.271310986843105],[12.766876664330596,5.271309780516646],[12.76712463724471,5.27129886791991],[12.76713227945322,5.27125738939159],[12.76715374354026,5.271257873296065],[12.767261059647765,5.27126111898181],[12.7676214159978,5.271272013380695],[12.76963360272641,5.27107804132066],[12.76962569505818,5.27102800599624],[12.76966019071031,5.271005429910645],[12.769843628499196,5.270989019888304],[12.77060136222263,5.27092341537033],[12.77071300528856,5.270913741707744],[12.77082576663557,5.27042373561159],[12.77089447086612,5.270120377433216],[12.77086303399558,5.27011342113528],[12.77093101724116,5.269793186984884],[12.7709913094971,5.2695245707273],[12.770981614719005,5.26952357638038],[12.77098876593768,5.269482536870015],[12.77098978094528,5.269476611207125],[12.77098995847915,5.26947661148998],[12.77099012503956,5.269472471639915],[12.770995149865364,5.269433781691305],[12.77101275381662,5.269434618004254],[12.7710513267472,5.269180614663355],[12.77111690433903,5.26885677525493],[12.771188166170745,5.26860115347722],[12.77122652976996,5.26832153667232],[12.77132677775377,5.267650736867694],[12.77133439255342,5.26761670303097],[12.771379267416435,5.2673918070993],[12.77138690692497,5.26735608491984],[12.77144931987189,5.26704392413217],[12.77151462423771,5.2667373359443],[12.771269344652126,5.26673259028783],[12.77081364585771,5.26670092580375],[12.770357868193535,5.26668468841325],[12.77013385585533,5.26666815585659],[12.769205477940794,5.26659373427768],[12.7689865168934,5.26656187765846],[12.7680071694702,5.266498555045075],[12.76782317412515,5.26648975256896],[12.76686783234886,5.266444062037465],[12.76666157232263,5.266434188834324],[12.76568242929491,5.26637324602518],[12.76548139634857,5.26636382844515],[12.76456952813729,5.26631372795228],[12.76436044594139,5.26630372054359],[12.76340441957107,5.2662579393014],[12.76226565579622,5.266177405688495],[12.76205440011294,5.266166690273366],[12.761242206344846,5.27029266134565],[12.761008404632186,5.27137604583896],[12.760969913500766,5.27155443732042],[12.76083627275417,5.27220720172295],[12.760052770325444,5.27214773635092],[12.760185154564056,5.271199621694336],[12.760317989977366,5.2702474212727],[12.76113059741067,5.2661198584716],[12.76088160559754,5.26610722789104],[12.75972698234006,5.266036621961206],[12.75879560085124,5.265977959298226],[12.758593160896034,5.265969785458],[12.75764584470326,5.26590997355294],[12.75743739236526,5.26589474670433],[12.75649328893018,5.26582952505487],[12.756277057364095,5.26581458829267],[12.75531050251333,5.2657478014425],[12.755118598704414,5.265734530008444],[12.754154446176905,5.26570355341593],[12.75364772935868,5.265680583553575],[12.75291227503864,5.26562290761149],[12.752660259269696,5.2656066988732],[12.75245884578855,5.26560024109199],[12.751517952370484,5.26554093235035],[12.75129292438014,5.265529707469824],[12.75037216869324,5.26546291742136],[12.750113714708455,5.26545261945108],[12.749196811222255,5.265395823000716],[12.748960481025165,5.265383047160896],[12.74804307413179,5.26532176887463],[12.74783932331629,5.265312443551295],[12.74689108958402,5.265266387045585],[12.74666928054138,5.26525158518902],[12.74572290765807,5.26518292755961],[12.74551461882514,5.26516606440592],[12.74459644250847,5.26510851314674],[12.744342760823095,5.26509413450253],[12.7434030837559,5.265040846258586],[12.74317468240679,5.265027885180956],[12.742869184930576,5.26501055343985],[12.742005555922084,5.26494850208533]]]}}; 

turf.intersect(feature1, feature2);

The error message is:

exception: TopologyException: found non-noded intersection between LINESTRING ( 12.74585 5.271301, 12.750727 5.27437 ) and LINESTRING ( 12.750701 5.274371, 12.751585 5.274324 )

What is wrong with that and can we fix it?

@stebogit
Copy link
Collaborator

stebogit commented Apr 2, 2018

@chupacabra007 what version of Turf are you using?
I believe this might be related to the same issue causing #819, you might be able to gather more info starting from that thread.

Sorry I can't be of further help. Maybe @rowanwins or @DenisCarriere might give you more detailed inputs on this?

@chupacabra007
Copy link
Author

I tested it against the last version of turf.

@rowanwins
Copy link
Member

A version number would help as we're currently exploring some changes to this module. Are you using the full version of turf via a cdn which is v5, or have you obstacle the turf/intersect module which is in the v6 series?

@chupacabra007
Copy link
Author

chupacabra007 commented Apr 3, 2018

I'm using version 5.1.6 from cdn - https://npmcdn.com/@turf/[email protected]/turf.min.js

@rowanwins
Copy link
Member

Doh shouldn't spotted that from the error sorry @chupacabra007

Currently v5 uses jsts for it's intersect function which is known to have issues depending on your geometries.

Perhaps try and run your polygon through @turf/clean-coords. Also check if your geometry has any kinks using @turf/kinks . And finally perhaps try using @turf/simplify, particularly on the second geometry.

@chupacabra007
Copy link
Author

I'm getting an error

turf.cleanCoords is not a function

@chupacabra007
Copy link
Author

turf.simplify simply does not work and raises the same error message about non-noded intersection

@DenisCarriere
Copy link
Member

I've just tried this and it seems to be working just fine.

$ npm install @turf/[email protected]
var fs = require('fs');
var intersect = require('@turf/intersect').default;
// feature1
// feature2
fs.writeFileSync('foo.json', JSON.stringify(intersect(feature1, feature2)));

image

Going to close this issue since it doesn't seem to be an issue in v6.x code.

@chupacabra007
Copy link
Author

Is there a minified version of turf 6?

@rowanwins
Copy link
Member

Hi @chupacabra007

No unfortunately not yet.

If you'd like to compile a browser ready version of the intersect code you can use something like browserify as described on the getting started page, in particular check out the section called 'Creating custom builds for use in the browser'

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants