nodes - 避免 PostGIS 中的边缘重复
问题描述
我很想在距离小于 5m 的节点之间创建边缘。以下 PostGIS 代码有效。
create table edges as
select a.id from_gid,
b.id to_gid,
st_shortestline(a.geom_26916, b.geom_26916),
st_distance(a.geom_26916, b.geom_26916) as distance
from flowers as a,
(select * from flowers) as b
where st_dwithin(a.geom_26916, b.geom_26916, 5);
然而,它给了我重复的边缘。如何修改代码以获得独特的边缘?谢谢!
解决方案
同一张表被查询两次(如a
和b
),因此它将返回记录 1 和 2 之间的一条边,以及记录 2 和 1 之间的第二条线。它还将返回同一记录的奇怪结果(一个点)。
您需要在 id 上添加过滤子句:
...
WHERE a.id < b.id AND st_dwithin(a.geom_26916, b.geom_26916, 5);
推荐阅读
- json - bash使用带有jq的变量在文件json中添加属性
- android - jUnit4 - 为什么测试可挂起函数失败并出现“RuntimeException:... AndroidJUnit4 无法加载”?
- javascript - 如何使用 Brain.js 进行预测?
- angular - 构建工作,但无法运行“ng test”
- c# - 后台工作人员未启动
- c# - Xamarin Forms`ContentView`绑定不起作用
- java - 为什么不在 Android 的控制台上显示 firebase 事件?
- vb.net - 是否存在解析包含在一个父 XML 节点中的所有信息的最佳实践?
- yaml - Conda 环境导出到 yaml 文件失败
- java - 达到 JobScheduler 限制 100 后,WorkManager 对作业做了什么?