Geographic Information Systems Asked by akushyn on May 8, 2021
I would like to get points from polygon border using PostGIS.
I’ve tried using ST_DumpPoints()
function, like this:
CREATE OR REPLACE FUNCTION get_points_from_polygon(polygon geometry)
RETURNS SETOF geometry AS
$$
DECLARE
point geometry;
BEGIN
FOR point IN
SELECT DISTINCT
points.geom
FROM (
SELECT (ST_DumpPoints(polygon)).*
) AS points LOOP
RETURN NEXT point;
END LOOP;
END;
$$
LANGUAGE plpgsql ;
But it gets sometimes huge list of points (~100-500) and that is not what I need.
I need to get N equidistant points on the border, like on the screenshot attached.
Then, when I have these points I will analyze viewshed polygons from point as observer
I’ve found, how to identify is the point on the polygon border
But have no idea , how to create first them and get as a list of points geometry.
What would be your suggestion to do this?
This script solves your problem:
WITH tbla AS (SELECT (ST_ExteriorRing(((ST_Dump(geom)).geom))) geom FROM <table_name>), intervals AS (SELECT generate_series (0, 99) as steps) SELECT steps AS stp, ST_LineInterpolatePoint(geom, steps/(SELECT count(steps)::float-1 FROM intervals)) geom FROM tbla, intervals GROUP BY intervals.steps, geom;
Set the required number of points on the line, in my example it is 100...
Correct answer by Cyril Mikhalchenko on May 8, 2021
Another slightly different formulation using ST_LineInterpolatePoint
. Note that the number of intervals needs to be substituted in two places.
WITH shell AS (
SELECT ST_ExteriorRing('POLYGON ((5 5, 10 15, 17 10, 5 5))') geom
)
SELECT i, ST_LineInterpolatePoint(geom, (i-1.0)/40) pt
FROM shell
JOIN generate_series (1, 40) AS step(i) ON true;
Answered by dr_jts on May 8, 2021
Get help from others!
Recent Answers
Recent Questions
© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP