You can buy this project and download/modify it how often you want.
An API for polygonizing sets of lines.