[pgrouting-users] Isochrones as polygons
Simon Georget
simon.georget at gmail.com
Wed May 13 10:48:27 PDT 2015
Hi list,
I'm trying to generate isochrones as polygons in the way it is explained in
that post :
https://smathermather.wordpress.com/2014/08/06/drivetime-analyses-pgrouting/
I'm not familiar with postgres/postgis and I get a bit confused when trying
to understand the difference between pgr_alphashape() /
pgr_pointsAsPolygon(). I've read a lot through the web but did not find lot
of examples scirpts.
I'm able to generate the drivingDistance() but I get lost when trying to
get points to generate my polygons.
Is there any sample script somewhere combining the use of
pgr_drivingDistance() with pgr_pointsAsPolygon() ?
Here is an attempt to adapt the script from smathermather with my data.
Note that I want to run it on multiple start points :
---------------------
CREATE OR REPLACE FUNCTION nn_search (geom geometry) RETURNS
int8 AS $$
SELECT id FROM roads_idf_l93_vertices_pgr AS r
ORDER BY geom <#> r.the_geom
LIMIT 1;
$$ LANGUAGE SQL VOLATILE;
-- cette fonction renvoie un polygone
-- elle prend en paramètre l'id du noeud et le cost
CREATE OR REPLACE FUNCTION alpha_shape (id integer, cost integer) RETURNS
geometry AS $$
WITH alphashape AS(SELECT pgr_alphaShape('WITH
DD AS (
SELECT seq, id1 AS node, cost
FROM pgr_drivingDistance(''SELECT id, source::int4 AS source,
target::int4 AS target, length::float8 AS cost FROM roads_idf_l93'',' || id
|| ', ' || cost || ', false, false)
),
points AS (
SELECT v.id::int4 AS id, x::float8, y::float8
FROM roads_idf_l93_vertices_pgr v, DD d
WHERE v.id = d.node)
SELECT * FROM points')),
alphapoints AS (
SELECT ST_Makepoint((pgr_alphashape).x, (pgr_alphashape).y) FROM
alphashape),
alphaline AS (
SELECT ST_MakeLine(ST_MakePoint) FROM alphapoints)
SELECT ST_MakePolygon(ST_AddPoint(ST_MakeLine, ST_StartPoint(ST_MakeLine)))
AS the_geom FROM alphaline
$$ LANGUAGE SQL VOLATILE;
CREATE TABLE alpha_test AS
WITH dest_ids AS (
SELECT nn_search(geom) AS id FROM gare_idf_l93
)
-- cost 1000 m
SELECT alpha_shape(id::int, 1000)::geometry, id FROM dest_ids;
-----------------------
Executing this script return the following error :
ERROR: Distance is too short. only 2 vertices for alpha shape calculation.
alpha shape calculation needs at least 3 vertices.
CONTEXT: SQL function "alpha_shape" statement 1
********** Erreur **********
ERROR: Distance is too short. only 2 vertices for alpha shape calculation.
alpha shape calculation needs at least 3 vertices.
État SQL :XX000
Contexte : SQL function "alpha_shape" statement 1
Any help would be appreciated. Thanks
simo
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.osgeo.org/pipermail/pgrouting-users/attachments/20150513/9ab5925b/attachment.html>
More information about the Pgrouting-users
mailing list