Class: QgsPoint¶
- class qgis.core.QgsPoint(x: object = Py_None, y: object = Py_None, z: object = Py_None, m: object = Py_None, wkbType: object = Py_None)¶
Bases:
QgsAbstractGeometry
Construct a point with the provided initial coordinate values.
If
wkbType
is set to QgsWkbTypes.Point, QgsWkbTypes.PointZ, QgsWkbTypes.PointM or QgsWkbTypes.PointZM the type will be set accordingly. If it is left to the default QgsWkbTypes.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.asWkt() # PointZ(120 343 77) pt_m = QgsPoint(33, 88, m=5) pt_m.m() # 5 pt_m.wkbType() # QgsWkbTypes.PointM pt = QgsPoint(30, 40, wkbType=QgsWkbTypes.PointZ) pt.z() # nan pt.wkbType() # QgsWkbTypes.PointZ
QgsPoint(
QgsPoint
)Point geometry type, with support for z-dimension and m-values.
Methods
- param mValue
- param zValue
- param vertex
- param doc
- param doc
- param precision
- rtype
QPainterPath
- rtype
QByteArray
- param precision
Calculates Cartesian azimuth between this point and other one (clockwise in degree, starting from north)
- rtype
QgsAbstractGeometry
- rtype
QgsRectangle
Default calculator for the minimal bounding box for the geometry.
- rtype
int
Returns pointer to child geometry (for geometries with child geometries - i.e. geom.
- param index
Clears any cached parameters associated with the geometry, e.g., bounding boxes
- rtype
QgsPoint
- param pt
- param type
- rtype
object
- rtype
QgsPoint
- param position
- rtype
int
Returns the Cartesian 2D distance between this point and a specified x, y coordinate.
Returns the Cartesian 3D distance between this point and a specified x, y, z coordinate.
Returns the Cartesian 2D squared distance between this point a specified x, y coordinate.
Returns the Cartesian 3D squared distance between this point and a specified x, y, z coordinate.
- param p
- rtype
bool
- rtype
bool
- param wkb
- param wkt
- rtype
str
Returns whether the geometry has any child geometries (
False
for point / curve,True
otherwise)Calculates Cartesian inclination between this point and other one (starting from zenith = 0 to nadir = 180.
- param position
- rtype
bool
- param flags
Returns the point’s m value.
- param position
- rtype
int
- param id
- rtype
int
Returns a new point which corresponds to this point projected by a specified distance with specified angles (azimuth and inclination), using Cartesian mathematics.
- param epsilon
- rtype
int
- param startVertex
Sets the point’s m-value.
Sets the point’s x-coordinate.
Sets the point’s y-coordinate.
Sets the point’s z-coordinate.
Updates the geometry type based on whether sub geometries contain z or m values.
- param hSpacing
- rtype
QgsPoint
Returns the point as a QPointF.
- param ct
Angle undefined.
- rtype
QgsPoint
vertexCount
- rtype
int
- param id
- param flags
Returns the point’s x-coordinate.
Returns the point’s y-coordinate.
Returns the point’s z-coordinate.
Attributes
- addMValue(self, mValue: float = 0) → bool¶
- Parameters
mValue (float = 0) –
- Return type
bool
- addZValue(self, zValue: float = 0) → bool¶
- Parameters
zValue (float = 0) –
- Return type
bool
- adjacentVertices(self, vertex: QgsVertexId) → Tuple[QgsVertexId, QgsVertexId]¶
- Parameters
vertex (QgsVertexId) –
- Return type
Tuple[
QgsVertexId
, QgsVertexId]
- asGml2(self, doc: QDomDocument, precision: int = 17, ns: str = '', axisOrder: QgsAbstractGeometry.AxisOrder = QgsAbstractGeometry.AxisOrder.XY) → QDomElement¶
- Parameters
doc (QDomDocument) –
precision (int = 17) –
ns (str = '') –
axisOrder (QgsAbstractGeometry.AxisOrder = QgsAbstractGeometry.AxisOrder.XY) –
- Return type
QDomElement
- asGml3(self, doc: QDomDocument, precision: int = 17, ns: str = '', axisOrder: QgsAbstractGeometry.AxisOrder = QgsAbstractGeometry.AxisOrder.XY) → QDomElement¶
- Parameters
doc (QDomDocument) –
precision (int = 17) –
ns (str = '') –
axisOrder (QgsAbstractGeometry.AxisOrder = QgsAbstractGeometry.AxisOrder.XY) –
- Return type
QDomElement
- asKml(self, precision: int = 17) → str¶
- Parameters
precision (int = 17) –
- Return type
str
- asQPainterPath(self) → QPainterPath¶
- Return type
QPainterPath
- asWkb(self, Union[QgsAbstractGeometry.WkbFlags, QgsAbstractGeometry.WkbFlag] = QgsAbstractGeometry.WkbFlags()) → QByteArray¶
- Return type
QByteArray
- asWkt(self, precision: int = 17) → str¶
- Parameters
precision (int = 17) –
- Return type
str
- azimuth(self, other: QgsPoint) → float¶
Calculates Cartesian azimuth between this point and other one (clockwise in degree, starting from north)
New in version 3.0.
- Parameters
other (QgsPoint) –
- Return type
float
- boundary(self) → QgsAbstractGeometry¶
- Return type
- boundingBox(self) → QgsRectangle¶
- Return type
- calculateBoundingBox(self) → QgsRectangle¶
Default calculator for the minimal bounding box for the geometry. Derived classes should override this method if a more efficient bounding box calculation is available.
- childCount(self) → int¶
- Return type
int
- childGeometry(self, index: int) → QgsAbstractGeometry¶
Returns pointer to child geometry (for geometries with child geometries - i.e. geom. collection / polygon)
Note
used for vertex_iterator implementation
New in version 3.0.
- clear(self)¶
- clearCache(self)¶
Clears any cached parameters associated with the geometry, e.g., bounding boxes
- closestSegment(self, pt: QgsPoint, epsilon: float = 4 * DBL_EPSILON) → Tuple[float, QgsPoint, QgsVertexId, int]¶
- Parameters
pt (QgsPoint) –
epsilon (float = 4*DBL_EPSILON) –
- Return type
Tuple[float,
QgsPoint
,QgsVertexId
, int]
- convertTo(self, type: QgsWkbTypes.Type) → bool¶
- Parameters
type (QgsWkbTypes.Type) –
- Return type
bool
- coordinateSequence(self) → object¶
- Return type
object
- deleteVertex(self, position: QgsVertexId) → bool¶
- Parameters
position (QgsVertexId) –
- Return type
bool
- dimension(self) → int¶
- Return type
int
- distance(self, x: float, y: float) → float¶
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.See also
New in version 3.0.
distance(self, other:
QgsPoint
) -> float Returns the Cartesian 2D distance between this point and another point. In certain cases it may be more appropriate to call the fasterdistanceSquared()
method, e.g., when comparing distances.New in version 3.0.
- Parameters
x (float) –
y (float) –
- Return type
float
- distance3D(self, x: float, y: float, z: float) → float¶
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
distanceSquared()
method, e.g., when comparing distances.See also
New in version 3.0.
distance3D(self, other:
QgsPoint
) -> float Returns the Cartesian 3D distance between this point and another point. In certain cases it may be more appropriate to call the fasterdistanceSquared()
method, e.g., when comparing distances.New in version 3.0.
- Parameters
x (float) –
y (float) –
z (float) –
- Return type
float
- distanceSquared(self, x: float, y: float) → float¶
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 callingdistance()
is not required.See also
New in version 3.0.
distanceSquared(self, other:
QgsPoint
) -> float Returns the Cartesian 2D squared distance between this point another point. Calling this is faster than callingdistance()
, and may be useful in use cases such as comparing distances where the extra expense of callingdistance()
is not required.See also
New in version 3.0.
- Parameters
x (float) –
y (float) –
- Return type
float
- distanceSquared3D(self, x: float, y: float, z: float) → float¶
Returns the Cartesian 3D squared distance between this point and a specified x, y, z coordinate. Calling this is faster than calling
distance()
, and may be useful in use cases such as comparing distances where the extra expense of callingdistance()
is not required.See also
New in version 3.0.
distanceSquared3D(self, other:
QgsPoint
) -> float Returns the Cartesian 3D squared distance between this point and another point. Calling this is faster than callingdistance()
, and may be useful in use cases such as comparing distances where the extra expense of callingdistance()
is not required.See also
New in version 3.0.
- Parameters
x (float) –
y (float) –
z (float) –
- Return type
float
- draw(self, p: QPainter)¶
- Parameters
p (QPainter) –
- dropMValue(self) → bool¶
- Return type
bool
- dropZValue(self) → bool¶
- Return type
bool
- fromWkb(self, wkb: QgsConstWkbPtr) → bool¶
- Parameters
wkb (QgsConstWkbPtr) –
- Return type
bool
- fromWkt(self, wkt: str) → bool¶
- Parameters
wkt (str) –
- Return type
bool
- geometryType(self) → str¶
- Return type
str
- hasChildGeometries(self) → bool¶
Returns whether the geometry has any child geometries (
False
for point / curve,True
otherwise)Note
used for vertex_iterator implementation
New in version 3.0.
- inclination(self, other: QgsPoint) → float¶
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).
New in version 3.0.
- Parameters
other (QgsPoint) –
- Return type
float
- insertVertex(self, position: QgsVertexId, vertex: QgsPoint) → bool¶
- Parameters
position (QgsVertexId) –
vertex (QgsPoint) –
- Return type
bool
- isEmpty(self) → bool¶
- Return type
bool
- isValid(self, flags: int = 0) → Tuple[bool, str]¶
- Parameters
flags (int = 0) –
- Return type
Tuple[bool, str]
- moveVertex(self, position: QgsVertexId, newPos: QgsPoint) → bool¶
- Parameters
position (QgsVertexId) –
newPos (QgsPoint) –
- Return type
bool
- nCoordinates(self) → int¶
- Return type
int
- nextVertex(self, id: QgsVertexId) → Tuple[bool, QgsPoint]¶
- Parameters
id (QgsVertexId) –
- Return type
Tuple[bool, QgsPoint]
- partCount(self) → int¶
- Return type
int
- project(self, distance: float, azimuth: float, inclination: float = 90) → QgsPoint¶
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
- 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.
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 1)' p = QgsPoint( QgsWkbTypes.PointZ, 1, 2, 2 ) # 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)'
New in version 3.0.
- removeDuplicateNodes(self, epsilon: float = 4 * DBL_EPSILON, useZValues: bool = False) → bool¶
- Parameters
epsilon (float = 4*DBL_EPSILON) –
useZValues (bool = False) –
- Return type
bool
- ringCount(self, int=0) → int¶
- Return type
int
- segmentLength(self, startVertex: QgsVertexId) → float¶
- Parameters
startVertex (QgsVertexId) –
- Return type
float
- setM(self, m: float)¶
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)¶
Sets the point’s x-coordinate.
See also
x
See also
rx()
- Parameters
x (float) –
- setY(self, y: float)¶
Sets the point’s y-coordinate.
See also
y
See also
ry()
- Parameters
y (float) –
- setZ(self, z: float)¶
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) –
- setZMTypeFromSubGeometry(self, subggeom: QgsAbstractGeometry, baseGeomType: QgsWkbTypes.Type)¶
Updates the geometry type based on whether sub geometries contain z or m values.
- snappedToGrid(self, hSpacing: float, vSpacing: float, dSpacing: float = 0, mSpacing: float = 0) → QgsPoint¶
- Parameters
hSpacing (float) –
vSpacing (float) –
dSpacing (float = 0) –
mSpacing (float = 0) –
- Return type
- staticMetaObject = <PyQt5.QtCore.QMetaObject object>¶
- swapXy(self)¶
- toQPointF(self) → QPointF¶
Returns the point as a QPointF.
New in version 2.14.
- Return type
QPointF
- transform(self, ct: QgsCoordinateTransform, d: QgsCoordinateTransform.TransformDirection = QgsCoordinateTransform.ForwardTransform, transformZ: bool = False)¶
- transform(self, t: QTransform, zTranslate: float = 0, zScale: float = 1, mTranslate: float = 0, mScale: float = 1) → None
- transform(self, transformer: QgsAbstractGeometryTransformer, feedback: QgsFeedback = None) → bool
- Parameters
ct (QgsCoordinateTransform) –
d (QgsCoordinateTransform.TransformDirection = QgsCoordinateTransform.ForwardTransform) –
transformZ (bool = False) –
- vertexAngle(self, vertex: QgsVertexId) → float¶
Angle undefined. Always returns 0.0
- Parameters
vertex (QgsVertexId) – the vertex id
- Return type
float
- Returns
0.0
- QgsPoint.vertexCount(self, int = 0, int = 0) -> int
- Return type
int
- vertexNumberFromVertexId(self, id: QgsVertexId) → int¶
- Parameters
id (QgsVertexId) –
- Return type
int
- wkbSize(self, flags: Union[QgsAbstractGeometry.WkbFlags, QgsAbstractGeometry.WkbFlag] = QgsAbstractGeometry.WkbFlags()) → int¶
- Parameters
flags (Union[QgsAbstractGeometry.WkbFlags) –
- Return type
int