几何类型:
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/