我想知道最簡單的javascript方法,用於從大型GeoJSON集合(大約10萬行)中刪除重複值(座標)。刪除重複值後,我想將更新後的集合記錄到控制檯或在網頁上顯示結果。下面是我的嘗試示例,但是我在控制檯中獲取的是一個空數組。從GeoJSON集合中刪除重複的值
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]
}
}
]
}
你們是不是要消除同一座標的項目? –