# Tip: Generate Image Footprints Using GDAL/OGR

**URL:** <https://openplanetary.discourse.group/t/tip-generate-image-footprints-using-gdal-ogr/141>\
**Category:** GDAL\
**Created:** [June 28, 2019, 3:06pm UTC](https://openplanetary.discourse.group/t/tip-generate-image-footprints-using-gdal-ogr/141 "2019-06-28T15:06:32Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![dpmayer](https://yyz2.discourse-cdn.com/free1/user_avatar/openplanetary.discourse.group/dpmayer/32/50_2.png) [@dpmayer](https://openplanetary.discourse.group/u/dpmayer)\
**Post date:** [June 28, 2019, 3:06pm UTC](https://openplanetary.discourse.group/t/tip-generate-image-footprints-using-gdal-ogr/141/1 "2019-06-28T15:06:32Z")

</div>

I often need to generate polygons that trace the outline of the valid data area of an image. I used to use `gdal_trace_outline` from dans-gdal-scripts ([https://github.com/gina-alaska/dans-gdal-scripts](https://github.com/gina-alaska/dans-gdal-scripts)), but that package isn’t actively maintained and I’ve had trouble getting it to compile against recent versions of GDAL installed from conda-forge.

Instead, I’ve figured out how to use GDAL to make a virtual raster mask and then use GDAL’s own `gdal_polygonize.py` to draw the footprint.

Here’s an example:

```auto

# Say you have an 8-bit image with a NoData value of 0,
# use gdal_translate to stretch values [1,255] to [1,1], 
# and assign 0 to represent the NoData value on output,
# save result as VRT rather than writing a new raster to disk.
gdal_translate -scale 1 255 1 1 -ot Byte -of vrt -a_nodata 0 input_ortho.tif input_ortho_mask.vrt

# Create a polygon shapefile that outlines the valid (DN==1) 
# regions of the VRT just created
gdal_polygonize.py -8 input_ortho_mask.vrt -f "ESRI Shapefile" mask_footprint.shp mask_footprint DN

```

---

<div class="post-metadata">

**Author:** ![dpmayer](https://yyz2.discourse-cdn.com/free1/user_avatar/openplanetary.discourse.group/dpmayer/32/50_2.png) [@dpmayer](https://openplanetary.discourse.group/u/dpmayer)\
**Post date:** [August 15, 2023, 3:30pm UTC](https://openplanetary.discourse.group/t/tip-generate-image-footprints-using-gdal-ogr/141/2 "2023-08-15T15:30:09Z")

</div>

As of GDAL 3.8.0 there is now a built in utility for generating image footprints, called `gdal_footprint`:  
[https://gdal.org/programs/gdal\_footprint.html#gdal-footprint](https://gdal.org/programs/gdal_footprint.html#gdal-footprint)
