0

Is there a method in PHP to covert a shapefile to GeoJSON? I need to upload shapefile and load it into a PostgreSQL table. I tried PHP exec(), but it didn't work.

2

PHP exec() should work, what error do you get? And what commands/utilities are you using to convert?

For example with ogr2ogr:

$command = "/usr/bin/ogr2ogr -f GeoJSON output.geojson input.shp";
exec($command);

You should use escapeshellarg if any of these params are coming from user input

0

I am posting this late answer just as a service for the community, since this is one of the questions that pop up when looking for "converting ESRI Shapefiles to GeoJSON with PHP".

My PHP Shapefile library can read and write any ESRI Shapefile and convert it natively from/to WKT and GeoJSON.

It is a free, open source, native PHP library, does not require any third party dependency or evil eval() and it is actively maintained.

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.