PostGIS在LINESTRING Z上创建缓冲区以具有POLYGON Z

时间:2019-09-26 05:09:04

标签: postgresql geometry postgis

我在PostgreSQL中有几个LINESTRING Z地理区域,它们看起来像 LINESTRING Z (1 2 1,1 1 4)

我想在此线串周围创建一个缓冲区,以便可以使用POLYGON Z geometry以便进一步导出到dxf。

我尝试过

select st_astext(st_buffer('LINESTRING Z (1 2 1,1 1 4)'::geometry, 2)) as geom;

它给了我

POLYGON((3 1,2.96157056080646 0.609819355967741,2.84775906502257 0.23463313526 9818,2.66293922460509 -0.111140466039206,2.41421356237309 -0.414213562373096,2. 1111404660392 -0.662939224605091,1.76536686473018 -0.847759065022574,1.39018064 403226 -0.961570560806461,1 -1,0.609819355967745 -0.961570560806461,0.234633135 269822 -0.847759065022574,-0.111140466039202 -0.662939224605092,-0.414213562373 094 -0.414213562373096,-0.662939224605089 -0.111140466039207,-0.847759065022572 0.234633135269818,-0.96157056080646 0.609819355967739,-1 1,-1 2,-0.96157056080 646 2.39018064403226,-0.847759065022572 2.76536686473018,-0.662939224605089 3.1 1114046603921,-0.414213562373094 3.4142135623731,-0.111140466039203 3.662939224 60509,0.234633135269821 3.84775906502257,0.609819355967744 3.96157056080646,1 4 ,1.39018064403226 3.96157056080646,1.76536686473018 3.84775906502257,2.11114046 60392 3.66293922460509,2.41421356237309 3.4142135623731,2.66293922460509 3.1111 4046603921,2.84775906502257 2.76536686473018,2.96157056080646 2.39018064403226, 3 2,3 1)) (1 row)

2D POLYGON中而不是POLYGON Z

我如何使其成为3D?

1 个答案:

答案 0 :(得分:0)

我不确定您要实现什么目标,但是您是否看过ST_Force3D

SELECT 
  ST_AsText(
    ST_Force3D(
      ST_Buffer('LINESTRING Z (1 2 1,1 1 4)'::GEOMETRY, 2)));

它将返回POLYGON Z几何:

 POLYGON Z ((3 1 0,2.96157056080646 0.609819355967741 0,2.84775906502257 0.234633135269818 0,2.66293922460509 -0.111140466039206 0,2.41421356237309 -0.414213562373096 0,2.1111404660392 -0.662939224605091 0,1.76536686473018 -0.847759065022574 0,1.39018064403226 -0.961570560806461 0,1 -1 0,0.609819355967745 -0.961570560806461 0,0.234633135269822 -0.847759065022574 0,-0.111140466039202 -0.662939224605092 0,-0.414213562373094 -0.414213562373096 0,-0.662939224605089 -0.111140466039207 0,-0.847759065022572 0.234633135269818 0,-0.96157056080646 0.609819355967739 0,-1 1 0,-1 2 0,-0.96157056080646 2.39018064403226 0,-0.847759065022572 2.76536686473018 0,-0.662939224605089 3.11114046603921 0,-0.414213562373094 3.4142135623731 0,-0.111140466039203 3.66293922460509 0,0.234633135269821 3.84775906502257 0,0.609819355967744 3.96157056080646 0,1 4 0,1.39018064403226 3.96157056080646 0,1.76536686473018 3.84775906502257 0,2.1111404660392 3.66293922460509 0,2.41421356237309 3.4142135623731 0,2.66293922460509 3.11114046603921 0,2.84775906502257 2.76536686473018 0,2.96157056080646 2.39018064403226 0,3 2 0,3 1 0))

函数ST_Buffer放弃Z尺寸,如文档所述:

  

...此函数忽略第三维(z),并将始终给出   二维缓冲区,即使呈现3d几何形状。

编辑:

这种查询方式将创建一个缓冲区,该缓冲区具有给定LINESTRING Z的平均Z值。

WITH j AS (
SELECT 
  ST_DumpPoints(
    ST_Buffer('LINESTRING Z (1 2 1,1 1 4)'::GEOMETRY, 2)
  ) AS pt,
  (SELECT AVG(z) AS avg_z 
  FROM (SELECT ST_Z((ST_DumpPoints('LINESTRING Z (1 2 1,1 1 4)'::GEOMETRY)).geom) AS z) AS z) AS lsz
)
SELECT ST_AsText(
  ST_MakePolygon(ST_MakeLine(ST_MakePoint(ST_X((pt).geom),ST_Y((pt).geom),lsz))))
FROM j
GROUP BY lsz;

----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
POLYGON Z ((3 1 2.5,2.96157056080646 0.609819355967741 2.5,2.84775906502257 0.234633135269818 2.5,2.66293922460509 -0.111140466039206 2.5,2.41421356237309 -0.414213562373096 2.5,2.1111404660392 -0.662939224605091 2.5,1.76536686473018 -0.847759065022574 2.5,1.39018064403226 -0.961570560806461 2.5,1 -1 2.5,0.609819355967745 -0.961570560806461 2.5,0.234633135269822 -0.847759065022574 2.5,-0.111140466039202 -0.662939224605092 2.5,-0.414213562373094 -0.414213562373096 2.5,-0.662939224605089 -0.111140466039207 2.5,-0.847759065022572 0.234633135269818 2.5,-0.96157056080646 0.609819355967739 2.5,-1 1 2.5,-1 2 2.5,-0.96157056080646 2.39018064403226 2.5,-0.847759065022572 2.76536686473018 2.5,-0.662939224605089 3.11114046603921 2.5,-0.414213562373094 3.4142135623731 2.5,-0.111140466039203 3.66293922460509 2.5,0.234633135269821 3.84775906502257 2.5,0.609819355967744 3.96157056080646 2.5,1 4 2.5,1.39018064403226 3.96157056080646 2.5,1.76536686473018 3.84775906502257 2.5,2.1111404660392 3.66293922460509 2.5,2.41421356237309 3.4142135623731 2.5,2.66293922460509 3.11114046603921 2.5,2.84775906502257 2.76536686473018 2.5,2.96157056080646 2.39018064403226 2.5,3 2 2.5,3 1 2.5))
(1 row)