QGIS API Documentation 3.35.0-Master (728e5967df5)
Searching...
No Matches
QgsPointXY Class Reference

A class to represent a 2D point. More...

`#include <qgspointxy.h>`

Inheritance diagram for QgsPointXY: [legend]

## Public Member Functions

QgsPointXY ()=default
Default constructor.

QgsPointXY (const QgsPoint &point)
Create a new point.

QgsPointXY (const QgsPointXY &p)
Create a point from another point.

QgsPointXY (double x, double y)
Create a point from x,y coordinates.

QgsPointXY (QPoint point)
Create a point from a QPoint.

QgsPointXY (QPointF point)
Create a point from a QPointF.

~QgsPointXY ()=default

QString asWkt () const
Returns the well known text representation for the point (e.g.

double azimuth (const QgsPointXY &other) const
Calculates azimuth between this point and other one (clockwise in degree, starting from north)

bool compare (const QgsPointXY &other, double epsilon=4 *std::numeric_limits< double >::epsilon()) const
Compares this point with another point with a fuzzy tolerance.

double distance (const QgsPointXY &other) const
Returns the distance between this point and another point.

double distance (double x, double y) const
Returns the distance between this point and a specified x, y coordinate.

bool isEmpty () const
Returns `true` if the geometry is empty.

void multiply (double scalar)
Multiply x and y by the given value.

operator QVariant () const
Allows direct construction of QVariants from points.

bool operator!= (const QgsPointXY &other) const
Inequality operator.

QgsPointXY operator* (double scalar) const
Multiplies the coordinates in this point by a scalar quantity.

QgsPointXYoperator*= (double scalar)
Multiplies the coordinates in this point by a scalar quantity in place.

QgsPointXY operator+ (QgsVector v) const
Adds a vector to this point.

QgsPointXYoperator+= (QgsVector v)
Adds a vector to this point in place.

QgsVector operator- (const QgsPointXY &p) const
Calculates the vector obtained by subtracting a point from this point.

QgsPointXY operator- (QgsVector v) const
Subtracts a vector from this point.

QgsPointXYoperator-= (QgsVector v)
Subtracts a vector from this point in place.

QgsPointXY operator/ (double scalar) const
Divides the coordinates in this point by a scalar quantity.

QgsPointXYoperator/= (double scalar)
Divides the coordinates in this point by a scalar quantity in place.

QgsPointXYoperator= (const QgsPointXY &other)
Assignment.

bool operator== (const QgsPointXY &other)
equality operator

QgsPointXY project (double distance, double bearing) const
Returns a new point which corresponds to this point projected by a specified distance in a specified bearing.

void set (double x, double y)
Sets the x and y value of the point.

void setX (double x)
Sets the x value of the point.

void setY (double y)
Sets the y value of the point.

double sqrDist (const QgsPointXY &other) const
Returns the squared distance between this point another point.

double sqrDist (double x, double y) const
Returns the squared distance between this point a specified x, y coordinate.

double sqrDistToSegment (double x1, double y1, double x2, double y2, QgsPointXY &minDistPoint, double epsilon=DEFAULT_SEGMENT_EPSILON) const
Returns the minimum distance between this point and a segment.

QPointF toQPointF () const
Converts a point to a QPointF.

QString toString (int precision=-1) const
Returns a string representation of the point (x, y) with a preset precision.

double x () const
Gets the x value of the point.

double y () const
Gets the y value of the point.

double x

double y

## Friends

uint qHash (const QgsPointXY &pnt)

## Detailed Description

A class to represent a 2D point.

A QgsPointXY represents a strictly 2-dimensional position, with only X and Y coordinates. This is a very lightweight class, designed to minimize the memory requirements of storing millions of points.

In many scenarios it is preferable to use a QgsPoint instead which also supports optional Z and M values. QgsPointXY should only be used for situations where a point can only EVER be two dimensional.

Some valid use cases for QgsPointXY include:

• A mouse cursor location
• A coordinate on a purely 2-dimensional rendered map, e.g. a QgsMapCanvas
• A coordinate in a raster, vector tile, or other purely 2-dimensional layer

Use cases for which QgsPointXY is NOT a valid choice include:

• Storage of coordinates for a geometry. Since QgsPointXY is strictly 2-dimensional it should never be used to store coordinates for vector geometries, as this will involve a loss of any z or m values present in the geometry.
QgsPoint
Since
QGIS 3.0

Definition at line 59 of file qgspointxy.h.

## ◆ QgsPointXY() [1/6]

 QgsPointXY::QgsPointXY ( )
default

Default constructor.

## ◆ QgsPointXY() [2/6]

 QgsPointXY::QgsPointXY ( const QgsPointXY & p )

Create a point from another point.

Definition at line 28 of file qgspointxy.cpp.

## ◆ QgsPointXY() [3/6]

 QgsPointXY::QgsPointXY ( double x, double y )
inline

Create a point from x,y coordinates.

Parameters
 x x coordinate y y coordinate

Definition at line 78 of file qgspointxy.h.

## ◆ QgsPointXY() [4/6]

 QgsPointXY::QgsPointXY ( QPointF point )
inline

Create a point from a QPointF.

Parameters
 point QPointF source
Since
QGIS 2.7

Definition at line 89 of file qgspointxy.h.

## ◆ QgsPointXY() [5/6]

 QgsPointXY::QgsPointXY ( QPoint point )
inline

Create a point from a QPoint.

Parameters
 point QPoint source
Since
QGIS 2.7

Definition at line 100 of file qgspointxy.h.

## ◆ QgsPointXY() [6/6]

 QgsPointXY::QgsPointXY ( const QgsPoint & point )

Create a new point.

Z and M values will be dropped.

Since
QGIS 3.0

Definition at line 35 of file qgspointxy.cpp.

## ◆ ~QgsPointXY()

 QgsPointXY::~QgsPointXY ( )
default

## ◆ asWkt()

 QString QgsPointXY::asWkt ( ) const

Returns the well known text representation for the point (e.g.

"POINT(x y)"). The wkt is created without an SRID.

Definition at line 69 of file qgspointxy.cpp.

## ◆ azimuth()

 double QgsPointXY::azimuth ( const QgsPointXY & other ) const

Calculates azimuth between this point and other one (clockwise in degree, starting from north)

Definition at line 80 of file qgspointxy.cpp.

## ◆ compare()

 bool QgsPointXY::compare ( const QgsPointXY & other, double epsilon = `4 * std::numeric_limits::epsilon()` ) const
inline

Compares this point with another point with a fuzzy tolerance.

Parameters
 other point to compare with epsilon maximum difference for coordinates between the points
Returns
`true` if points are equal within specified tolerance
Since
QGIS 2.9

Definition at line 259 of file qgspointxy.h.

## ◆ distance() [1/2]

 double QgsPointXY::distance ( const QgsPointXY & other ) const
inline

Returns the distance between this point and another point.

Parameters
 other other point
sqrDist()
Since
QGIS 2.16

Definition at line 223 of file qgspointxy.h.

## ◆ distance() [2/2]

 double QgsPointXY::distance ( double x, double y ) const
inline

Returns the distance between this point and a specified x, y coordinate.

Parameters
 x x-coordniate y y-coordinate
sqrDist()
Since
QGIS 2.16

Definition at line 212 of file qgspointxy.h.

## ◆ isEmpty()

 bool QgsPointXY::isEmpty ( ) const
inline

Returns `true` if the geometry is empty.

Unlike QgsPoint, this class is also used to retrieve graphical coordinates like QPointF. It therefore has the default coordinates (0.0). A QgsPointXY is considered empty, when the coordinates have not been explicitly filled in.

Since
QGIS 3.10

Definition at line 250 of file qgspointxy.h.

## ◆ multiply()

 void QgsPointXY::multiply ( double scalar )
inline

Multiply x and y by the given value.

Definition at line 299 of file qgspointxy.h.

## ◆ operator QVariant()

 QgsPointXY::operator QVariant ( ) const
inline

Allows direct construction of QVariants from points.

Definition at line 346 of file qgspointxy.h.

## ◆ operator!=()

 bool QgsPointXY::operator!= ( const QgsPointXY & other ) const
inline

Inequality operator.

Definition at line 282 of file qgspointxy.h.

## ◆ operator*()

 QgsPointXY QgsPointXY::operator* ( double scalar ) const
inline

Multiplies the coordinates in this point by a scalar quantity.

Definition at line 334 of file qgspointxy.h.

## ◆ operator*=()

 QgsPointXY & QgsPointXY::operator*= ( double scalar )
inline

Multiplies the coordinates in this point by a scalar quantity in place.

Definition at line 340 of file qgspointxy.h.

## ◆ operator+()

 QgsPointXY QgsPointXY::operator+ ( QgsVector v ) const
inline

Adds a vector to this point.

Definition at line 328 of file qgspointxy.h.

## ◆ operator+=()

 QgsPointXY & QgsPointXY::operator+= ( QgsVector v )
inline

Adds a vector to this point in place.

Definition at line 322 of file qgspointxy.h.

## ◆ operator-() [1/2]

 QgsVector QgsPointXY::operator- ( const QgsPointXY & p ) const
inline

Calculates the vector obtained by subtracting a point from this point.

Definition at line 319 of file qgspointxy.h.

## ◆ operator-() [2/2]

 QgsPointXY QgsPointXY::operator- ( QgsVector v ) const
inline

Subtracts a vector from this point.

Definition at line 331 of file qgspointxy.h.

## ◆ operator-=()

 QgsPointXY & QgsPointXY::operator-= ( QgsVector v )
inline

Subtracts a vector from this point in place.

Definition at line 325 of file qgspointxy.h.

## ◆ operator/()

 QgsPointXY QgsPointXY::operator/ ( double scalar ) const
inline

Divides the coordinates in this point by a scalar quantity.

Definition at line 337 of file qgspointxy.h.

## ◆ operator/=()

 QgsPointXY & QgsPointXY::operator/= ( double scalar )
inline

Divides the coordinates in this point by a scalar quantity in place.

Definition at line 343 of file qgspointxy.h.

## ◆ operator=()

 QgsPointXY & QgsPointXY::operator= ( const QgsPointXY & other )
inline

Assignment.

Definition at line 306 of file qgspointxy.h.

## ◆ operator==()

 bool QgsPointXY::operator== ( const QgsPointXY & other )
inline

equality operator

Definition at line 265 of file qgspointxy.h.

## ◆ project()

 QgsPointXY QgsPointXY::project ( double distance, double bearing ) const

Returns a new point which corresponds to this point projected by a specified distance in a specified bearing.

Parameters
 distance distance to project bearing angle to project in, clockwise in degrees starting from north
Since
QGIS 2.16

Definition at line 87 of file qgspointxy.cpp.

## ◆ set()

 void QgsPointXY::set ( double x, double y )
inline

Sets the x and y value of the point.

Definition at line 140 of file qgspointxy.h.

## ◆ setX()

 void QgsPointXY::setX ( double x )
inline

Sets the x value of the point.

Parameters
 x x coordinate

Definition at line 123 of file qgspointxy.h.

## ◆ setY()

 void QgsPointXY::setY ( double y )
inline

Sets the y value of the point.

Parameters
 y y coordinate

Definition at line 133 of file qgspointxy.h.

## ◆ sqrDist() [1/2]

 double QgsPointXY::sqrDist ( const QgsPointXY & other ) const
inline

Returns the squared distance between this point another point.

distance()

Definition at line 200 of file qgspointxy.h.

## ◆ sqrDist() [2/2]

 double QgsPointXY::sqrDist ( double x, double y ) const
inline

Returns the squared distance between this point a specified x, y coordinate.

distance()

Definition at line 191 of file qgspointxy.h.

## ◆ sqrDistToSegment()

 double QgsPointXY::sqrDistToSegment ( double x1, double y1, double x2, double y2, QgsPointXY & minDistPoint, double epsilon = `DEFAULT_SEGMENT_EPSILON` ) const

Returns the minimum distance between this point and a segment.

Definition at line 95 of file qgspointxy.cpp.

## ◆ toQPointF()

 QPointF QgsPointXY::toQPointF ( ) const
inline

Converts a point to a QPointF.

Returns
QPointF with same x and y values
Since
QGIS 2.7

Definition at line 170 of file qgspointxy.h.

## ◆ toString()

 QString QgsPointXY::toString ( int precision = `-1` ) const

Returns a string representation of the point (x, y) with a preset precision.

If precision is -1, then a default precision will be used.

Definition at line 51 of file qgspointxy.cpp.

## ◆ x()

 double QgsPointXY::x ( ) const
inline

Gets the x value of the point.

Returns
x coordinate

Definition at line 151 of file qgspointxy.h.

## ◆ y()

 double QgsPointXY::y ( ) const
inline

Gets the y value of the point.

Returns
y coordinate

Definition at line 160 of file qgspointxy.h.

## ◆ qHash

 uint qHash ( const QgsPointXY & pnt )
friend

Definition at line 431 of file qgspointxy.h.

## ◆ x

 double QgsPointXY::x

Definition at line 63 of file qgspointxy.h.

## ◆ y

 double QgsPointXY::y