0

I create a LineString containing a CoordinateSequence of length 167 and then do a buffer operation using the following code:

geos::operation::buffer::BufferParameters buffer_params;
geos::operation::buffer::BufferOp buffer_op(input, buffer_params);
std::unique_ptr<geos::geom::Geometry> output(buffer_op.getResultGeometry(1.5));

This throws a geos::geom::TopologyException with message:

TopologyException: depth mismatch at  at -6 -10.5

What does this mean and what can I do about it?

Alex Flint
  • 6,040
  • 8
  • 41
  • 80

1 Answers1

0

One must use PrecisionModel::makePrecise when creating GEOS geometries. The solution was to add makePrecise calls like this:

geos::geom::LineString* LineStringFromPath(const std::vector<Math::LineSegment2D>& segments,
                                           const geos::geom::GeometryFactory& factory) {
    const geos::geom::PrecisionModel& pm = *factory.getPrecisionModel();

    // Geos will take ownership over this coordinate sequence:
    geos::geom::CoordinateSequence* cl = new geos::geom::CoordinateArraySequence();
    cl->add(geos::geom::Coordinate(pm.makePrecise(segments.front().start[0]),
                                   pm.makePrecise(segments.front().start[1])));

    for (const auto& segment : segments) {
        // Geos will take ownership over this coordinatesequence:
        cl->add(geos::geom::Coordinate(pm.makePrecise(segment.end[0]),
                                       pm.makePrecise(segment.end[1])));
    }

    // Create the full geometry. Object returned from this method must be deleted by caller.
    return factory.createLineString(cl);
}
Alex Flint
  • 6,040
  • 8
  • 41
  • 80