I'm trying to adapt the pgr_fromAtoB function to pgr_fromAtoMult replacing pgr_dijkstra function to pgr_drivingdistance.Here is the code:

CREATE OR REPLACE FUNCTION pgr_fromAtoMult(IN tbl character varying, IN x double precision, IN y double precision, OUT seq integer, OUT gid integer, OUT name text, OUT heading double precision, OUT cost double precision, OUT geom geometry)

    sql     text;
    rec     record;
    source  integer;
    point   integer;
    dist    double precision;

        -- Find nearest node
        EXECUTE 'SELECT id::integer FROM layer_vertices_pgr
                        ORDER BY the_geom <-> ST_GeometryFromText(''POINT('
                        || x || ' ' || y || ')'',4326) LIMIT 1' INTO rec;
        source := rec.id;

        -- Changing pgr_dijkstra to pgr_drivingdistance query 
        seq := 0;
        sql := 'SELECT id, geom_way, osm_name, cost, source, target,
                                ST_Reverse(geom_way) AS flip_geom FROM 

' ||
                        'pgr_drivingdistance(''SELECT id as id, source::int, dist::double precision, '
                                        || 'time_4::float AS cost FROM '
                                        || quote_ident(tbl) || ''', '
                                        || source || ', ' || dist
                                        || ' , false, false), '
                                || quote_ident(tbl) || ' WHERE id2 = id ORDER BY seq';

        -- Remember start point
    point := source;

            -- Flip geometry (if required)
            IF ( point != rec.source ) THEN
                    rec.geom_way := rec.flip_geom;
                    point := rec.source;
                    point := rec.target;
            END IF;

            -- Calculate heading (simplified)
            EXECUTE 'SELECT degrees( ST_Azimuth(
                            ST_StartPoint(''' || rec.geom_way::text || '''),
                            ST_EndPoint(''' || rec.geom_way::text || ''') ) )'
                    INTO heading;

            -- Return record
            seq     := seq + 1;
            gid     := rec.id;
            name    := rec.osm_name;
            cost    := rec.cost;
            geom    := rec.geom_way;
            RETURN NEXT;

  COST 100
  ROWS 1000;
ALTER FUNCTION pgr_fromAtoMult(character varying, double precision, double precision)
  OWNER TO postgres;

And here is the Error:

ERROR:  el registro «rec» no tiene un campo «source»
CONTEXT:  sentencia SQL: «SELECT ( point != rec.source )»
función PL/pgSQL pgr_fromAtoMult(character varying,double precision,double precision) en la línea 32 en IF
********** Error **********

ERROR: el registro «rec» no tiene un campo «source»
SQL state: 42703
Context: sentencia SQL: «SELECT ( point != rec.source )»

Your query that is producing rec is this one with only field id:

EXECUTE 'SELECT id::integer FROM layer_vertices_pgr
                    ORDER BY the_geom <-> ST_GeometryFromText(''POINT('
                    || x || ' ' || y || ')'',4326) LIMIT 1' INTO rec;

You create the query with field source in text variable sql, but never actually execute that query into rec.

  • Thank you for your answer. I am new to sql and i am still testing basic changes on functions . The final objective is to generate multiples paths from one point(user click on map-long lat coordinates) using as parameter distance or cost from pgr_drivingdistance.
    – user19566
    Jan 31 '15 at 10:36

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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