Skip to main content
added 115 characters in body
Source Link
Ben H
  • 103
  • 2

Same to joanolo´s answer but smaller:

CREATE or REPLACE FUNCTION pointscanner
(
    IN _source integer,
    IN _target integer,
    IN _k integer,
    IN _directed boolean,
    IN _quant integer
) 
RETURNS table(
    way geometry, name text, 
    distance double precision, tags hstore, 
    "operator" text, admin_level text, 
    z_order integer)
AS $$
DECLARE 
    geomRoute geometry;
    routeBB box2d;
BEGIN
    SELECT INTO geomRoute ST_Union(geom) from route_agg($1, $2, $3, $4);
    routeBB := ST_Extent(geomRoute);

    RETURN QUERY
    SELECT 
        pt.way, 
        pt.name, 
        ST_Distance( ra.geomgeomRoute, ST_Transform(pt.way,4326) ) as distance, 
        pt.tags, 
        pt.operator, 
        pt.admin_level, 
        pt.z_order 
    FROM 
        planet_osm_point pt, 
        route_agg(_source, _target, _k, _directed) ra
    WHERE
        ST_Extent(ST_Union(ra.geom))routeBB && ST_Transform(pt.way, 4326)
    ORDER BY 
        distance ASC 
    LIMIT 
        _quant;
END; $$  
LANGUAGE 'plpgsql' VOLATILE;  

Same to joanolo´s answer but smaller:

CREATE or REPLACE FUNCTION pointscanner
(
    IN _source integer,
    IN _target integer,
    IN _k integer,
    IN _directed boolean,
    IN _quant integer
) 
RETURNS table(
    way geometry, name text, 
    distance double precision, tags hstore, 
    "operator" text, admin_level text, 
    z_order integer)
AS $$
BEGIN
    RETURN QUERY
    SELECT 
        pt.way, 
        pt.name, 
        ST_Distance( ra.geom, ST_Transform(pt.way,4326) ) as distance, 
        pt.tags, 
        pt.operator, 
        pt.admin_level, 
        pt.z_order 
    FROM 
        planet_osm_point pt, 
        route_agg(_source, _target, _k, _directed) ra
    WHERE
        ST_Extent(ST_Union(ra.geom)) && ST_Transform(pt.way, 4326)
    ORDER BY 
        distance ASC 
    LIMIT 
        _quant;
END; $$  
LANGUAGE 'plpgsql' VOLATILE;  

Same to joanolo´s answer but smaller:

CREATE or REPLACE FUNCTION pointscanner
(
    IN _source integer,
    IN _target integer,
    IN _k integer,
    IN _directed boolean,
    IN _quant integer
) 
RETURNS table(
    way geometry, name text, 
    distance double precision, tags hstore, 
    "operator" text, admin_level text, 
    z_order integer)
AS $$
DECLARE 
    geomRoute geometry;
    routeBB box2d;
BEGIN
    SELECT INTO geomRoute ST_Union(geom) from route_agg($1, $2, $3, $4);
    routeBB := ST_Extent(geomRoute);

    RETURN QUERY
    SELECT 
        pt.way, 
        pt.name, 
        ST_Distance( geomRoute, ST_Transform(pt.way,4326) ) as distance, 
        pt.tags, 
        pt.operator, 
        pt.admin_level, 
        pt.z_order 
    FROM 
        planet_osm_point pt
    WHERE
        routeBB && ST_Transform(pt.way, 4326)
    ORDER BY 
        distance ASC 
    LIMIT 
        _quant;
END; $$  
LANGUAGE 'plpgsql' VOLATILE;  
Source Link
Ben H
  • 103
  • 2

Same to joanolo´s answer but smaller:

CREATE or REPLACE FUNCTION pointscanner
(
    IN _source integer,
    IN _target integer,
    IN _k integer,
    IN _directed boolean,
    IN _quant integer
) 
RETURNS table(
    way geometry, name text, 
    distance double precision, tags hstore, 
    "operator" text, admin_level text, 
    z_order integer)
AS $$
BEGIN
    RETURN QUERY
    SELECT 
        pt.way, 
        pt.name, 
        ST_Distance( ra.geom, ST_Transform(pt.way,4326) ) as distance, 
        pt.tags, 
        pt.operator, 
        pt.admin_level, 
        pt.z_order 
    FROM 
        planet_osm_point pt, 
        route_agg(_source, _target, _k, _directed) ra
    WHERE
        ST_Extent(ST_Union(ra.geom)) && ST_Transform(pt.way, 4326)
    ORDER BY 
        distance ASC 
    LIMIT 
        _quant;
END; $$  
LANGUAGE 'plpgsql' VOLATILE;