Skip to content

Instantly share code, notes, and snippets.

@tyrasd
Created January 14, 2015 11:29
Show Gist options
  • Save tyrasd/7dfae5fe56873767017e to your computer and use it in GitHub Desktop.
Save tyrasd/7dfae5fe56873767017e to your computer and use it in GitHub Desktop.
check if two GeoJSON geometries are equal
function equals(g1,g2) {
function _equalCoords(c1,c2) {
if (typeof c1 === 'number')
return c1===c2;
else
if (Array.isArray(c1) && Array.isArray(c2) && c1.length===c2.length)
return c1.reduce(function(memo, val, index) {
return memo && _equalCoords(c1[index], c2[index]);
}, true);
else
return false;
}
return g1.type === g2.type && _equalCoords(g1.coordinates, g2.coordinates);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment