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