Class: QgsPointXY¶
Represents 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.
See also
Class Hierarchy¶
Subclasses¶
A |
Methods
Returns the well known text representation for the point (e.g. "POINT(x y)"). |
|
Calculates azimuth between this point and other one (clockwise in degree, starting from north) |
|
Compares this point with another point with a fuzzy tolerance |
|
Returns the distance between this point and a specified x, y coordinate. |
|
Compares this point with another point with a fuzzy tolerance using distance comparison |
|
Returns |
|
Multiply x and y by the given value |
|
Returns a new point which corresponds to this point projected by a specified distance in a specified bearing. |
|
Sets the x and y value of the point |
|
Sets the x value of the point |
|
Sets the y value of the point |
|
Returns the squared distance between this point a specified x, y coordinate. |
|
Returns the minimum distance between this point and a segment |
|
Converts a point to a QPointF |
|
Returns a string representation of the point (x, y) with a preset precision. |
|
Gets the x value of the point |
|
Gets the y value of the point |
- class qgis.core.QgsPointXY[source]¶
Bases:
object
- __init__()
- __init__(p: QgsPointXY)
- Parameters:
p (QgsPointXY)
- __init__(x: float, y: float)
Create a point from x,y coordinates
- Parameters:
x (float) – x coordinate
y (float) – y coordinate
- __init__(point: QPointF | QPoint)
Create a point from a QPointF
- Parameters:
point (Union[QPointF, QPoint]) – QPointF source
- __init__(point: QPoint)
Create a point from a QPoint
- Parameters:
point (QPoint) – QPoint source
- __init__(point: QgsPoint)
Create a new point. Z and M values will be dropped.
- Parameters:
point (QgsPoint)
- asWkt(self) str [source]¶
Returns the well known text representation for the point (e.g. “POINT(x y)”). The wkt is created without an SRID.
- Return type:
str
- azimuth(self, other: QgsPointXY) float [source]¶
Calculates azimuth between this point and other one (clockwise in degree, starting from north)
- Parameters:
other (QgsPointXY)
- Return type:
float
- compare(self, other: QgsPointXY, epsilon: float = 4 * DBL_EPSILON) bool [source]¶
Compares this point with another point with a fuzzy tolerance
- Parameters:
other (QgsPointXY) – point to compare with
epsilon (float = 4*DBL_EPSILON) – maximum difference for coordinates between the points
- Return type:
bool
- Returns:
True
if points are equal within specified tolerance
See also
- distance(self, x: float, y: float) float [source]¶
Returns the distance between this point and a specified x, y coordinate.
- Parameters:
x (float) – x-coordniate
y (float) – y-coordinate
See also
- Return type:
float
- distance(self, other: QgsPointXY) float [source]
Returns the distance between this point and another point.
- Parameters:
other (
QgsPointXY
) – other point
See also
- Return type:
float
- distanceCompare(self, other: QgsPointXY, epsilon: float = 4 * DBL_EPSILON) bool [source]¶
Compares this point with another point with a fuzzy tolerance using distance comparison
- Parameters:
other (QgsPointXY) – point to compare with
epsilon (float = 4*DBL_EPSILON) – maximum difference for coordinates between the points
- Return type:
bool
- Returns:
True
if points are equal within specified tolerance
See also
Added in version 3.36.
- isEmpty(self) bool [source]¶
Returns
True
if the geometry is empty. UnlikeQgsPoint
, this class is also used to retrieve graphical coordinates like QPointF. It therefore has the default coordinates (0.0). AQgsPointXY
is considered empty, when the coordinates have not been explicitly filled in.Added in version 3.10.
- Return type:
bool
- multiply(self, scalar: float)[source]¶
Multiply x and y by the given value
- Parameters:
scalar (float)
- project(self, distance: float, bearing: float) QgsPointXY [source]¶
Returns a new point which corresponds to this point projected by a specified distance in a specified bearing.
- Parameters:
distance (float) – distance to project
bearing (float) – angle to project in, clockwise in degrees starting from north
- Return type:
- set(self, x: float, y: float)[source]¶
Sets the x and y value of the point
- Parameters:
x (float)
y (float)
- sqrDist(self, x: float, y: float) float [source]¶
Returns the squared distance between this point a specified x, y coordinate.
See also
- Parameters:
x (float)
y (float)
- Return type:
float
- sqrDist(self, other: QgsPointXY) float [source]
Returns the squared distance between this point another point.
See also
- Parameters:
other (
QgsPointXY
)- Return type:
float
- sqrDistToSegment(self, x1: float, y1: float, x2: float, y2: float, epsilon: float = Qgis.DEFAULT_SEGMENT_EPSILON)[source]¶
Returns the minimum distance between this point and a segment
- Parameters:
x1 (float)
y1 (float)
x2 (float)
y2 (float)
epsilon (float = Qgis.DEFAULT_SEGMENT_EPSILON) -> (float)
- toQPointF(self) QPointF [source]¶
Converts a point to a QPointF
- Return type:
QPointF
- Returns:
QPointF with same x and y values