It sounds like you want to serialize and the deserialize all the tf data in a tf2_ros Buffer, which doesn't look supported.
One possibly glitchy approach is to record the /tf
and /tf_static
topics into a bag for 10-20 seconds, then play it back in a loop, then do tf lookups. There may be glitches for lookups around when the bag loops, or around anything on tf_static.
To do better than that you would iterate through all the tf messages in the bag file (http://wiki.ros.org/rosbag/Code%20API...) and load them into a BufferCore object, which can be private and unchanging once your are done setting transforms into it (as opposed to listening to /tf and overwriting stored transforms with new ones, and forgetting transforms as they get too old with a regular paired buffer and transform listener). Then you can query the BufferCore. See #q289323
There is a get_frames method in Buffer that has a tf2_frames
service- but it only returns what the frames are named and their parent child relationship in yaml, not their spatial relationship (and there would need to be a corresponding set_frames method to turn yaml back into a query-able Buffer). It looks like it was mainly meant to support the view_frames visualization.
Did you try
rosrun tf view_frames
?view_frames
saves the tree as pdf. I want to save it in some format so that I can read from it programatically.