QGIS API Documentation
3.16.0-Hannover (43b64b13f3)
|
Go to the documentation of this file.
28 #include <QPainterPath>
29 #include <QRegularExpression>
30 #include <QJsonObject>
32 #include <nlohmann/json.hpp>
51 else if ( std::isnan(
z ) )
53 if ( std::isnan(
m ) )
58 else if ( std::isnan(
m ) )
67 , mZ( std::numeric_limits<double>::quiet_NaN() )
68 , mM( std::numeric_limits<double>::quiet_NaN() )
73 mX = std::numeric_limits<double>::quiet_NaN();
74 mY = std::numeric_limits<double>::quiet_NaN();
81 , mZ( std::numeric_limits<double>::quiet_NaN() )
82 , mM( std::numeric_limits<double>::quiet_NaN() )
90 , mZ(
QgsWkbTypes::hasZ( wkbType ) ? z : std::numeric_limits<double>::quiet_NaN() )
91 , mM(
QgsWkbTypes::hasM( wkbType ) ? m : std::numeric_limits<double>::quiet_NaN() )
111 auto gridifyValue = [](
double value,
double spacing,
bool extraCondition = true ) ->
double
113 if ( spacing > 0 && extraCondition )
114 return std::round( value / spacing ) * spacing;
120 auto x = gridifyValue( mX, hSpacing );
121 auto y = gridifyValue( mY, vSpacing );
172 QString secondWithoutParentheses =
parts.second;
173 secondWithoutParentheses = secondWithoutParentheses.remove(
'(' ).remove(
')' ).simplified().remove(
' ' );
174 parts.second =
parts.second.remove(
'(' ).remove(
')' );
175 if ( (
parts.second.compare( QLatin1String(
"EMPTY" ), Qt::CaseInsensitive ) == 0 ) ||
176 secondWithoutParentheses.isEmpty() )
179 QRegularExpression
rx( QStringLiteral(
"\\s" ) );
180 QStringList coordinates =
parts.second.split(
rx, QString::SkipEmptyParts );
193 QRegularExpression rxIsNumber( QStringLiteral(
"^[+-]?(\\d\\.?\\d*[Ee][+\\-]?\\d+|(\\d+\\.\\d*|\\d*\\.\\d+)|\\d+)$" ) );
194 if ( coordinates.filter( rxIsNumber ).size() != coordinates.size() )
197 if ( coordinates.size() < 2 )
202 else if ( coordinates.size() == 3 && !
is3D() && !
isMeasure() )
208 else if ( coordinates.size() >= 4 && ( !
is3D() || !
isMeasure() ) )
217 mX = coordinates[idx++].toDouble();
218 mY = coordinates[idx++].toDouble();
219 if (
is3D() && coordinates.length() > 2 )
220 mZ = coordinates[idx++].toDouble();
222 mM = coordinates[idx++].toDouble();
235 int binarySize =
sizeof( char ) +
sizeof( quint32 );
236 binarySize += ( 2 +
is3D() +
isMeasure() ) *
sizeof(
double );
246 wkb << static_cast<quint32>(
wkbType() );
264 wkt += QLatin1String(
" EMPTY" );
267 wkt += QLatin1String(
" (" );
280 QDomElement elemPoint = doc.createElementNS( ns, QStringLiteral(
"Point" ) );
281 QDomElement elemCoordinates = doc.createElementNS( ns, QStringLiteral(
"coordinates" ) );
284 QString cs = QStringLiteral(
"," );
286 QString ts = QStringLiteral(
" " );
288 elemCoordinates.setAttribute( QStringLiteral(
"cs" ), cs );
289 elemCoordinates.setAttribute( QStringLiteral(
"ts" ), ts );
291 QString strCoordinates;
292 if ( axisOrder == QgsAbstractGeometry::AxisOrder::XY )
296 elemCoordinates.appendChild( doc.createTextNode( strCoordinates ) );
297 elemPoint.appendChild( elemCoordinates );
303 QDomElement elemPoint = doc.createElementNS( ns, QStringLiteral(
"Point" ) );
304 QDomElement elemPosList = doc.createElementNS( ns, QStringLiteral(
"pos" ) );
305 elemPosList.setAttribute( QStringLiteral(
"srsDimension" ),
is3D() ? 3 : 2 );
306 QString strCoordinates;
307 if ( axisOrder == QgsAbstractGeometry::AxisOrder::XY )
314 elemPosList.appendChild( doc.createTextNode( strCoordinates ) );
315 elemPoint.appendChild( elemPosList );
325 {
"coordinates", json::array() },
346 p.drawRect( QRectF( mX - 2, mY - 2, 4, 4 ) );
351 return QPainterPath();
356 mX = mY = std::numeric_limits<double>::quiet_NaN();
360 mZ = std::numeric_limits<double>::quiet_NaN();
365 mM = std::numeric_limits<double>::quiet_NaN();
408 if (
id.vertex != 0 )
463 Q_UNUSED( segmentPt )
464 Q_UNUSED( vertexAfter )
563 void QgsPoint::transform(
const QTransform &t,
double zTranslate,
double zScale,
double mTranslate,
double mScale )
567 t.map( mX, mY, &
x, &
y );
573 mZ = mZ * zScale + zTranslate;
577 mM = mM * mScale + mTranslate;
588 mZ = std::numeric_limits<double>::quiet_NaN();
599 mM = std::numeric_limits<double>::quiet_NaN();
620 mZ = std::numeric_limits<double>::quiet_NaN();
621 mM = std::numeric_limits<double>::quiet_NaN();
626 mM = std::numeric_limits<double>::quiet_NaN();
630 mZ = std::numeric_limits<double>::quiet_NaN();
662 double zDistSquared = 0.0;
663 if (
is3D() || !std::isnan(
z ) )
664 zDistSquared = ( mZ -
z ) * ( mZ -
z );
666 return std::sqrt( ( mX -
x ) * ( mX -
x ) + ( mY -
y ) * ( mY -
y ) + zDistSquared );
671 double zDistSquared = 0.0;
673 zDistSquared = ( mZ - other.
z() ) * ( mZ - other.
z() );
675 return std::sqrt( ( mX - other.
x() ) * ( mX - other.
x() ) + ( mY - other.
y() ) * ( mY - other.
y() ) + zDistSquared );
680 double zDistSquared = 0.0;
681 if (
is3D() || !std::isnan(
z ) )
682 zDistSquared = ( mZ -
z ) * ( mZ -
z );
684 return ( mX -
x ) * ( mX -
x ) + ( mY -
y ) * ( mY -
y ) + zDistSquared;
689 double zDistSquared = 0.0;
691 zDistSquared = ( mZ - other.
z() ) * ( mZ - other.
z() );
693 return ( mX - other.
x() ) * ( mX - other.
x() ) + ( mY - other.
y() ) * ( mY - other.
y() ) + zDistSquared;
698 double dx = other.
x() - mX;
699 double dy = other.
y() - mY;
700 return ( std::atan2( dx, dy ) * 180.0 / M_PI );
710 double dz = other.
z() - mZ;
712 return ( std::acos( dz /
distance ) * 180.0 / M_PI );
718 double radsXy =
azimuth * M_PI / 180.0;
719 double dx = 0.0, dy = 0.0, dz = 0.0;
734 dx =
distance * std::sin( radsZ ) * std::sin( radsXy );
735 dy =
distance * std::sin( radsZ ) * std::cos( radsXy );
739 return QgsPoint( mX + dx, mY + dy, mZ + dz, mM, pType );
744 return std::isnan( mX ) || std::isnan( mY );
754 return QStringLiteral(
"Point" );
769 Q_ASSERT( index == 0 );
775 double nan = std::numeric_limits<double>::quiet_NaN();
int partCount() const override
Returns count of parts contained in the geometry.
QVector< QgsRingSequence > QgsCoordinateSequence
QDomElement asGml3(QDomDocument &doc, int precision=17, const QString &ns="gml", QgsAbstractGeometry::AxisOrder axisOrder=QgsAbstractGeometry::AxisOrder::XY) const override
Returns a GML3 representation of the geometry.
int ringCount(int=0) const override
Returns the number of rings of which this geometry is built.
json asJsonObject(int precision=17) const override
Returns a json object representation of the geometry.
static Type dropM(Type type) SIP_HOLDGIL
Drops the m dimension (if present) for a WKB type and returns the new type.
virtual void clearCache() const
Clears any cached parameters associated with the geometry, e.g., bounding boxes.
QgsPoint(double x=std::numeric_limits< double >::quiet_NaN(), double y=std::numeric_limits< double >::quiet_NaN(), double z=std::numeric_limits< double >::quiet_NaN(), double m=std::numeric_limits< double >::quiet_NaN(), QgsWkbTypes::Type wkbType=QgsWkbTypes::Unknown)
Construct a point with the provided initial coordinate values.
QString geometryType() const override SIP_HOLDGIL
Returns a unique string representing the geometry type.
QgsPoint vertexAt(QgsVertexId) const override
Returns the point corresponding to a specified vertex id.
bool fromWkb(QgsConstWkbPtr &wkb) override
Sets the geometry from a WKB string.
double distance(double x, double y) const SIP_HOLDGIL
Returns the Cartesian 2D distance between this point and a specified x, y coordinate.
Point geometry type, with support for z-dimension and m-values.
bool addZValue(double zValue=0) override
Adds a z-dimension to the geometry, initialized to a preset value.
QString asWkt(int precision=17) const override
Returns a WKT representation of the geometry.
void draw(QPainter &p) const override
Draws the geometry using the specified QPainter.
static Type flatType(Type type) SIP_HOLDGIL
Returns the flat type for a WKB type.
QgsGeometryConstPartIterator parts() const
Returns Java-style iterator for traversal of parts of the geometry.
double closestSegment(const QgsPoint &pt, QgsPoint &segmentPt, QgsVertexId &vertexAfter, int *leftOf=nullptr, double epsilon=4 *std::numeric_limits< double >::epsilon()) const override
Searches for the closest segment of the geometry to a given point.
void adjacentVertices(QgsVertexId vertex, QgsVertexId &previousVertex, QgsVertexId &nextVertex) const override
Returns the vertices adjacent to a specified vertex within a geometry.
void clear() override
Clears the geometry, ie reset it to a null geometry.
static Type addZ(Type type) SIP_HOLDGIL
Adds the z dimension to a WKB type and returns the new type.
QString wktTypeStr() const
Returns the WKT type string of the geometry.
QgsCoordinateSequence coordinateSequence() const override
Retrieves the sequence of geometries, rings and nodes.
Type
The WKB type describes the number of dimensions a geometry has.
bool isEmpty() const SIP_HOLDGIL
Returns true if the geometry is empty.
QgsWkbTypes::Type mWkbType
QgsPoint * toCurveType() const override
Returns the geometry converted to the more generic curve type.
A rectangle specified with double values.
int vertexCount(int=0, int=0) const override
Returns the number of vertices of which this geometry is built.
int vertexNumberFromVertexId(QgsVertexId id) const override
Returns the vertex number corresponding to a vertex id.
QgsPoint project(double distance, double azimuth, double inclination=90.0) const SIP_HOLDGIL
Returns a new point which correspond to this point projected by a specified distance with specified a...
QString qgsDoubleToString(double a, int precision=17)
Returns a string representation of a double.
void transformVertices(const std::function< QgsPoint(const QgsPoint &) > &transform) override
Transforms the vertices from the geometry in place, applying the transform function to every vertex.
bool dropMValue() override
Drops any measure values which exist in the geometry.
QgsPoint * clone() const override
Clones the geometry by performing a deep copy.
bool isMeasure() const SIP_HOLDGIL
Returns true if the geometry contains m values.
QgsPoint * snappedToGrid(double hSpacing, double vSpacing, double dSpacing=0, double mSpacing=0) const override
Makes a new geometry with all the points or vertices snapped to the closest point of the grid.
double ANALYSIS_EXPORT leftOf(const QgsPoint &thepoint, const QgsPoint *p1, const QgsPoint *p2)
Returns whether 'thepoint' is left or right of the line from 'p1' to 'p2'. Negative values mean left ...
static Type addM(Type type) SIP_HOLDGIL
Adds the m dimension to a WKB type and returns the new type.
double & rx()
Returns a reference to the x-coordinate of this point.
double segmentLength(QgsVertexId startVertex) const override
Returns the length of the segment of the geometry which begins at startVertex.
bool addMValue(double mValue=0) override
Adds a measure to the geometry, initialized to a preset value.
QgsWkbTypes::Type wkbType() const SIP_HOLDGIL
Returns the WKB type of the geometry.
AxisOrder
Axis order for GML generation.
int wkbSize(QgsAbstractGeometry::WkbFlags flags=QgsAbstractGeometry::WkbFlags()) const override
Returns the length of the QByteArray returned by asWkb()
bool qgsDoubleNear(double a, double b, double epsilon=4 *std::numeric_limits< double >::epsilon())
Compare two doubles (but allow some difference)
double azimuth(const QgsPoint &other) const SIP_HOLDGIL
Calculates Cartesian azimuth between this point and other one (clockwise in degree,...
double qgsRound(double number, int places)
Returns a double number, rounded (as close as possible) to the specified number of places.
bool dropZValue() override
Drops any z-dimensions which exist in the geometry.
double vertexAngle(QgsVertexId vertex) const override
Angle undefined.
static bool hasM(Type type) SIP_HOLDGIL
Tests whether a WKB type contains m values.
int nCoordinates() const override SIP_HOLDGIL
Returns the number of nodes contained in the geometry.
static endian_t endian()
Returns whether this machine uses big or little endian.
static Type dropZ(Type type) SIP_HOLDGIL
Drops the z dimension (if present) for a WKB type and returns the new type.
QgsAbstractGeometry * boundary() const override
Returns the closure of the combinatorial boundary of the geometry (ie the topological boundary of the...
QVector< QgsPointSequence > QgsRingSequence
int childCount() const override
Returns number of child geometries (for geometries with child geometries) or child points (for geomet...
Abstract base class for all geometries.
double inclination(const QgsPoint &other) const SIP_HOLDGIL
Calculates Cartesian inclination between this point and other one (starting from zenith = 0 to nadir ...
QDomElement asGml2(QDomDocument &doc, int precision=17, const QString &ns="gml", QgsAbstractGeometry::AxisOrder axisOrder=QgsAbstractGeometry::AxisOrder::XY) const override
Returns a GML2 representation of the geometry.
bool is3D() const SIP_HOLDGIL
Returns true if the geometry is 3D and contains a z-value.
bool removeDuplicateNodes(double epsilon=4 *std::numeric_limits< double >::epsilon(), bool useZValues=false) override
Removes duplicate nodes from the geometry, wherever removing the nodes does not result in a degenerat...
A class to represent a 2D point.
void swapXy() override
Swaps the x and y coordinates from the geometry.
QPainterPath asQPainterPath() const override
Returns the geometry represented as a QPainterPath.
int dimension() const override SIP_HOLDGIL
Returns the inherent dimension of the geometry.
bool moveVertex(QgsVertexId position, const QgsPoint &newPos) override
Moves a vertex within the geometry.
bool fromWkt(const QString &wkt) override
Sets the geometry from a WKT string.
QVector< QgsPoint > QgsPointSequence
QgsPoint childPoint(int index) const override
Returns point at index (for geometries without child geometries - i.e.
QByteArray asWkb(QgsAbstractGeometry::WkbFlags=QgsAbstractGeometry::WkbFlags()) const override
void transform(const QgsCoordinateTransform &ct, QgsCoordinateTransform::TransformDirection d=QgsCoordinateTransform::ForwardTransform, bool transformZ=false) override SIP_THROW(QgsCsException)
Transforms the geometry using a coordinate transform.
bool nextVertex(QgsVertexId &id, QgsPoint &vertex) const override
Returns next vertex id and coordinates.
Utility class for identifying a unique vertex within a geometry.
bool convertTo(QgsWkbTypes::Type type) override
Converts the geometry to a specified type.
static bool hasZ(Type type) SIP_HOLDGIL
Tests whether a WKB type contains the z-dimension.
double distanceSquared3D(double x, double y, double z) const SIP_HOLDGIL
Returns the Cartesian 3D squared distance between this point and a specified x, y,...
QgsPoint * createEmptyWithSameType() const override
Creates a new geometry with the same class and same WKB type as the original and transfers ownership.
bool isEmpty() const override SIP_HOLDGIL
Returns true if the geometry is empty.
Handles storage of information regarding WKB types and their properties.
QgsWkbTypes::Type readHeader() const
readHeader
static QPair< QgsWkbTypes::Type, QString > wktReadBlock(const QString &wkt)
Parses a WKT block of the format "TYPE( contents )" and returns a pair of geometry type to contents (...
QString asKml(int precision=17) const override
Returns a KML representation of the geometry.
void filterVertices(const std::function< bool(const QgsPoint &) > &filter) override
Filters the vertices from the geometry in place, removing any which do not return true for the filter...
bool isValid(QString &error, int flags=0) const override SIP_HOLDGIL
Checks validity of the geometry, and returns true if the geometry is valid.
QgsRectangle boundingBox() const override SIP_HOLDGIL
Returns the minimal bounding box for the geometry.
bool deleteVertex(QgsVertexId position) override
Deletes a vertex within the geometry.
bool insertVertex(QgsVertexId position, const QgsPoint &vertex) override
Inserts a vertex into the geometry.
double distance3D(double x, double y, double z) const SIP_HOLDGIL
Returns the Cartesian 3D distance between this point and a specified x, y, z coordinate.