QGIS API Documentation 3.34.0-Prizren (ffbdd678812)
Loading...
Searching...
No Matches
qgspoint.cpp
Go to the documentation of this file.
1/***************************************************************************
2 qgspointv2.cpp
3 --------------
4 begin : September 2014
5 copyright : (C) 2014 by Marco Hugentobler
6 email : marco at sourcepole dot ch
7 ***************************************************************************/
8
9/***************************************************************************
10 * *
11 * This program is free software; you can redistribute it and/or modify *
12 * it under the terms of the GNU General Public License as published by *
13 * the Free Software Foundation; either version 2 of the License, or *
14 * (at your option) any later version. *
15 * *
16 ***************************************************************************/
17
18
19#include "qgspoint.h"
20#include "qgsapplication.h"
22#include "qgsgeometryutils.h"
23#include "qgsmaptopixel.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 ) 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 false;
134}
135
137{
138 const Qgis::WkbType type = wkbPtr.readHeader();
140 {
141 clear();
142 return false;
143 }
144 mWkbType = type;
145
146 wkbPtr >> mX;
147 wkbPtr >> mY;
148 if ( is3D() )
149 wkbPtr >> mZ;
150 if ( isMeasure() )
151 wkbPtr >> mM;
152
153 clearCache();
154
155 return true;
156}
157
158/***************************************************************************
159 * This class is considered CRITICAL and any change MUST be accompanied with
160 * full unit tests.
161 * See details in QEP #17
162 ****************************************************************************/
163
164bool QgsPoint::fromWkt( const QString &wkt )
165{
166 clear();
167
168 QPair<Qgis::WkbType, QString> parts = QgsGeometryUtils::wktReadBlock( wkt );
169
171 return false;
172 mWkbType = parts.first;
173
174 QString secondWithoutParentheses = parts.second;
175 secondWithoutParentheses = secondWithoutParentheses.remove( '(' ).remove( ')' ).simplified().remove( ' ' );
176 parts.second = parts.second.remove( '(' ).remove( ')' );
177 if ( ( parts.second.compare( QLatin1String( "EMPTY" ), Qt::CaseInsensitive ) == 0 ) ||
178 secondWithoutParentheses.isEmpty() )
179 return true;
180
181 const thread_local QRegularExpression rx( QStringLiteral( "\\s" ) );
182#if QT_VERSION < QT_VERSION_CHECK(5, 15, 0)
183 QStringList coordinates = parts.second.split( rx, QString::SkipEmptyParts );
184#else
185 QStringList coordinates = parts.second.split( rx, Qt::SkipEmptyParts );
186#endif
187
188 // So far the parser hasn't looked at the coordinates. We'll avoid having anything but numbers and return NULL instead of 0 as a coordinate.
189 // Without this check, "POINT (a, b)" or "POINT (( 4, 3 ))" returned "POINT (0 ,0)"
190 // And some strange conversion...
191 // .. python:
192 // p = QgsPoint()
193 // p.fromWkt("POINT (-3.12, -4.2")
194 // False
195 // p.fromWkt( "POINT (-5.1234, -1.4321)" )
196 // True
197 // p.asWkt()
198 // 'Point (0 -1.43209999999999993)'
199 const thread_local QRegularExpression rxIsNumber( QStringLiteral( "^[+-]?(\\d\\.?\\d*[Ee][+\\-]?\\d+|(\\d+\\.\\d*|\\d*\\.\\d+)|\\d+)$" ) );
200 if ( coordinates.filter( rxIsNumber ).size() != coordinates.size() )
201 return false;
202
203 if ( coordinates.size() < 2 )
204 {
205 clear();
206 return false;
207 }
208 else if ( coordinates.size() == 3 && !is3D() && !isMeasure() )
209 {
210 // 3 dimensional coordinates, but not specifically marked as such. We allow this
211 // anyway and upgrade geometry to have Z dimension
213 }
214 else if ( coordinates.size() >= 4 && ( !is3D() || !isMeasure() ) )
215 {
216 // 4 (or more) dimensional coordinates, but not specifically marked as such. We allow this
217 // anyway and upgrade geometry to have Z&M dimensions
220 }
221
222 int idx = 0;
223 mX = coordinates[idx++].toDouble();
224 mY = coordinates[idx++].toDouble();
225 if ( is3D() && coordinates.length() > 2 )
226 mZ = coordinates[idx++].toDouble();
227 if ( isMeasure() && coordinates.length() > 2 + is3D() )
228 mM = coordinates[idx++].toDouble();
229
230 return true;
231}
232
233/***************************************************************************
234 * This class is considered CRITICAL and any change MUST be accompanied with
235 * full unit tests.
236 * See details in QEP #17
237 ****************************************************************************/
238
239int QgsPoint::wkbSize( WkbFlags ) const
240{
241 int binarySize = sizeof( char ) + sizeof( quint32 );
242 binarySize += ( 2 + is3D() + isMeasure() ) * sizeof( double );
243 return binarySize;
244}
245
246QByteArray QgsPoint::asWkb( WkbFlags flags ) const
247{
248 QByteArray wkbArray;
249 wkbArray.resize( QgsPoint::wkbSize( flags ) );
250 QgsWkbPtr wkb( wkbArray );
251 wkb << static_cast<char>( QgsApplication::endian() );
252 wkb << static_cast<quint32>( wkbType() );
253 wkb << mX << mY;
254 if ( is3D() )
255 {
256 wkb << mZ;
257 }
258 if ( isMeasure() )
259 {
260 wkb << mM;
261 }
262 return wkbArray;
263}
264
265QString QgsPoint::asWkt( int precision ) const
266{
267 QString wkt = wktTypeStr();
268
269 if ( isEmpty() )
270 wkt += QLatin1String( " EMPTY" );
271 else
272 {
273 wkt += QLatin1String( " (" );
274 wkt += qgsDoubleToString( mX, precision ) + ' ' + qgsDoubleToString( mY, precision );
275 if ( is3D() )
276 wkt += ' ' + qgsDoubleToString( mZ, precision );
277 if ( isMeasure() )
278 wkt += ' ' + qgsDoubleToString( mM, precision );
279 wkt += ')';
280 }
281 return wkt;
282}
283
284QDomElement QgsPoint::asGml2( QDomDocument &doc, int precision, const QString &ns, const QgsAbstractGeometry::AxisOrder axisOrder ) const
285{
286 QDomElement elemPoint = doc.createElementNS( ns, QStringLiteral( "Point" ) );
287 QDomElement elemCoordinates = doc.createElementNS( ns, QStringLiteral( "coordinates" ) );
288
289 // coordinate separator
290 const QString cs = QStringLiteral( "," );
291 // tuple separator
292 const QString ts = QStringLiteral( " " );
293
294 elemCoordinates.setAttribute( QStringLiteral( "cs" ), cs );
295 elemCoordinates.setAttribute( QStringLiteral( "ts" ), ts );
296
297 QString strCoordinates;
298 if ( axisOrder == QgsAbstractGeometry::AxisOrder::XY )
299 strCoordinates = qgsDoubleToString( mX, precision ) + cs + qgsDoubleToString( mY, precision );
300 else
301 strCoordinates = qgsDoubleToString( mY, precision ) + cs + qgsDoubleToString( mX, precision );
302 elemCoordinates.appendChild( doc.createTextNode( strCoordinates ) );
303 elemPoint.appendChild( elemCoordinates );
304 return elemPoint;
305}
306
307QDomElement QgsPoint::asGml3( QDomDocument &doc, int precision, const QString &ns, const QgsAbstractGeometry::AxisOrder axisOrder ) const
308{
309 QDomElement elemPoint = doc.createElementNS( ns, QStringLiteral( "Point" ) );
310 QDomElement elemPosList = doc.createElementNS( ns, QStringLiteral( "pos" ) );
311 elemPosList.setAttribute( QStringLiteral( "srsDimension" ), is3D() ? 3 : 2 );
312 QString strCoordinates;
313 if ( axisOrder == QgsAbstractGeometry::AxisOrder::XY )
314 strCoordinates = qgsDoubleToString( mX, precision ) + ' ' + qgsDoubleToString( mY, precision );
315 else
316 strCoordinates = qgsDoubleToString( mY, precision ) + ' ' + qgsDoubleToString( mX, precision );
317 if ( is3D() )
318 strCoordinates += ' ' + qgsDoubleToString( mZ, precision );
319
320 elemPosList.appendChild( doc.createTextNode( strCoordinates ) );
321 elemPoint.appendChild( elemPosList );
322 return elemPoint;
323}
324
325
327{
328 json j
329 {
330 { "type", "Point" },
331 { "coordinates", json::array() },
332 };
333 if ( ! isEmpty() )
334 {
335 j["coordinates"].push_back( qgsRound( mX, precision ) );
336 j["coordinates"].push_back( qgsRound( mY, precision ) );
337 if ( is3D() )
338 {
339 j["coordinates"].push_back( qgsRound( mZ, precision ) );
340 }
341 }
342 return j;
343}
344
345QString QgsPoint::asKml( int precision ) const
346{
347 return QStringLiteral( "<Point><coordinates>%1,%2</coordinates></Point>" ).arg( qgsDoubleToString( mX, precision ), qgsDoubleToString( mY, precision ) );
348}
349
350void QgsPoint::draw( QPainter &p ) const
351{
352 p.drawRect( QRectF( mX - 2, mY - 2, 4, 4 ) );
353}
354
355QPainterPath QgsPoint::asQPainterPath() const
356{
357 return QPainterPath();
358}
359
361{
362 mX = mY = std::numeric_limits<double>::quiet_NaN();
363 if ( is3D() )
364 mZ = 0.;
365 else
366 mZ = std::numeric_limits<double>::quiet_NaN();
367
368 if ( isMeasure() )
369 mM = 0.;
370 else
371 mM = std::numeric_limits<double>::quiet_NaN();
372
373 clearCache();
374}
375
376
377/***************************************************************************
378 * This class is considered CRITICAL and any change MUST be accompanied with
379 * full unit tests.
380 * See details in QEP #17
381 ****************************************************************************/
382
384{
385 clearCache();
386 if ( transformZ )
387 {
388 ct.transformInPlace( mX, mY, mZ, d );
389 }
390 else
391 {
392 double z = 0.0;
393 ct.transformInPlace( mX, mY, z, d );
394 }
395}
396
398{
400
401 cs.append( QgsRingSequence() );
402 cs.back().append( QgsPointSequence() << QgsPoint( *this ) );
403
404 return cs;
405}
406
408{
409 return 1;
410}
411
413{
414 if ( id.vertex != 0 )
415 return -1;
416 else
417 return 0;
418}
419
421{
422 return nullptr;
423}
424
425bool QgsPoint::isValid( QString &, Qgis::GeometryValidityFlags ) const
426{
427 return true;
428}
429
430bool QgsPoint::insertVertex( QgsVertexId position, const QgsPoint &vertex )
431{
432 Q_UNUSED( position )
433 Q_UNUSED( vertex )
434 return false;
435}
436
437/***************************************************************************
438 * This class is considered CRITICAL and any change MUST be accompanied with
439 * full unit tests.
440 * See details in QEP #17
441 ****************************************************************************/
442
443bool QgsPoint::moveVertex( QgsVertexId position, const QgsPoint &newPos )
444{
445 Q_UNUSED( position )
446 clearCache();
447 mX = newPos.mX;
448 mY = newPos.mY;
449 if ( is3D() && newPos.is3D() )
450 {
451 mZ = newPos.mZ;
452 }
453 if ( isMeasure() && newPos.isMeasure() )
454 {
455 mM = newPos.mM;
456 }
457 return true;
458}
459
461{
462 Q_UNUSED( position )
463 return false;
464}
465
466double QgsPoint::closestSegment( const QgsPoint &pt, QgsPoint &segmentPt, QgsVertexId &vertexAfter, int *leftOf, double epsilon ) const
467{
468 Q_UNUSED( pt )
469 Q_UNUSED( segmentPt )
470 Q_UNUSED( vertexAfter )
471 if ( leftOf )
472 *leftOf = 0;
473 Q_UNUSED( epsilon )
474 return -1; // no segments - return error
475}
476
477bool QgsPoint::nextVertex( QgsVertexId &id, QgsPoint &vertex ) const
478{
479 if ( id.vertex < 0 )
480 {
481 id.vertex = 0;
482 if ( id.part < 0 )
483 {
484 id.part = 0;
485 }
486 if ( id.ring < 0 )
487 {
488 id.ring = 0;
489 }
490 vertex = *this;
491 return true;
492 }
493 else
494 {
495 return false;
496 }
497}
498
499void QgsPoint::adjacentVertices( QgsVertexId, QgsVertexId &previousVertex, QgsVertexId &nextVertex ) const
500{
501 previousVertex = QgsVertexId();
503}
504
505double QgsPoint::vertexAngle( QgsVertexId vertex ) const
506{
507 Q_UNUSED( vertex )
508 return 0.0;
509}
510
511int QgsPoint::vertexCount( int, int ) const
512{
513 return 1;
514}
515
516int QgsPoint::ringCount( int ) const
517{
518 return 1;
519}
520
522{
523 return 1;
524}
525
527{
528 return *this;
529}
530
532{
533 return clone();
534}
535
537{
538 return 0.0;
539}
540
541bool QgsPoint::boundingBoxIntersects( const QgsRectangle &rectangle ) const
542{
543 return rectangle.contains( mX, mY );
544}
545
547{
548 return box3d.contains( mX, mY, mZ );
549}
550
551/***************************************************************************
552 * This class is considered CRITICAL and any change MUST be accompanied with
553 * full unit tests.
554 * See details in QEP #17
555 ****************************************************************************/
556
557bool QgsPoint::addZValue( double zValue )
558{
560 return false;
561
563 mZ = zValue;
564 clearCache();
565 return true;
566}
567
568bool QgsPoint::addMValue( double mValue )
569{
571 return false;
572
574 mM = mValue;
575 clearCache();
576 return true;
577}
578
579void QgsPoint::transform( const QTransform &t, double zTranslate, double zScale, double mTranslate, double mScale )
580{
581 clearCache();
582 qreal x, y;
583 t.map( mX, mY, &x, &y );
584 mX = x;
585 mY = y;
586
587 if ( is3D() )
588 {
589 mZ = mZ * zScale + zTranslate;
590 }
591 if ( isMeasure() )
592 {
593 mM = mM * mScale + mTranslate;
594 }
595}
596
597
599{
600 if ( !is3D() )
601 return false;
602
604 mZ = std::numeric_limits<double>::quiet_NaN();
605 clearCache();
606 return true;
607}
608
610{
611 if ( !isMeasure() )
612 return false;
613
615 mM = std::numeric_limits<double>::quiet_NaN();
616 clearCache();
617 return true;
618}
619
621{
622 std::swap( mX, mY );
623 clearCache();
624}
625
627{
628 if ( type == mWkbType )
629 return true;
630
631 clearCache();
632
633 switch ( type )
634 {
636 mZ = std::numeric_limits<double>::quiet_NaN();
637 mM = std::numeric_limits<double>::quiet_NaN();
638 mWkbType = type;
639 return true;
642 mM = std::numeric_limits<double>::quiet_NaN();
643 mWkbType = type;
644 return true;
646 mZ = std::numeric_limits<double>::quiet_NaN();
647 mWkbType = type;
648 return true;
650 mWkbType = type;
651 return true;
652 default:
653 break;
654 }
655
656 return false;
657}
658
660{
661 if ( !transformer )
662 return false;
663
664 const bool res = transformer->transformPoint( mX, mY, mZ, mM );
665 clearCache();
666 return res;
667}
668
669void QgsPoint::filterVertices( const std::function<bool ( const QgsPoint & )> & )
670{
671 // no meaning for points
672}
673
674void QgsPoint::transformVertices( const std::function<QgsPoint( const QgsPoint & )> &transform )
675{
676 const QgsPoint res = transform( *this );
677 mX = res.x();
678 mY = res.y();
679 if ( is3D() )
680 mZ = res.z();
681 if ( isMeasure() )
682 mM = res.m();
683 clearCache();
684}
685
686double QgsPoint::distance3D( double x, double y, double z ) const
687{
688 double zDistSquared = 0.0;
689 if ( is3D() || !std::isnan( z ) )
690 zDistSquared = ( mZ - z ) * ( mZ - z );
691
692 return std::sqrt( ( mX - x ) * ( mX - x ) + ( mY - y ) * ( mY - y ) + zDistSquared );
693}
694
695double QgsPoint::distance3D( const QgsPoint &other ) const
696{
697 double zDistSquared = 0.0;
698 if ( is3D() || other.is3D() )
699 zDistSquared = ( mZ - other.z() ) * ( mZ - other.z() );
700
701 return std::sqrt( ( mX - other.x() ) * ( mX - other.x() ) + ( mY - other.y() ) * ( mY - other.y() ) + zDistSquared );
702}
703
704double QgsPoint::distanceSquared3D( double x, double y, double z ) const
705{
706 double zDistSquared = 0.0;
707 if ( is3D() || !std::isnan( z ) )
708 zDistSquared = ( mZ - z ) * ( mZ - z );
709
710 return ( mX - x ) * ( mX - x ) + ( mY - y ) * ( mY - y ) + zDistSquared;
711}
712
713double QgsPoint::distanceSquared3D( const QgsPoint &other ) const
714{
715 double zDistSquared = 0.0;
716 if ( is3D() || other.is3D() )
717 zDistSquared = ( mZ - other.z() ) * ( mZ - other.z() );
718
719 return ( mX - other.x() ) * ( mX - other.x() ) + ( mY - other.y() ) * ( mY - other.y() ) + zDistSquared;
720}
721
722double QgsPoint::azimuth( const QgsPoint &other ) const
723{
724 const double dx = other.x() - mX;
725 const double dy = other.y() - mY;
726 return ( std::atan2( dx, dy ) * 180.0 / M_PI );
727}
728
729double QgsPoint::inclination( const QgsPoint &other ) const
730{
731 const double distance = distance3D( other );
732 if ( qgsDoubleNear( distance, 0.0 ) )
733 {
734 return 90.0;
735 }
736 const double dz = other.z() - mZ;
737
738 return ( std::acos( dz / distance ) * 180.0 / M_PI );
739}
740
741QgsPoint QgsPoint::project( double distance, double azimuth, double inclination ) const
742{
743 Qgis::WkbType pType = mWkbType;
744 const double radsXy = azimuth * M_PI / 180.0;
745 double dx = 0.0, dy = 0.0, dz = 0.0;
746
747 inclination = std::fmod( inclination, 360.0 );
748
749 if ( !qgsDoubleNear( inclination, 90.0 ) )
750 pType = QgsWkbTypes::addZ( pType );
751
752 if ( !is3D() && qgsDoubleNear( inclination, 90.0 ) )
753 {
754 dx = distance * std::sin( radsXy );
755 dy = distance * std::cos( radsXy );
756 }
757 else
758 {
759 const double radsZ = inclination * M_PI / 180.0;
760 dx = distance * std::sin( radsZ ) * std::sin( radsXy );
761 dy = distance * std::sin( radsZ ) * std::cos( radsXy );
762 dz = distance * std::cos( radsZ );
763 }
764
765 return QgsPoint( mX + dx, mY + dy, mZ + dz, mM, pType );
766}
767
769{
770 // nothing to do
771}
772
774{
775 return std::isnan( mX ) || std::isnan( mY );
776}
777
779{
780 return QgsBox3D( mX, mY, mZ, mX, mY, mZ );
781}
782
784{
785 return QStringLiteral( "Point" );
786}
787
789{
790 return 0;
791}
792
794{
795 return 1;
796}
797
799{
800 Q_ASSERT( index == 0 );
801 return *this;
802}
803
805{
806 const double nan = std::numeric_limits<double>::quiet_NaN();
807 return new QgsPoint( nan, nan, nan, nan, mWkbType );
808}
809
811{
812 const QgsPoint *otherPoint = qgsgeometry_cast< const QgsPoint * >( other );
813 if ( !otherPoint )
814 return -1;
815
816 if ( mX < otherPoint->mX )
817 {
818 return -1;
819 }
820 else if ( mX > otherPoint->mX )
821 {
822 return 1;
823 }
824
825 if ( mY < otherPoint->mY )
826 {
827 return -1;
828 }
829 else if ( mY > otherPoint->mY )
830 {
831 return 1;
832 }
833
834 if ( is3D() && !otherPoint->is3D() )
835 return 1;
836 else if ( !is3D() && otherPoint->is3D() )
837 return -1;
838 else if ( is3D() && otherPoint->is3D() )
839 {
840 if ( mZ < otherPoint->mZ )
841 {
842 return -1;
843 }
844 else if ( mZ > otherPoint->mZ )
845 {
846 return 1;
847 }
848 }
849
850 if ( isMeasure() && !otherPoint->isMeasure() )
851 return 1;
852 else if ( !isMeasure() && otherPoint->isMeasure() )
853 return -1;
854 else if ( isMeasure() && otherPoint->isMeasure() )
855 {
856 if ( mM < otherPoint->mM )
857 {
858 return -1;
859 }
860 else if ( mM > otherPoint->mM )
861 {
862 return 1;
863 }
864 }
865
866 return 0;
867}
WkbType
The WKB type describes the number of dimensions a geometry has.
Definition qgis.h:182
@ Unknown
Unknown.
@ PointM
PointM.
@ PointZ
PointZ.
@ Point25D
Point25D.
@ PointZM
PointZM.
TransformDirection
Flags for raster layer temporal capabilities.
Definition qgis.h:1937
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.
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:44
bool contains(const QgsBox3D &other) const
Returns true when box contains other box.
Definition qgsbox3d.cpp:149
A const WKB pointer.
Definition qgswkbptr.h:138
Qgis::WkbType readHeader() const
readHeader
Definition qgswkbptr.cpp:55
Class for doing transforms between two map coordinate systems.
void transformInPlace(double &x, double &y, double &z, Qgis::TransformDirection direction=Qgis::TransformDirection::Forward) const
Transforms an array of x, y and z double coordinates in place, from the source CRS to the destination...
Base class for feedback objects to be used for cancellation of something running in a worker thread.
Definition qgsfeedback.h:45
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:59
bool isEmpty() const
Returns true if the geometry is empty.
Definition qgspointxy.h:249
Point geometry type, with support for z-dimension and m-values.
Definition qgspoint.h:49
int wkbSize(QgsAbstractGeometry::WkbFlags flags=QgsAbstractGeometry::WkbFlags()) const override
Returns the length of the QByteArray returned by asWkb()
Definition qgspoint.cpp:239
QgsBox3D boundingBox3D() const override
Returns the 3D bounding box for the geometry.
Definition qgspoint.cpp:778
bool fromWkb(QgsConstWkbPtr &wkb) override
Sets the geometry from a WKB string.
Definition qgspoint.cpp:136
void filterVertices(const std::function< bool(const QgsPoint &) > &filter) override
Filters the vertices from the geometry in place, removing any which do not return true for the filter...
Definition qgspoint.cpp:669
double inclination(const QgsPoint &other) const
Calculates Cartesian inclination between this point and other one (starting from zenith = 0 to nadir ...
Definition qgspoint.cpp:729
QgsCoordinateSequence coordinateSequence() const override
Retrieves the sequence of geometries, rings and nodes.
Definition qgspoint.cpp:397
double vertexAngle(QgsVertexId vertex) const override
Angle undefined.
Definition qgspoint.cpp:505
QDomElement asGml3(QDomDocument &doc, int precision=17, const QString &ns="gml", QgsAbstractGeometry::AxisOrder axisOrder=QgsAbstractGeometry::AxisOrder::XY) const override
Returns a GML3 representation of the geometry.
Definition qgspoint.cpp:307
bool addMValue(double mValue=0) override
Adds a measure to the geometry, initialized to a preset value.
Definition qgspoint.cpp:568
QPainterPath asQPainterPath() const override
Returns the geometry represented as a QPainterPath.
Definition qgspoint.cpp:355
QByteArray asWkb(QgsAbstractGeometry::WkbFlags=QgsAbstractGeometry::WkbFlags()) const override
Definition qgspoint.cpp:246
double & rx()
Returns a reference to the x-coordinate of this point.
Definition qgspoint.h:246
void clear() override
Clears the geometry, ie reset it to a null geometry.
Definition qgspoint.cpp:360
bool fromWkt(const QString &wkt) override
Sets the geometry from a WKT string.
Definition qgspoint.cpp:164
bool boundingBoxIntersects(const QgsRectangle &rectangle) const override
Returns true if the bounding box of this geometry intersects with a rectangle.
Definition qgspoint.cpp:541
bool dropMValue() override
Drops any measure values which exist in the geometry.
Definition qgspoint.cpp:609
bool insertVertex(QgsVertexId position, const QgsPoint &vertex) override
Inserts a vertex into the geometry.
Definition qgspoint.cpp:430
double azimuth(const QgsPoint &other) const
Calculates Cartesian azimuth between this point and other one (clockwise in degree,...
Definition qgspoint.cpp:722
void adjacentVertices(QgsVertexId vertex, QgsVertexId &previousVertex, QgsVertexId &nextVertex) const override
Returns the vertices adjacent to a specified vertex within a geometry.
Definition qgspoint.cpp:499
bool addZValue(double zValue=0) override
Adds a z-dimension to the geometry, initialized to a preset value.
Definition qgspoint.cpp:557
QgsAbstractGeometry * boundary() const override
Returns the closure of the combinatorial boundary of the geometry (ie the topological boundary of the...
Definition qgspoint.cpp:420
void draw(QPainter &p) const override
Draws the geometry using the specified QPainter.
Definition qgspoint.cpp:350
QgsPoint * toCurveType() const override
Returns the geometry converted to the more generic curve type.
Definition qgspoint.cpp:531
QString asWkt(int precision=17) const override
Returns a WKT representation of the geometry.
Definition qgspoint.cpp:265
QgsPoint childPoint(int index) const override
Returns point at index (for geometries without child geometries - i.e.
Definition qgspoint.cpp:798
bool isValid(QString &error, Qgis::GeometryValidityFlags flags=Qgis::GeometryValidityFlags()) const override
Checks validity of the geometry, and returns true if the geometry is valid.
Definition qgspoint.cpp:425
int dimension() const override
Returns the inherent dimension of the geometry.
Definition qgspoint.cpp:788
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.cpp:686
double closestSegment(const QgsPoint &pt, QgsPoint &segmentPt, QgsVertexId &vertexAfter, int *leftOf=nullptr, double epsilon=4 *std::numeric_limits< double >::epsilon()) const override
Searches for the closest segment of the geometry to a given point.
Definition qgspoint.cpp:466
double distanceSquared3D(double x, double y, double z) const
Returns the Cartesian 3D squared distance between this point and a specified x, y,...
Definition qgspoint.cpp:704
int ringCount(int=0) const override
Returns the number of rings of which this geometry is built.
Definition qgspoint.cpp:516
QDomElement asGml2(QDomDocument &doc, int precision=17, const QString &ns="gml", QgsAbstractGeometry::AxisOrder axisOrder=QgsAbstractGeometry::AxisOrder::XY) const override
Returns a GML2 representation of the geometry.
Definition qgspoint.cpp:284
QgsPoint vertexAt(QgsVertexId) const override
Returns the point corresponding to a specified vertex id.
Definition qgspoint.cpp:526
QgsPoint * createEmptyWithSameType() const override
Creates a new geometry with the same class and same WKB type as the original and transfers ownership.
Definition qgspoint.cpp:804
bool moveVertex(QgsVertexId position, const QgsPoint &newPos) override
Moves a vertex within the geometry.
Definition qgspoint.cpp:443
void normalize() final
Reorganizes the geometry into a normalized form (or "canonical" form).
Definition qgspoint.cpp:768
bool deleteVertex(QgsVertexId position) override
Deletes a vertex within the geometry.
Definition qgspoint.cpp:460
double z
Definition qgspoint.h:54
double x
Definition qgspoint.h:52
void transformVertices(const std::function< QgsPoint(const QgsPoint &) > &transform) override
Transforms the vertices from the geometry in place, applying the transform function to every vertex.
Definition qgspoint.cpp:674
QgsPoint * snappedToGrid(double hSpacing, double vSpacing, double dSpacing=0, double mSpacing=0) const override
Makes a new geometry with all the points or vertices snapped to the closest point of the grid.
Definition qgspoint.cpp:110
bool convertTo(Qgis::WkbType type) override
Converts the geometry to a specified type.
Definition qgspoint.cpp:626
int compareToSameClass(const QgsAbstractGeometry *other) const final
Compares to an other geometry of the same class, and returns a integer for sorting of the two geometr...
Definition qgspoint.cpp:810
int vertexNumberFromVertexId(QgsVertexId id) const override
Returns the vertex number corresponding to a vertex id.
Definition qgspoint.cpp:412
int childCount() const override
Returns number of child geometries (for geometries with child geometries) or child points (for geomet...
Definition qgspoint.cpp:793
bool isEmpty() const override
Returns true if the geometry is empty.
Definition qgspoint.cpp:773
json asJsonObject(int precision=17) const override
Returns a json object representation of the geometry.
Definition qgspoint.cpp:326
void transform(const QgsCoordinateTransform &ct, Qgis::TransformDirection d=Qgis::TransformDirection::Forward, bool transformZ=false) override
Transforms the geometry using a coordinate transform.
Definition qgspoint.cpp:383
double distance(double x, double y) const
Returns the Cartesian 2D distance between this point and a specified x, y coordinate.
Definition qgspoint.h:343
int vertexCount(int=0, int=0) const override
Returns the number of vertices of which this geometry is built.
Definition qgspoint.cpp:511
int nCoordinates() const override
Returns the number of nodes contained in the geometry.
Definition qgspoint.cpp:407
void swapXy() override
Swaps the x and y coordinates from the geometry.
Definition qgspoint.cpp:620
QString geometryType() const override
Returns a unique string representing the geometry type.
Definition qgspoint.cpp:783
double segmentLength(QgsVertexId startVertex) const override
Returns the length of the segment of the geometry which begins at startVertex.
Definition qgspoint.cpp:536
bool dropZValue() override
Drops any z-dimensions which exist in the geometry.
Definition qgspoint.cpp:598
double m
Definition qgspoint.h:55
QgsPoint project(double distance, double azimuth, double inclination=90.0) const
Returns a new point which corresponds to this point projected by a specified distance with specified ...
Definition qgspoint.cpp:741
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:477
int partCount() const override
Returns count of parts contained in the geometry.
Definition qgspoint.cpp:521
QString asKml(int precision=17) const override
Returns a KML representation of the geometry.
Definition qgspoint.cpp:345
bool removeDuplicateNodes(double epsilon=4 *std::numeric_limits< double >::epsilon(), bool useZValues=false) override
Removes duplicate nodes from the geometry, wherever removing the nodes does not result in a degenerat...
Definition qgspoint.cpp:131
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:43
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:4271
double qgsRound(double number, int places)
Returns a double number, rounded (as close as possible) to the specified number of places.
Definition qgis.h:4386
bool qgsDoubleNear(double a, double b, double epsilon=4 *std::numeric_limits< double >::epsilon())
Compare two doubles (but allow some difference)
Definition qgis.h:4332
QVector< QgsRingSequence > QgsCoordinateSequence
QVector< QgsPointSequence > QgsRingSequence
QVector< QgsPoint > QgsPointSequence
int precision
Utility class for identifying a unique vertex within a geometry.
Definition qgsvertexid.h:31