Rewrite groups of shapes to layers.