GDALRaster Info

gdallocationinfo

What is gdallocationinfo?

gdallocationinfo reports the pixel value at a given location in a raster, along with diagnostic metadata about the queried point. It accepts coordinates in pixel space, the raster's CRS, or a user-specified CRS, making it the canonical tool for "what is the value of this DEM at longitude/latitude X,Y" questions from scripts, GIS sessions, or ad-hoc verification.

Shell
gdallocationinfo [options] <srcfile> [<x> <y>]

Commonly used options:

  • -b <band> — query only specific bands (repeatable)
  • -xml — XML output (default is text)
  • -geoloc — treat x,y as in the source CRS
  • -wgs84 — treat x,y as longitude/latitude (EPSG:4326)
  • -l_srs <CRS> — treat x,y as coordinates in this CRS
  • -valonly — print only the pixel values (no decoration), ideal for scripting
  • -lifonly — print only location-info metadata (for VRT/geoloc rasters)
  • -overview <level> — query an overview level instead of full resolution

If no x y is given on the command line, coordinates are read from stdin, one pair per line.

When would you use gdallocationinfo?

Use gdallocationinfo for scripted pixel queries and quick inspections. Typical jobs: looking up the elevation at a survey point (gdallocationinfo -wgs84 -valonly dem.tif 12.5 41.9), extracting pixel values for a list of sample points by piping them through stdin (awk '{print $1,$2}' samples.csv | gdallocationinfo -wgs84 -valonly scene.tif), or debugging a classification by checking the value at a known reference location before running full analysis.

-valonly is the script-friendly output — just the pixel value, ready to pipe into awk, paste, or similar. Combine with -wgs84 or -l_srs when the input coordinates are in a different CRS from the raster. For vector-point sampling at scale, consider gdal_translate or a Python script with rasterio.sample, which is usually faster for large point lists than invoking gdallocationinfo repeatedly.

FAQs

How do I query many points at once?

Pipe them through stdin. For example paste -d' ' longs.txt lats.txt | gdallocationinfo -wgs84 -valonly dem.tif reads one coordinate pair per line and emits one value per line. This is dramatically faster than invoking gdallocationinfo once per point since the dataset is only opened once.

Why do I get "Location is off this file!"?

The query coordinate is outside the raster extent. Check the coordinate CRS (-wgs84 vs -geoloc), confirm the raster's extent with gdalinfo, and ensure you are not mixing axis orders (longitude,latitude vs latitude,longitude — always longitude first for -wgs84).

Does gdallocationinfo interpolate between pixels?

No. It returns the value of the pixel containing the query location — nearest-neighbour by construction. For bilinear sampling between pixels, use gdal_translate -outsize with a bilinear resampler to produce a finer raster first, or write a short Python script with rasterio that supports resampled sampling.

Can I query overviews to get approximate values faster?

Yes — -overview <level> selects a pyramid level. Useful when you only need a coarse sample on a huge raster (e.g. a quick mean-elevation check) and do not need full-resolution precision. Confirm the overview level exists with gdalinfo.