如何在单个 PostGIS 几何列中存储多个圆?
How to store multiple circles in a single PostGIS geometry column?
我需要在 PostGIS 的单个几何列中存储多个圆。
到目前为止,我只能存储一个这样的:
UPDATE element SET geo = ST_Buffer(ST_MakePoint(-71.1043443253471, 42.3150676015829), 6, 'quad_segs=8') WHERE id = 1;
这里有使用GEOMETRYCOLLECTION的方法吗?
提前致谢。
使用 ST_Union
聚合缓冲区,然后使用 ST_ForceCollection
创建集合,例如将缓冲区附加到现有几何体:
UPDATE element
SET geo =
ST_ForceCollection(
ST_Union(geo, ST_Buffer(ST_MakePoint(-80.10, 45.31), 3) ))
WHERE id = 1;
演示:db<>fiddle
SELECT
ST_ForceCollection(
ST_Union(
ST_Buffer(ST_MakePoint(-71.10, 42.31), 6),
ST_Buffer(ST_MakePoint(-80.10, 45.31), 3)
));
st_astext
------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
GEOMETRYCOLLECTION(POLYGON((-77.1576441587903 44.72472903395162,-77.32836140246613 44.161949702904735,-77.60559116309236 43.6432893009412,-77.97867965644035 43.188679656440364,-78.43328930094118 42.81559116309237,-78.95194970290473 42.538361402466144,-79.51472903395161 42.36764415879031,-80.1 42.31,-80.68527096604838 42.36764415879031,-81.24805029709526 42.53836140246614,-81.76671069905879 42.815591163092364,-82.22132034355963 43.18867965644036,-82.59440883690763 43.64328930094119,-82.87163859753385 44.16194970290473,-83.04235584120968 44.72472903395161,-83.1 45.309999999999995,-83.04235584120968 45.89527096604838,-82.87163859753386 46.45805029709526,-82.59440883690763 46.9767106990588,-82.22132034355964 47.431320343559634,-81.7667106990588 47.80440883690763,-81.24805029709528 48.08163859753386,-80.68527096604839 48.25235584120969,-80.10000000000001 48.31,-79.51472903395162 48.2523558412097,-78.95194970290474 48.08163859753387,-78.4332893009412 47.80440883690765,-77.97867965644036 47.431320343559655,-77.60559116309237 46.97671069905883,-77.32836140246614 46.45805029709529,-77.1576441587903 45.89527096604841,-77.1 45.31,-77.1576441587903 44.72472903395162)),POLYGON((-65.21528831758062 41.139458067903234,-65.55672280493228 40.01389940580947,-66.11118232618472 38.976578601882395,-66.8573593128807 38.06735931288072,-67.76657860188237 37.32118232618473,-68.80389940580945 36.766722804932286,-69.92945806790321 36.42528831758062,-71.09999999999998 36.31,-72.27054193209675 36.425288317580616,-73.39610059419053 36.76672280493228,-74.4334213981176 37.321182326184726,-75.34264068711927 38.06735931288071,-76.08881767381526 38.97657860188238,-76.64327719506771 40.01389940580945,-76.98471168241937 41.13945806790321,-77.1 42.30999999999998,-76.98471168241937 43.48054193209675,-76.64327719506772 44.60610059419052,-76.08881767381529 45.643421398117596,-75.3426406871193 46.55264068711927,-74.43342139811763 47.29881767381526,-73.39610059419056 47.85327719506771,-72.27054193209679 48.19471168241938,-71.10000000000002 48.31,-69.92945806790325 48.19471168241939,-68.80389940580949 47.85327719506773,-67.76657860188242 47.29881767381529,-66.85735931288073 46.55264068711931,-66.11118232618475 45.643421398117646,-65.55672280493229 44.60610059419057,-65.21528831758062 43.48054193209681,-65.1 42.31,-65.21528831758062 41.139458067903234)))
(1 row)
或使用 CTE
WITH j (geom) AS (
VALUES (ST_Buffer(ST_MakePoint(-71.10, 42.31), 6)),
(ST_Buffer(ST_MakePoint(-80.10, 45.31), 3))
)
SELECT ST_ForceCollection(ST_Union(geom)) FROM j;
st_astext
------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
GEOMETRYCOLLECTION(POLYGON((-77.1576441587903 44.72472903395162,-77.32836140246613 44.161949702904735,-77.60559116309236 43.6432893009412,-77.97867965644035 43.188679656440364,-78.43328930094118 42.81559116309237,-78.95194970290473 42.538361402466144,-79.51472903395161 42.36764415879031,-80.1 42.31,-80.68527096604838 42.36764415879031,-81.24805029709526 42.53836140246614,-81.76671069905879 42.815591163092364,-82.22132034355963 43.18867965644036,-82.59440883690763 43.64328930094119,-82.87163859753385 44.16194970290473,-83.04235584120968 44.72472903395161,-83.1 45.309999999999995,-83.04235584120968 45.89527096604838,-82.87163859753386 46.45805029709526,-82.59440883690763 46.9767106990588,-82.22132034355964 47.431320343559634,-81.7667106990588 47.80440883690763,-81.24805029709528 48.08163859753386,-80.68527096604839 48.25235584120969,-80.10000000000001 48.31,-79.51472903395162 48.2523558412097,-78.95194970290474 48.08163859753387,-78.4332893009412 47.80440883690765,-77.97867965644036 47.431320343559655,-77.60559116309237 46.97671069905883,-77.32836140246614 46.45805029709529,-77.1576441587903 45.89527096604841,-77.1 45.31,-77.1576441587903 44.72472903395162)),POLYGON((-65.21528831758062 41.139458067903234,-65.55672280493228 40.01389940580947,-66.11118232618472 38.976578601882395,-66.8573593128807 38.06735931288072,-67.76657860188237 37.32118232618473,-68.80389940580945 36.766722804932286,-69.92945806790321 36.42528831758062,-71.09999999999998 36.31,-72.27054193209675 36.425288317580616,-73.39610059419053 36.76672280493228,-74.4334213981176 37.321182326184726,-75.34264068711927 38.06735931288071,-76.08881767381526 38.97657860188238,-76.64327719506771 40.01389940580945,-76.98471168241937 41.13945806790321,-77.1 42.30999999999998,-76.98471168241937 43.48054193209675,-76.64327719506772 44.60610059419052,-76.08881767381529 45.643421398117596,-75.3426406871193 46.55264068711927,-74.43342139811763 47.29881767381526,-73.39610059419056 47.85327719506771,-72.27054193209679 48.19471168241938,-71.10000000000002 48.31,-69.92945806790325 48.19471168241939,-68.80389940580949 47.85327719506773,-67.76657860188242 47.29881767381529,-66.85735931288073 46.55264068711931,-66.11118232618475 45.643421398117646,-65.55672280493229 44.60610059419057,-65.21528831758062 43.48054193209681,-65.1 42.31,-65.21528831758062 41.139458067903234)))
(1 row)
我需要在 PostGIS 的单个几何列中存储多个圆。 到目前为止,我只能存储一个这样的:
UPDATE element SET geo = ST_Buffer(ST_MakePoint(-71.1043443253471, 42.3150676015829), 6, 'quad_segs=8') WHERE id = 1;
这里有使用GEOMETRYCOLLECTION的方法吗?
提前致谢。
使用 ST_Union
聚合缓冲区,然后使用 ST_ForceCollection
创建集合,例如将缓冲区附加到现有几何体:
UPDATE element
SET geo =
ST_ForceCollection(
ST_Union(geo, ST_Buffer(ST_MakePoint(-80.10, 45.31), 3) ))
WHERE id = 1;
演示:db<>fiddle
SELECT
ST_ForceCollection(
ST_Union(
ST_Buffer(ST_MakePoint(-71.10, 42.31), 6),
ST_Buffer(ST_MakePoint(-80.10, 45.31), 3)
));
st_astext
------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
GEOMETRYCOLLECTION(POLYGON((-77.1576441587903 44.72472903395162,-77.32836140246613 44.161949702904735,-77.60559116309236 43.6432893009412,-77.97867965644035 43.188679656440364,-78.43328930094118 42.81559116309237,-78.95194970290473 42.538361402466144,-79.51472903395161 42.36764415879031,-80.1 42.31,-80.68527096604838 42.36764415879031,-81.24805029709526 42.53836140246614,-81.76671069905879 42.815591163092364,-82.22132034355963 43.18867965644036,-82.59440883690763 43.64328930094119,-82.87163859753385 44.16194970290473,-83.04235584120968 44.72472903395161,-83.1 45.309999999999995,-83.04235584120968 45.89527096604838,-82.87163859753386 46.45805029709526,-82.59440883690763 46.9767106990588,-82.22132034355964 47.431320343559634,-81.7667106990588 47.80440883690763,-81.24805029709528 48.08163859753386,-80.68527096604839 48.25235584120969,-80.10000000000001 48.31,-79.51472903395162 48.2523558412097,-78.95194970290474 48.08163859753387,-78.4332893009412 47.80440883690765,-77.97867965644036 47.431320343559655,-77.60559116309237 46.97671069905883,-77.32836140246614 46.45805029709529,-77.1576441587903 45.89527096604841,-77.1 45.31,-77.1576441587903 44.72472903395162)),POLYGON((-65.21528831758062 41.139458067903234,-65.55672280493228 40.01389940580947,-66.11118232618472 38.976578601882395,-66.8573593128807 38.06735931288072,-67.76657860188237 37.32118232618473,-68.80389940580945 36.766722804932286,-69.92945806790321 36.42528831758062,-71.09999999999998 36.31,-72.27054193209675 36.425288317580616,-73.39610059419053 36.76672280493228,-74.4334213981176 37.321182326184726,-75.34264068711927 38.06735931288071,-76.08881767381526 38.97657860188238,-76.64327719506771 40.01389940580945,-76.98471168241937 41.13945806790321,-77.1 42.30999999999998,-76.98471168241937 43.48054193209675,-76.64327719506772 44.60610059419052,-76.08881767381529 45.643421398117596,-75.3426406871193 46.55264068711927,-74.43342139811763 47.29881767381526,-73.39610059419056 47.85327719506771,-72.27054193209679 48.19471168241938,-71.10000000000002 48.31,-69.92945806790325 48.19471168241939,-68.80389940580949 47.85327719506773,-67.76657860188242 47.29881767381529,-66.85735931288073 46.55264068711931,-66.11118232618475 45.643421398117646,-65.55672280493229 44.60610059419057,-65.21528831758062 43.48054193209681,-65.1 42.31,-65.21528831758062 41.139458067903234)))
(1 row)
或使用 CTE
WITH j (geom) AS (
VALUES (ST_Buffer(ST_MakePoint(-71.10, 42.31), 6)),
(ST_Buffer(ST_MakePoint(-80.10, 45.31), 3))
)
SELECT ST_ForceCollection(ST_Union(geom)) FROM j;
st_astext
------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
GEOMETRYCOLLECTION(POLYGON((-77.1576441587903 44.72472903395162,-77.32836140246613 44.161949702904735,-77.60559116309236 43.6432893009412,-77.97867965644035 43.188679656440364,-78.43328930094118 42.81559116309237,-78.95194970290473 42.538361402466144,-79.51472903395161 42.36764415879031,-80.1 42.31,-80.68527096604838 42.36764415879031,-81.24805029709526 42.53836140246614,-81.76671069905879 42.815591163092364,-82.22132034355963 43.18867965644036,-82.59440883690763 43.64328930094119,-82.87163859753385 44.16194970290473,-83.04235584120968 44.72472903395161,-83.1 45.309999999999995,-83.04235584120968 45.89527096604838,-82.87163859753386 46.45805029709526,-82.59440883690763 46.9767106990588,-82.22132034355964 47.431320343559634,-81.7667106990588 47.80440883690763,-81.24805029709528 48.08163859753386,-80.68527096604839 48.25235584120969,-80.10000000000001 48.31,-79.51472903395162 48.2523558412097,-78.95194970290474 48.08163859753387,-78.4332893009412 47.80440883690765,-77.97867965644036 47.431320343559655,-77.60559116309237 46.97671069905883,-77.32836140246614 46.45805029709529,-77.1576441587903 45.89527096604841,-77.1 45.31,-77.1576441587903 44.72472903395162)),POLYGON((-65.21528831758062 41.139458067903234,-65.55672280493228 40.01389940580947,-66.11118232618472 38.976578601882395,-66.8573593128807 38.06735931288072,-67.76657860188237 37.32118232618473,-68.80389940580945 36.766722804932286,-69.92945806790321 36.42528831758062,-71.09999999999998 36.31,-72.27054193209675 36.425288317580616,-73.39610059419053 36.76672280493228,-74.4334213981176 37.321182326184726,-75.34264068711927 38.06735931288071,-76.08881767381526 38.97657860188238,-76.64327719506771 40.01389940580945,-76.98471168241937 41.13945806790321,-77.1 42.30999999999998,-76.98471168241937 43.48054193209675,-76.64327719506772 44.60610059419052,-76.08881767381529 45.643421398117596,-75.3426406871193 46.55264068711927,-74.43342139811763 47.29881767381526,-73.39610059419056 47.85327719506771,-72.27054193209679 48.19471168241938,-71.10000000000002 48.31,-69.92945806790325 48.19471168241939,-68.80389940580949 47.85327719506773,-67.76657860188242 47.29881767381529,-66.85735931288073 46.55264068711931,-66.11118232618475 45.643421398117646,-65.55672280493229 44.60610059419057,-65.21528831758062 43.48054193209681,-65.1 42.31,-65.21528831758062 41.139458067903234)))
(1 row)