BufferOp.h
/**********************************************************************
*
* GEOS - Geometry Engine Open Source
* http://geos.osgeo.org
*
* Copyright (C) 2009-2011 Sandro Santilli <strk@kbt.io>
* Copyright (C) 2005-2007 Refractions Research Inc.
* Copyright (C) 2001-2002 Vivid Solutions Inc.
*
* This is free software; you can redistribute and/or modify it under
* the terms of the GNU Lesser General Public Licence as published
* by the Free Software Foundation.
* See the COPYING file for more information.
*
**********************************************************************
*
* Last port: operation/buffer/BufferOp.java r378 (JTS-1.12)
*
**********************************************************************/
#pragma once
#include <memory> // for unique_ptr
#include <vector> // for vector
#include <geos/export.h>
#include <geos/operation/buffer/BufferParameters.h> // for enum values
#include <geos/geom/Geometry.h> // to materialize Geometry
#include <geos/util/TopologyException.h> // for composition
#ifdef _MSC_VER
#pragma warning(push)
#pragma warning(disable: 4251) // warning C4251: needs to have dll-interface to be used by clients of class
#endif
// Forward declarations
namespace geos {
namespace geom {
class PrecisionModel;
class Geometry;
}
}
namespace geos {
namespace operation { // geos.operation
namespace buffer { // geos.operation.buffer
class GEOS_DLL BufferOp {
private:
static constexpr int MAX_PRECISION_DIGITS = 12;
const geom::Geometry* argGeom;
util::TopologyException saveException;
double distance;
BufferParameters bufParams;
std::unique_ptr<geom::Geometry> resultGeometry;
bool isInvertOrientation = false;
static double precisionScaleFactor(const geom::Geometry* g,
double distance, int maxPrecisionDigits);
void computeGeometry();
void bufferOriginalPrecision();
void bufferReducedPrecision(int precisionDigits);
void bufferReducedPrecision();
void bufferFixedPrecision(const geom::PrecisionModel& fixedPM);
static void extractPolygons(
geom::Geometry* poly0,
std::vector<std::unique_ptr<geom::Geometry>>& polys);
public:
enum {
CAP_ROUND = BufferParameters::CAP_ROUND,
CAP_BUTT = BufferParameters::CAP_FLAT,
CAP_SQUARE = BufferParameters::CAP_SQUARE
};
static std::unique_ptr<geom::Geometry> bufferOp(
const geom::Geometry* g,
double distance,
int quadrantSegments = BufferParameters::DEFAULT_QUADRANT_SEGMENTS,
int endCapStyle = BufferParameters::CAP_ROUND);
static std::unique_ptr<geom::Geometry> bufferOp(
const geom::Geometry* g,
double distance,
BufferParameters& bufParms);
BufferOp(const geom::Geometry* g)
:
argGeom(g),
bufParams(),
resultGeometry(nullptr),
isInvertOrientation(false)
{
}
BufferOp(const geom::Geometry* g, const BufferParameters& params)
:
argGeom(g),
bufParams(params),
resultGeometry(nullptr),
isInvertOrientation(false)
{
}
inline void setEndCapStyle(int nEndCapStyle);
inline void setQuadrantSegments(int nQuadrantSegments);
inline void setSingleSided(bool isSingleSided);
std::unique_ptr<geom::Geometry> getResultGeometry(double nDistance);
static std::unique_ptr<geom::Geometry> bufferByZero(
const geom::Geometry* geom,
bool isBothOrientations);
};
// BufferOp inlines
void
BufferOp::setQuadrantSegments(int q)
{
bufParams.setQuadrantSegments(q);
}
void
BufferOp::setEndCapStyle(int s)
{
bufParams.setEndCapStyle((BufferParameters::EndCapStyle)s);
}
void
BufferOp::setSingleSided(bool isSingleSided)
{
bufParams.setSingleSided(isSingleSided);
}
} // namespace geos::operation::buffer
} // namespace geos::operation
} // namespace geos
#ifdef _MSC_VER
#pragma warning(pop)
#endif
geos::geom::Geometry
Basic implementation of Geometry, constructed and destructed by GeometryFactory.
Definition Geometry.h:196
geos::geom::PrecisionModel
Specifies the precision model of the Coordinate in a Geometry.
Definition PrecisionModel.h:87
geos::operation::buffer::BufferOp::setQuadrantSegments
void setQuadrantSegments(int nQuadrantSegments)
Sets the number of segments used to approximate a angle fillet.
Definition BufferOp.h:283
geos::operation::buffer::BufferOp::getResultGeometry
std::unique_ptr< geom::Geometry > getResultGeometry(double nDistance)
Returns the buffer computed for a geometry for a given buffer distance.
geos::operation::buffer::BufferOp::setEndCapStyle
void setEndCapStyle(int nEndCapStyle)
Specifies the end cap style of the generated buffer.
Definition BufferOp.h:289
geos::operation::buffer::BufferOp::bufferOp
static std::unique_ptr< geom::Geometry > bufferOp(const geom::Geometry *g, double distance, int quadrantSegments=BufferParameters::DEFAULT_QUADRANT_SEGMENTS, int endCapStyle=BufferParameters::CAP_ROUND)
Computes the buffer for a geometry for a given buffer distance and accuracy of approximation.
geos::operation::buffer::BufferOp::setSingleSided
void setSingleSided(bool isSingleSided)
Sets whether the computed buffer should be single-sided.
Definition BufferOp.h:295
geos::operation::buffer::BufferOp::CAP_ROUND
@ CAP_ROUND
Definition BufferOp.h:145
geos::operation::buffer::BufferOp::CAP_BUTT
@ CAP_BUTT
Definition BufferOp.h:149
geos::operation::buffer::BufferOp::CAP_SQUARE
@ CAP_SQUARE
Definition BufferOp.h:153
geos::operation::buffer::BufferOp::BufferOp
BufferOp(const geom::Geometry *g, const BufferParameters &params)
Initializes a buffer computation for the given geometry with the given set of parameters.
Definition BufferOp.h:201
geos::operation::buffer::BufferOp::BufferOp
BufferOp(const geom::Geometry *g)
Initializes a buffer computation for the given geometry.
Definition BufferOp.h:184
geos::operation::buffer::BufferOp::bufferByZero
static std::unique_ptr< geom::Geometry > bufferByZero(const geom::Geometry *geom, bool isBothOrientations)
geos::operation::buffer::BufferParameters
Contains the parameters which describe how a buffer should be constructed.
Definition BufferParameters.h:56
geos::operation::buffer::BufferParameters::EndCapStyle
EndCapStyle
End cap styles.
Definition BufferParameters.h:61
geos::operation::buffer::BufferParameters::CAP_SQUARE
@ CAP_SQUARE
Specifies a square line buffer end cap style.
Definition BufferParameters.h:70
geos::operation::buffer::BufferParameters::CAP_ROUND
@ CAP_ROUND
Specifies a round line buffer end cap style.
Definition BufferParameters.h:64
geos::operation::buffer::BufferParameters::CAP_FLAT
@ CAP_FLAT
Specifies a flat line buffer end cap style.
Definition BufferParameters.h:67
geos::operation::buffer::BufferParameters::DEFAULT_QUADRANT_SEGMENTS
static const int DEFAULT_QUADRANT_SEGMENTS
The default number of facets into which to divide a fillet of 90 degrees.
Definition BufferParameters.h:94
geos::util::TopologyException
Indicates an invalid or inconsistent topological situation encountered during processing.
Definition TopologyException.h:34
geos::geom
Definition Angle.h:26
geos::operation::buffer
Provides classes for computing buffers of geometries.
Definition namespaces.h:182
geos::operation
Provides classes for implementing operations on geometries.
Definition CleanCoverage.h:34
geos
Basic namespace for all GEOS functionalities.
Definition geos.h:38