After reading a bit of GDAL Virtual File Systems docs, I am trying to write a zipped Shapefile using this gdal command involving the use of /vsizip/:

ogr2ogr -f "ESRI Shapefile" /vsizip/test.zip\test.shp WFS:"https://www.wondermap.it/cgi-bin/qgis_mapserv.fcgi?&map=/home/ubuntu/qgis/projects/Demo_sci_WMS/demo_sci.qgs&SERVICE=WFS&VERSION=1.1.0&REQUEST=GetFeature&typename=domini_sciabili&bbox=544138,5098446,564138,5108446"

, and I get this error:

ERROR 1: Read-write random access not supported for /vsizip
ERROR 1: Cannot create test.shx while another file is being written in the .zip
ERROR 1: Failed to create file /vsizip/test.zip/test.shx: No such file or directory
ERROR 1: Terminating translation prematurely after failed
translation of layer domini_sciabili (use -skipfailures to skip errors)

The code is only writing test.shp (0KB though) inside test.zip.

I get what is happening (the error is self-explanatory), but sincerely, I don't know if I can go farther than this without probably using the GDAL API. Am I wrong?


In GDAL 3.1+ you can create zipped shapefiles, although not using vsizip (as far as I've tested). See docs page

Starting with GDAL 3.1, the driver can also support reading, creating and editing .shz files (ZIP files containing the .shp, .shx, .dbf and other side-car files of a single layer) and .shp.zip files (ZIP files contains one or several layers). Creation and editing involves the creation of temporary files.

You simply need to change the output filename extension:

ogr2ogr -f "ESRI Shapefile" C:\Temp\test.shp.zip WFS:"https://www.wondermap.it/cgi-bin/qgis_mapserv.fcgi?&map=/home/ubuntu/qgis/projects/Demo_sci_WMS/demo_sci.qgs&SERVICE=WFS&VERSION=1.1.0&REQUEST=GetFeature&typename=domini_sciabili&bbox=544138,5098446,564138,5108446"

Answering myself thanks to this answer on the GDAL mailing list.

I can't, because Shapefile is a multi file format, and OGR updates the files in a non sequential way. I have to create a temporary shapefile and zip it afterwards.

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.