Friday, 8 June 2018

gdal - Piping data to ogr2ogr


Is it possible to directly pipe data to ogr2ogr? I'm trying to curl a GeoJSON file and pipe it to ogr2ogr to covert it to another format.


Without using a pipe, I was able to achieve this by first writing a file and then converting it using the following command, but I'm curious if it is possible to skip that step.


curl "https://raw.githubusercontent.com/nvkelso/natural-earth-vector/master/geojson/ne_50m_admin_0_countries.geojson" -o "countries.geojson" && ogr2ogr -f "KML" countries.kml countries.geojson


I also tried creating a variable with the curl output instead of piping it, but ogr2ogr was not able to read it:


DATA=$(curl -s "https://raw.githubusercontent.com/nvkelso/natural-earth-vector/master/geojson/ne_50m_admin_0_countries.geojson") && ogr2ogr -f "KML" countries.kml $DATA

Answer



OGR has its own idiom for stdin, /vsistdin/. Use that as ogr2ogr's first argument (the dst_datasource_name) and you can pipe curl's output to it:


curl "https://raw.githubusercontent.com/nvkelso/natural-earth-vector/master/geojson/ne_50m_admin_0_countries.geojson" | ogr2ogr -f "KML" countries.kml /vsistdin/

No comments:

Post a Comment

arcpy - Changing output name when exporting data driven pages to JPG?

Is there a way to save the output JPG, changing the output file name to the page name, instead of page number? I mean changing the script fo...