We can maybe use this code https://github.com/betravis/shape-tools/blob/master/path-to-polygon/index.html as a starting point. A lot of input data will not have closed polygons required for interacting with spaces.