Automated generation texture coordinates for shapes is not easy... I have an idea that is not the best, but maybe it help you
if the shape lays in a plane you can create a square that contains the shape, is easy to get the texture coordinates in [0..1] range interpolating vertex positions inside the square in the plane.