Currently I fetch polygons from a database table using ST_AsText(). The results are in text format, like this:

POLYGON((84 104,212 48,321 122,243 179,275 238,131 240,84 104))

I am not quite sure if ST_AsText() and string manipulation is the way to go for good performance. Is there another way to fetch the points?

How can I get all points of a polygon as an array in PHP?

  • 2
    JSON might be a better solution postgis.org/docs/ST_AsGeoJSON.html is fast with openlayers
    – Mapperz
    Commented May 8, 2013 at 14:23
  • Thanks, that is a great option since I can directly forward that to Leaflet. If you would write an answer, I'll mark it as accepted.
    – danijar
    Commented May 8, 2013 at 14:59
  • Posted a longer answer basis on @danijar feedback.
    – Mapperz
    Commented May 8, 2013 at 15:07

1 Answer 1


For current method ST_AsText() I suggest that you request GeoJSON instead this can be requested from PostGIS natively


SELECT ST_AsGeoJSON(the_geom) from fe_edges limit 1;

(1 row)
--3d point

SELECT ST_AsGeoJSON('LINESTRING(1 2 3, 4 5 6)');


in response to JSON might be a better solution ST_AsGeoJSON is fast with openlayers

Full official documentation: http://postgis.net/docs/ST_AsGeoJSON.html


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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