当前位置:网站首页>pgr_createTopology
pgr_createTopology
2022-08-11 11:26:00 【爱是与世界平行】
1 pgr_createTopology 概述
函数作用:根据几何信息构建网络拓扑。
函数返回:
- 在网络拓扑图和顶点表建立好之后就OK了。
- 由于错误导致网络拓扑构建失败。
2 pgr_createTopology 参数说明
varchar pgr_createTopology(text edge_table, double precision tolerance,
text the_geom:='the_geom', text id:='id',
text source:='source',text target:='target',
text rows_where:='true', boolean clean:=false)
拓扑创建函数接受以下参数:
edge_table:text,表名
tolerance:float8,误差缓冲值,两个点的距离在这个距离内,就算重合为一点。这个距离使用st_length计算
the_geom:text,该表的空间坐标字段
id:text,该表的主键
source:text,空间起点编号
target:text,空间终点编号
rows_where:text,条件选择子集或行。默认值为true,表示源或目标具有空值的所有行,否则将使用条件。
clean:text,每次执行都重建拓扑图,默认false
说明:
- 执行SQL后,数据库中会创建或更新soure、target字段。
- 如果索引不存在,将创建一个索引,以加快以下列的进程:id、the_geom、source、target。
函数返回:
当创建拓扑结果成功时:
则会自动创建出来一个新表,存储了节点信息,表名:<edge_table>_vertices_pgr.
填充顶点表的id和the_geom列。新表会自动生成id和the_geom列, 并填充数据。
引用顶点表的id填充边缘表的源列和目标列。即关联新表和旧表,新表的ID关联旧表的source和target。
当创建拓扑失败时:
- 找不到表中所需的列,或者该列的类型不合适。
- 生成的数据构造的条件不合适,貌似就是数据结构不合理,构造出的数据不对。
- source、target或者id相同。
- SRID无法确定。
3 The Vertices Table
新创建出来的点集表包涵函数pgr_analyzeGraph and pgr_analyzeOneway 。
新表结构为:
| id: | bigint 顶点的标识符。 |
|---|---|
| cnt: | integer edge_table中引用此顶点的顶点数。See pgr_analyzeGraph. |
| chk: | integer 指示顶点可能有问题。See pgr_analyzeGraph. |
| ein: | integer edge_table中引用这个顶点的顶点数。See pgr_analyzeOneway. |
| eout: | integer edge_table中引用该顶点作为输出的顶点数。See pgr_analyzeOneway. |
| the_geom: | geometry Point geometry of the vertex:顶点的点几何。 |
4 SQL注意事项
4.1 参数使用顺序
当参数按形参中描述的顺序给出时,我们得到的结果与使用函数的最简单方法相同。
SELECT pgr_createTopology('edge_table', 0.001,
'the_geom', 'id', 'source', 'target');
NOTICE: PROCESSING:
NOTICE: pgr_createTopology('edge_table', 0.001, 'the_geom', 'id', 'source', 'target', rows_where := 'true', clean := f)
NOTICE: Performing checks, please wait .....
NOTICE: Creating Topology, Please wait...
NOTICE: -------------> TOPOLOGY CREATED FOR 18 edges
NOTICE: Rows with NULL geometry or NULL id: 0
NOTICE: Vertices table for table public.edge_table is: public.edge_table_vertices_pgr
NOTICE: ----------------------------------------------
pgr_createtopology
--------------------
OK
(1 row)
警告:
当参数没有按适当的顺序给出时,将会发生错误。
在这个例子中,表ege_table的列id作为几何列传递给函数,而几何列the_geom作为id列传递给函数。
SELECT pgr_createTopology('edge_table', 0.001,
'id', 'the_geom');
NOTICE: PROCESSING:
NOTICE: pgr_createTopology('edge_table', 0.001, 'id', 'the_geom', 'source', 'target', rows_where := 'true', clean := f)
NOTICE: Performing checks, please wait .....
NOTICE: ----> PGR ERROR in pgr_createTopology: Wrong type of Column id:the_geom
NOTICE: Unexpected error raise_exception
pgr_createtopology
--------------------
FAIL
(1 row)
4.2 命名表示法
当使用命名表示法时,用默认值定义的参数可以省略,只要值与默认值匹配,并且参数的顺序不重要。
SELECT pgr_createTopology('edge_table', 0.001,
the_geom:='the_geom', id:='id', source:='source', target:='target');
pgr_createtopology
--------------------
OK
(1 row)
SELECT pgr_createTopology('edge_table', 0.001,
source:='source', id:='id', target:='target', the_geom:='the_geom');
pgr_createtopology
--------------------
OK
(1 row)
SELECT pgr_createTopology('edge_table', 0.001, source:='source');
pgr_createtopology
--------------------
OK
(1 row)
4.3 选择指定行
使用rows_where参数选择行,根据id选择行。
SELECT pgr_createTopology('edge_table', 0.001, rows_where:='id < 10');
pgr_createtopology
--------------------
OK
(1 row)
选择与id = 5行的几何图形相邻的行。
SELECT pgr_createTopology('edge_table', 0.001,
rows_where:='the_geom && (SELECT st_buffer(the_geom, 0.05) FROM edge_table WHERE id=5)');
pgr_createtopology
--------------------
OK
(1 row)
Selecting the rows where the geometry is near the geometry of the row with gid =100 of the table othertable.
CREATE TABLE otherTable AS (SELECT 100 AS gid, st_point(2.5, 2.5) AS other_geom);
SELECT 1
SELECT pgr_createTopology('edge_table', 0.001,
rows_where:='the_geom && (SELECT st_buffer(other_geom, 1) FROM otherTable WHERE gid=100)');
pgr_createtopology
--------------------
OK
(1 row)
5 示例
这个例子开始一个干净的拓扑,有5条边,然后增加到其余的边。
SELECT pgr_createTopology('edge_table', 0.001, rows_where:='id < 6', clean := true);
NOTICE: PROCESSING:
NOTICE: pgr_createTopology('edge_table', 0.001, 'the_geom', 'id', 'source', 'target', rows_where := 'id < 6', clean := t)
NOTICE: Performing checks, please wait .....
NOTICE: Creating Topology, Please wait...
NOTICE: -------------> TOPOLOGY CREATED FOR 5 edges
NOTICE: Rows with NULL geometry or NULL id: 0
NOTICE: Vertices table for table public.edge_table is: public.edge_table_vertices_pgr
NOTICE: ----------------------------------------------
pgr_createtopology
--------------------
OK
(1 row)
SELECT pgr_createTopology('edge_table', 0.001);
NOTICE: PROCESSING:
NOTICE: pgr_createTopology('edge_table', 0.001, 'the_geom', 'id', 'source', 'target', rows_where := 'true', clean := f)
NOTICE: Performing checks, please wait .....
NOTICE: Creating Topology, Please wait...
NOTICE: -------------> TOPOLOGY CREATED FOR 13 edges
NOTICE: Rows with NULL geometry or NULL id: 0
NOTICE: Vertices table for table public.edge_table is: public.edge_table_vertices_pgr
NOTICE: ----------------------------------------------
pgr_createtopology
--------------------
OK
(1 row)
边栏推荐
- Hugging Face快速入门(重点讲解模型(Transformers)和数据集部分(Datasets))
- 2022-08-10北京华为OD机试真题分享
- a-upload上传图片去掉预览icon
- B端产品需求分析与优先级判断
- 独家采访 | 智能源于自发产生而非计划:进化论拥趸,前OpenAI研究经理、UBC大学副教授Jeff Clune
- 沃土云创计划重磅来袭
- EastWave应用:负折射现象实时演示
- Web3 创业者指南:如何为你的产品构建一个去中心化社区?
- Getting Started with Chrome Plug-in Development - Nanny Level Raiders
- leetcode:360. 有序转化数组
猜你喜欢

Starting from zero configuration vim (11) -- plug-in management

简单记录openguass_exporter对接prometheus通过grafanai来实现可视化监控

Bitmap这个“内存刺客”你也要小心

Network Security - nmap

五分钟教你内网穿透
![C# Call AutoNavi Map API to obtain latitude, longitude and positioning [Detailed 4D explanation with complete code]](/img/39/75a32a787c4e85026a768fd5781f25.png)
C# Call AutoNavi Map API to obtain latitude, longitude and positioning [Detailed 4D explanation with complete code]

a-upload上传图片

闪灯芯片银行塔闪灯IC参数应用

openresty概述及Lua语言的嵌入

独家采访 | 智能源于自发产生而非计划:进化论拥趸,前OpenAI研究经理、UBC大学副教授Jeff Clune
随机推荐
爆赞!阿里P8首次分享出基于Docker的企业级Redis实战开源笔记
leetcode:360. 有序转化数组
fiddler双向认证
Kubernetes应用发布思路分析
黑马瑞吉外卖之分类信息的分页查询
天花板级微服务大佬总结出这份451页笔记告诉你微服务就该这么学
Through the thermal lens focus on different types of gaussian model
Ince-Gaussian mode
rem如何使用
PerfView project (first) : how to find hot spots function
Flutter 教程之 在 Flutter 中生成 JSON 模型,在 Flutter GetX 中过滤列表和延迟搜索
C语言,怪题小谈
Use Function Compute to package and download OSS files [Encounter Pit Collection]
How long does it take to train a neural network, neural network training takes too long
Flutter 教程之 Flutter 中的 HMS 定位工具包
资本市场做好为工业互联网“买单”的准备了吗?
智能恒等于推荐系统
C# 调用高德地图API获取经纬度以及定位【万字详解附完整代码】
2022-08-10北京华为OD机试真题分享
EXCLUSIVE INTERVIEW | INTELLIGENCE IS SPONTANED, NOT PLANNED: Evolution Fan, Former OpenAI Research Manager and UBC Associate Professor Jeff Clune