Postgis-挤出多边形


11

我想在Postgis中拉伸多边形以创建伪3D效果。为此,我编写了一个粗略的函数来实现它。这是非常多的测试代码,它为多边形上的每个点创建一个新的Y顶点,然后通过返回原始点将其关闭:-

CREATE OR REPLACE FUNCTION public.extrude_polygon(wkb_geometry_param geometry, height integer, simplify boolean DEFAULT false)
  RETURNS geometry AS
 $BODY$
DECLARE
f int;
ret_geom geometry;
wkb_geometry geometry;
BEGIN

--convert polygon to linestring
IF ST_GeometryType(wkb_geometry_param) != 'ST_Polygon' THEN 
    RETURN NULL;
END IF;

IF simplify THEN
    wkb_geometry =         ST_Simplify(ST_Transform(ST_Exteriorring(wkb_geometry_param), 27700), 0.5);
ELSE
wkb_geometry = ST_Transform(ST_Exteriorring(wkb_geometry_param), 27700);
END IF;

--initialise output geometry
ret_geom =ST_MakeLine(ST_PointN(wkb_geometry,1),ST_PointN(wkb_geometry,1));

--Move first point to up

SELECT ST_AddPoint(ret_geom,
      ST_MakePoint(ST_X(ST_PointN(wkb_geometry, 1)), 
                   ST_Y(ST_PointN(wkb_geometry, 1)) + height)
) into ret_geom;

FOR f IN 1..ST_NPoints(wkb_geometry) LOOP
    IF f < ST_NPoints(wkb_geometry) THEN
    --across to next high point
    SELECT ST_AddPoint(ret_geom,
               ST_MakePoint(ST_X(ST_PointN(wkb_geometry, f + 1)), 
               ST_Y(ST_PointN(wkb_geometry, f + 1)) + height)
    ) into ret_geom;
    --down to next point
    SELECT ST_AddPoint(ret_geom, ST_PointN(wkb_geometry,f + 1)) into ret_geom;
    --back to last point
    SELECT  ST_AddPoint(ret_geom, ST_PointN(wkb_geometry,f)) into ret_geom;
    --back then up again
    SELECT ST_AddPoint(ret_geom, ST_PointN(wkb_geometry,f + 1)) into ret_geom;
    SELECT ST_AddPoint(ret_geom,
               ST_MakePoint(ST_X(ST_PointN(wkb_geometry, f + 1)), 
               ST_Y(ST_PointN(wkb_geometry, f + 1)) + height)
    ) into ret_geom;
ELSE
    --across to first high point
    SELECT ST_AddPoint(ret_geom,
               ST_MakePoint(ST_X(ST_PointN(wkb_geometry, 1)), 
               ST_Y(ST_PointN(wkb_geometry, 1)) + height)
           ) into ret_geom;

    SELECT ST_AddPoint(ret_geom, ST_PointN(wkb_geometry,1)) into ret_geom;

END IF;
END LOOP;

RETURN ST_Buffer(ST_Buffer(ST_MakePolygon(ret_geom),10), -10);


END;

$BODY$
  LANGUAGE plpgsql

它适用于简单的多边形,但内部环有问题,但主要问题是它确实很慢。我需要将结果形状输出为可以在mapserver中着色和渲染的多边形。因此,最后进行缓冲区操作,这是我知道的将形状缩小为轮廓的唯一方法。

最终结果将是代表原始多边形的拉伸形状。然后,我可以将原始多边形偏移相同的拉伸距离,然后将其放在顶部以制作屋顶。 在此处输入图片说明

我考虑过在postgis-2.1.1中使用ST_Extrude函数,但会创建ST_PolyhedralSurface类型,但无法在mapserver中渲染它。据我所知,由于ST_Buffer不适用于ST_polyhedralsurfaces,因此无法创建此轮廓。

所以,我的问题是,我的功能可以改善吗?还是有更好的方法。输出需要按照我通过将偏移多边形放置到我的拉伸形状上所创建的图的外观进行查看。


好问题!也许您可以将数据输出为KML,以便通过挤出获得更大的便利性和灵活性?这里有一些出发点:postgis.net/docs/ST_AsKML.htmlcode.google.com/p/postexperiments/wiki/...gdal.org/drv_libkml.html
布伦特爱德华兹

Answers:


3

一种非常简单的多边形(如圆形)的快速解决方案。结果必须在正确的方向上呈现2个不同的表。

- poly带有输入多边形的表

- poly_prj从投影点开始具有多边形的表格

WITH points AS (
  SELECT (ST_DumpPoints(geom)).geom AS geom 
FROM poly
  SELECT 
    ST_MakePolygon(
      ST_MakeLine(
        ST_Project(geom, 5000, radians(0.0))::geometry)) AS geom 
  FROM points;

- cvx具有2个特征的凸包的表。

桌子poly_prj必须在桌子上cvx

之后,您可以使用QGIS 2.10中的新填充选项!

在此处输入图片说明

By using our site, you acknowledge that you have read and understand our Cookie Policy and Privacy Policy.
Licensed under cc by-sa 3.0 with attribution required.