gdal_edit
What is gdal_edit?
gdal_edit.py modifies a raster's georeferencing, CRS, NoData value, and metadata in place — without reading or rewriting pixels. It is the right tool when a file's pixels are correct but its declared metadata is wrong: a missing CRS, an incorrect geotransform, a NoData value that needs to be set, or a metadata key that must be added.
gdal_edit.py [options] <dataset>Commonly used options:
-a_srs <CRS>— assign a CRS (e.g.EPSG:32633) without reprojecting-a_ullr <ulx> <uly> <lrx> <lry>— assign the upper-left/lower-right geotransform corners-tr <xres> <yres>— assign pixel size-a_ulurll <ulx> <uly> <urx> <ury> <llx> <lly>— assign an affine geotransform from three corners-a_nodata <value>/-unsetnodata— set or remove NoData-a_coord_epoch <epoch>— set the coordinate epoch for dynamic CRS-scale <value>/-offset <value>— set pixel scale/offset metadata-a_stats/-unsetstats— recompute or remove statistics-mo <KEY=VALUE>— set a metadata item-gcp <pixel> <line> <x> <y> [<z>]— append a GCP (repeatable)-unsetgt/-unsetgcp/-unsetmd— clear geotransform, GCPs, or metadata
When would you use gdal_edit?
Use gdal_edit.py whenever metadata is wrong but pixels are correct. Typical jobs: setting the CRS on a TIFF that was delivered without one (gdal_edit.py -a_srs EPSG:25832 scene.tif), declaring a sentinel value as NoData so downstream tools skip it (gdal_edit.py -a_nodata -9999 dem.tif), adjusting a one-off geotransform after a provider mis-tagged pixel origin, or adding organisation-specific metadata items (-mo PRODUCT_LEVEL=L2A).
It also supports attaching GCPs, useful when you have a scanned map or unreferenced image and want to add control points before calling gdalwarp -order 1 -refine_gcps to actually resample. Remember that gdal_edit.py never reprojects — it only relabels. For reprojection, use gdalwarp.
FAQs
Does gdal_edit change pixel values?
No — it only writes metadata headers. The pixel raster is untouched. This is what makes it fast (near instant on arbitrarily large files) and reversible in principle, though you should still back up before editing in place.
How is gdal_edit different from -a_srs in gdal_translate?
gdal_translate -a_srs does the same relabelling but copies pixel data into a new file in the process. gdal_edit.py -a_srs modifies the source file directly with zero I/O on pixels. Both are approximations — neither reprojects. Prefer gdal_edit.py when you want to fix a file in place and keep the original layout; prefer gdal_translate when you want a new file and may also change format or band structure.
Will gdal_edit work on any raster format?
Only formats where GDAL can update metadata in place — GeoTIFF is the primary supported case. JPEG, PNG, and similar formats lack sufficient metadata surface. For those, rewrite through gdal_translate. Check the driver's capabilities with gdalinfo --format <driver> before trusting gdal_edit.py on unusual formats.
How do I remove a NoData value that was set by mistake?
Pass -unsetnodata. Similarly, -unsetgt, -unsetgcp, and -unsetmd clear geotransform, GCPs, or metadata respectively. These unsets are irreversible on the source file, so keep a backup.