turfjs / turf-intersect Goto Github PK
View Code? Open in Web Editor NEWfind the intersection of features
find the intersection of features
Is there any interest in a pull request that would allow for MultiPolygons as input/output? I'd guess a lot of people are writing the same "loop through the input polygons, loop through the comparison polygons, combine all the shards of overlap" code.
It's not super-complicated to wrap this with that extra code but it seems like it would make sense to include it here unless there's a design reason I'm missing for limiting it to polygons.
How would I use the intersect function to look for intersection in a collection? The examples I found on the Internet all make use of for loops and this is extremely slow on a very large collection.
Basically I have feature collection of polygons (can also be lines). I also have a point. What I now want is to get all the features that intersect with this point (Without iterating through all features in the collection).
hey ✋ !! When I call many times to detect the intersection in huge files throw the error, but in small files with few data, it works ok.
111 tiles processed in 4s
/Users/ruben/apps/osmlint/node_modules/@turf/turf/turf.js:39775
throw savedException
^
Error
at TopologyException.RuntimeException [as constructor] (/Users/ruben/apps/osmlint/node_modules/@turf/turf/turf.js:24925:19)
at new TopologyException (/Users/ruben/apps/osmlint/node_modules/@turf/turf/turf.js:30875:25)
at FastNodingValidator.checkValid (/Users/ruben/apps/osmlint/node_modules/@turf/turf/turf.js:38993:31)
at EdgeNodingValidator.checkValid (/Users/ruben/apps/osmlint/node_modules/@turf/turf/turf.js:39019:12)
at Function.checkValid (/Users/ruben/apps/osmlint/node_modules/@turf/turf/turf.js:39037:13)
at OverlayOp.computeOverlay (/Users/ruben/apps/osmlint/node_modules/@turf/turf/turf.js:40836:25)
at OverlayOp.getResultGeometry (/Users/ruben/apps/osmlint/node_modules/@turf/turf/turf.js:40812:10)
at Function.OverlayOp.overlayOp (/Users/ruben/apps/osmlint/node_modules/@turf/turf/turf.js:40935:20)
at SnapIfNeededOverlayOp.getResultGeometry (/Users/ruben/apps/osmlint/node_modules/@turf/turf/turf.js:39762:24)
at Function.overlayOp (/Users/ruben/apps/osmlint/node_modules/@turf/turf/turf.js:39789:13)```
undefined
=> no intersect
Polygon => overlap
MultiLineString => share a border
JSTS handles linestrings and the current turf-intersect does as a result. We should support this and document it.
cc @geographa
how can I get the properties from the intersect which come from poly1 and poly2
I came across a strange edge case bug today--unless I am missing something. Anyways thanks for the awesome library.
Here is a way to test the edge case:
var poly1 = turf.polygon([[[0,0],[0,5],[5,5],[5,0],[0,0]]]);
var poly2 = turf.polygon([[[4,0],[4,5],[9,5],[9,0],[4,0]]]);
var intersection = turf.intersect(poly1, poly2);
// returns null -- but I expected it to return a polygon
Intersect raises an error {}
with an undefined
stack...
Just curious as to how we'll determine when we're "done" or feature complete. Will turf-intersect only be concerned with the geometries? Coming from a GIS background, I kind of expect the output to include the attributes too.
It currently returns an empty GeometryCollection, which is weird.
probably will need to implement this:
http://en.wikipedia.org/wiki/Weiler%E2%80%93Atherton_clipping_algorithm
Here is my code:
var turfIntersect = require('turf-intersect'),
feature1 = {
"type": "Feature",
"geometry": {
"type": "Polygon",
"coordinates": [
[
[
-0.002507080691666959,
-0.0011250000000000001
],
[
-0.0023009735543523544,
-0.001
],
[
-0.0023750000000000004,
-0.001
],
[
-0.0023820806916669593,
-0.0011250000000000001
],
[
-0.002507080691666959,
-0.0011250000000000001
]
]
]
},
"properties": {
"id": "Ekhec9w1i2",
"generationDebugging_polyAreaKm": 0.1936254535770603,
"generationDebugging_reasonStopped": "area below minimum block size"
}
},
feature2 = {
"type": "Feature",
"geometry": {
"type": "MultiPolygon",
"coordinates": [
[
[
[
0.0009087550118278532,
-0.0013568242308416504
],
[
0.0008458222552659575,
-0.0012938914744331181
],
[
0.0008458222552659575,
-0.0012309587180245858
],
[
0.0007828894987040619,
-0.0011680259616160535
],
[
0.0007828894987040619,
-0.0011050932052075212
],
[
0.0007828894987040619,
-0.001042160448798989
],
[
0.0007828894987040619,
-0.0009792276923904566
],
[
0.0008458222552659575,
-0.0009162949359819244
],
[
0.0008458222552659575,
-0.000853362179573392
],
[
0.0009087550118278532,
-0.0007904294231648598
],
[
0.0009716877683897488,
-0.000853362179573392
],
[
0.0009716877683897488,
-0.0007904294231648598
],
[
0.0010346205249516444,
-0.000853362179573392
],
[
0.0010346205249516444,
-0.0007904294231648598
],
[
0.0010346205249516444,
-0.0007274966667563275
],
[
0.00109755328151354,
-0.0007274966667563275
],
[
0.00109755328151354,
-0.0007904294231648598
],
[
0.0011604860380754355,
-0.000853362179573392
],
[
0.0011604860380754355,
-0.0009162949359819244
],
[
0.001223418794637331,
-0.0009792276923904566
],
[
0.001223418794637331,
-0.001042160448798989
],
[
0.001223418794637331,
-0.0011050932052075212
],
[
0.001223418794637331,
-0.0011680259616160535
],
[
0.0011604860380754355,
-0.0012309587180245858
],
[
0.00109755328151354,
-0.0012938914744331181
],
[
0.00109755328151354,
-0.0013568242308416504
],
[
0.0010346205249516444,
-0.0013568242308416504
],
[
0.0009716877683897488,
-0.0013568242308416504
],
[
0.0009087550118278532,
-0.0013568242308416504
]
],
[
[
0.0010346205249516444,
-0.000853362179573392
],
[
0.0010346205249516444,
-0.0009162949359819244
],
[
0.00109755328151354,
-0.000853362179573392
],
[
0.0010346205249516444,
-0.000853362179573392
]
],
[
[
0.0010346205249516444,
-0.0009162949359819244
],
[
0.0009716877683897488,
-0.0009162949359819244
],
[
0.0009716877683897488,
-0.0009792276923904566
],
[
0.0010346205249516444,
-0.0009162949359819244
]
]
],
[
[
[
0.0009716877683897488,
-0.0007274966667563275
],
[
0.0009716877683897488,
-0.0007904294231648598
],
[
0.0009087550118278532,
-0.0007904294231648598
],
[
0.0009087550118278532,
-0.0007274966667563275
],
[
0.0009087550118278532,
-0.0006645639103477952
],
[
0.0009087550118278532,
-0.0006016311539392629
],
[
0.0009716877683897488,
-0.0006016311539392629
],
[
0.0009087550118278532,
-0.0005386983975307306
],
[
0.0009716877683897488,
-0.00047576564112219825
],
[
0.0009716877683897488,
-0.00041283288471366596
],
[
0.0010346205249516444,
-0.00034990012830513366
],
[
0.00109755328151354,
-0.00028696737189660136
],
[
0.0011604860380754355,
-0.00034990012830513366
],
[
0.0011604860380754355,
-0.00041283288471366596
],
[
0.00109755328151354,
-0.00047576564112219825
],
[
0.00109755328151354,
-0.0005386983975307306
],
[
0.00109755328151354,
-0.0006016311539392629
],
[
0.0010346205249516444,
-0.0006645639103477952
],
[
0.0009716877683897488,
-0.0006645639103477952
],
[
0.0009716877683897488,
-0.0007274966667563275
]
]
]
]
},
"properties": {}
};
console.log('intersect', turfIntersect(feature1, feature2));
When I run this, I get:
λ node sample.js
/Users/nick.heiner/public-repos/iberville/node_modules/turf-intersect/node_modules/jsts/lib/jsts.js:1436
rlayOp.overlayOp(this.geom[0],this.geom[1],opCode);}catch(ex){throw savedExcep
^
Error
at Object.<anonymous> (/Users/nick.heiner/public-repos/iberville/node_modules/turf-intersect/node_modules/jsts/lib/jsts.js:21:414)
at Module._compile (module.js:460:26)
at Object.Module._extensions..js (module.js:478:10)
at Module.load (module.js:355:32)
at Function.Module._load (module.js:310:12)
at Module.require (module.js:365:17)
at require (module.js:384:17)
at Object.<anonymous> (/Users/nick.heiner/public-repos/iberville/node_modules/turf-intersect/node_modules/jsts/index.js:2:12)
at Module._compile (module.js:460:26)
at Object.Module._extensions..js (module.js:478:10)
λ node --version
v0.12.7
λ npm ls --depth 0 turf-intersect
[email protected] /Users/nick.heiner/public-repos/iberville
└── [email protected]
Is this a bug, or am I doing something wrong? If I am doing something wrong, it would be nice if the error were more descriptive.
Hi
When trying to use intersect on the following feature(same feature in both params) it returns null
const intersection = intersect(polygon, polygon);
I expected it to return the same feature since both features are identical.
The feature:
feature.TXT
Please advise
Hi,
Sorry i don't know how to call them in english, but turfjs crash if you try to intersect a crossed polygon like this:
the thrown error is:
0x800a139e - Erreur d’exécution JavaScript: TopologyError: found non-noded intersection between LINESTRING ( 614147.9168432382 146363.16929745465, 614292.1574302447 146242.24904487425 ) and LINESTRING ( 614178.1469063832 146184.38006685363, 614237.7433165836 146332.93923430957 ) [ (614224.2120870375, 146299.20921283241) ]
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.