I would like to know the simplest javascript method for removing duplicate values (coordinates) from a large GeoJSON collection (approx 100k lines). After removing the duplicate values I would like to log the updated collection to the console or display the result on a webpage. A sample of my attempt is below, however all I am getting in the console is an empty array.
window.onload = init;
function init() {
function eliminateDuplicates(arr) {
var i;
var len = arr.length;
var out = [];
var obj = {};
for (i = 0; i < len; i++) {
obj[arr[i]]=0;
}
for (i in obj) {
out.push(i);
}
return out;
}
var newCollection = eliminateDuplicates(arr);
console.log(newCollection);
}
var arr =
{
"type": "FeatureCollection",
"features": [
{
"type": "Feature","properties": {"@id": "123",
"name": "test1",
"description": "Lorem Ipsum is simply dummy text of the printing and typesetting industry."},
"geometry": {
"type": "Point","coordinates": [-73.994720, 40.686902]
}
},
{
"type": "Feature","properties": {"@id": "1234",
"name": "test2",
"description": "Lorem Ipsum is simply dummy text of the printing and typesetting industry."},
"geometry": {
"type": "Point","coordinates": [-73.994720, 40.686902]
}
},
{
"type": "Feature","properties": {"@id": "1945",
"name": "test3",
"description": "Lorem Ipsum is simply dummy text of the printing and typesetting industry."},
"geometry": {
"type": "Point","coordinates": [-73.989205, 40.686675]
}
},
{
"type": "Feature","properties": {"@id": "1946",
"name": "test3",
"description": "Lorem Ipsum is simply dummy text of the printing and typesetting industry."},
"geometry": {
"type": "Point","coordinates": [-73.994655, 40.687391]
}
},
{
"type": "Feature","properties": {"@id": "1947",
"name": "test4",
"description": "Lorem Ipsum is simply dummy text of the printing and typesetting industry."},
"geometry": {
"type": "Point","coordinates": [-73.985557, 40.687683]
}
}
]
}