3

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?

3
  • 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
4

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

2

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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