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

I'd like to do a GeoJSON dump of a PostGIS table, but I want to export features (the geometry and the properties) not just the geometry. I've been digging into the ST_AsGeoJSON function but it looks like I can only get the coordinate information (which makes sense since it's a geometry function).

For example:

select st_asgeojson(the_geom) from street_centerline limit 1;



I'm curious if anyone knows of a simple way to get the property information as well. Has anyone written a pgsql2geojson script yet?

share|improve this question
Is PostGIS able to leverage the improvements in PostgreSQL 9.2? As postgres now natively supports 9.2, is anyone aware of a similar development in PostGIS? Would be nice to do without the ogr2ogr segway. – user12212 Oct 24 '12 at 14:53

Here is an obvious solution to my own question - ogr2ogr! I'm not sure why I didn't think of it sooner. It has both PostGIS and GeoJSON drivers so this should work great.

share|improve this answer

For completeness here's an actual example with ogr2ogr:

ogr2ogr -f GeoJSON out.json \
  "PG:host=localhost dbname=gis user=ubuntu password=toomanysecrets" \ 
  -sql "select way,name,amenity from planet_osm_point where amenenity is not null"

Make sure your user has read access to the geometry_columns table.


GRANT SELECT ON geometry_columns to ubuntu;
GRANT SELECT ON geography_columns to ubuntu;
GRANT SELECT ON spatial_ref_sys to ubuntu;
share|improve this answer

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.