How can I access the current feature's/layer's CRS from an QGIS expression, or from a custom expression in PyQGIS?
In my expression, I use the following to buffer a (currently lat-long-specified) feature in map units (m).
I'd like to generalize this to work with any layer, whatever its layer CRS is, i.e. without hardcoding the
'EPSG:4326'. But there doesn't seem to be a
@layer_crs variable. Is there some other way to access this using core expression functions and variables?
As an alternative, I'm open to (and might even prefer) a PyQGIS solution that can be put into a custom function. But (I may be wrong), the
QgsFeature passed as the
feature parameter in an expression custom function does not know its (source) CRS or even its layer.
I've also looked at the optional
context parameter to a custom function, but have gotten lost whether I can shovel through the
QgsExpressionContext object this provides to find the parent layer and its source CRS.