Geographic Information Systems Stack Exchange is a question and answer site for cartographers, geographers and GIS professionals. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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?

share|improve this question
JSON might be a better solution is fast with openlayers – Mapperz May 8 '13 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 May 8 '13 at 14:59
Posted a longer answer basis on @danijar feedback. – Mapperz May 8 '13 at 15:07
up vote 3 down vote accepted

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:

share|improve this answer
I have one related question. It there some kind of reverse function? Would be really helpful if I could store from JSON by something like ST_GeomFromGeoJSON(). – danijar May 8 '13 at 15:16 will take GeoJSON and import it into PostGIS – Mapperz May 8 '13 at 15:19
I must have overseen it, thanks! – danijar May 8 '13 at 16:12

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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