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