Skip to content

Instantly share code, notes, and snippets.

@PizzaBrandon
Created May 25, 2018 17:50
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save PizzaBrandon/1d897159017fc1654b061611d408ad46 to your computer and use it in GitHub Desktop.
Save PizzaBrandon/1d897159017fc1654b061611d408ad46 to your computer and use it in GitHub Desktop.
turf/intersect 6.1.2 bug
const feature1 = {
"type": "Feature",
"geometry": {
"type": "Polygon",
"coordinates": [
[
[-85.42358091, 41.76872876],
[-85.42358054, 41.76871738],
[-85.42343269, 41.76871941],
[-85.42342892, 41.7687873],
[-85.42343247, 41.76882923],
[-85.42343403, 41.76885906],
[-85.42343247, 41.76893021],
[-85.4234327, 41.76893113],
[-85.42343245, 41.768932],
[-85.42343245, 41.76896821],
[-85.42357911, 41.76896572],
[-85.42357911, 41.76895253],
[-85.42357911, 41.768932],
[-85.42358073, 41.76885781],
[-85.42357713, 41.76878899],
[-85.42358091, 41.76872876]
]
]
}
};
const feature2 = {
"type": "Feature",
"geometry": {
"type": "Polygon",
"coordinates": [
[
[-85.42775567, 41.76834521],
[-85.42261052, 41.76843269],
[-85.42260803, 41.76844995],
[-85.4226073, 41.76845496],
[-85.42260484, 41.76848048],
[-85.42260083, 41.76852204],
[-85.42260191, 41.76856362],
[-85.42260586, 41.7685989],
[-85.42263068, 41.76862319],
[-85.42334654, 41.76860736],
[-85.42335464, 41.76862399],
[-85.4233818, 41.76867993],
[-85.42338342, 41.76869724],
[-85.42338701, 41.76872004],
[-85.42339693, 41.76871991],
[-85.42343269, 41.76871941],
[-85.42358054, 41.76871738],
[-85.42358091, 41.76872876],
[-85.42357713, 41.768789],
[-85.42358073, 41.76885781],
[-85.42357911, 41.768932],
[-85.42357911, 41.76895253],
[-85.42357911, 41.76896572],
[-85.42595679, 41.76892533],
[-85.42595476, 41.76888531],
[-85.42599703, 41.7688939],
[-85.42599798, 41.76892451],
[-85.426518, 41.76891567],
[-85.42776659, 41.76889445],
[-85.42781994, 41.76889354],
[-85.42781971, 41.76888565],
[-85.42781923, 41.76886922],
[-85.42780934, 41.76879664],
[-85.42782049, 41.76870985],
[-85.42782211, 41.76864827],
[-85.42782265, 41.76858656],
[-85.42782337, 41.76852915],
[-85.42782301, 41.76847763],
[-85.42782337, 41.7684563],
[-85.42775364, 41.76845772],
[-85.42775456, 41.76840654],
[-85.42775499, 41.76838269],
[-85.42775536, 41.76836222],
[-85.42775567, 41.76834521]
]
]
}
};
try {
const intersection = turf.intersect(feature1, feature2);
} catch (e) {
// Error with `Each LinearRing of a Polygon must have 4 or more Positions.`
console.error(e);
}
const intersection = turf.intersect(feature2, feature1);
// intersection is {"type":"Feature","properties":{},"geometry":{"type":"MultiPolygon","coordinates":[[[[-85.42357713,41.76878899],[-85.42357713,41.768789],[-85.42357713,41.76878899]]],[[[-85.42343269,41.76871941],[-85.42339693,41.76871991],[-85.42343247,41.76882923],[-85.42342892,41.7687873],[-85.42343245,41.768932]]]]}}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment