35#include "moc_qgsrectangle.cpp"
37using namespace Qt::StringLiterals;
47 if ( polygon->numInteriorRings() > 0 )
53 return QgsRectangle( exterior->xAt( 0 ), exterior->yAt( 0 ), exterior->xAt( 2 ), exterior->yAt( 2 ) );
62 const double xMax = xMin +
width;
64 const double yMax = yMin +
height;
82 const double xmin = mXmin - v.
x();
83 const double xmax = mXmax - v.
x();
84 const double ymin = mYmin - v.
y();
85 const double ymax = mYmax - v.
y();
91 const double xmin = mXmin + v.
x();
92 const double xmax = mXmax + v.
x();
93 const double ymin = mYmin + v.
y();
94 const double ymax = mYmax + v.
y();
127 return u
"Polygon EMPTY"_s;
142 precision =
static_cast<int>( std::ceil( -1.0 * std::log10( std::min(
width(),
height() ) ) ) ) + 1;
144 if ( precision > 20 )
152 rep = u
"%1,%2 : %3,%4"_s.arg( mXmin, 0,
'f', precision ).arg( mYmin, 0,
'f', precision ).arg( mXmax, 0,
'f', precision ).arg( mYmax, 0,
'f', precision );
168 QTextStream foo( &rep );
170 foo.setRealNumberPrecision( 8 );
171 foo.setRealNumberNotation( QTextStream::FixedNotation );
174 foo << mXmin <<
' ' << mYmin <<
", " << mXmin <<
' ' << mYmax <<
", " << mXmax <<
' ' << mYmax <<
", " << mXmax <<
' ' << mYmin <<
", " << mXmin <<
' ' << mYmin;
181 return QgsBox3D( mXmin, mYmin, zMin, mXmax, mYmax, zMax );
189 auto normalizeLongitude = [](
double x ) {
190 double res = std::fmod( x, 360 );
193 else if ( res < -180 )
201 const double x = normalizeLongitude(
xMinimum() );
207 const double x1 = normalizeLongitude(
xMinimum() );
208 const double x2 = normalizeLongitude(
xMaximum() );
221 const double x1 = normalizeLongitude(
xMinimum() );
222 const double x2 = normalizeLongitude(
xMaximum() );
233 auto gridifyValue = [](
double value,
double spacing ) ->
double {
235 return std::round( value / spacing ) * spacing;
240 return QgsRectangle( gridifyValue( mXmin, spacing ), gridifyValue( mYmin, spacing ), gridifyValue( mXmax, spacing ), gridifyValue( mYmax, spacing ) );
251 double xmin, ymin, xmax, ymax;
252 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 Q_INVOKABLE 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 rectangle specified with double values.
Q_INVOKABLE QString toString(int precision=16) const
Returns a string representation of form xmin,ymin : xmax,ymax Coordinates will be rounded to the spec...
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.
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.
void setXMinimum(double x)
Set the minimum x value.
Q_INVOKABLE QString asWktPolygon() const
Returns a string representation of the rectangle as a WKT Polygon.
static QgsRectangle fromEdges(double left, double top, double right, double bottom)
Creates a rectangle from the left, top, right and bottom edges.
Q_INVOKABLE 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.
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.
void setXMaximum(double x)
Set the maximum x value.
std::pair< QgsRectangle, QgsRectangle > splitAtAntimeridian() const
Splits the rectangle at the antimeridian (longitude 180 degrees).
double left() const
Returns the left side of the rectangle.
double right() const
Returns the right side of the rectangle.
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 bottom() const
Returns the bottom side 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.
double top() const
Returns the top side of the rectangle.
Represent a 2-dimensional 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).
T qgsgeometry_cast(QgsAbstractGeometry *geom)
#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.