std::vector<std::string> polygonize(const std::string &input1, const std::string &input2) { std::vector<std::string> result; WKTReader wktr; WKTWriter wktw; Geometry *line1 = wktr.read(input1); Geometry *line2 = wktr.read(input2); // Unioning the linestrings inserts nodes for polygonization Geometry *nodedLineStrings = line1->Union(line2); // Add additional lineStrings to each end to close them off LineString *ls1 = dynamic_cast<LineString*>(line1); LineString *ls2 = dynamic_cast<LineString*>(line2); Point *sp1 = ls1->getStartPoint(); Point *sp2 = ls2->getStartPoint(); Point *ep1 = ls1->getEndPoint(); Point *ep2 = ls2->getEndPoint(); Geometry *smallests = smallestSegment(sp1, ep1, sp2, ep2); nodedLineStrings = nodedLineStrings->Union(smallests); // Use GEOS to polygonize the strings geos::operation::polygonize::Polygonizer polygonizer; polygonizer.add(nodedLineStrings); std::vector<Polygon*> *polygons = polygonizer.getPolygons(); for(int inx = 0; inx < polygons->size(); inx++){ result.push_back(wktw.write((*polygons)[inx])); } return result; }