22 #include <QTextStream>
42 if ( poly.size() != 1 )
46 if ( polyline.size() == 5 && polyline.at( 0 ) == polyline.at( 4 ) && geom.
isGeosValid() )
47 return QgsRectangle( polyline.at( 0 ).x(), polyline.at( 0 ).y(), polyline.at( 2 ).x(), polyline.at( 2 ).y() );
55 double xMax = xMin +
width;
57 double yMax = yMin +
height;
70 double xmin = mXmin - v.
x();
71 double xmax = mXmax - v.
x();
72 double ymin = mYmin - v.
y();
73 double ymax = mYmax - v.
y();
79 double xmin = mXmin + v.
x();
80 double xmax = mXmax + v.
x();
81 double ymin = mYmin + v.
y();
82 double ymax = mYmax + v.
y();
116 QLatin1String(
"POLYGON((" ) +
122 QStringLiteral(
"))" );
136 precision =
static_cast<int>( std::ceil( -1.0 * std::log10( std::min(
width(),
height() ) ) ) ) + 1;
144 rep = QStringLiteral(
"Empty" );
146 rep = QStringLiteral(
"%1,%2 : %3,%4" )
163 QTextStream foo( &rep );
165 foo.setRealNumberPrecision( 8 );
166 foo.setRealNumberNotation( QTextStream::FixedNotation );
170 << mXmin <<
' ' << mYmin <<
", "
171 << mXmin <<
' ' << mYmax <<
", "
172 << mXmax <<
' ' << mYmax <<
", "
173 << mXmax <<
' ' << mYmin <<
", "
174 << mXmin <<
' ' << mYmin;
182 return QgsBox3d( mXmin, mYmin, zMin, mXmax, mYmax, zMax );
188 auto gridifyValue = [](
double value,
double spacing ) ->
double
191 return std::round( value / spacing ) * spacing;
197 gridifyValue( mXmin, spacing ),
198 gridifyValue( mYmin, spacing ),
199 gridifyValue( mXmax, spacing ),
200 gridifyValue( mYmax, spacing )
212 double xmin, ymin, xmax, ymax;
213 in >> xmin >> ymin >> xmax >> ymax;
A 3-dimensional box composed of x, y, z coordinates.
A geometry is the spatial representation of a feature.
QgsPolygonXY asPolygon() const
Returns the contents of the geometry as a polygon.
bool isMultipart() const SIP_HOLDGIL
Returns true if WKB of the geometry is of WKBMulti* type.
static QgsGeometry fromWkt(const QString &wkt)
Creates a new geometry from a WKT string.
bool isGeosValid(QgsGeometry::ValidityFlags flags=QgsGeometry::ValidityFlags()) const
Checks validity of the geometry using GEOS.
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 yMaximum() const SIP_HOLDGIL
Returns the y maximum value (top side of rectangle).
double xMaximum() const SIP_HOLDGIL
Returns the x maximum value (right side of rectangle).
QgsBox3d toBox3d(double zMin, double zMax) const
Converts the rectangle to a 3D box, with the specified zMin and zMax z values.
static QgsRectangle fromWkt(const QString &wkt)
Creates a new rectangle from a wkt string.
double xMinimum() const SIP_HOLDGIL
Returns the x minimum value (left side of rectangle).
double yMinimum() const SIP_HOLDGIL
Returns the y minimum value (bottom side of rectangle).
void setYMinimum(double y) SIP_HOLDGIL
Set the minimum y value.
QgsRectangle & operator-=(QgsVector v)
Moves this rectangle in the direction of the reversed vector.
QString asWktPolygon() const
Returns a string representation of the rectangle as a WKT Polygon.
void setXMaximum(double x) SIP_HOLDGIL
Set the maximum x value.
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.
void setXMinimum(double x) SIP_HOLDGIL
Set the minimum x value.
double height() const SIP_HOLDGIL
Returns the height of the rectangle.
QgsRectangle scaled(double scaleFactor, const QgsPointXY *center=nullptr) const
Scale the rectangle around its center point.
void setYMaximum(double y) SIP_HOLDGIL
Set the maximum y value.
double width() const SIP_HOLDGIL
Returns the width of the rectangle.
static QgsRectangle fromCenterAndSize(QgsPointXY center, double width, double height)
Creates a new rectangle, given the specified center point and width and height.
bool isEmpty() const
Returns true if the rectangle is empty.
QString asPolygon() const
Returns the rectangle as a polygon.
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.
QgsPointXY center() const SIP_HOLDGIL
Returns the center point of the rectangle.
A class to represent a vector.
double y() const SIP_HOLDGIL
Returns the vector's y-component.
double x() const SIP_HOLDGIL
Returns the vector's x-component.
QString qgsDoubleToString(double a, int precision=17)
Returns a string representation of a double.
QVector< QgsPolylineXY > QgsPolygonXY
Polygon: first item of the list is outer ring, inner rings (if any) start from second item.
QVector< QgsPointXY > QgsPolylineXY
Polyline as represented as a vector of two-dimensional points.
#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.