使用PostGIS沿极包裹海岸线进行点采样


11

我正在执行一项任务,要求我在海岸线上每1000公里获取一次采样点,并且遇到了南极洲的问题。据我所知,在函数中使用几何图形似乎是一个问题,而实际上我认为应该将地理信息用于此操作。

使用这个非常相似的问题中的函数,我可以产生如下所示的结果:不好的结果

如您所见,ST_AddMeasure()并且ST_LocateAlong()似乎没有球形地处理几何,这导致许多点位于南极上。甚至沿日期线(左侧)在剪辑上添加了一个点。根据这两个函数的文档,只能使用几何

可以在此处找到用于生成多边形和点的代码,但这是用于生成点的SQL:

CREATE TABLE atest AS WITH line AS 
  (SELECT
      id,
      ST_ExteriorRing((ST_Dump(geom)).geom) AS geom
    FROM line_sample_test),
linemeasure AS
    (SELECT
        ST_AddMeasure(line.geom, 0, (ST_Length(line.geom))::int) AS linem,
    generate_series(0, (ST_Length(line.geom))::int, 10) AS i
FROM line),

geometries AS (
    SELECT
        i,
        ST_LocateAlong(linem, i) AS geom 
    FROM linemeasure)

SELECT
    * from geometries;

如何在此海岸线上每1000公里产生一个点?


您是否尝试过ST_Segmentize?它也只能在几何体上工作,但至少似乎是一种更快的生成点的方法。无论如何,为什么不删除极点呢?它看起来更像是所用投影的副作用而不是错误。
lynxlynxlynx

5
从您的图片看来,您在EPSG:4326中具有几何形状。南极洲更适合极地立体投影,例如EPSG:3031。即使这样,您似乎仍需要沿日期线处理一条到杆子和后部的切割线。
Toby Speight 2015年

Answers:


3

正如其中一项评论中所建议,我首先将输入几何转换为极坐标立体投影。

另外,您将希望使用ST_Buffer它(使用的数量0)来摆脱所得的切割线。

因此,这将获得您想要的结果:

-- ST_Transform(geom,3031) reprojects to south polar stereographic,
-- in meters.  ST_Buffer(...) doesn't change the shape, but removes
-- the cut line to the pole (at 180 degrees).
WITH line AS (
    SELECT ST_ExteriorRing(
        ST_Buffer(ST_Transform(geom, 3031), 0)
    ) AS geom
    FROM line_sample_test
),

-- This just generates a table of numbers.  In this case, from 0
-- to the geometry length, counting by 1,000,000 (1000 km).
linemeasure AS (
    SELECT generate_series(0, ST_Length(geom)::int, 1000000) AS i
    FROM line
),

-- Convert those values to a fraction of the overall length (for
-- use as input to ST_LineInterpolatePoint)
linefraction AS (
    SELECT i / ST_Length(geom) AS fraction
    FROM line, linemeasure
),

-- Do the interpolation
geometries AS (
    SELECT ST_LineInterpolatePoint(l.geom, lf.fraction) AS geom
    FROM linefraction lf, line l
),

-- Convert back to EPSG:4326 (i.e. lat/lon coords)
geometries_4326 AS (
    SELECT ST_Transform(geom, 4326) AS geom FROM geometries
)
SELECT * FROM geometries_4326

请注意,此查询确实假设line_sample_test表中只有一行,因此请根据实际输入数据进行必要的调整。


我不知道ST_Buffer(geom, 0)消除切割线的技巧-这很有用!
Toby Speight
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.