Created
January 2, 2019 17:03
-
-
Save davebrent/28a686e7555f0e65f0859a6994bce5c0 to your computer and use it in GitHub Desktop.
Polygon intersection bug
This file contains hidden or 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
{"type":"FeatureCollection","name":"clipping polygon","features":[{"type":"Feature","properties":{},"geometry":{"type":"Polygon","coordinates":[[[-5.0844225050718475,56.76993147270265],[-5.02639658883008,56.76993147270265],[-5.02639658883008,56.83302498513894],[-5.0844225050718475,56.83302498513894],[-5.0844225050718475,56.76993147270265]]]}}]} |
This file contains hidden or 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 (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)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment