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