2

After using the function pgr_drivingdistance() I am attempting to make a polygon with pgr_alphashape. Following the example found in the documentation I should do the following: https://docs.pgrouting.org/2.4/en/pgr_alphaShape.html#pgr-alphashape

--Create a table with 1 Polygon where the agg_cost is lower then 5
DROP TABLE IF EXISTS temp.polygon; 
CREATE TABLE schema.polygon as  
SELECT ST_MakePolygon(ST_AddPoint(foo.openline, 
    ST_StartPoint(foo.openline)))
    FROM (
SELECT ST_MakeLine(points ORDER BY id) AS openline
FROM (
    SELECT ST_MakePoint(x, y) AS points, row_number() over() AS id
    FROM pgr_alphaShape('
        SELECT 
            source::integer as id, 
            ST_X(the_geom)::float as x, 
            ST_Y(the_geom)::float as y,
            agg_cost as cost
        from 
            temp.exampleresult as kar
        INNER JOIN schema.table_vertices as vert
        ON kar.source = vert.id
        where agg_cost < 5;')   
    ) AS a
) AS foo;   

It works and it generates a polygon. However the polygon is self intersecting and has a weird shape. Where should I be looking to debug?

So the goal is to create after a nicely filled network with pgr_drivingdistance() a polygon which is based on the agg_cost.

This is what I am aiming for: https://anitagraser.com/2011/02/12/drive-time-isochrones/

I suppose the sequence of my points is not correct.

Ok so without my join of the agg_cost it works perfectly for all vertices. But with the join it does not:

DROP TABLE IF EXISTS temp.polygon; 
CREATE TABLE schema.polygon as  
SELECT ST_MakePolygon(ST_AddPoint(foo.openline, 
    ST_StartPoint(foo.openline)))
    FROM (
SELECT ST_MakeLine(points ORDER BY id) AS openline
FROM (
    SELECT ST_MakePoint(x, y) AS points, row_number() over() AS id
    FROM pgr_alphaShape('
        SELECT 
            source::integer as id, 
            ST_X(the_geom)::float as x, 
            ST_Y(the_geom)::float as y,
            agg_cost as cost
        from 
            schema.table_vertices') 
    ) AS a
) AS foo;   

1 Answer 1

1

In my memory, there is a case which alpha shape result includes multi polygons with separator (coordinate x = null and y = null).

So, could you check the separator or just try to use pgr_pointsAsPolygon function which support such multi polygons case ?

[pgr_pointsAsPolygon — pgRouting Manual (2.4)] https://docs.pgrouting.org/2.4/en/pgr_pointsAsPolygon.html#pgr-points-as-polygon

You can see pgr_pointsAsPolygon logic at here. https://github.com/pgRouting/pgrouting/blob/v2.4.2/src/alpha_shape/sql/alpha_shape.sql#L59-L93

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.