[GIS] How to read shapefile from .zip with OGR command line tools

ogrogr2ogrshapefile

I have thousands of shapefiles in .zip archives to work with. How can I use and other GDAL/OGR tools to work with these data without having to extract the archives first?

From gdal cheatsheet and Reading a GDAL dataset in a .gz file or a .zip archive I know that I can use the visizip driver, but for formats that consist of multiple files per data layer like shapefile you need to explicitly name the file inside the archive:

ogrinfo /vsizip/archive.zip/105A_wetland_a.shp

How might I efficiently work with archives, that could contain multiple shapefiles per zip, without having to know the and pass the name of each layer ahead of time? e.g.

ogrinfo /vsizip/archive.zip

Example archive file: bndt_105a_shp_en.zip from Geogratis.

Best Answer

Your command is basically OK but the error message looks worse than it actually is. The important message is

It may be corrupt or read-only file accessed in update mode.

You can open files from zip but you can't update them. If you read the zip as read-only you can get rid of the error messages.

ogrinfo /vsizip/bndt_105a_shp_en.zip -ro
INFO: Open of `/vsizip/bndt_105a_shp_en.zip'
      using driver `ESRI Shapefile' successful.
1: 105A_buildin_p (Point)
2: 105A_builtup_a (Polygon)
3: 105A_builtup_p (Point)
4: 105A_campgro_p (Point)
5: 105A_contour_l (Line String)
6: 105A_dis_str_p (Point)
7: 105A_elev_pt_p (Point)
8: 105A_esker_l (Line String)
9: 105A_haz_air_p (Point)
10: 105A_haz_nav_p (Point)
11: 105A_li_road_l (Line String)
12: 105A_mininga_a (Polygon)
13: 105A_nav_aid_p (Point)
14: 105A_nts_lim_l (Line String)
15: 105A_picnic_p (Point)
16: 105A_road_l (Line String)
17: 105A_runway_p (Point)
18: 105A_sand_a (Polygon)
19: 105A_seapl_b_p (Point)
20: 105A_ski_cen_p (Point)
21: 105A_toponym_p (Point)
22: 105A_tower_p (Point)
23: 105A_trail_l (Line String)
24: 105A_vegetat_a (Polygon)
25: 105A_wat_dis_a (Polygon)
26: 105A_wat_dis_l (Line String)
27: 105A_wat_dis_p (Point)
28: 105A_water_b_a (Polygon)
29: 105A_water_c_l (Line String)
30: 105A_wetland_a (Polygon)

It is possible to convert all the layers into any format that supports multiple layers with a one-line command. As an example a conversion into GeoPackage:

ogr2ogr -f gpkg test.gpkg /vsizip/bndt_105a_shp_en.zip

Adding more data to existing layers and adding new layers into existing GeoPackage should go this way:

ogr2ogr -f gpkg -update -append test.gpkg /vsizip/another.zip