QGIS API Documentation 3.37.0-Master (fdefdf9c27f)
qgspoint.cpp
Go to the documentation of this file.
1/***************************************************************************
2 qgspointv2.cpp
3 --------------
4 begin : September 2014
5 copyright : (C) 2014 by Marco Hugentobler
6 email : marco at sourcepole dot ch
7 ***************************************************************************/
8
9/***************************************************************************
10 * *
11 * This program is free software; you can redistribute it and/or modify *
12 * it under the terms of the GNU General Public License as published by *
13 * the Free Software Foundation; either version 2 of the License, or *
14 * (at your option) any later version. *
15 * *
16 ***************************************************************************/
17
18
19#include "qgspoint.h"
20#include "qgsapplication.h"
22#include "qgsgeometryutils.h"
23#include "qgsmaptopixel.h"
24#include "qgswkbptr.h"
26#include "qgsbox3d.h"
27
28#include <cmath>
29#include <QPainter>
30#include <QPainterPath>
31#include <QRegularExpression>
32#include <QJsonObject>
33#include <QJsonArray>
34#include <nlohmann/json.hpp>
35
36/***************************************************************************
37 * This class is considered CRITICAL and any change MUST be accompanied with
38 * full unit tests.
39 * See details in QEP #17
40 ****************************************************************************/
41
42QgsPoint::QgsPoint( double x, double y, double z, double m, Qgis::WkbType wkbType )
43 : mX( x )
44 , mY( y )
45 , mZ( z )
46 , mM( m )
47{
49 {
52 }
53 else if ( std::isnan( z ) )
54 {
55 if ( std::isnan( m ) )
57 else
59 }
60 else if ( std::isnan( m ) )
62 else
64}
65
67 : mX( p.x() )
68 , mY( p.y() )
69 , mZ( std::numeric_limits<double>::quiet_NaN() )
70 , mM( std::numeric_limits<double>::quiet_NaN() )
71{
73 if ( p.isEmpty() )
74 {
75 mX = std::numeric_limits<double>::quiet_NaN();
76 mY = std::numeric_limits<double>::quiet_NaN();
77 }
78}
79
81 : mX( p.x() )
82 , mY( p.y() )
83 , mZ( std::numeric_limits<double>::quiet_NaN() )
84 , mM( std::numeric_limits<double>::quiet_NaN() )
85{
87}
88
89QgsPoint::QgsPoint( Qgis::WkbType wkbType, double x, double y, double z, double m )
90 : mX( x )
91 , mY( y )
92 , mZ( QgsWkbTypes::hasZ( wkbType ) ? z : std::numeric_limits<double>::quiet_NaN() )
93 , mM( QgsWkbTypes::hasM( wkbType ) ? m : std::numeric_limits<double>::quiet_NaN() )
94{
97}
98
99/***************************************************************************
100 * This class is considered CRITICAL and any change MUST be accompanied with
101 * full unit tests.
102 * See details in QEP #17
103 ****************************************************************************/
104
106{
107 return new QgsPoint( *this );
108}
109
110QgsPoint *QgsPoint::snappedToGrid( double hSpacing, double vSpacing, double dSpacing, double mSpacing ) const
111{
112 // helper function
113 auto gridifyValue = []( double value, double spacing, bool extraCondition = true ) -> double
114 {
115 if ( spacing > 0 && extraCondition )
116 return std::round( value / spacing ) * spacing;
117 else
118 return value;
119 };
120
121 // Get the new values
122 const auto x = gridifyValue( mX, hSpacing );
123 const auto y = gridifyValue( mY, vSpacing );
124 const auto z = gridifyValue( mZ, dSpacing, QgsWkbTypes::hasZ( mWkbType ) );
125 const auto m = gridifyValue( mM, mSpacing, QgsWkbTypes::hasM( mWkbType ) );
126
127 // return the new object
128 return new QgsPoint( mWkbType, x, y, z, m );
129}
130
132{
133 return false;
134}
135
137{
138 const Qgis::WkbType type = wkbPtr.readHeader();
140 {
141 clear();
142 return false;
143 }
144 mWkbType = type;
145
146 wkbPtr >> mX;
147 wkbPtr >> mY;
148 if ( is3D() )
149 wkbPtr >> mZ;
150 if ( isMeasure() )
151 wkbPtr >> mM;
152
153 clearCache();
154
155 return true;
156}
157
158/***************************************************************************
159 * This class is considered CRITICAL and any change MUST be accompanied with
160 * full unit tests.
161 * See details in QEP #17
162 ****************************************************************************/
163
164bool QgsPoint::fromWkt( const QString &wkt )
165{
166 clear();
167
168 QPair<Qgis::WkbType, QString> parts = QgsGeometryUtils::wktReadBlock( wkt );
169
171 return false;
172 mWkbType = parts.first;
173
174 QString secondWithoutParentheses = parts.second;
175 secondWithoutParentheses = secondWithoutParentheses.remove( '(' ).remove( ')' ).simplified().remove( ' ' );
176 parts.second = parts.second.remove( '(' ).remove( ')' );
177 if ( ( parts.second.compare( QLatin1String( "EMPTY" ), Qt::CaseInsensitive ) == 0 ) ||
178 secondWithoutParentheses.isEmpty() )
179 return true;
180
181 const thread_local QRegularExpression rx( QStringLiteral( "\\s" ) );
182 QStringList coordinates = parts.second.split( rx, Qt::SkipEmptyParts );
183
184 // So far the parser hasn't looked at the coordinates. We'll avoid having anything but numbers and return NULL instead of 0 as a coordinate.
185 // Without this check, "POINT (a, b)" or "POINT (( 4, 3 ))" returned "POINT (0 ,0)"
186 // And some strange conversion...
187 // .. python:
188 // p = QgsPoint()
189 // p.fromWkt("POINT (-3.12, -4.2")
190 // False
191 // p.fromWkt( "POINT (-5.1234, -1.4321)" )
192 // True
193 // p.asWkt()
194 // 'Point (0 -1.43209999999999993)'
195 const thread_local QRegularExpression rxIsNumber( QStringLiteral( "^[+-]?(\\d\\.?\\d*[Ee][+\\-]?\\d+|(\\d+\\.\\d*|\\d*\\.\\d+)|\\d+)$" ) );
196 if ( coordinates.filter( rxIsNumber ).size() != coordinates.size() )
197 return false;
198
199 if ( coordinates.size() < 2 )
200 {
201 clear();
202 return false;
203 }
204 else if ( coordinates.size() == 3 && !is3D() && !isMeasure() )
205 {
206 // 3 dimensional coordinates, but not specifically marked as such. We allow this
207 // anyway and upgrade geometry to have Z dimension
209 }
210 else if ( coordinates.size() >= 4 && ( !is3D() || !isMeasure() ) )
211 {
212 // 4 (or more) dimensional coordinates, but not specifically marked as such. We allow this
213 // anyway and upgrade geometry to have Z&M dimensions
216 }
217
218 int idx = 0;
219 mX = coordinates[idx++].toDouble();
220 mY = coordinates[idx++].toDouble();
221 if ( is3D() && coordinates.length() > 2 )
222 mZ = coordinates[idx++].toDouble();
223 if ( isMeasure() && coordinates.length() > 2 + is3D() )
224 mM = coordinates[idx++].toDouble();
225
226 return true;
227}
228
229/***************************************************************************
230 * This class is considered CRITICAL and any change MUST be accompanied with
231 * full unit tests.
232 * See details in QEP #17
233 ****************************************************************************/
234
236{
237 int binarySize = sizeof( char ) + sizeof( quint32 );
238 binarySize += ( 2 + is3D() + isMeasure() ) * sizeof( double );
239 return binarySize;
240}
241
242QByteArray QgsPoint::asWkb( WkbFlags flags ) const
243{
244 QByteArray wkbArray;
245 wkbArray.resize( QgsPoint::wkbSize( flags ) );
246 QgsWkbPtr wkb( wkbArray );
247 wkb << static_cast<char>( QgsApplication::endian() );
248 wkb << static_cast<quint32>( wkbType() );
249 wkb << mX << mY;
250 if ( is3D() )
251 {
252 wkb << mZ;
253 }
254 if ( isMeasure() )
255 {
256 wkb << mM;
257 }
258 return wkbArray;
259}
260
261QString QgsPoint::asWkt( int precision ) const
262{
263 QString wkt = wktTypeStr();
264
265 if ( isEmpty() )
266 wkt += QLatin1String( " EMPTY" );
267 else
268 {
269 wkt += QLatin1String( " (" );
270 wkt += qgsDoubleToString( mX, precision ) + ' ' + qgsDoubleToString( mY, precision );
271 if ( is3D() )
272 wkt += ' ' + qgsDoubleToString( mZ, precision );
273 if ( isMeasure() )
274 wkt += ' ' + qgsDoubleToString( mM, precision );
275 wkt += ')';
276 }
277 return wkt;
278}
279
280QDomElement QgsPoint::asGml2( QDomDocument &doc, int precision, const QString &ns, const QgsAbstractGeometry::AxisOrder axisOrder ) const
281{
282 QDomElement elemPoint = doc.createElementNS( ns, QStringLiteral( "Point" ) );
283 QDomElement elemCoordinates = doc.createElementNS( ns, QStringLiteral( "coordinates" ) );
284
285 // coordinate separator
286 const QString cs = QStringLiteral( "," );
287 // tuple separator
288 const QString ts = QStringLiteral( " " );
289
290 elemCoordinates.setAttribute( QStringLiteral( "cs" ), cs );
291 elemCoordinates.setAttribute( QStringLiteral( "ts" ), ts );
292
293 QString strCoordinates;
294 if ( axisOrder == QgsAbstractGeometry::AxisOrder::XY )
295 strCoordinates = qgsDoubleToString( mX, precision ) + cs + qgsDoubleToString( mY, precision );
296 else
297 strCoordinates = qgsDoubleToString( mY, precision ) + cs + qgsDoubleToString( mX, precision );
298 elemCoordinates.appendChild( doc.createTextNode( strCoordinates ) );
299 elemPoint.appendChild( elemCoordinates );
300 return elemPoint;
301}
302
303QDomElement QgsPoint::asGml3( QDomDocument &doc, int precision, const QString &ns, const QgsAbstractGeometry::AxisOrder axisOrder ) const
304{
305 QDomElement elemPoint = doc.createElementNS( ns, QStringLiteral( "Point" ) );
306 QDomElement elemPosList = doc.createElementNS( ns, QStringLiteral( "pos" ) );
307 elemPosList.setAttribute( QStringLiteral( "srsDimension" ), is3D() ? 3 : 2 );
308 QString strCoordinates;
309 if ( axisOrder == QgsAbstractGeometry::AxisOrder::XY )
310 strCoordinates = qgsDoubleToString( mX, precision ) + ' ' + qgsDoubleToString( mY, precision );
311 else
312 strCoordinates = qgsDoubleToString( mY, precision ) + ' ' + qgsDoubleToString( mX, precision );
313 if ( is3D() )
314 strCoordinates += ' ' + qgsDoubleToString( mZ, precision );
315
316 elemPosList.appendChild( doc.createTextNode( strCoordinates ) );
317 elemPoint.appendChild( elemPosList );
318 return elemPoint;
319}
320
321
323{
324 json j
325 {
326 { "type", "Point" },
327 { "coordinates", json::array() },
328 };
329 if ( ! isEmpty() )
330 {
331 j["coordinates"].push_back( qgsRound( mX, precision ) );
332 j["coordinates"].push_back( qgsRound( mY, precision ) );
333 if ( is3D() )
334 {
335 j["coordinates"].push_back( qgsRound( mZ, precision ) );
336 }
337 }
338 return j;
339}
340
341QString QgsPoint::asKml( int precision ) const
342{
343 return QStringLiteral( "<Point><coordinates>%1,%2</coordinates></Point>" ).arg( qgsDoubleToString( mX, precision ), qgsDoubleToString( mY, precision ) );
344}
345
346void QgsPoint::draw( QPainter &p ) const
347{
348 p.drawRect( QRectF( mX - 2, mY - 2, 4, 4 ) );
349}
350
351QPainterPath QgsPoint::asQPainterPath() const
352{
353 return QPainterPath();
354}
355
357{
358 mX = mY = std::numeric_limits<double>::quiet_NaN();
359 if ( is3D() )
360 mZ = 0.;
361 else
362 mZ = std::numeric_limits<double>::quiet_NaN();
363
364 if ( isMeasure() )
365 mM = 0.;
366 else
367 mM = std::numeric_limits<double>::quiet_NaN();
368
369 clearCache();
370}
371
372
373/***************************************************************************
374 * This class is considered CRITICAL and any change MUST be accompanied with
375 * full unit tests.
376 * See details in QEP #17
377 ****************************************************************************/
378
380{
381 clearCache();
382 if ( transformZ )
383 {
384 ct.transformInPlace( mX, mY, mZ, d );
385 }
386 else
387 {
388 double z = 0.0;
389 ct.transformInPlace( mX, mY, z, d );
390 }
391}
392
394{
396
397 cs.append( QgsRingSequence() );
398 cs.back().append( QgsPointSequence() << QgsPoint( *this ) );
399
400 return cs;
401}
402
404{
405 return 1;
406}
407
409{
410 if ( id.vertex != 0 )
411 return -1;
412 else
413 return 0;
414}
415
417{
418 return nullptr;
419}
420
422{
423 return true;
424}
425
426bool QgsPoint::insertVertex( QgsVertexId position, const QgsPoint &vertex )
427{
428 Q_UNUSED( position )
429 Q_UNUSED( vertex )
430 return false;
431}
432
433/***************************************************************************
434 * This class is considered CRITICAL and any change MUST be accompanied with
435 * full unit tests.
436 * See details in QEP #17
437 ****************************************************************************/
438
439bool QgsPoint::moveVertex( QgsVertexId position, const QgsPoint &newPos )
440{
441 Q_UNUSED( position )
442 clearCache();
443 mX = newPos.mX;
444 mY = newPos.mY;
445 if ( is3D() && newPos.is3D() )
446 {
447 mZ = newPos.mZ;
448 }
449 if ( isMeasure() && newPos.isMeasure() )
450 {
451 mM = newPos.mM;
452 }
453 return true;
454}
455
457{
458 Q_UNUSED( position )
459 return false;
460}
461
462double QgsPoint::closestSegment( const QgsPoint &pt, QgsPoint &segmentPt, QgsVertexId &vertexAfter, int *leftOf, double epsilon ) const
463{
464 Q_UNUSED( pt )
465 Q_UNUSED( segmentPt )
466 Q_UNUSED( vertexAfter )
467 if ( leftOf )
468 *leftOf = 0;
469 Q_UNUSED( epsilon )
470 return -1; // no segments - return error
471}
472
473bool QgsPoint::nextVertex( QgsVertexId &id, QgsPoint &vertex ) const
474{
475 if ( id.vertex < 0 )
476 {
477 id.vertex = 0;
478 if ( id.part < 0 )
479 {
480 id.part = 0;
481 }
482 if ( id.ring < 0 )
483 {
484 id.ring = 0;
485 }
486 vertex = *this;
487 return true;
488 }
489 else
490 {
491 return false;
492 }
493}
494
495void QgsPoint::adjacentVertices( QgsVertexId, QgsVertexId &previousVertex, QgsVertexId &nextVertex ) const
496{
497 previousVertex = QgsVertexId();
499}
500
501double QgsPoint::vertexAngle( QgsVertexId vertex ) const
502{
503 Q_UNUSED( vertex )
504 return 0.0;
505}
506
507int QgsPoint::vertexCount( int, int ) const
508{
509 return 1;
510}
511
512int QgsPoint::ringCount( int ) const
513{
514 return 1;
515}
516
518{
519 return 1;
520}
521
523{
524 return *this;
525}
526
528{
529 return clone();
530}
531
533{
534 return 0.0;
535}
536
537bool QgsPoint::boundingBoxIntersects( const QgsRectangle &rectangle ) const
538{
539 return rectangle.contains( mX, mY );
540}
541
543{
544 return box3d.contains( mX, mY, mZ );
545}
546
547/***************************************************************************
548 * This class is considered CRITICAL and any change MUST be accompanied with
549 * full unit tests.
550 * See details in QEP #17
551 ****************************************************************************/
552
553bool QgsPoint::addZValue( double zValue )
554{
556 return false;
557
559 mZ = zValue;
560 clearCache();
561 return true;
562}
563
564bool QgsPoint::addMValue( double mValue )
565{
567 return false;
568
570 mM = mValue;
571 clearCache();
572 return true;
573}
574
575void QgsPoint::transform( const QTransform &t, double zTranslate, double zScale, double mTranslate, double mScale )
576{
577 clearCache();
578 qreal x, y;
579 t.map( mX, mY, &x, &y );
580 mX = x;
581 mY = y;
582
583 if ( is3D() )
584 {
585 mZ = mZ * zScale + zTranslate;
586 }
587 if ( isMeasure() )
588 {
589 mM = mM * mScale + mTranslate;
590 }
591}
592
593
595{
596 if ( !is3D() )
597 return false;
598
600 mZ = std::numeric_limits<double>::quiet_NaN();
601 clearCache();
602 return true;
603}
604
606{
607 if ( !isMeasure() )
608 return false;
609
611 mM = std::numeric_limits<double>::quiet_NaN();
612 clearCache();
613 return true;
614}
615
617{
618 std::swap( mX, mY );
619 clearCache();
620}
621
623{
624 if ( type == mWkbType )
625 return true;
626
627 clearCache();
628
629 switch ( type )
630 {
632 mZ = std::numeric_limits<double>::quiet_NaN();
633 mM = std::numeric_limits<double>::quiet_NaN();
634 mWkbType = type;
635 return true;
638 mM = std::numeric_limits<double>::quiet_NaN();
639 mWkbType = type;
640 return true;
642 mZ = std::numeric_limits<double>::quiet_NaN();
643 mWkbType = type;
644 return true;
646 mWkbType = type;
647 return true;
648 default:
649 break;
650 }
651
652 return false;
653}
654
656{
657 if ( !transformer )
658 return false;
659
660 const bool res = transformer->transformPoint( mX, mY, mZ, mM );
661 clearCache();
662 return res;
663}
664
665void QgsPoint::filterVertices( const std::function<bool ( const QgsPoint & )> & )
666{
667 // no meaning for points
668}
669
670void QgsPoint::transformVertices( const std::function<QgsPoint( const QgsPoint & )> &transform )
671{
672 const QgsPoint res = transform( *this );
673 mX = res.x();
674 mY = res.y();
675 if ( is3D() )
676 mZ = res.z();
677 if ( isMeasure() )
678 mM = res.m();
679 clearCache();
680}
681
682double QgsPoint::azimuth( const QgsPoint &other ) const
683{
684 const double dx = other.x() - mX;
685 const double dy = other.y() - mY;
686 return ( std::atan2( dx, dy ) * 180.0 / M_PI );
687}
688
689double QgsPoint::inclination( const QgsPoint &other ) const
690{
691 const double distance = distance3D( other );
692 if ( qgsDoubleNear( distance, 0.0 ) )
693 {
694 return 90.0;
695 }
696 const double dz = other.z() - mZ;
697
698 return ( std::acos( dz / distance ) * 180.0 / M_PI );
699}
700
701QgsPoint QgsPoint::project( double distance, double azimuth, double inclination ) const
702{
703 Qgis::WkbType pType = mWkbType;
704 const double radsXy = azimuth * M_PI / 180.0;
705 double dx = 0.0, dy = 0.0, dz = 0.0;
706
707 inclination = std::fmod( inclination, 360.0 );
708
709 if ( !qgsDoubleNear( inclination, 90.0 ) )
710 pType = QgsWkbTypes::addZ( pType );
711
712 if ( !is3D() && qgsDoubleNear( inclination, 90.0 ) )
713 {
714 dx = distance * std::sin( radsXy );
715 dy = distance * std::cos( radsXy );
716 }
717 else
718 {
719 const double radsZ = inclination * M_PI / 180.0;
720 dx = distance * std::sin( radsZ ) * std::sin( radsXy );
721 dy = distance * std::sin( radsZ ) * std::cos( radsXy );
722 dz = distance * std::cos( radsZ );
723 }
724
725 return QgsPoint( mX + dx, mY + dy, mZ + dz, mM, pType );
726}
727
729{
730 // nothing to do
731}
732
734{
735 return std::isnan( mX ) || std::isnan( mY );
736}
737
739{
740 return QgsBox3D( mX, mY, mZ, mX, mY, mZ );
741}
742
744{
745 return QStringLiteral( "Point" );
746}
747
749{
750 return 0;
751}
752
754{
755 return 1;
756}
757
759{
760 Q_ASSERT( index == 0 );
761 return *this;
762}
763
765{
766 const double nan = std::numeric_limits<double>::quiet_NaN();
767 return new QgsPoint( nan, nan, nan, nan, mWkbType );
768}
769
771{
772 const QgsPoint *otherPoint = qgsgeometry_cast< const QgsPoint * >( other );
773 if ( !otherPoint )
774 return -1;
775
776 if ( mX < otherPoint->mX )
777 {
778 return -1;
779 }
780 else if ( mX > otherPoint->mX )
781 {
782 return 1;
783 }
784
785 if ( mY < otherPoint->mY )
786 {
787 return -1;
788 }
789 else if ( mY > otherPoint->mY )
790 {
791 return 1;
792 }
793
794 if ( is3D() && !otherPoint->is3D() )
795 return 1;
796 else if ( !is3D() && otherPoint->is3D() )
797 return -1;
798 else if ( is3D() && otherPoint->is3D() )
799 {
800 if ( mZ < otherPoint->mZ )
801 {
802 return -1;
803 }
804 else if ( mZ > otherPoint->mZ )
805 {
806 return 1;
807 }
808 }
809
810 if ( isMeasure() && !otherPoint->isMeasure() )
811 return 1;
812 else if ( !isMeasure() && otherPoint->isMeasure() )
813 return -1;
814 else if ( isMeasure() && otherPoint->isMeasure() )
815 {
816 if ( mM < otherPoint->mM )
817 {
818 return -1;
819 }
820 else if ( mM > otherPoint->mM )
821 {
822 return 1;
823 }
824 }
825
826 return 0;
827}
QFlags< GeometryValidityFlag > GeometryValidityFlags
Geometry validity flags.
Definition: qgis.h:1648
WkbType
The WKB type describes the number of dimensions a geometry has.
Definition: qgis.h:182
@ Unknown
Unknown.
@ PointM
PointM.
@ PointZ
PointZ.
@ Point25D
Point25D.
@ PointZM
PointZM.
TransformDirection
Indicates the direction (forward or inverse) of a transform.
Definition: qgis.h:2191
An abstract base class for classes which transform geometries by transforming input points to output ...
virtual bool transformPoint(double &x, double &y, double &z, double &m)=0
Transforms the point defined by the coordinates (x, y, z) and the specified m value.
Abstract base class for all geometries.
bool isMeasure() const
Returns true if the geometry contains m values.
QFlags< WkbFlag > WkbFlags
bool is3D() const
Returns true if the geometry is 3D and contains a z-value.
AxisOrder
Axis order for GML generation.
QString wktTypeStr() const
Returns the WKT type string of the geometry.
virtual void clearCache() const
Clears any cached parameters associated with the geometry, e.g., bounding boxes.
Qgis::WkbType wkbType() const
Returns the WKB type of the geometry.
QgsGeometryConstPartIterator parts() const
Returns Java-style iterator for traversal of parts of the geometry.
static endian_t endian()
Returns whether this machine uses big or little endian.
A 3-dimensional box composed of x, y, z coordinates.
Definition: qgsbox3d.h:43
bool contains(const QgsBox3D &other) const
Returns true when box contains other box.
Definition: qgsbox3d.cpp:149
A const WKB pointer.
Definition: qgswkbptr.h:138
Qgis::WkbType readHeader() const
readHeader
Definition: qgswkbptr.cpp:55
Class for doing transforms between two map coordinate systems.
void transformInPlace(double &x, double &y, double &z, Qgis::TransformDirection direction=Qgis::TransformDirection::Forward) const
Transforms an array of x, y and z double coordinates in place, from the source CRS to the destination...
Base class for feedback objects to be used for cancellation of something running in a worker thread.
Definition: qgsfeedback.h:44
static QPair< Qgis::WkbType, QString > wktReadBlock(const QString &wkt)
Parses a WKT block of the format "TYPE( contents )" and returns a pair of geometry type to contents (...
A class to represent a 2D point.
Definition: qgspointxy.h:60
bool isEmpty() const
Returns true if the geometry is empty.
Definition: qgspointxy.h:243
Point geometry type, with support for z-dimension and m-values.
Definition: qgspoint.h:49
int wkbSize(QgsAbstractGeometry::WkbFlags flags=QgsAbstractGeometry::WkbFlags()) const override
Returns the length of the QByteArray returned by asWkb()
Definition: qgspoint.cpp:235
QgsBox3D boundingBox3D() const override
Returns the 3D bounding box for the geometry.
Definition: qgspoint.cpp:738
bool fromWkb(QgsConstWkbPtr &wkb) override
Sets the geometry from a WKB string.
Definition: qgspoint.cpp:136
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...
Definition: qgspoint.cpp:665
double inclination(const QgsPoint &other) const
Calculates Cartesian inclination between this point and other one (starting from zenith = 0 to nadir ...
Definition: qgspoint.cpp:689
QgsCoordinateSequence coordinateSequence() const override
Retrieves the sequence of geometries, rings and nodes.
Definition: qgspoint.cpp:393
double vertexAngle(QgsVertexId vertex) const override
Angle undefined.
Definition: qgspoint.cpp:501
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.
Definition: qgspoint.cpp:303
bool addMValue(double mValue=0) override
Adds a measure to the geometry, initialized to a preset value.
Definition: qgspoint.cpp:564
QPainterPath asQPainterPath() const override
Returns the geometry represented as a QPainterPath.
Definition: qgspoint.cpp:351
QByteArray asWkb(QgsAbstractGeometry::WkbFlags=QgsAbstractGeometry::WkbFlags()) const override
Returns a WKB representation of the geometry.
Definition: qgspoint.cpp:242
double & rx()
Returns a reference to the x-coordinate of this point.
Definition: qgspoint.h:298
void clear() override
Clears the geometry, ie reset it to a null geometry.
Definition: qgspoint.cpp:356
bool fromWkt(const QString &wkt) override
Sets the geometry from a WKT string.
Definition: qgspoint.cpp:164
bool boundingBoxIntersects(const QgsRectangle &rectangle) const override
Returns true if the bounding box of this geometry intersects with a rectangle.
Definition: qgspoint.cpp:537
bool dropMValue() override
Drops any measure values which exist in the geometry.
Definition: qgspoint.cpp:605
bool insertVertex(QgsVertexId position, const QgsPoint &vertex) override
Inserts a vertex into the geometry.
Definition: qgspoint.cpp:426
double azimuth(const QgsPoint &other) const
Calculates Cartesian azimuth between this point and other one (clockwise in degree,...
Definition: qgspoint.cpp:682
void adjacentVertices(QgsVertexId vertex, QgsVertexId &previousVertex, QgsVertexId &nextVertex) const override
Returns the vertices adjacent to a specified vertex within a geometry.
Definition: qgspoint.cpp:495
bool addZValue(double zValue=0) override
Adds a z-dimension to the geometry, initialized to a preset value.
Definition: qgspoint.cpp:553
QgsAbstractGeometry * boundary() const override
Returns the closure of the combinatorial boundary of the geometry (ie the topological boundary of the...
Definition: qgspoint.cpp:416
void draw(QPainter &p) const override
Draws the geometry using the specified QPainter.
Definition: qgspoint.cpp:346
QgsPoint * toCurveType() const override
Returns the geometry converted to the more generic curve type.
Definition: qgspoint.cpp:527
QString asWkt(int precision=17) const override
Returns a WKT representation of the geometry.
Definition: qgspoint.cpp:261
QgsPoint childPoint(int index) const override
Returns point at index (for geometries without child geometries - i.e.
Definition: qgspoint.cpp:758
Q_GADGET double x
Definition: qgspoint.h:52
bool isValid(QString &error, Qgis::GeometryValidityFlags flags=Qgis::GeometryValidityFlags()) const override
Checks validity of the geometry, and returns true if the geometry is valid.
Definition: qgspoint.cpp:421
int dimension() const override
Returns the inherent dimension of the geometry.
Definition: qgspoint.cpp:748
QgsPoint * clone() const override
Clones the geometry by performing a deep copy.
Definition: qgspoint.cpp:105
double distance3D(double x, double y, double z) const
Returns the Cartesian 3D distance between this point and a specified x, y, z coordinate.
Definition: qgspoint.h:437
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.
Definition: qgspoint.cpp:462
int ringCount(int=0) const override
Returns the number of rings of which this geometry is built.
Definition: qgspoint.cpp:512
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.
Definition: qgspoint.cpp:280
QgsPoint vertexAt(QgsVertexId) const override
Returns the point corresponding to a specified vertex id.
Definition: qgspoint.cpp:522
QgsPoint * createEmptyWithSameType() const override
Creates a new geometry with the same class and same WKB type as the original and transfers ownership.
Definition: qgspoint.cpp:764
bool moveVertex(QgsVertexId position, const QgsPoint &newPos) override
Moves a vertex within the geometry.
Definition: qgspoint.cpp:439
void normalize() final
Reorganizes the geometry into a normalized form (or "canonical" form).
Definition: qgspoint.cpp:728
bool deleteVertex(QgsVertexId position) override
Deletes a vertex within the geometry.
Definition: qgspoint.cpp:456
double z
Definition: qgspoint.h:54
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.
Definition: qgspoint.cpp:670
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.
Definition: qgspoint.cpp:110
bool convertTo(Qgis::WkbType type) override
Converts the geometry to a specified type.
Definition: qgspoint.cpp:622
int compareToSameClass(const QgsAbstractGeometry *other) const final
Compares to an other geometry of the same class, and returns a integer for sorting of the two geometr...
Definition: qgspoint.cpp:770
int vertexNumberFromVertexId(QgsVertexId id) const override
Returns the vertex number corresponding to a vertex id.
Definition: qgspoint.cpp:408
int childCount() const override
Returns number of child geometries (for geometries with child geometries) or child points (for geomet...
Definition: qgspoint.cpp:753
bool isEmpty() const override
Returns true if the geometry is empty.
Definition: qgspoint.cpp:733
json asJsonObject(int precision=17) const override
Returns a json object representation of the geometry.
Definition: qgspoint.cpp:322
void transform(const QgsCoordinateTransform &ct, Qgis::TransformDirection d=Qgis::TransformDirection::Forward, bool transformZ=false) override
Transforms the geometry using a coordinate transform.
Definition: qgspoint.cpp:379
double distance(double x, double y) const
Returns the Cartesian 2D distance between this point and a specified x, y coordinate.
Definition: qgspoint.h:393
int vertexCount(int=0, int=0) const override
Returns the number of vertices of which this geometry is built.
Definition: qgspoint.cpp:507
int nCoordinates() const override
Returns the number of nodes contained in the geometry.
Definition: qgspoint.cpp:403
void swapXy() override
Swaps the x and y coordinates from the geometry.
Definition: qgspoint.cpp:616
QString geometryType() const override
Returns a unique string representing the geometry type.
Definition: qgspoint.cpp:743
double segmentLength(QgsVertexId startVertex) const override
Returns the length of the segment of the geometry which begins at startVertex.
Definition: qgspoint.cpp:532
bool dropZValue() override
Drops any z-dimensions which exist in the geometry.
Definition: qgspoint.cpp:594
double m
Definition: qgspoint.h:55
QgsPoint project(double distance, double azimuth, double inclination=90.0) const
Returns a new point which corresponds to this point projected by a specified distance with specified ...
Definition: qgspoint.cpp:701
double y
Definition: qgspoint.h:53
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(), Qgis::WkbType wkbType=Qgis::WkbType::Unknown)
Construct a point with the provided initial coordinate values.
Definition: qgspoint.cpp:42
bool nextVertex(QgsVertexId &id, QgsPoint &vertex) const override
Returns next vertex id and coordinates.
Definition: qgspoint.cpp:473
int partCount() const override
Returns count of parts contained in the geometry.
Definition: qgspoint.cpp:517
QString asKml(int precision=17) const override
Returns a KML representation of the geometry.
Definition: qgspoint.cpp:341
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...
Definition: qgspoint.cpp:131
A rectangle specified with double values.
Definition: qgsrectangle.h:42
bool contains(const QgsRectangle &rect) const
Returns true when rectangle contains other rectangle.
Definition: qgsrectangle.h:385
WKB pointer handler.
Definition: qgswkbptr.h:44
Handles storage of information regarding WKB types and their properties.
Definition: qgswkbtypes.h:42
static Qgis::WkbType dropM(Qgis::WkbType type)
Drops the m dimension (if present) for a WKB type and returns the new type.
Definition: qgswkbtypes.h:1144
static Qgis::WkbType dropZ(Qgis::WkbType type)
Drops the z dimension (if present) for a WKB type and returns the new type.
Definition: qgswkbtypes.h:1127
static Qgis::WkbType addM(Qgis::WkbType type)
Adds the m dimension to a WKB type and returns the new type.
Definition: qgswkbtypes.h:1092
static Qgis::WkbType addZ(Qgis::WkbType type)
Adds the z dimension to a WKB type and returns the new type.
Definition: qgswkbtypes.h:1068
static bool hasZ(Qgis::WkbType type)
Tests whether a WKB type contains the z-dimension.
Definition: qgswkbtypes.h:973
static bool hasM(Qgis::WkbType type)
Tests whether a WKB type contains m values.
Definition: qgswkbtypes.h:1023
static Qgis::WkbType flatType(Qgis::WkbType type)
Returns the flat type for a WKB type.
Definition: qgswkbtypes.h:628
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 ...
Definition: MathUtils.cpp:222
QString qgsDoubleToString(double a, int precision=17)
Returns a string representation of a double.
Definition: qgis.h:5124
double qgsRound(double number, int places)
Returns a double number, rounded (as close as possible) to the specified number of places.
Definition: qgis.h:5248
bool qgsDoubleNear(double a, double b, double epsilon=4 *std::numeric_limits< double >::epsilon())
Compare two doubles (but allow some difference)
Definition: qgis.h:5207
QVector< QgsRingSequence > QgsCoordinateSequence
QVector< QgsPointSequence > QgsRingSequence
QVector< QgsPoint > QgsPointSequence
int precision
Utility class for identifying a unique vertex within a geometry.
Definition: qgsvertexid.h:30