2

I have point geometry in PostgreSQL/PostGIS which I query as follows:

SELECT ST_AsText(geom) as pointgeom 
FROM pointable. 

I'm using Python as server side script.

I want to pass the result as GeoJSON response to overlay on Google Maps but I'm new to GeoJSON.

If this make sense, can any one shade light on the code that encode the pointgeom to GeoJSON format and handover to JavaScript?

closed as off-topic by PolyGeo Jul 31 at 11:34

This question appears to be off-topic. The users who voted to close gave this specific reason:

  • "When seeking help to debug/write/improve code always provide the desired behavior, a specific problem/error and the shortest code (as formatted text, not pictures) needed to reproduce it in the question body. Providing a clear problem statement and a code attempt helps others to help you." – PolyGeo
If this question can be reworded to fit the rules in the help center, please edit the question.

4

If you are using Django (GeoDjango), look at vectorformats, which will produce GeoJSON that you can use directly in Google Maps -- we are using this in production, on a decent sized database, millions or rows and complex polygons, and it works really well.

If you want to query Postgis directly, use ST_AsGeoJSON as @underdark says, but note, you need to do a bit more work to get the properties in the output (which, of course, can be very useful client side in Google Maps for selection, display, etc). I posted about exactly this recently, the essence of which is that you need to use row_to_json and array_to_json in conjunction with ST_AsGeoJSON.

2

Don't code, use

ST_AsGeoJSON — Return the geometry as a GeoJSON element.

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