Take the 2-minute tour ×
Geographic Information Systems Stack Exchange is a question and answer site for cartographers, geographers and GIS professionals. It's 100% free, no registration required.

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

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 performant polygon reading. 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
2  
JSON might be a better solution postgis.org/docs/ST_AsGeoJSON.html 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

1 Answer 1

up vote 2 down vote accepted

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 ST_AsGeoJSON is fast with openlayers

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

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
    
postgis.org/documentation/manual-svn/ST_GeomFromGeoJSON.html 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

 
discard

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.