mirror of
https://github.com/qgis/QGIS.git
synced 2025-10-26 00:04:03 -04:00
The comparisons among QGIS were conducted on coordinates using a fixed epsilon: specifically, 1e-8 for QgsPoint and the default value for qgsDoubleNear: 4 * DBL_EPSILON. Initially, I've standardized its use to 1e-8 universally; it's already significantly adequate for our Cartesian cases (1e-3 should suffice for many), potentially fitting just right for geographical contexts. Furthermore, in response to precision concerns, we're using the fuzzyEqual and fuzzyDistanceEqual methods. These methods enable users/developers to compare geometries more easily and with a given precision. The API remains intact as operator==/equals() have been shifted into fuzzyEqual (with an epsilon of 1e-8). To consolidate the code between fuzzyEqual and fuzzyDistanceEqual, helper functions, fuzzyHelpers, have been introduced following the logic of the respective segments to be executed.
510 lines
17 KiB
Plaintext
510 lines
17 KiB
Plaintext
/************************************************************************
|
|
* This file has been generated automatically from *
|
|
* *
|
|
* src/core/geometry/qgspoint.h *
|
|
* *
|
|
* Do not edit manually ! Edit header and run scripts/sipify.pl again *
|
|
************************************************************************/
|
|
|
|
|
|
|
|
|
|
|
|
class QgsPoint: QgsAbstractGeometry
|
|
{
|
|
%Docstring(signature="appended")
|
|
Point geometry type, with support for z-dimension and m-values.
|
|
|
|
A :py:class:`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, :py:class:`QgsPoint` is
|
|
used as the low-level storage of geometry coordinates throughout QGIS.
|
|
|
|
In some scenarios it is preferable to use the :py:class:`QgsPointXY` class instead, which is
|
|
lighter and has smaller memory requirements compared to :py:class:`QgsPoint`. See the :py:class:`QgsPointXY`
|
|
documentation for examples of situations where it is appropriate to use :py:class:`QgsPointXY`
|
|
instead of :py:class:`QgsPoint`.
|
|
|
|
.. seealso:: :py:class:`QgsPointXY`
|
|
|
|
.. versionadded:: 3.0
|
|
%End
|
|
|
|
%TypeHeaderCode
|
|
#include "qgspoint.h"
|
|
%End
|
|
public:
|
|
static const QMetaObject staticMetaObject;
|
|
|
|
public:
|
|
|
|
QgsPoint( SIP_PYOBJECT x /TypeHint="Optional[Union[QgsPoint, QPointF, float]]"/ = Py_None, SIP_PYOBJECT y /TypeHint="Optional[float]"/ = Py_None, SIP_PYOBJECT z /TypeHint="Optional[float]"/ = Py_None, SIP_PYOBJECT m /TypeHint="Optional[float]"/ = Py_None, SIP_PYOBJECT wkbType /TypeHint="Optional[int]"/ = Py_None ) [( double x = 0.0, double y = 0.0, double z = 0.0, double m = 0.0, Qgis::WkbType wkbType = Qgis::WkbType::Unknown )];
|
|
%Docstring
|
|
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.
|
|
|
|
.. code-block:: python
|
|
|
|
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)
|
|
%End
|
|
%MethodCode
|
|
if ( sipCanConvertToType( a0, sipType_QgsPointXY, SIP_NOT_NONE ) && a1 == Py_None && a2 == Py_None && a3 == Py_None && a4 == Py_None )
|
|
{
|
|
int state;
|
|
sipIsErr = 0;
|
|
|
|
QgsPointXY *p = reinterpret_cast<QgsPointXY *>( sipConvertToType( a0, sipType_QgsPointXY, 0, SIP_NOT_NONE, &state, &sipIsErr ) );
|
|
if ( sipIsErr )
|
|
{
|
|
sipReleaseType( p, sipType_QgsPointXY, state );
|
|
}
|
|
else
|
|
{
|
|
sipCpp = new sipQgsPoint( QgsPoint( *p ) );
|
|
}
|
|
}
|
|
else if ( sipCanConvertToType( a0, sipType_QPointF, SIP_NOT_NONE ) && a1 == Py_None && a2 == Py_None && a3 == Py_None && a4 == Py_None )
|
|
{
|
|
int state;
|
|
sipIsErr = 0;
|
|
|
|
QPointF *p = reinterpret_cast<QPointF *>( sipConvertToType( a0, sipType_QPointF, 0, SIP_NOT_NONE, &state, &sipIsErr ) );
|
|
if ( sipIsErr )
|
|
{
|
|
sipReleaseType( p, sipType_QPointF, state );
|
|
}
|
|
else
|
|
{
|
|
sipCpp = new sipQgsPoint( QgsPoint( *p ) );
|
|
}
|
|
}
|
|
else if (
|
|
( a0 == Py_None || PyFloat_AsDouble( a0 ) != -1.0 || !PyErr_Occurred() ) &&
|
|
( a1 == Py_None || PyFloat_AsDouble( a1 ) != -1.0 || !PyErr_Occurred() ) &&
|
|
( a2 == Py_None || PyFloat_AsDouble( a2 ) != -1.0 || !PyErr_Occurred() ) &&
|
|
( a3 == Py_None || PyFloat_AsDouble( a3 ) != -1.0 || !PyErr_Occurred() ) )
|
|
{
|
|
double x = a0 == Py_None ? std::numeric_limits<double>::quiet_NaN() : PyFloat_AsDouble( a0 );
|
|
double y = a1 == Py_None ? std::numeric_limits<double>::quiet_NaN() : PyFloat_AsDouble( a1 );
|
|
double z = a2 == Py_None ? std::numeric_limits<double>::quiet_NaN() : PyFloat_AsDouble( a2 );
|
|
double m = a3 == Py_None ? std::numeric_limits<double>::quiet_NaN() : PyFloat_AsDouble( a3 );
|
|
Qgis::WkbType wkbType = a4 == Py_None ? Qgis::WkbType::Unknown : static_cast<Qgis::WkbType>( sipConvertToEnum( a4, sipType_Qgis_WkbType ) );
|
|
sipCpp = new sipQgsPoint( QgsPoint( x, y, z, m, wkbType ) );
|
|
}
|
|
else // Invalid ctor arguments
|
|
{
|
|
PyErr_SetString( PyExc_TypeError, QStringLiteral( "Invalid type in constructor arguments." ).toUtf8().constData() );
|
|
sipIsErr = 1;
|
|
}
|
|
%End
|
|
|
|
|
|
|
|
|
|
|
|
public:
|
|
virtual bool fuzzyEqual( const QgsAbstractGeometry &other, double epsilon = 1e-8 ) const /HoldGIL/;
|
|
|
|
virtual bool fuzzyDistanceEqual( const QgsAbstractGeometry &other, double epsilon = 1e-8 ) const /HoldGIL/;
|
|
|
|
virtual bool operator==( const QgsAbstractGeometry &other ) const /HoldGIL/;
|
|
|
|
virtual bool operator!=( const QgsAbstractGeometry &other ) const /HoldGIL/;
|
|
|
|
double x() const /HoldGIL/;
|
|
%Docstring
|
|
Returns the point's x-coordinate.
|
|
|
|
.. seealso:: :py:func:`setX`
|
|
|
|
.. seealso:: :py:func:`rx`
|
|
%End
|
|
|
|
double y() const /HoldGIL/;
|
|
%Docstring
|
|
Returns the point's y-coordinate.
|
|
|
|
.. seealso:: :py:func:`setY`
|
|
|
|
.. seealso:: :py:func:`ry`
|
|
%End
|
|
|
|
double z() const /HoldGIL/;
|
|
%Docstring
|
|
Returns the point's z-coordinate.
|
|
|
|
.. seealso:: :py:func:`setZ`
|
|
|
|
.. seealso:: :py:func:`rz`
|
|
%End
|
|
|
|
double m() const /HoldGIL/;
|
|
%Docstring
|
|
Returns the point's m value.
|
|
|
|
.. seealso:: :py:func:`setM`
|
|
|
|
.. seealso:: :py:func:`rm`
|
|
%End
|
|
|
|
|
|
|
|
|
|
|
|
void setX( double x ) /HoldGIL/;
|
|
%Docstring
|
|
Sets the point's x-coordinate.
|
|
|
|
.. seealso:: x
|
|
|
|
.. seealso:: :py:func:`rx`
|
|
%End
|
|
|
|
void setY( double y ) /HoldGIL/;
|
|
%Docstring
|
|
Sets the point's y-coordinate.
|
|
|
|
.. seealso:: y
|
|
|
|
.. seealso:: :py:func:`ry`
|
|
%End
|
|
|
|
void setZ( double z ) /HoldGIL/;
|
|
%Docstring
|
|
Sets the point's z-coordinate.
|
|
|
|
.. note::
|
|
|
|
calling this will have no effect if the point does not contain a z-dimension. Use :py:func:`~QgsPoint.addZValue` to
|
|
add a z value and force the point to have a z dimension.
|
|
|
|
.. seealso:: z
|
|
|
|
.. seealso:: :py:func:`rz`
|
|
%End
|
|
|
|
void setM( double m ) /HoldGIL/;
|
|
%Docstring
|
|
Sets the point's m-value.
|
|
|
|
.. note::
|
|
|
|
calling this will have no effect if the point does not contain a m-dimension. Use :py:func:`~QgsPoint.addMValue` to
|
|
add a m value and force the point to have an m dimension.
|
|
|
|
.. seealso:: m
|
|
|
|
.. seealso:: :py:func:`rm`
|
|
%End
|
|
|
|
QPointF toQPointF() const /HoldGIL/;
|
|
%Docstring
|
|
Returns the point as a QPointF.
|
|
|
|
.. versionadded:: 2.14
|
|
%End
|
|
|
|
double distance( double x, double y ) const /HoldGIL/;
|
|
%Docstring
|
|
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 :py:func:`~QgsPoint.distanceSquared` method, e.g.,
|
|
when comparing distances.
|
|
|
|
.. seealso:: :py:func:`distanceSquared`
|
|
|
|
.. versionadded:: 3.0
|
|
%End
|
|
|
|
double distance( const QgsPoint &other ) const /HoldGIL/;
|
|
%Docstring
|
|
Returns the Cartesian 2D distance between this point and another point. In certain
|
|
cases it may be more appropriate to call the faster :py:func:`~QgsPoint.distanceSquared` method, e.g.,
|
|
when comparing distances.
|
|
|
|
.. seealso:: :py:func:`distanceSquared`
|
|
|
|
.. versionadded:: 3.0
|
|
%End
|
|
|
|
double distanceSquared( double x, double y ) const /HoldGIL/;
|
|
%Docstring
|
|
Returns the Cartesian 2D squared distance between this point a specified x, y coordinate. Calling
|
|
this is faster than calling :py:func:`~QgsPoint.distance`, and may be useful in use cases such as comparing
|
|
distances where the extra expense of calling :py:func:`~QgsPoint.distance` is not required.
|
|
|
|
.. seealso:: :py:func:`distance`
|
|
|
|
.. versionadded:: 3.0
|
|
%End
|
|
|
|
double distanceSquared( const QgsPoint &other ) const /HoldGIL/;
|
|
%Docstring
|
|
Returns the Cartesian 2D squared distance between this point another point. Calling
|
|
this is faster than calling :py:func:`~QgsPoint.distance`, and may be useful in use cases such as comparing
|
|
distances where the extra expense of calling :py:func:`~QgsPoint.distance` is not required.
|
|
|
|
.. seealso:: :py:func:`distance`
|
|
|
|
.. versionadded:: 3.0
|
|
%End
|
|
|
|
double distance3D( double x, double y, double z ) const /HoldGIL/;
|
|
%Docstring
|
|
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 :py:func:`~QgsPoint.distanceSquared3D` method, e.g.,
|
|
when comparing distances.
|
|
|
|
.. seealso:: :py:func:`distanceSquared3D`
|
|
|
|
.. versionadded:: 3.0
|
|
%End
|
|
|
|
double distance3D( const QgsPoint &other ) const /HoldGIL/;
|
|
%Docstring
|
|
Returns the Cartesian 3D distance between this point and another point. In certain
|
|
cases it may be more appropriate to call the faster :py:func:`~QgsPoint.distanceSquared3D` method, e.g.,
|
|
when comparing distances.
|
|
|
|
.. seealso:: :py:func:`distanceSquared3D`
|
|
|
|
.. versionadded:: 3.0
|
|
%End
|
|
|
|
double distanceSquared3D( double x, double y, double z ) const /HoldGIL/;
|
|
%Docstring
|
|
Returns the Cartesian 3D squared distance between this point and a specified x, y, z coordinate. Calling
|
|
this is faster than calling :py:func:`~QgsPoint.distance3D`, and may be useful in use cases such as comparing
|
|
distances where the extra expense of calling :py:func:`~QgsPoint.distance3D` is not required.
|
|
|
|
.. seealso:: :py:func:`distance3D`
|
|
|
|
.. versionadded:: 3.0
|
|
%End
|
|
|
|
double distanceSquared3D( const QgsPoint &other ) const /HoldGIL/;
|
|
%Docstring
|
|
Returns the Cartesian 3D squared distance between this point and another point. Calling
|
|
this is faster than calling :py:func:`~QgsPoint.distance3D`, and may be useful in use cases such as comparing
|
|
distances where the extra expense of calling :py:func:`~QgsPoint.distance3D` is not required.
|
|
|
|
.. seealso:: :py:func:`distance3D`
|
|
|
|
.. versionadded:: 3.0
|
|
%End
|
|
|
|
double azimuth( const QgsPoint &other ) const /HoldGIL/;
|
|
%Docstring
|
|
Calculates Cartesian azimuth between this point and other one (clockwise in degree, starting from north)
|
|
|
|
.. versionadded:: 3.0
|
|
%End
|
|
|
|
double inclination( const QgsPoint &other ) const /HoldGIL/;
|
|
%Docstring
|
|
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).
|
|
|
|
.. versionadded:: 3.0
|
|
%End
|
|
|
|
QgsPoint project( double distance, double azimuth, double inclination = 90.0 ) const /HoldGIL/;
|
|
%Docstring
|
|
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.
|
|
|
|
:param distance: distance to project
|
|
:param azimuth: angle to project in X Y, clockwise in degrees starting from north
|
|
:param inclination: angle to project in Z (3D). If the point is 2D, the Z value is assumed to be 0.
|
|
|
|
:return: 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
|
|
-------
|
|
|
|
.. code-block:: python
|
|
|
|
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)'
|
|
|
|
.. versionadded:: 3.0
|
|
%End
|
|
|
|
QgsVector operator-( const QgsPoint &p ) const /HoldGIL/;
|
|
|
|
QgsPoint &operator+=( QgsVector v ) /HoldGIL/;
|
|
|
|
QgsPoint &operator-=( QgsVector v ) /HoldGIL/;
|
|
|
|
QgsPoint operator+( QgsVector v ) const /HoldGIL/;
|
|
|
|
QgsPoint operator-( QgsVector v ) const /HoldGIL/;
|
|
|
|
void normalize() final /HoldGIL/;
|
|
virtual bool isEmpty() const /HoldGIL/;
|
|
|
|
virtual QgsBox3D boundingBox3D() const /HoldGIL/;
|
|
|
|
virtual QString geometryType() const /HoldGIL/;
|
|
|
|
virtual int dimension() const /HoldGIL/;
|
|
|
|
virtual QgsPoint *clone() const /Factory/;
|
|
|
|
virtual QgsPoint *snappedToGrid( double hSpacing, double vSpacing, double dSpacing = 0, double mSpacing = 0 ) const /Factory/;
|
|
|
|
virtual bool removeDuplicateNodes( double epsilon = 4 * DBL_EPSILON, bool useZValues = false );
|
|
|
|
virtual void clear();
|
|
|
|
virtual bool fromWkb( QgsConstWkbPtr &wkb );
|
|
|
|
virtual bool fromWkt( const QString &wkt );
|
|
|
|
virtual int wkbSize( QgsAbstractGeometry::WkbFlags flags = QgsAbstractGeometry::WkbFlags() ) const;
|
|
|
|
virtual QByteArray asWkb( QgsAbstractGeometry::WkbFlags = QgsAbstractGeometry::WkbFlags() ) const;
|
|
|
|
virtual QString asWkt( int precision = 17 ) const;
|
|
|
|
virtual QDomElement asGml2( QDomDocument &doc, int precision = 17, const QString &ns = "gml", QgsAbstractGeometry::AxisOrder axisOrder = QgsAbstractGeometry::AxisOrder::XY ) const;
|
|
|
|
virtual QDomElement asGml3( QDomDocument &doc, int precision = 17, const QString &ns = "gml", QgsAbstractGeometry::AxisOrder axisOrder = QgsAbstractGeometry::AxisOrder::XY ) const;
|
|
|
|
virtual QString asKml( int precision = 17 ) const;
|
|
|
|
virtual void draw( QPainter &p ) const;
|
|
|
|
virtual QPainterPath asQPainterPath() const;
|
|
|
|
virtual void transform( const QgsCoordinateTransform &ct, Qgis::TransformDirection d = Qgis::TransformDirection::Forward, bool transformZ = false ) throw( QgsCsException );
|
|
|
|
virtual void transform( const QTransform &t, double zTranslate = 0.0, double zScale = 1.0, double mTranslate = 0.0, double mScale = 1.0 );
|
|
|
|
virtual QgsCoordinateSequence coordinateSequence() const;
|
|
|
|
virtual int nCoordinates() const /HoldGIL/;
|
|
|
|
virtual int vertexNumberFromVertexId( QgsVertexId id ) const;
|
|
|
|
virtual QgsAbstractGeometry *boundary() const /Factory/;
|
|
|
|
virtual bool isValid( QString &error /Out/, Qgis::GeometryValidityFlags flags = Qgis::GeometryValidityFlags() ) const /HoldGIL/;
|
|
|
|
|
|
virtual bool insertVertex( QgsVertexId position, const QgsPoint &vertex );
|
|
|
|
virtual bool moveVertex( QgsVertexId position, const QgsPoint &newPos );
|
|
|
|
virtual bool deleteVertex( QgsVertexId position );
|
|
|
|
|
|
virtual double closestSegment( const QgsPoint &pt, QgsPoint &segmentPt /Out/, QgsVertexId &vertexAfter /Out/, int *leftOf /Out/ = 0, double epsilon = 4 * DBL_EPSILON ) const;
|
|
|
|
virtual bool nextVertex( QgsVertexId &id, QgsPoint &vertex /Out/ ) const;
|
|
|
|
virtual void adjacentVertices( QgsVertexId vertex, QgsVertexId &previousVertex /Out/, QgsVertexId &nextVertex /Out/ ) const;
|
|
|
|
|
|
virtual double vertexAngle( QgsVertexId vertex ) const;
|
|
|
|
%Docstring
|
|
Angle undefined. Always returns 0.0
|
|
|
|
:param vertex: the vertex id
|
|
|
|
:return: 0.0
|
|
%End
|
|
|
|
virtual int vertexCount( int /*part*/ = 0, int /*ring*/ = 0 ) const;
|
|
|
|
virtual int ringCount( int /*part*/ = 0 ) const;
|
|
|
|
virtual int partCount() const;
|
|
|
|
virtual QgsPoint vertexAt( QgsVertexId /*id*/ ) const;
|
|
|
|
virtual QgsPoint *toCurveType() const /Factory/;
|
|
|
|
virtual double segmentLength( QgsVertexId startVertex ) const;
|
|
|
|
virtual bool boundingBoxIntersects( const QgsRectangle &rectangle ) const /HoldGIL/;
|
|
|
|
virtual bool boundingBoxIntersects( const QgsBox3D &box3d ) const /HoldGIL/;
|
|
|
|
|
|
virtual bool addZValue( double zValue = 0 );
|
|
|
|
virtual bool addMValue( double mValue = 0 );
|
|
|
|
virtual bool dropZValue();
|
|
|
|
virtual bool dropMValue();
|
|
|
|
virtual void swapXy();
|
|
|
|
virtual bool convertTo( Qgis::WkbType type );
|
|
|
|
|
|
virtual bool transform( QgsAbstractGeometryTransformer *transformer, QgsFeedback *feedback = 0 );
|
|
|
|
|
|
|
|
virtual QgsPoint *createEmptyWithSameType() const /Factory/;
|
|
|
|
|
|
SIP_PYOBJECT __repr__();
|
|
%MethodCode
|
|
QString str = QStringLiteral( "<QgsPoint: %1>" ).arg( sipCpp->asWkt() );
|
|
sipRes = PyUnicode_FromString( str.toUtf8().constData() );
|
|
%End
|
|
|
|
protected:
|
|
|
|
int compareToSameClass( const QgsAbstractGeometry *other ) const final;
|
|
virtual int childCount() const;
|
|
|
|
virtual QgsPoint childPoint( int index ) const;
|
|
|
|
|
|
};
|
|
|
|
|
|
/************************************************************************
|
|
* This file has been generated automatically from *
|
|
* *
|
|
* src/core/geometry/qgspoint.h *
|
|
* *
|
|
* Do not edit manually ! Edit header and run scripts/sipify.pl again *
|
|
************************************************************************/
|