For current method ST_AsText()
I suggest that you request GeoJSON
instead this can be requested from PostGIS natively
Example:
SELECT ST_AsGeoJSON(the_geom) from fe_edges limit 1;
st_asgeojson
-----------------------------------------------------------------------------------------------------------
{"type":"MultiLineString","coordinates":[[[-89.734634999999997,31.492072000000000],
[-89.734955999999997,31.492237999999997]]]}
(1 row)
--3d point
SELECT ST_AsGeoJSON('LINESTRING(1 2 3, 4 5 6)');
st_asgeojson
-----------------------------------------------------------------------------------------
{"type":"LineString","coordinates":[[1,2,3],[4,5,6]]}
in response to JSON might be a better solution postgis.org/docs/ST_AsGeoJSON.html is fast with openlayers
Full official documentation:
http://www.postgis.org/docs/ST_AsGeoJSON.html