-
-
Save jakeNiemiec/7d75093e5e8d9fe52008871c109bb855 to your computer and use it in GitHub Desktop.
Polygon intersection bug
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Created by .ignore support plugin (hsz.mobi) | |
### Example user template template | |
### Example user template | |
# IntelliJ project files | |
.idea | |
*.iml | |
out | |
gen | |
node_modules |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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 | |
)); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"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==" | |
} | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"name": "7d75093e5e8d9fe52008871c109bb855", | |
"version": "1.0.0", | |
"description": "", | |
"main": "index.js", | |
"scripts": { | |
"run": "node index.js" | |
}, | |
"repository": { | |
"type": "git", | |
"url": "git+ssh://[email protected]/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