6

I know I can convert a Shapefile to GeoJSON as the following:

ogr2ogr -f GeoJSON outputFile.json inputFile.shp

Instead of writing the result of this conversion to the file outputFile.json, I'd like to print this result directly on stdout, without having to write a file on the system. Since I'm inside a bash script I know I can find alternative solutions as the following one:

tmpFile=$(mktemp).json
ogr2ogr -f GeoJSON $tmpFile inputFile.shp
cat $tmpFile

However, I'd like to know if ogr2ogr supports printing to stdout instead of writing on files, just so I can do it in one line of code. I've searched in the man ogr2ogr page but it doesn't even contain the word stdout there. Is it possible to print the output of ogr2ogr directly to stdout?

1 Answer 1

8

Use the /vsistdout/ virtual filesystem:

ogr2ogr -f GeoJSON /vsistdout/ inputFile.shp

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.