Skip to content

Instantly share code, notes, and snippets.

@untoldwind
Created Feb 2, 2019
Embed
What would you like to do?
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