Skip to content

Instantly share code, notes, and snippets.

@jakeNiemiec
Forked from davebrent/actual.json
Last active January 2, 2019 22:41
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 jakeNiemiec/7d75093e5e8d9fe52008871c109bb855 to your computer and use it in GitHub Desktop.
Save jakeNiemiec/7d75093e5e8d9fe52008871c109bb855 to your computer and use it in GitHub Desktop.
Polygon intersection bug
# Created by .ignore support plugin (hsz.mobi)
### Example user template template
### Example user template
# IntelliJ project files
.idea
*.iml
out
gen
node_modules
Display the source blob
Display the rendered blob
Raw
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Display the source blob
Display the rendered blob
Raw
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Display the source blob
Display the rendered blob
Raw
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
// npm install martinez-polygon-clipping polygon-clipping
// node index.js
const fs = require('fs');
const martinez = require('martinez-polygon-clipping');
const polygonClipping = require('polygon-clipping');
const input = require('./input.json');
const clip = require('./clip.json');
function apply(op, area, clip) {
// console.log(input);
// console.log(clip);
const result = op(
area,
clip,
);
return JSON.stringify({
'type': 'FeatureCollection',
'features': [{
'type': 'Feature',
'properties': {},
'geometry': {
'type': 'MultiPolygon',
'coordinates': result
}
}]
});
}
fs.writeFileSync('./expected.json', apply(
polygonClipping.difference,
input.features[0].geometry.coordinates,
clip.features[0].geometry.coordinates
));
fs.writeFileSync('./actual.json', apply(
martinez.diff,
input.features[0].geometry.coordinates,
clip.features[0].geometry.coordinates
));
Display the source blob
Display the rendered blob
Raw
{
"type": "FeatureCollection",
"features": [
{
"type": "Feature",
"properties": {},
"geometry": {
"type": "Polygon",
"coordinates": [
[
[6,2.5],
[12,2.5],
[12,13],
[6,13],
[6,2.5]
],
[
[8,3.5],
[10,3.5],
[10,6],
[8,6],
[8,3.5]
],
[
[8, 12],
[10, 12],
[10, 9],
[8, 9],
[8, 12]
]
]
}
}
]
}
{
"name": "7d75093e5e8d9fe52008871c109bb855",
"version": "1.0.0",
"lockfileVersion": 1,
"requires": true,
"dependencies": {
"babel-plugin-add-module-exports": {
"version": "0.2.1",
"resolved": "https://registry.npmjs.org/babel-plugin-add-module-exports/-/babel-plugin-add-module-exports-0.2.1.tgz",
"integrity": "sha1-mumh9KjcZ/DN7E9K7aHkOl/2XiU="
},
"martinez-polygon-clipping": {
"version": "0.5.0",
"resolved": "https://registry.npmjs.org/martinez-polygon-clipping/-/martinez-polygon-clipping-0.5.0.tgz",
"integrity": "sha512-FvHURxJTieS4LEHL+aJmWbqCUBk2GrYU5zolgXNAQLJsjnAff7Hqqk5MM1Kl91FnPOcyiAs/cVey11bb0D7qug==",
"requires": {
"splaytree": "^0.1.4",
"tinyqueue": "^1.2.0"
}
},
"polygon-clipping": {
"version": "0.9.2",
"resolved": "https://registry.npmjs.org/polygon-clipping/-/polygon-clipping-0.9.2.tgz",
"integrity": "sha512-UO+53kvxmuyMpO6RqepUTj3lQPcFJ6NbqJbfwxcOZv3xTuWUQd2q12JiyT5Sd2NAHgxzHH2ht2BQSuclJaEyDQ==",
"requires": {
"babel-plugin-add-module-exports": "^0.2.1",
"splaytree": "^2.0.2",
"tinyqueue": "^1.2.3"
},
"dependencies": {
"splaytree": {
"version": "2.0.3",
"resolved": "https://registry.npmjs.org/splaytree/-/splaytree-2.0.3.tgz",
"integrity": "sha512-IziTvWQv9F1EiKq9XveosQRGTLrdUW0jLokpmAXz0+hnLgBZitvU0j4gUvCGASKwUQvCZaofhff1H8OmE2LRdA=="
}
}
},
"splaytree": {
"version": "0.1.4",
"resolved": "https://registry.npmjs.org/splaytree/-/splaytree-0.1.4.tgz",
"integrity": "sha512-D50hKrjZgBzqD3FT2Ek53f2dcDLAQT8SSGrzj3vidNH5ISRgceeGVJ2dQIthKOuayqFXfFjXheHNo4bbt9LhRQ=="
},
"tinyqueue": {
"version": "1.2.3",
"resolved": "https://registry.npmjs.org/tinyqueue/-/tinyqueue-1.2.3.tgz",
"integrity": "sha512-Qz9RgWuO9l8lT+Y9xvbzhPT2efIUIFd69N7eF7tJ9lnQl0iLj1M7peK7IoUGZL9DJHw9XftqLreccfxcQgYLxA=="
}
}
}
{
"name": "7d75093e5e8d9fe52008871c109bb855",
"version": "1.0.0",
"description": "",
"main": "index.js",
"scripts": {
"run": "node index.js"
},
"repository": {
"type": "git",
"url": "git+ssh://git@gist.github.com/7d75093e5e8d9fe52008871c109bb855.git"
},
"author": "",
"license": "ISC",
"bugs": {
"url": "https://gist.github.com/7d75093e5e8d9fe52008871c109bb855"
},
"homepage": "https://gist.github.com/7d75093e5e8d9fe52008871c109bb855",
"dependencies": {
"martinez-polygon-clipping": "^0.5.0",
"polygon-clipping": "^0.9.2"
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment