Take the 2-minute tour ×
Geographic Information Systems Stack Exchange is a question and answer site for cartographers, geographers and GIS professionals. It's 100% free, no registration required.

I'm tried to work on the scenario that avoiding go through some path if there is a barrier near that path. It can run well with the query below:

SELECT * FROM shortest_path('SELECT gid AS id, source::int4, target::int4, shp_leng::double precision AS cost
    FROM network1
    where gid <> 35'
    ,18, 36, false, false);

Which means that the the path with gid 35 in the network1 table won't be taken into the calculation of shortest_path function. But now, if I want to use find_nearest_link_within_distance function to fine the nearest path by a specific point, I got some problem, my code is like this:

SELECT * FROM shortest_path('SELECT gid AS id, source::int4, target::int4, shp_leng::double precision AS cost
    FROM network1
    where gid <> 
    (find_nearest_link_within_distance(
'POINT(120.218325 22.998469)',
0.5,
'network1'))'
    ,18, 36, false, false);

The error information:

ERROR:  syntax error at or near "POINT"

LINE 5: 'POINT(120.218325 22.998469)', Seems like find_nearest_link_within_distance can't be put between ' '. I can't find the solution, can someone help me out with that?

share|improve this question

2 Answers 2

I've solved the problem by adding a escape single quotes whenever a single quotes appear, just like this:

SELECT * FROM shortest_path('SELECT gid AS id, source::int4, target::int4, shp_leng::double precision AS cost
    FROM network1 where gid <>
    find_nearest_link_within_distance(''POINT(120.218325 22.998469)'', 0.1, ''network1'')',
    (SELECT id(foo.x)
FROM (
   SELECT find_node_by_nearest_link_within_distance(
    'POINT(120.222605 22.997879)',
    0.1,
    'network1')::link_point as x
) AS foo
),
    (SELECT id(foo.x)
FROM (
   SELECT find_node_by_nearest_link_within_distance(
    'POINT(120.22 23)',
    0.1,
    'network1')::link_point as x
) AS foo
),
    false, false);
share|improve this answer

You could try with ... (SELECT find_nearest_link_within_distance(...)) ...

share|improve this answer
    
I couldn't find this function in the standard PostGIS manual. Is this a custom function? where can I find it? –  Devdatta Tengshe Mar 9 '13 at 14:03
    
You can find these two functions in pgRouting. Here is a detail tutorial about using pgRouting⇩ underdark.wordpress.com/2011/02/07/… –  Yi Min Chiang Mar 10 '13 at 4:33
    
Thanks for your advice. I've tried that before, but it still can't work and I receive the same error information... –  Yi Min Chiang Mar 10 '13 at 4:40

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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