transform_layer function

Transform layer according to metadata