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