I'm generating contours from four 5x5 degree SRTM DEMs in southeastern Australia. I'm using gdalwarp to reproject the DEM, then gdal_contour to generate contours.

First, I generated contours for each block separately. The shapefiles were 9, 45, 73 and 270 MB. Then I merged the source TIFFs, and generated a single contour file. It's 2.0GB (that is, more than 4x the size of the combined individual contours).

Why is this? Here are the two scripts:

Individual contours:

for f in srtm_66_19 srtm_65_19 srtm_66_20 srtm_65_20
gdalwarp -s_srs EPSG:4326 -t_srs EPSG:3785 -r bilinear $f.tif $f-3785.tif 

# contours
gdal_contour -a elev -i 20 $f-3785.tif $f-3785-contour.shp


Merged contours:

gdal_merge.py srtm_66_19.tif srtm_65_19.tif srtm_66_20.tif srtm_65_20.tif -o srtm.tif
gdalwarp -s_srs EPSG:4326 -t_srs EPSG:3785 -r bilinear $f.tif $f-3785.tif 
gdal_contour -a elev -i 20 $f-3785.tif $f-3785-contour.shp

And the complete file listing:

-rw-rw-r-- 1 ubuntu ubuntu  20M Sep  9 17:36 new/srtm-3785-contour.dbf
-rw-rw-r-- 1 ubuntu ubuntu  399 Sep  9 17:08 new/srtm-3785-contour.prj
-rw-rw-r-- 1 ubuntu ubuntu 2.0G Sep  9 17:36 new/srtm-3785-contour.shp
-rw-rw-r-- 1 ubuntu ubuntu 7.6M Sep  9 17:36 new/srtm-3785-contour.shx
-rw-rw-r-- 1 ubuntu ubuntu 404M Sep  9 17:07 new/srtm-3785.tif
-rw-rw-r-- 1 ubuntu ubuntu 8.9M Sep  9 13:34 srtm_65_19-3785-contour.shp
-rw-rw-r-- 1 ubuntu ubuntu  68M Sep  9 12:28 srtm_65_19-3785.tif
-rw-rw-r-- 1 ubuntu ubuntu  69M Sep  9 12:28 srtm_65_19.tif
-rw-rw-r-- 1 ubuntu ubuntu  73M Sep  9 13:38 srtm_65_20-3785-contour.shp
-rw-rw-r-- 1 ubuntu ubuntu  67M Sep  9 12:28 srtm_65_20-3785.tif
-rw-rw-r-- 1 ubuntu ubuntu  69M Sep  9 12:28 srtm_65_20.tif
-rw-rw-r-- 1 ubuntu ubuntu  45M Sep  9 12:28 srtm_66_19-3785-contour.shp
-rw-rw-r-- 1 ubuntu ubuntu  68M Sep  9 12:28 srtm_66_19-3785.tif
-rw-rw-r-- 1 ubuntu ubuntu  69M Sep  9 12:28 srtm_66_19.tif
-rw-rw-r-- 1 ubuntu ubuntu 270M Sep  9 13:37 srtm_66_20-3785-contour.shp
-rw-rw-r-- 1 ubuntu ubuntu  67M Sep  9 12:28 srtm_66_20-3785.tif
-rw-rw-r-- 1 ubuntu ubuntu  69M Sep  9 12:28 srtm_66_20.tif

Why so big? Is there anything I can do about this? I'd prefer to work with merged files as they're easier to manage in TileMill.

1 Answer 1


I would like to put this as a comment, but I don't have enough reputation (???).

Anyways, you could keep using the individual DEM files if you created a .vrt file with gdalbuildvirt.

On the other hand, the problem I got when creating contours from individual files was that they look funny where DEMs meet. I tried to create them from the .vrt file, but my are was too big and run out of memory.

  • Oh, what do you mean? You can have a VRT file that kind of spans several different source Shapefiles, so you don't need to actually merge them? Mar 15, 2017 at 5:58
  • No, you can have VRT that spans several raster and then apply contours on that. Mar 15, 2017 at 12:31

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.