【发布时间】:2020-04-05 15:47:40
【问题描述】:
我正在尝试使用 topojson 将两个多边形特征合并在一起。这两个多边形最初不包含我认为 topojson.merge 执行合并所需的相似/共享点。在执行拓扑之前,我遍历多边形并将共享点添加到需要它们的多边形中。生成的 FeatureCollection“集合”如下所示:
{
"type": "FeatureCollection",
"features": [
{
"type": "Feature",
"properties":
{
"id": "area_1"
},
"geometry":
{
"type": "Polygon",
"coordinates": [
[
[148, 105],
[160, 105],
[160, 113],
[148, 113]
]
]
}
},
{
"type": "Feature",
"properties":
{
"id": "area_2"
},
"geometry":
{
"type": "Polygon",
"coordinates": [
[
[143, 113],
[148, 113],
[160, 113],
[171, 113],
[171, 132],
[143, 132]
]
]
}
}]
}
let topology = topojson.topology({ collection: collection });
得到的拓扑是:
{
"type": "Topology",
"objects":
{
"collection":
{
"type": "GeometryCollection",
"geometries": [
{
"type": "Polygon",
"arcs": [
[-1]
],
"properties":
{
"id": "area_1"
}
},
{
"type": "Polygon",
"arcs": [
[-2]
],
"properties":
{
"id": "area_2"
}
}]
}
},
"arcs": [
[
[
[148, 105],
[160, 105],
[160, 113],
[148, 113]
]
],
[
[
[143, 113],
[148, 113],
[160, 113],
[171, 113],
[171, 132],
[143, 132]
]
]
]
}
这是我如何调用合并:
topojson.merge(topology, topology.objects.collection.geometries);
结果错误是:
Uncaught TypeError: Cannot read property '0' of undefined - stitch.js:13
发生错误的代码行:
arcs.forEach(function (i, j) {
var arc = topology.arcs[i < 0 ? ~i : i],
t;
if (arc.length < 3 && !arc[1][0] && !arc[1][1]) {
t = arcs[++emptyIndex], arcs[emptyIndex] = i, arcs[j] = t;
}
});
似乎发生错误是因为代码正在寻找比它们存在的更远一步的弧...
我做错了什么?
【问题讨论】:
标签: javascript geojson topojson