I am working with a PHP web application where we have a user submitting a ShapeFile.

I am able to convert that ShapeFile then to a format of geojson.

What I am wondering now is how I can best get that geojson into a PostGIS table as a geometry column?

1 Answer 1


It might be easier to use shp2pgsl to directly load the shapefile into a PostGIS table, for example:

shp2pgsql -d -I shapefile.shp table | psql -U user database

If you prefer to use GeoJSON directly, there is ST_GeomFromGeoJSON, but for this (as I understand), you'll need to parse and insert individual features from the GeoJSON file. See this answer for additional details.

You can always keep the GeoJSON file on the server for transfer to the client, or export individual features from PostGIS as GeoJSON, using ST_AsGeoJSON

If going directly from shape to PostGIS doesn't fit your use case, perhaps include some additional information.


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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