pg自相交问题

文章讲述了如何在PostGIS中处理FeatureCollection类型的几何数据,通过ST_Union去除公共部分并合并几何对象,以及使用ST_MakeValid确保几何合法性。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

几何类型:

multi:是geometrycollection的字子类

geometrycollection 一个geomlist

ST_Collect 将几何集合类型(mutil,geometrycollection)合并原封不动输出geometrycollection

ST_Union 将几何对象合并(去除公共部分)合并为一个新的对象

自相交:共有部分还是堆叠显示,没有合并边界---一般在FeatureCollection几何类型会遇到

1,获取解析出FeatureCollection中geometry部分(PostGIS可以识别的数据格式)

2,对每个geometry转为合法化ST_MakeValid

3,对合法化的geomtry进行融合st_union

SELECT ST_Union(t.geom) FROM (

WITH data AS (SELECT

'{

"type": "FeatureCollection",

"features": [{

"type": "Feature",

"properties": {},

"geometry": {

"type": "Polygon",

"coordinates": [

[

[120.52757263183594, 31.495432803134843],

[120.59211730957031, 31.31199502365151],

[120.89012145996094, 31.35950051982242],

[120.74729919433594, 31.283245492650792],

[120.52757263183594, 31.495432803134843]

]

]

}

}, {

"type": "Feature",

"properties": {},

"geometry": {

"type": "Polygon",

"coordinates": [

[

[120.74386596679688, 31.487235582017444],

[120.84548950195312, 31.269747790889888],

[121.01783752441405, 31.378261512889125],

[120.91827392578125, 31.487821121636433],

[120.74386596679688, 31.487235582017444]

]

]

}

}]

}'::json AS fc)

SELECT

row_number() OVER () AS gid,

ST_MakeValid(ST_GeomFromGeoJSON(feat->>'geometry')) AS geom,

feat->'properties' AS properties

FROM (

SELECT json_array_elements(fc->'features') AS feat

FROM DATA

) AS f

) AS t

參看:

https://www.freesion.com/article/9211435161/

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值