Class: QgsPoint

Point geometry type, with support for z-dimension and m-values.

A QgsPoint represents a 2, 3 or 4-dimensional position, with X and Y and optional Z or M coordinates. Since it supports these additional dimensions, QgsPoint is used as the low-level storage of geometry coordinates throughout QGIS.

In some scenarios it is preferable to use the QgsPointXY class instead, which is lighter and has smaller memory requirements compared to QgsPoint. See the QgsPointXY documentation for examples of situations where it is appropriate to use QgsPointXY instead of QgsPoint.

See also

QgsPointXY

Class Hierarchy

Inheritance diagram of qgis.core.QgsPoint

Base classes

QgsAbstractGeometry

Abstract base class for all geometries.

Abstract Methods

vertexAngle

Angle undefined.

Methods

azimuth

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

distance

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

distance3D

Returns the Cartesian 3D distance between this point and a specified x, y, z coordinate.

distanceSquared

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

distanceSquared3D

Returns the Cartesian 3D squared distance between this point and a specified x, y, z coordinate.

inclination

Calculates Cartesian inclination between this point and other one (starting from zenith = 0 to nadir = 180.

m

Returns the point's m value.

project

Returns a new point which corresponds to this point projected by a specified distance with specified angles (azimuth and inclination), using Cartesian mathematics.

setM

Sets the point's m-value.

setX

Sets the point's x-coordinate.

setY

Sets the point's y-coordinate.

setZ

Sets the point's z-coordinate.

toQPointF

Returns the point as a QPointF.

x

Returns the point's x-coordinate.

y

Returns the point's y-coordinate.

z

Returns the point's z-coordinate.

class qgis.core.QgsPoint[source]

Bases: QgsAbstractGeometry

__init__(x: QgsPoint | QPointF | QPoint | float | None = Py_None, y: float | None = Py_None, z: float | None = Py_None, m: float | None = Py_None, wkbType: int | None = Py_None)

Construct a point with the provided initial coordinate values.

If wkbType is set to Qgis.WkbType.Point, Qgis.WkbType.PointZ, Qgis.WkbType.PointM or Qgis.WkbType.PointZM the type will be set accordingly. If it is left to the default Qgis.WkbType.Unknown, the type will be set based on the following rules:

  • If only x and y are specified, the type will be a 2D point.

  • If any or both of the Z and M are specified, the appropriate type will be created.

pt = QgsPoint(43.4, 5.3)
pt.asWkt() # Point(43.4 5.3)

pt_z = QgsPoint(120, 343, 77)
pt_z.asWkt() # PointZ(120 343 77)

pt_m = QgsPoint(33, 88, m=5)
pt_m.m() # 5
pt_m.wkbType() # 2001 (QgsWkbTypes.PointM)

pt = QgsPoint(30, 40, wkbType=QgsWkbTypes.PointZ)
pt.z() # nan
pt.wkbType() # 1001 (QgsWkbTypes.PointZ)
Parameters:
  • x (Optional[Union[QgsPoint, Union[QPointF, QPoint], float]] = Py_None)

  • y (Optional[float] = Py_None)

  • z (Optional[float] = Py_None)

  • m (Optional[float] = Py_None)

  • wkbType (Optional[int] = Py_None)

__init__(a0: QgsPoint)
Parameters:

a0 (QgsPoint)

azimuth(self, other: QgsPoint) float[source]

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

Parameters:

other (QgsPoint)

Return type:

float

distance(self, x: float, y: float) float[source]

Returns the Cartesian 2D distance between this point and a specified x, y coordinate. In certain cases it may be more appropriate to call the faster distanceSquared() method, e.g., when comparing distances.

Parameters:
  • x (float)

  • y (float)

Return type:

float

distance(self, other: QgsPoint) float[source]

Returns the Cartesian 2D distance between this point and another point. In certain cases it may be more appropriate to call the faster distanceSquared() method, e.g., when comparing distances.

Parameters:

other (QgsPoint)

Return type:

float

distance3D(self, x: float, y: float, z: float) float[source]

Returns the Cartesian 3D distance between this point and a specified x, y, z coordinate. In certain cases it may be more appropriate to call the faster distanceSquared3D() method, e.g., when comparing distances.

Parameters:
  • x (float)

  • y (float)

  • z (float)

Return type:

float

distance3D(self, other: QgsPoint) float[source]

Returns the Cartesian 3D distance between this point and another point. In certain cases it may be more appropriate to call the faster distanceSquared3D() method, e.g., when comparing distances.

Parameters:

other (QgsPoint)

Return type:

float

distanceSquared(self, x: float, y: float) float[source]

Returns the Cartesian 2D squared distance between this point a specified x, y coordinate. Calling this is faster than calling distance(), and may be useful in use cases such as comparing distances where the extra expense of calling distance() is not required.

See also

distance()

Parameters:
  • x (float)

  • y (float)

Return type:

float

distanceSquared(self, other: QgsPoint) float[source]

Returns the Cartesian 2D squared distance between this point another point. Calling this is faster than calling distance(), and may be useful in use cases such as comparing distances where the extra expense of calling distance() is not required.

See also

distance()

Parameters:

other (QgsPoint)

Return type:

float

distanceSquared3D(self, x: float, y: float, z: float) float[source]

Returns the Cartesian 3D squared distance between this point and a specified x, y, z coordinate. Calling this is faster than calling distance3D(), and may be useful in use cases such as comparing distances where the extra expense of calling distance3D() is not required.

See also

distance3D()

Parameters:
  • x (float)

  • y (float)

  • z (float)

Return type:

float

distanceSquared3D(self, other: QgsPoint) float[source]

Returns the Cartesian 3D squared distance between this point and another point. Calling this is faster than calling distance3D(), and may be useful in use cases such as comparing distances where the extra expense of calling distance3D() is not required.

See also

distance3D()

Parameters:

other (QgsPoint)

Return type:

float

inclination(self, other: QgsPoint) float[source]

Calculates Cartesian inclination between this point and other one (starting from zenith = 0 to nadir = 180. Horizon = 90) Returns 90.0 if the distance between this point and other one is equal to 0 (same point).

Parameters:

other (QgsPoint)

Return type:

float

m(self) float[source]

Returns the point’s m value.

See also

setM()

See also

rm()

Return type:

float

project(self, distance: float, azimuth: float, inclination: float = 90) QgsPoint[source]

Returns a new point which corresponds to this point projected by a specified distance with specified angles (azimuth and inclination), using Cartesian mathematics. M value is preserved.

Parameters:
  • distance (float) – distance to project

  • azimuth (float) – angle to project in X Y, clockwise in degrees starting from north

  • inclination (float = 90) – angle to project in Z (3D). If the point is 2D, the Z value is assumed to be 0.

Return type:

QgsPoint

Returns:

The point projected. If a 2D point is projected a 3D point will be returned except if inclination is 90. A 3D point is always returned if a 3D point is projected.

Example

p = QgsPoint( 1, 2 ) # 2D point
pr = p.project ( 1, 0 )
# pr is a 2D point: 'Point (1 3)'
pr = p.project ( 1, 0, 90 )
# pr is a 2D point: 'Point (1 3)'
pr = p.project (1, 0, 0 )
# pr is a 3D point: 'PointZ (1 2 nan)'
p = QgsPoint( 1, 2, 2, wkbType=QgsWkbTypes.PointZ ) # 3D point
pr = p.project ( 1, 0 )
# pr is a 3D point: 'PointZ (1 3 2)'
pr = p.project ( 1, 0, 90 )
# pr is a 3D point: 'PointZ (1 3 2)'
pr = p.project (1, 0, 0 )
# pr is a 3D point: 'PointZ (1 2 3)'
setM(self, m: float)[source]

Sets the point’s m-value.

Note

calling this will have no effect if the point does not contain a m-dimension. Use addMValue() to add a m value and force the point to have an m dimension.

See also

m

See also

rm()

Parameters:

m (float)

setX(self, x: float)[source]

Sets the point’s x-coordinate.

See also

x

See also

rx()

Parameters:

x (float)

setY(self, y: float)[source]

Sets the point’s y-coordinate.

See also

y

See also

ry()

Parameters:

y (float)

setZ(self, z: float)[source]

Sets the point’s z-coordinate.

Note

calling this will have no effect if the point does not contain a z-dimension. Use addZValue() to add a z value and force the point to have a z dimension.

See also

z

See also

rz()

Parameters:

z (float)

toQPointF(self) QPointF[source]

Returns the point as a QPointF.

Return type:

QPointF

abstract vertexAngle(self, vertex: QgsVertexId) float[source]

Angle undefined. Always returns 0.0

Parameters:

vertex (QgsVertexId) – the vertex id

Return type:

float

Returns:

0.0

x(self) float[source]

Returns the point’s x-coordinate.

See also

setX()

See also

rx()

Return type:

float

y(self) float[source]

Returns the point’s y-coordinate.

See also

setY()

See also

ry()

Return type:

float

z(self) float[source]

Returns the point’s z-coordinate.

See also

setZ()

See also

rz()

Return type:

float