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