42 if ( polygon->numInteriorRings() > 0 )
45 if (
const QgsLineString *exterior = qgsgeometry_cast< QgsLineString * >( polygon->exteriorRing() ) )
47 if ( exterior->numPoints() == 5
51 return QgsRectangle( exterior->xAt( 0 ), exterior->yAt( 0 ), exterior->xAt( 2 ), exterior->yAt( 2 ) );
60 const double xMax = xMin +
width;
62 const double yMax = yMin +
height;
75 const double xmin = mXmin - v.
x();
76 const double xmax = mXmax - v.
x();
77 const double ymin = mYmin - v.
y();
78 const double ymax = mYmax - v.
y();
84 const double xmin = mXmin + v.
x();
85 const double xmax = mXmax + v.
x();
86 const double ymin = mYmin + v.
y();
87 const double ymax = mYmax + v.
y();
122 return QStringLiteral(
"POLYGON EMPTY" );
125 return QStringLiteral(
"POLYGON((%1 %2, %3 %2, %3 %4, %1 %4, %1 %2))" ).arg(
142 precision =
static_cast<int>( std::ceil( -1.0 * std::log10( std::min(
width(),
height() ) ) ) ) + 1;
150 rep = QStringLiteral(
"Null" );
152 rep = QStringLiteral(
"%1,%2 : %3,%4" )
167 return QStringLiteral(
"EMPTY" );
172 QTextStream foo( &rep );
174 foo.setRealNumberPrecision( 8 );
175 foo.setRealNumberNotation( QTextStream::FixedNotation );
179 << mXmin <<
' ' << mYmin <<
", "
180 << mXmin <<
' ' << mYmax <<
", "
181 << mXmax <<
' ' << mYmax <<
", "
182 << mXmax <<
' ' << mYmin <<
", "
183 << mXmin <<
' ' << mYmin;
191 return QgsBox3D( mXmin, mYmin, zMin, mXmax, mYmax, zMax );
196 if (
isNull() )
return *
this;
199 auto gridifyValue = [](
double value,
double spacing ) ->
double
202 return std::round( value / spacing ) * spacing;
208 gridifyValue( mXmin, spacing ),
209 gridifyValue( mYmin, spacing ),
210 gridifyValue( mXmax, spacing ),
211 gridifyValue( mYmax, spacing )
223 double xmin, ymin, xmax, ymax;
224 in >> xmin >> ymin >> xmax >> ymax;
virtual const QgsAbstractGeometry * simplifiedTypeRef() const
Returns a reference to the simplest lossless representation of this geometry, e.g.
A 3-dimensional box composed of x, y, z coordinates.
A geometry is the spatial representation of a feature.
const QgsAbstractGeometry * constGet() const
Returns a non-modifiable (const) reference to the underlying abstract geometry primitive.
static QgsGeometry fromWkt(const QString &wkt)
Creates a new geometry from a WKT string.
bool isGeosValid(Qgis::GeometryValidityFlags flags=Qgis::GeometryValidityFlags()) const
Checks validity of the geometry using GEOS.
bool isEmpty() const
Returns true if the geometry is empty (eg a linestring with no vertices, or a collection with no geom...
Line string geometry type, with support for z-dimension and m-values.
A class to represent a 2D point.
A rectangle specified with double values.
QString toString(int precision=16) const
Returns a string representation of form xmin,ymin : xmax,ymax Coordinates will be truncated to the sp...
void scale(double scaleFactor, const QgsPointXY *c=nullptr)
Scale the rectangle around its center point.
QgsRectangle & operator+=(QgsVector v)
Moves this rectangle in the direction of the vector.
QgsRectangle()=default
Constructor for a null rectangle.
double xMinimum() const
Returns the x minimum value (left side of rectangle).
static QgsRectangle fromWkt(const QString &wkt)
Creates a new rectangle from a wkt string.
void setYMinimum(double y)
Set the minimum y value.
QgsRectangle & operator-=(QgsVector v)
Moves this rectangle in the direction of the reversed vector.
double yMinimum() const
Returns the y minimum value (bottom side of rectangle).
void setXMinimum(double x)
Set the minimum x value.
QString asWktPolygon() const
Returns a string representation of the rectangle as a WKT Polygon.
double width() const
Returns the width of the rectangle.
double xMaximum() const
Returns the x maximum value (right side of rectangle).
bool isNull() const
Test if the rectangle is null (holding no spatial information).
QString asWktCoordinates() const
Returns a string representation of the rectangle in WKT format.
QgsRectangle operator-(QgsVector v) const
Returns a rectangle offset from this one in the direction of the reversed vector.
double yMaximum() const
Returns the y maximum value (top side of rectangle).
QgsRectangle scaled(double scaleFactor, const QgsPointXY *center=nullptr) const
Scale the rectangle around its center point.
void setYMaximum(double y)
Set the maximum y value.
QgsPointXY center() const
Returns the center point of the rectangle.
void setXMaximum(double x)
Set the maximum x value.
static QgsRectangle fromCenterAndSize(const QgsPointXY ¢er, double width, double height)
Creates a new rectangle, given the specified center point and width and height.
QString asPolygon() const
Returns the rectangle as a polygon.
double height() const
Returns the height of the rectangle.
QgsRectangle snappedToGrid(double spacing) const
Returns a copy of this rectangle that is snapped to a grid with the specified spacing between the gri...
QgsRectangle operator+(QgsVector v) const
Returns a rectangle offset from this one in the direction of the vector.
QgsBox3D toBox3d(double zMin, double zMax) const
Converts the rectangle to a 3D box, with the specified zMin and zMax z values.
A class to represent a vector.
double y() const
Returns the vector's y-component.
double x() const
Returns the vector's x-component.
QString qgsDoubleToString(double a, int precision=17)
Returns a string representation of a double.
bool qgsDoubleNear(double a, double b, double epsilon=4 *std::numeric_limits< double >::epsilon())
Compare two doubles (but allow some difference)
#define QgsDebugMsgLevel(str, level)
QDataStream & operator>>(QDataStream &in, QgsRectangle &rectangle)
Reads a rectangle from stream in into rectangle.
QDataStream & operator<<(QDataStream &out, const QgsRectangle &rectangle)
Writes the list rectangle to stream out.