How To Get Rid of Needless SRTM Files Fast

Posted: June 20, 2012 in GIS
Tags: , , ,

It is quite annoying to download the whole 1Gb archive of SRTM30 DEMs when you need only couple of dozens of them. In case of Leningrad region for example I had to download 4 archives and face necessity of finding needed DEMs amongst several thousands(!!!) of files and deletion the rest… Too tedious and too long task to do it manually. Lets optimise it!

 We will use QGIS and Linux (I prefer openSUSE) console (and a text editor of your choice). The algorithm is applicable to other similar issues too.

Firstly we will get the list of names of files that we need to save (for our actual project). Collect all DEMs from archives in a single folder. And use Image Boundary plugin (or Raster tile index from “Raster” menu) to create a polygon shp-file with borders of all the DEMs from the folder and corresponding file name and path.

Open this layer in your canvas and select polygons that intersects your area of interest:

Now you can either to “save selection as” CSV from the layer menu or “copy selected rows to clipboard” from attribute table and paste it to the empty text-file. In LibreOffice Calc (or use other text editor for this) delete all columns exept that which contains file names and add to the list name of the text-file itself (lets name it FILELIST). NOTE: this file should contain ONLY NAMES without pathsPlace this file to the directory with DEMs.

We are ready for the final step – deletion of a thousands of DEMs that we are not going to use. A recipe I found here: using console go to the folder with DEMs and execute following command:

ls -1 | sort FILELIST FILELIST - | uniq -u | xargs rm

Where FILELIST is our text-file containing names of files that we need to KEEP. This command will delete all files from the folder except files which names are listed in FILELIST.

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s