buffer a polygon but return a wrong polyon with unexpected sequence of points
my key code is:
std::vector<Vec2d> points = ReadPoints(); // read my test points to create a raw polygon, returned points is not closed
geos::geom::CoordinateSequence coords;
for (const auto &p : points) {
coords.add(geos::geom::Coordinate(p.x, p.y));
}
// construct closed coords
coords.add(geos::geom::Coordinate(points.front().x, points.front().y));
const auto *g_geom_factory =
geos::geom::GeometryFactory::getDefaultInstance();
const auto geom = g_geom_factory->createPolygon(std::move(coords));
const double dist = 0.8;
std::unique_ptr<Geometry> buffered_poly;
const auto poly =
geos::operation::buffer::BufferOp::bufferByZero(geom.get(), true);
buffered_poly = poly->buffer(dist);
size_t buffered_points_size = buffered_poly->getNumPoints() - 1;
std::vector<Vec2d> buffered_points;
for (size_t i = 0; i < buffered_points_size; ++i) {
const geos::geom::Coordinate p = buffered_poly->getCoordinates()->getAt(i);
buffered_points.push_back(Vec2d(p.x, p.y));
}
the output result is shown at the below fig:
in this fig, the blue represents the raw polygon, the red represents the result polygon after buffer operation. As we can see, the red polygon is obviously wrong with unexpected sequence of points.
my test raw polygon is written in points.txt: points.txt
Does this issue still occur when the buffering (or anything else), does not create a hole, or repeated edges? Holes and repeated edges might better be represented as something else other than in the same polygon as the main outline, e.g. multiple polygons.
What happens if the level of buffering is reduced, so the hole is never created?
The example should be provided in WKT or WKB, not some custom format which takes effort to read.
The buffer is computed correctly, and contains a hole.
The problem is with your code. The Geometry.getCoordinates() method returns all coordinates in the geometry in a single array, so it does not distinguish between the shell and hole, but concatenates them.