Created
January 14, 2015 11:29
-
-
Save tyrasd/7dfae5fe56873767017e to your computer and use it in GitHub Desktop.
check if two GeoJSON geometries are equal
This file contains 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
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