PG等距离切分线,返回点串

--PG将线等距离切割,line 必须是Polyline类型,不能是mutilLine类型,interval_length间隔距离
CREATE
OR REPLACE FUNCTION GetLinePoints (line geometry,interval_length FLOAT) RETURNS VARCHAR AS $$
DECLARE pointCount integer;
DECLARE ii INTEGER ;
DECLARE num INTEGER ;
DECLARE pointLatLog VARCHAR;
BEGIN
    ii := 1 ; num = 1 ; pointLatLog:='';
--获取等距离分割后的点数
pointCount=st_npoints(ST_Segmentize (st_transform (line, 3857),interval_length));
FOR ii IN 1..pointCount LOOP raise notice '%', num; 
--将点的坐标进行切分
--120.21668534667,30.2468406908998,120.217042136705,30.2466049913211,120.21739892674,30.2463692911771,120.217755716775,30.2461335904676,120.21811250681,30.2458978891928,120.218469296845,30.2456621873526,120.218557880024,30.2456036676422
pointLatLog=pointLatLog||(SELECT
    st_x(
        st_transform(ST_PointN (ST_Segmentize (
                st_transform (line, 3857),
                interval_length
            ),
            num
        ),4326))||','||st_y(
        st_transform(ST_PointN (
            ST_Segmentize (
                st_transform (line, 3857),
                interval_length
            ),
            num
        ),4326)));
    IF( num

你可能感兴趣的:(PG等距离切分线,返回点串)