Skip to content

Conversation

@lbartoletti
Copy link
Contributor

Summary of Changes

Fix WKT polygon definitions to comply with OGC standards

Problem

Several WKT files contained invalid polygon definitions where the first and last coordinates did not match, violating the OGC Simple Features specification, which requires polygon rings to be closed.

This caused errors when attempting to read these files with other libraries like SFCGAL, even though CGAL's WKT method handles unclosed polygons gracefully.

Changes

  • examples/Polygon_repair/data/winding.wkt: Added closing point (0 0)
  • examples/Polygon_repair/data/flat.wkt: Closed all 4 polygons
  • test/Polygon_repair/data/in/overlapping-edge-inside.wkt: Closed second polygon in MULTIPOLYGON

Notes

  • test/Polygon_repair/data/in/not-closed.wkt was intentionally left unclosed as it serves as a test case for the repair algorithm
  • These changes do not affect CGAL's test results, as the repair algorithm produces identical output for both closed and unclosed input

Release Management

  • Affected package(s):
  • Issue(s) solved (if any): fix #0000, fix #0000,...
  • Feature/Small Feature (if any):
  • Link to compiled documentation (obligatory for small feature) wrong link name to be changed
  • License and copyright ownership:

@afabri
Copy link
Member

afabri commented Nov 21, 2025

Did you check what CGAL::IO::write_WTK() produces? Does it repeat the first point?

@lbartoletti
Copy link
Contributor Author

Did you check what CGAL::IO::write_WTK() produces? Does it repeat the first point?

afaiu, CGAL use Boost. Boost Geometry closes polygon for you:

#include <boost/geometry.hpp>
#include <boost/geometry/geometries/linestring.hpp>
#include <boost/geometry/geometries/point_xy.hpp>
#include <boost/geometry/geometries/polygon.hpp>
#include <iostream>

int main() {
  using point_type = boost::geometry::model::d2::point_xy<double>;

  boost::geometry::model::polygon<point_type> closed;
  boost::geometry::model::polygon<point_type> open;

  boost::geometry::read_wkt("POLYGON((0 0,0 7,4 2,2 0,0 0))", closed);
  boost::geometry::read_wkt("POLYGON((0 0,0 7,4 2,2 0))", open);

  std::cout << boost::geometry::wkt(closed) << std::endl;
  std::cout << boost::geometry::wkt(open) << std::endl;

  return 0;
}

returns:

POLYGON((0 0,0 7,4 2,2 0,0 0))
POLYGON((0 0,0 7,4 2,2 0,0 0))

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants