I am developing a routing application using GeoServer, PostgreSQL, HTML and JavaScript. To display the routing layer on the HTML webpage, I followed the instructions from this workshop. GeoServer does not preview the pgRouting layer. The Error message is: "Internal Error: Rendering Process failed". I used the following query when I created the pgRouting SQL view inside geoserver:
SELECT geom FROM pgr_fromAtoB('roads', %x1%, %y1%, %x2%, %y2%
) ORDER BY seq) AS route
This query uses the function pgr_fromAtoB. I Created this function in PostgreSQL as follows:
IN edges_subset varchar,
IN x1 double precision,
IN y1 double precision,
IN x2 double precision,
IN y2 double precision,
OUT seq INTEGER,
OUT cost FLOAT,
OUT name TEXT,
OUT geom geometry,
OUT heading FLOAT
)
RETURNS SETOF record AS
$BODY$
WITH
dijkstra AS (
SELECT * FROM pgr_dijkstra(
'SELECT gid as id, source, target, length AS cost FROM ' || $1,
-- source
(SELECT id FROM roads_vertices_pgr
ORDER BY the_geom <-> ST_SetSRID(ST_Point(x1,y1),4326) LIMIT 1),
-- target
(SELECT id FROM roads_vertices_pgr
ORDER BY the_geom <-> ST_SetSRID(ST_Point(x2,y2),4326) LIMIT 1),
false) -- undirected
),
with_geom AS (
SELECT dijkstra.seq, dijkstra.cost, roads.name,
CASE
WHEN dijkstra.node = roads.source THEN geom
ELSE ST_Reverse(geom)
END AS route_geom
FROM dijkstra JOIN roads
ON (edge = gid) ORDER BY seq
)
SELECT *,
ST_azimuth(ST_StartPoint(route_geom), ST_EndPoint(route_geom))
FROM with_geom;
$BODY$
LANGUAGE 'sql';
I cannot figure out if the error is within the function I created or somewhere else. I ran the dijkstra algorithm on the roads shapefile inside PostgreSQL and it works fine. There is no projection or geometry issue either. Please, Can anyone suggest a solution to this??