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 really struggling with optimizing one of my sources. Instead of doing all the request and foreach loops in my serverside application. I am thinking about shifting it fully to the database side. But I am struggeling!

SELECT ST_asText( ST_ConcaveHull(ST_Collect(the_geom), 0.95)) FROM ways
JOIN
(SELECT seq, id1 AS node, cost
        FROM pgr_drivingDistance(
                'SELECT gid as id, source, target, reverse_cost as cost FROM ways',
                pgr_pointtoid(ST_setSRID(ST_MakePoint(7.26, 46.57),4326), 0.01)::Integer
, 10, false, false)) as dd_route
 ON
 ways.gid = dd_route.node;

But now I would like to replace the static point with a list or an array, and I just cant figure out how. I know there are a few cracks in postgres on this site.

We could use the following query to gather the data:

SELECT ST_SetSRID(ST_MakePoint(tmp[1]::double precision, tmp[2]::double precision), 4326) FROM (
    SELECT string_to_array(unnest(content), ',') as tmp FROM (
        SELECT string_to_array('7.26,46.57/8.26,46.25', '/') as content
    ) as data_array
) as data_row

The idea is now to the static set ST_MakePoint statement with a 'kind of foreach' statement.

Thanks for help.

share|improve this question
add comment

1 Answer

Generally (not always) if you are reaching for a procedural style in SQL you might be looking for the wrong thing.

If you have all the points you need to calculate driving directions to you could do something like this:

 (SELECT seq, id1 AS node, cost
    FROM (SELECT pgr_drivingDistance(
            'SELECT gid as id, source, target, reverse_cost as cost FROM ways',
            pgr_pointtoid(points.geom, 0.01)::Integer
  , 10, false, false) FROM points)
 ) as dd_route

So you have a sub query:

   SELECT pgr_drivingDistance(
                'SELECT gid as id, source, target, reverse_cost as cost FROM ways',
                pgr_pointtoid(points.geom, 0.01)::Integer
      , 10, false, false) FROM points

Which returns the drivingDistance for each point in the points table

share|improve this answer
add comment

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.