Skip to content

Instantly share code, notes, and snippets.

@davebrent
Created January 2, 2019 17:03
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save davebrent/28a686e7555f0e65f0859a6994bce5c0 to your computer and use it in GitHub Desktop.
Save davebrent/28a686e7555f0e65f0859a6994bce5c0 to your computer and use it in GitHub Desktop.
Polygon intersection bug
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 (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))
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.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment