0

我有 PostgreSQL8.4+PostGIS。

我有一列中有一个带有线串几何形状的表格。我有这个线串的一个点,我想得到下一个点。为此,我想使用函数ST_NPointsST_PointN。为了使用它,我必须对所有点进行排序找到我的点,然后我会知道下一点是我需要的。

这是我的桌子:

-- Table: filedata

-- DROP TABLE filedata;

CREATE TABLE filedata
(
  num serial NOT NULL,
 id integer,
 mydata character(25),
 the_geom geometry,
 CONSTRAINT filedata_pkey PRIMARY KEY (num)
)
WITH (
OIDS=FALSE
);
ALTER TABLE filedata OWNER TO postgres;

和示例线串:

"LINESTRING(60.7014631515719 56.8441322356241,60.7023117507097 56.8445673405349,60.702948200063 56.8447993944193,60.703902874093 56.8448574076656,60.706236521722 56.8447993944193,60.7094187684889 56.8449444273664,60.7121236782406 56.8450894597515,60.715571112238 56.8452925041466,60.718382096882 56.8454085290207,60.7204505572805 56.8453505166286,60.7222538304482 56.8450314468649,60.7246405155233 56.8444513130533,60.7260194891224 56.8440742212539,60.7260194891224 56.8440742212539,60.7260194891224 56.8440742212539,60.7260194891224 56.844045214035)"
4

1 回答 1

2

假设您指的是线串顺序中的下一个,您可以执行以下操作:

WITH 
  -- The input data; this would be from the `filedata` table normally
  geom(line) AS (VALUES ('LINESTRING(60.7014631515719 56.8441322356241,60.7023117507097 56.8445673405349,60.702948200063 56.8447993944193,60.703902874093 56.8448574076656,60.706236521722 56.8447993944193,60.7094187684889 56.8449444273664,60.7121236782406 56.8450894597515,60.715571112238 56.8452925041466,60.718382096882 56.8454085290207,60.7204505572805 56.8453505166286,60.7222538304482 56.8450314468649,60.7246405155233 56.8444513130533,60.7260194891224 56.8440742212539,60.7260194891224 56.8440742212539,60.7260194891224 56.8440742212539,60.7260194891224 56.844045214035)'::geometry)),
  -- Create a set of (index,point) rows
  --
  point_series(line,n) AS (
      SELECT line, generate_series(1, ST_NPoints(line)) FROM geom
  ),
  -- Annotate that row set to include the prior point in each row,
  -- ie (n, point_n, point_n_minus_one)
  --
  lagged_points(pointidx, point, lagpoint) AS (
    SELECT n, ST_PointN(line,n) AS pointn,
           lag(ST_PointN(line,n)) OVER () AS point_n1
    FROM point_series
  )
-- Now SELECT the point we want, the point after
-- the one specified in the WHERE clause
SELECT astext(point)
FROM lagged_points
WHERE lagpoint = 'POINT(60.7014631515719 56.8441322356241)'::geometry;

geometry如果 PostGIS 提供了一种转换成点数组的方法,这会简单得多。idx如果它具有等效于 intarray 的功能,它也会更简单。

于 2012-10-15T12:37:10.827 回答