Skip to content

Commit 5c4c382

Browse files
committed
new doc
1 parent e76a2e1 commit 5c4c382

File tree

9 files changed

+105
-0
lines changed

9 files changed

+105
-0
lines changed

202004/20200410_02.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@ PostgreSQL , plan , pg_stat_statements
1414
## 背景
1515
https://rjuju.github.io/postgresql/2020/04/04/new-in-pg13-monitoring-query-planner.html
1616

17+
https://www.depesz.com/2020/04/02/waiting-for-postgresql-13-allow-pg_stat_statements-to-track-planning-statistics/
18+
1719
PG 13 pg_stat_statements支持跟踪plan统计信息, 有什么用?
1820

1921
1、OLTP场景, 并发高, sql简单同时基本上同一sql可以使用一个单一执行计划, 除非数据发生倾斜(PG的绑定变量可以通过custom plan算法解决), 所以让数据库尽量少的开销浪费在执行计划上.

202004/20200412_01.md

Lines changed: 101 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,101 @@
1+
## PostgreSQL Polygon Averaging in PostGIS - 多边形叠加统计
2+
3+
### 作者
4+
digoal
5+
6+
### 日期
7+
2020-04-12
8+
9+
### 标签
10+
PostgreSQL , postgis , 多边形 , 叠加 , 统计
11+
12+
----
13+
14+
## 背景
15+
https://info.crunchydata.com/blog/polygon-averaging-in-postgis
16+
17+
Let's say we received polygons from 10 users. If we used ST_Intersection on those polygons, the remaining polygon would only represent the points included in all 10 polygons. If we used ST_Union, the output would represent the points included in at least 1 polygon.
18+
19+
Can anyone recommend a way to output a polygon that represents the points that are in n polygons, where n is greater than 1 and less than the total number of polygons (10 in this case)?
20+
21+
这个问题是要知道在多个多边形叠加后, 在多边形内取一个点, 这个点到底被多少个多边形覆盖到了, 切出一个个的面, 每个面有多少个多边形叠加.
22+
23+
![pic](20200412_01_pic_001.png)
24+
25+
```
26+
WITH
27+
edges AS
28+
( SELECT
29+
(ST_Dump(
30+
ST_UnaryUnion(
31+
ST_Collect(
32+
ST_ExteriorRing(p.geom))))).geom
33+
FROM polygons p )
34+
```
35+
36+
This requires a few functions:
37+
38+
- [ST_ExteriorRing](https://postgis.net/docs/ST_ExteriorRing.html) to get the polygon boundary,
39+
- [ST_UnaryUnion](https://postgis.net/docs/ST_UnaryUnion.html) to mash all the rings together and break them at crossing points, and S
40+
- [ST_Dump](https://postgis.net/docs/ST_Dump.html) to convert the output of the union (a multi-linestring) back into one row per geometry.
41+
42+
![pic](20200412_01_pic_002.png)
43+
44+
```
45+
parts AS (
46+
SELECT (ST_Dump(ST_Polygonize(geom))).geom FROM edges
47+
)
48+
49+
50+
parts_count AS (
51+
SELECT parts.geom, count(*)
52+
FROM parts
53+
JOIN polygons p
54+
ON ST_Intersects(p.geom, ST_PointOnSurface(parts.geom))
55+
GROUP BY parts.geom
56+
)
57+
```
58+
59+
![pic](20200412_01_pic_003.png)
60+
61+
```
62+
SELECT ST_Union(geom) AS geom, 4 as count
63+
FROM parts_count
64+
WHERE count > 4
65+
```
66+
67+
![pic](20200412_01_pic_004.png)
68+
69+
```
70+
CREATE TABLE average AS
71+
WITH
72+
edges AS (
73+
SELECT (ST_Dump(ST_UnaryUnion(ST_Collect(ST_ExteriorRing(p.geom))))).geom
74+
FROM polygons2 p
75+
),
76+
parts AS (
77+
SELECT (ST_Dump(ST_Polygonize(geom))).geom FROM edges
78+
),
79+
parts_count AS (
80+
SELECT parts.geom, count(*)
81+
FROM parts
82+
JOIN polygons2 p
83+
ON ST_Intersects(p.geom, ST_PointOnSurface(parts.geom))
84+
GROUP BY parts.geom
85+
)
86+
SELECT ST_Union(geom) AS geom, 4 as count
87+
FROM parts_count
88+
WHERE count > 4
89+
```
90+
91+
![pic](20200412_01_pic_005.png)
92+
93+
94+
#### [免费领取阿里云RDS PostgreSQL实例、ECS虚拟机](https://www.aliyun.com/database/postgresqlactivity "57258f76c37864c6e6d23383d05714ea")
95+
96+
97+
#### [digoal's PostgreSQL文章入口](https://github.com/digoal/blog/blob/master/README.md "22709685feb7cab07d30f30387f0a9ae")
98+
99+
100+
![digoal's weixin](../pic/digoal_weixin.jpg "f7ad92eeba24523fd47a6e1a0e691b59")
101+

202004/20200412_01_pic_001.png

153 KB
Loading

202004/20200412_01_pic_002.png

76.9 KB
Loading

202004/20200412_01_pic_003.png

157 KB
Loading

202004/20200412_01_pic_004.png

143 KB
Loading

202004/20200412_01_pic_005.png

69.5 KB
Loading

202004/readme.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
### 文章列表
44
----
5+
##### 20200412_01.md [《PostgreSQL Polygon Averaging in PostGIS - 多边形叠加统计》](20200412_01.md)
56
##### 20200410_02.md [《PostgreSQL 13 pg_stat_statements支持跟踪plan统计信息》](20200410_02.md)
67
##### 20200410_01.md [《PostgreSQL 13 支持wal insert统计框架 - wal activity monitor》](20200410_01.md)
78
##### 20200408_01.md [《为什么pgpool sr_check_password为空也能认证成功》](20200408_01.md)

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@ digoal's|PostgreSQL|文章|归类
5454

5555
### 所有文档如下
5656
----
57+
##### 202004/20200412_01.md [《PostgreSQL Polygon Averaging in PostGIS - 多边形叠加统计》](202004/20200412_01.md)
5758
##### 202004/20200410_02.md [《PostgreSQL 13 pg_stat_statements支持跟踪plan统计信息》](202004/20200410_02.md)
5859
##### 202004/20200410_01.md [《PostgreSQL 13 支持wal insert统计框架 - wal activity monitor》](202004/20200410_01.md)
5960
##### 202004/20200408_01.md [《为什么pgpool sr_check_password为空也能认证成功》](202004/20200408_01.md)

0 commit comments

Comments
 (0)