I was recently working with the SWReGAP data DVDs and wanted to develop an ArcGIS geoprocessing model to copy the DVD data, clip the rasters to the state of Arizona boundary and reproject them.
Because the DVDs contained a raster dataset for each species that was stored as a zip file, I wanted a way to decompress each raster within my model rather than simply decompressing all the zip files to a folder on my hard drive and using the uncompressed files in my model. (This is because each DVD was filled to capacity with 2+ GB zip files, so decompressing the DVD contents to my hard disk first filled up the remaining space on my hard drive. So I decided that I should decompress each file individually and delete it when I was finished.)
So I set about developing a script tool to decompress each zip file so that I could incorporate the script tool into my ArcGIS geoprocessing model. I tried using the zipfile libraries built into Python, but ran into problems decompressing these files because each zip file was too large for the readfile buffer used by the Python routines.
This led me to 7-Zip, an open source to WinZip. While 7-Zip contains a user interface, I was particularly interested in the 7-Zip Command Line Version as this made it possible for me to call the command line from my ArcGIS script too.
With the 7-Zip Command Line Version installed and a few lines of Python, I had a script tool that was capable of extracting a zip file and could be included in an ArcGIS geoprocessing model. I then developed a second script to decompress a whole folder of zip files, and a third script for zipping a feature class.
infile = arcpy.GetParameterAsText(0)
outpath = arcpy.GetParameterAsText(1)
# create 7zip command
zipcommand = “7za e -tzip \”%s\” -o\”%s\”” % (infile, outpath)
# execute command
except Exception as e:
I then added the script to a toolbox in ArcGIS as a script tool and set two parameters: 1) Zipfile Name as a file, and 2) Output Location as a folder. When clicked, the script tool appears like the one below:
I was pleased enough with the resulting tool that I developed a simple model that incorporated the tool into an iterator to loop through a folder of zip files and extract each one. That model is illustrated below:
Finally, I also created a second script tool that decompresses an entire folder of zipfiles to a specified location.
Since these have been helpful in automating my workflow I thought I would offer them to the GIS community as a zip file that contains a folder with an ArcGIS Toolbox, two script tools and a sample mode. You can download them from my website at: http://www.johndonoghue.net/ecology/resources.html
To use the ArcGIS Script tools:
There are a couple of things you need to do before the tools will work. Follow the simple steps below to obtain a copy of 7-Zip Command Line Version and modify your system paths.
- Download and install 7-Zip Command Line Version. When you download the application it will consist of a zip file. decompress the zip file to a folder on your hard disk. I highly recommend extracting the files to a folder in your root directory named something like C:\7Zip or the default C:\7za920. If you extract them into a folder inside your program files folder on 64-bit systems, you may not be able to run the scripts as Python cannot find the executable even with the path statement.
- Add the path to your 7-Zip installation to your Windows PATH environment variables – add it to both the System PATH variable and the User PATH variable . For example, my path was: C:\7za920; (see http://www.computerhope.com/issues/ch000549.htm if you need help doing this).
- Finally,download the Tools from my website and extract them to a folder on your hard drive. You should then be able to use them as you would any ArcGIS script .
I hope you find these tools helpful in your work.