Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cannot create Polygon from Points pgr_pointsaspolygon() #709

Closed
Stophface opened this issue Dec 17, 2016 · 4 comments
Closed

Cannot create Polygon from Points pgr_pointsaspolygon() #709

Stophface opened this issue Dec 17, 2016 · 4 comments

Comments

@Stophface
Copy link

Stophface commented Dec 17, 2016

I want to calculate catchment areas. Doing that, I splitted up my process into two functions.
The first functions identifies the points which can be reached in time. With the second function I want to create polygons, based on driving time.

CREATE OR REPLACE FUNCTION nodes(lon numeric, lat numeric, time integer)
RETURNS void AS
$$

CREATE table nodes_tab AS
SELECT dd.seq, dd.node, dd.cost, dd.agg_cost,
ST_SetSRID(
	ST_Point(
		ST_X(wvp.the_geom), 
		ST_Y(wvp.the_geom)), 4326
	) as the_geom
FROM pgr_drivingdistance('
	SELECT gid AS id,
		source,
		target,
		CASE 
		WHEN some_f(a) = -1.0 
		THEN -1.0 
		ELSE cost_s END 
		AS cost,
	reverse_cost_s AS reverse_cost
	FROM ways',
	pgr_pointToEdgeNode('ways', ST_SetSRID(
		ST_Point($1, $2), 
		4326), 0.01
	),
	$3, 
	directed := true) AS dd INNER JOIN 
		ways_vertices_pgr 
		AS wvp 
		ON dd.node = wvp.id;
$$ 
language 'sql';

The created table is correct.
Then I want to create polygons, based on the points.
Doing that I use the pointsaspolygons function http://docs.pgrouting.org/latest/en/src/alpha_shape/doc/pgr_pointsAsPolygon.html#pgr-points-as-polygon

SELECT pgr_pointsAsPolygon( 
		'cnt.seq AS id, 
		ST_X(cnt.the_geom) AS x, 
		ST_Y(cnt.the_geom) AS y')
		FROM nodes_tab cnt;

That throws me an error I do not even understand:

ERROR: syntax error at or near "cnt"
LINE 1: cnt.seq AS id,
^
QUERY: cnt.seq AS id,
ST_X(cnt.the_geom) AS x,
ST_Y(cnt.the_geom) AS y
CONTEXT: PL/pgSQL function pgr_pointsaspolygon(character varying,double precision) line 17 at FOR over EXECUTE statement
********** Error **********

ERROR: syntax error at or near "cnt"
SQL state: 42601
Context: PL/pgSQL function pgr_pointsaspolygon(character varying,double precision) line 17 at FOR over EXECUTE statement

At the first glance one could think that this is related to this error:
http://gis.stackexchange.com/questions/215203/cannot-create-pgr-pointsaspolygon-from-pgr-drivingdistance-function/215218#215218

However, I am not using a nested query with quotes...
Note: I asked here as well if this behaviour is known: http://gis.stackexchange.com/questions/221794/cannot-create-polygon-from-points

@Stophface Stophface changed the title Cannot create Polygon from Points Cannot create Polygon from Points pgr_pointsaspolygon() Dec 17, 2016
@cvvergara
Copy link
Member

from your query::

SELECT pgr_pointsAsPolygon( 
		'cnt.seq AS id, 
		ST_X(cnt.the_geom) AS x, 
		ST_Y(cnt.the_geom) AS y')
		FROM nodes_tab cnt;

the inner SQL query is:

                 cnt.seq AS id, 
		ST_X(cnt.the_geom) AS x, 
		ST_Y(cnt.the_geom) AS y

but the real query is

SELECT cnt.seq AS id,  
		ST_X(cnt.the_geom) AS x, 
		ST_Y(cnt.the_geom) AS y
		FROM nodes_tab cnt

this last query is the one that should be used as inner query

rewriting:

SELECT pgr_pointsAsPolygon( 
		'SELECT cnt.seq AS id,  
		ST_X(cnt.the_geom) AS x, 
		ST_Y(cnt.the_geom) AS y
		FROM nodes_tab cnt'
);

p.d. you are using

pgr_pointToEdgeNode('ways', ST_SetSRID(
		ST_Point($1, $2), 
		4326), 0.01
	),

Which is currently is experimental. it has its issues, and based on #315 is going to be deprecated.

@Stophface
Copy link
Author

@cvvergara and again: Thank you :)
Thanks for pointing the pgr_pointToEdgeNode() problem out. The authors of this book http://locatepress.com/pgrouting recommended using it...

@cvvergara
Copy link
Member

The decision of deprecating it is recent and is not done yet.
just be careful. of when it is deprecated.

@cvvergara
Copy link
Member

pgr_pointsAsPolygon has has been depracated on version 3.0.0
and pgr_alphaShape has been rewritten on v3.0.0
Please consider that this function will eventually be removed from pgRouting and moved to PostGIS.

@cvvergara cvvergara added this to the Release 3.0.0 milestone Jul 22, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants