【发布时间】:2015-05-22 12:23:42
【问题描述】:
我想知道从大型 GeoJSON 集合(大约 100k 行)中删除重复值(坐标)的最简单的 javascript 方法。删除重复值后,我想将更新的集合记录到控制台或在网页上显示结果。下面是我的尝试示例,但是我在控制台中得到的只是一个空数组。
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]
}
}
]
}
【问题讨论】:
-
您是否要消除具有相同坐标的项目?
标签: javascript duplicate-removal geojson