Comments (7)
Thanks @usmanijaaz . There will limitations in any system, especially when large datasets are involved. Ideally though we'd be able to handle those gracefully. Or at least add something in the documentation to set user expectations.
Do you have other options for providing returnedFeatures geojson as well e.g. dropbox? That's going to be key in reproducing and potentially narrowing down the cause.
Hi @smallsaucepan,
Sure thing, here is a link to a drive folder where I have uploaded the file for you: https://drive.google.com/file/d/1jhG28WNTWb6R9qznLfvTjYcSPyT-sdfc/view?usp=drive_link
from turf.
Hi @usmanijaaz . Can you please attach geojson files of returnedFeatures and siteBoundary? Also, have you commented out other code in your checkIntersection function to eliminate other potential causes?
from turf.
Hi @usmanijaaz . Can you please attach geojson files of returnedFeatures and siteBoundary? Also, have you commented out other code in your checkIntersection function to eliminate other potential causes?
Hi @smallsaucepan , thanks for your response. I am attaching the siteBoundary file you requested and I'm also attaching a screenshot for your convenience to understand returnedFeatures data as I am not able to upload file due to its size. As you can see in the screenshot, there are multiple rings in geometry and 1st ring contains 155036 coordinates.
And the first line of code in checkIntersection
function is if (turf.intersect(ourSiteBoundary, polygonFromReturnedFeatures))
, the code freezes here and never move past this line.
from turf.
Thanks @usmanijaaz . There will limitations in any system, especially when large datasets are involved. Ideally though we'd be able to handle those gracefully. Or at least add something in the documentation to set user expectations.
Do you have other options for providing returnedFeatures geojson as well e.g. dropbox? That's going to be key in reproducing and potentially narrowing down the cause.
from turf.
Thanks @usmanijaaz . Investigated and found a safety check in the polygon-clipping library that is meant to stop infinite loops. The behaviour wasn't exactly what you were seeing (the code threw an error, rather than hanging), however it sounds too similar not to be related.
Taking the returnedFeatures json you provided, I loaded different combinations of the rings (big rings, small rings, all rings) and tried calling intersect. Big rings and small rings by themselves worked ok, but all rings together produced this error after a few seconds:
turf-issue-2601/node_modules/polygon-clipping/dist/polygon-clipping.cjs.js:1726
throw new Error("Infinite loop when putting segment endpoints in a priority queue " + "(queue size too big).");
^
Error: Infinite loop when putting segment endpoints in a priority queue (queue size too big).
Looking further in to that, polygon-clipping has some code that says "if I need to run this loop more than a million times I'm probably in an infinite loop so abort". Turns out you can also hit this threshold with a big enough polygon!
polygon-clipping lets you override this env.POLYGON_CLIPPING_MAX_QUEUE_SIZE
so from the command line you could try:
$ POLYGON_CLIPPING_MAX_QUEUE_SIZE=10000000 npx tsx ./test.ts
(that's 10 million)
Doing this allowed intersect to run through all the rings at once and produce the below polygon in about 5 seconds.
![Screenshot 2024-05-06 at 10 58 12 pm](https://private-user-images.githubusercontent.com/5403628/328186668-ad99bdd3-3106-4b0a-b3c6-bb30c222a8d5.png?jwt=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJnaXRodWIuY29tIiwiYXVkIjoicmF3LmdpdGh1YnVzZXJjb250ZW50LmNvbSIsImtleSI6ImtleTUiLCJleHAiOjE3MTY1NTA3MDQsIm5iZiI6MTcxNjU1MDQwNCwicGF0aCI6Ii81NDAzNjI4LzMyODE4NjY2OC1hZDk5YmRkMy0zMTA2LTRiMGEtYjNjNi1iYjMwYzIyMmE4ZDUucG5nP1gtQW16LUFsZ29yaXRobT1BV1M0LUhNQUMtU0hBMjU2JlgtQW16LUNyZWRlbnRpYWw9QUtJQVZDT0RZTFNBNTNQUUs0WkElMkYyMDI0MDUyNCUyRnVzLWVhc3QtMSUyRnMzJTJGYXdzNF9yZXF1ZXN0JlgtQW16LURhdGU9MjAyNDA1MjRUMTEzMzI0WiZYLUFtei1FeHBpcmVzPTMwMCZYLUFtei1TaWduYXR1cmU9YTE0Y2ZkZGNhNTg3NmM2MWVhMGZlNTQzZjZlN2Y5MDU3NjUxNzIzYzQwY2I4Zjg0ODYzMDJjMzBlNGE2OWUyZCZYLUFtei1TaWduZWRIZWFkZXJzPWhvc3QmYWN0b3JfaWQ9MCZrZXlfaWQ9MCZyZXBvX2lkPTAifQ.J6PnYjBVsyiA5VW-RYHv591QpFbgaKpR2uek4m8nJQg)
Give that a try and see if it helps or changes the situation.
from turf.
Thanks @usmanijaaz . Investigated and found a safety check in the polygon-clipping library that is meant to stop infinite loops. The behaviour wasn't exactly what you were seeing (the code threw an error, rather than hanging), however it sounds too similar not to be related.
Taking the returnedFeatures json you provided, I loaded different combinations of the rings (big rings, small rings, all rings) and tried calling intersect. Big rings and small rings by themselves worked ok, but all rings together produced this error after a few seconds:
turf-issue-2601/node_modules/polygon-clipping/dist/polygon-clipping.cjs.js:1726 throw new Error("Infinite loop when putting segment endpoints in a priority queue " + "(queue size too big)."); ^ Error: Infinite loop when putting segment endpoints in a priority queue (queue size too big).
Looking further in to that, polygon-clipping has some code that says "if I need to run this loop more than a million times I'm probably in an infinite loop so abort". Turns out you can also hit this threshold with a big enough polygon!
polygon-clipping lets you override this
env.POLYGON_CLIPPING_MAX_QUEUE_SIZE
so from the command line you could try:$ POLYGON_CLIPPING_MAX_QUEUE_SIZE=10000000 npx tsx ./test.ts
(that's 10 million)
Doing this allowed intersect to run through all the rings at once and produce the below polygon in about 5 seconds.
Give that a try and see if it helps or changes the situation.
Oh got it @smallsaucepan, thanks a lot for looking into this. I have currently deployed the solution where i split rings into two categories and process them separately and it is working fine for me.
However, I was wondering that I am using turf's npm package in my angular app, How can i set an environment variable for polygon_clipping library in my application.
from turf.
Happy to help!
Hmm, setting it via Angular in the browser sounds a bit fiddly. Maybe take a look at this for some ideas - https://stackoverflow.com/a/46269080/3606644
Also note that if you increase that value and then get into the type of infinite loop the code is checking for, it will take 10x as long / use 10x as much memory before the failsafe activates.
Best of luck!
from turf.
Related Issues (20)
- lineOverlap tolerance is not handled in every case
- turf.centerOfMass for multiple polygons in Feature Collection HOT 2
- booleanIntersects false positive for self-intersecting lines HOT 2
- [Bug report]: ts declaration broken HOT 2
- Could not find a declaration file for module '@turf/turf'. HOT 3
- booleanContains doesn't get good result when detect an unusual polygon HOT 1
- Typescript typing error when import "@turf/turf" HOT 2
- Can coordinate system parameters be added to some conversion methods?
- Drawing a curved line from Point A to Point B HOT 1
- Could not find a declaration file for module '@turf/mask' HOT 3
- There was a loss of accuracy when using the turf.intersect function
- BooleanWithin does not work correctly with (Island polygon / Doughnut).
- Property 'booleanPointInPolygon' does not exist on type 'TurfStatic' HOT 1
- isobands generating countered some wrong results HOT 3
- Broken TS types HOT 4
- splitLineWithPoints doesn't split correctly HOT 2
- Randomly generated polygons do not comply with the right-hand rule. HOT 1
- turf.convex does not wrap the polygons as expected
- How to change the outline of the masked area in a polygon? HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from turf.