44 return QStringLiteral(
"Polygon" );
49 auto result = std::make_unique< QgsPolygon >();
51 return result.release();
102 for (
int i = 0; i < nRings; ++i )
104 std::unique_ptr< QgsLineString > line(
new QgsLineString() );
105 line->fromWkbPoints( ringType, wkbPtr );
126 int binarySize =
sizeof( char ) +
sizeof( quint32 ) +
sizeof( quint32 );
135 binarySize +=
sizeof( quint32 ) + curve->numPoints() * ( 2 + curve->is3D() + curve->isMeasure() ) *
sizeof(
double );
169 wkb << static_cast<quint32>( type );
181 curve->points( pts );
193 wkt += QLatin1String(
" EMPTY" );
196 wkt += QLatin1String(
" (" );
200 if ( qgsgeometry_cast<QgsLineString *>(
mExteriorRing.get() ) )
203 childWkt = childWkt.mid( childWkt.indexOf(
'(' ) );
205 wkt += childWkt +
',';
209 if ( !curve->isEmpty() )
212 if ( ! qgsgeometry_cast<QgsLineString *>( curve ) )
214 std::unique_ptr<QgsLineString> line( curve->curveToLine() );
222 childWkt = childWkt.mid( childWkt.indexOf(
'(' ) );
223 wkt += childWkt +
',';
226 if ( wkt.endsWith(
',' ) )
248 QgsLineString *lineString = qgsgeometry_cast< QgsLineString *>( ring );
249 if ( lineString && !lineString->
isClosed() )
281 QgsLineString *lineString = qgsgeometry_cast< QgsLineString *>( ring );
282 if ( lineString && !lineString->
isClosed() )
314 multiLine->
reserve( nInteriorRings + 1 );
316 for (
int i = 0; i < nInteriorRings; ++i )
327 return std::numeric_limits< double >::quiet_NaN();
330 double minimumDistance = std::numeric_limits<double>::max();
331 double minDistX = 0.0;
332 double minDistY = 0.0;
335 for (
int ringIndex = 0; ringIndex < numRings; ++ringIndex )
340 for (
int i = 0, j = len - 1; i < len; j = i++ )
342 double aX = ring->
xAt( i );
343 double aY = ring->
yAt( i );
344 double bX = ring->
xAt( j );
345 double bY = ring->
yAt( j );
347 if ( ( ( aY > y ) != ( bY > y ) ) &&
348 ( x < ( bX - aX ) * ( y - aY ) / ( bY - aY ) + aX ) )
351 minimumDistance = std::min( minimumDistance,
QgsGeometryUtilsBase::sqrDistToLine( x, y, aX, aY, bX, bY, minDistX, minDistY, 4 * std::numeric_limits<double>::epsilon() ) );
355 return ( inside ? 1 : -1 ) * std::sqrt( minimumDistance );
370 for (
int i = 0; i < nInteriorRings; ++i )
WkbType
The WKB type describes the number of dimensions a geometry has.
@ LineString25D
LineString25D.
@ LineStringM
LineStringM.
@ LineStringZM
LineStringZM.
@ LineStringZ
LineStringZ.
Abstract base class for all geometries.
virtual bool convertTo(Qgis::WkbType type)
Converts the geometry to a specified type.
QFlags< WkbFlag > WkbFlags
QString wktTypeStr() const
Returns the WKT type string of the geometry.
Qgis::WkbType wkbType() const
Returns the WKB type of the geometry.
void setZMTypeFromSubGeometry(const QgsAbstractGeometry *subggeom, Qgis::WkbType baseGeomType)
Updates the geometry type based on whether sub geometries contain z or m values.
virtual bool hasCurvedSegments() const
Returns true if the geometry contains curved segments.
@ FlagExportTrianglesAsPolygons
Triangles should be exported as polygon geometries.
virtual QgsAbstractGeometry * clone() const =0
Clones the geometry by performing a deep copy.
static endian_t endian()
Returns whether this machine uses big or little endian.
Qgis::WkbType readHeader() const
readHeader
Curve polygon geometry type.
bool isEmpty() const override
Returns true if the geometry is empty.
QVector< QgsCurve * > mInteriorRings
void clear() override
Clears the geometry, ie reset it to a null geometry.
virtual void setExteriorRing(QgsCurve *ring)
Sets the exterior ring of the polygon.
virtual void addInteriorRing(QgsCurve *ring)
Adds an interior ring to the geometry (takes ownership)
std::unique_ptr< QgsCurve > mExteriorRing
Abstract base class for curved geometry type.
QgsCurve * segmentize(double tolerance=M_PI_2/90, SegmentationToleranceType toleranceType=MaximumAngle) const override
Returns a geometry without curves.
virtual QgsLineString * curveToLine(double tolerance=M_PI_2/90, SegmentationToleranceType toleranceType=MaximumAngle) const =0
Returns a new line string geometry corresponding to a segmentized approximation of the curve.
void reserve(int size)
Attempts to allocate memory for at least size geometries.
static double sqrDistToLine(double ptX, double ptY, double x1, double y1, double x2, double y2, double &minDistX, double &minDistY, double epsilon)
Returns the squared distance between a point and a line.
static void pointsToWKB(QgsWkbPtr &wkb, const QgsPointSequence &points, bool is3D, bool isMeasure, QgsAbstractGeometry::WkbFlags flags)
Returns a LinearRing { uint32 numPoints; Point points[numPoints]; }.
Line string geometry type, with support for z-dimension and m-values.
bool isClosed() const override
Returns true if the curve is closed.
int numPoints() const override
Returns the number of points in the curve.
double yAt(int index) const override
Returns the y-coordinate of the specified node in the line string.
void close()
Closes the line string by appending the first point to the end of the line, if it is not already clos...
double xAt(int index) const override
Returns the x-coordinate of the specified node in the line string.
Multi line string geometry collection.
bool addGeometry(QgsAbstractGeometry *g) override
Adds a geometry and takes ownership. Returns true in case of success.
QgsCurvePolygon * toCurveType() const override
Returns the geometry converted to the more generic curve type QgsCurvePolygon.
void setExteriorRing(QgsCurve *ring) override
Sets the exterior ring of the polygon.
void addInteriorRing(QgsCurve *ring) override
Adds an interior ring to the geometry (takes ownership)
int wkbSize(QgsAbstractGeometry::WkbFlags flags=QgsAbstractGeometry::WkbFlags()) const override
Returns the length of the QByteArray returned by asWkb()
QByteArray asWkb(QgsAbstractGeometry::WkbFlags flags=QgsAbstractGeometry::WkbFlags()) const override
Returns a WKB representation of the geometry.
QgsPolygon * clone() const override
Clones the geometry by performing a deep copy.
void clear() override
Clears the geometry, ie reset it to a null geometry.
QString geometryType() const override
Returns a unique string representing the geometry type.
double pointDistanceToBoundary(double x, double y) const
Returns the distance from a point to the boundary of the polygon (either the exterior ring or any clo...
QgsAbstractGeometry * boundary() const override
Returns the closure of the combinatorial boundary of the geometry (ie the topological boundary of the...
friend class QgsCurvePolygon
QgsPolygon()
Constructor for an empty polygon geometry.
QgsPolygon * createEmptyWithSameType() const override
Creates a new geometry with the same class and same WKB type as the original and transfers ownership.
bool fromWkb(QgsConstWkbPtr &wkb) override
Sets the geometry from a WKB string.
QgsPolygon * surfaceToPolygon() const override
Gets a polygon representation of this surface.
QString asWkt(int precision=17) const override
Returns a WKT representation of the geometry.
void clearCache() const override
Clears any cached parameters associated with the geometry, e.g., bounding boxes.
static Qgis::WkbType flatType(Qgis::WkbType type)
Returns the flat type for a WKB type.
QVector< QgsPoint > QgsPointSequence