Skip to content

Instantly share code, notes, and snippets.

@untoldwind
Created February 2, 2019 11:37
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 untoldwind/e95b7eff8ad61527a5dc4bdd889169b0 to your computer and use it in GitHub Desktop.
Save untoldwind/e95b7eff8ad61527a5dc4bdd889169b0 to your computer and use it in GitHub Desktop.
Test geojson with javascript algorithm
npm install
node main.js
const martinez = require('martinez-polygon-clipping');
const geojson2svg = require('geojson-to-svg');
const gj1 = {
"type": "Feature",
"properties": {},
"geometry": { "type": "Polygon", "coordinates": [[[ -530, -530], [-530, 530], [530, 530], [530, -530], [ -530, -530]]] }
}
const gj2 = {
"type": "Feature",
"properties": {},
"geometry": { "type": "Polygon", "coordinates": [[[1.2500125250252, -531],[-98, -531],[-98, 531],[1.250012525025, 531],[1.2500125250252, -531]]] }
}
const intersection = {
"type": "Feature",
"geometry": {
"type": "Polygon",
"coordinates": martinez.intersection(gj1.geometry.coordinates, gj2.geometry.coordinates)
}
};
console.log(JSON.stringify(intersection, null, " "));
console.log(geojson2svg()
.data(gj1)
.render());
console.log(geojson2svg()
.data(gj2)
.render());
{
"dependencies": {
"geojson-to-svg": "^1.0.3",
"martinez-polygon-clipping": "^0.5.0"
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment