gdal icon indicating copy to clipboard operation
gdal copied to clipboard

GDAL CLI: raster calc - make lng/lat available in 'calc'

Open PostholerCom opened this issue 1 month ago • 4 comments

Feature description

Greetings,

'gdal raster calc' has pixel values in the A or A[band] format.

The feature request would be to make lng/lat available in --calc, ie, something like A[x] for lng, A[y] for lat. This would be like making an entire new band of information available with no new overhead.

Whether you're calculating sun angles, temperate zones, declination, etc, on the fly, it would be a HUGE addition for many applications.

Thanks! Scott

Additional context

No response

PostholerCom avatar Nov 22 '25 23:11 PostholerCom

Do the _CENTER_X_ and _CENTER_Y_ built-in variables work for you, or do you need lat/lon values for a raster in projected coordinates?

dbaston avatar Nov 22 '25 23:11 dbaston

Do the _CENTER_X_ and _CENTER_Y_ built-in variables work for you, or do you need lat/lon values for a raster in projected coordinates?

Thanks for the quick response, Dan!

I'm unfamiliar with those built in variables. Are they documented somewhere?

If CENTER* vars are pixel row/column and not lat/lon in data set CRS, then I think that would require some hoops to jump through? I'm not sure, I don't know what they are. :)

PostholerCom avatar Nov 23 '25 00:11 PostholerCom

They are the cell center X/Y in the dataset CRS. They're described on the VRT driver page under the "expression" pixel function (https://gdal.org/en/latest/drivers/raster/vrt.html#built-in-pixel-functions). But I can appreciate that you would have no reason to go looking for the information there -- it should be made clear in the gdal raster calc doc.

dbaston avatar Nov 23 '25 01:11 dbaston

They are the cell center X/Y in the dataset CRS. They're described on the VRT driver page under the "expression" pixel function

That works perfect. Thanks Dan!

PostholerCom avatar Nov 23 '25 01:11 PostholerCom