Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Polygon intersection bug
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
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 (intersection) {
const result = intersection(
input.features[0].geometry.coordinates,
clip.features[0].geometry.coordinates)
const features = result.map((coordinates) => ({
"type": "Feature",
"properties": {},
"geometry": {
"type": "Polygon",
"coordinates": coordinates
}
}))
return JSON.stringify({
"type": "FeatureCollection",
"features": features
})
}
fs.writeFileSync('./expected.json', apply(polygonClipping.intersection))
fs.writeFileSync('./actual.json', apply(martinez.intersection))
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.