QGIS API Documentation 4.0.0-Norrköping (1ddcee3d0e4)
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 ) 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 }
373 return j;
374}
375
376QString QgsPoint::asKml( int precision ) const
377{
378 return u"<Point><coordinates>%1,%2</coordinates></Point>"_s.arg( qgsDoubleToString( mX, precision ), qgsDoubleToString( mY, precision ) );
379}
380
381void QgsPoint::draw( QPainter &p ) const
382{
383 p.drawRect( QRectF( mX - 2, mY - 2, 4, 4 ) );
384}
385
386QPainterPath QgsPoint::asQPainterPath() const
387{
388 return QPainterPath();
389}
390
392{
393 mX = mY = std::numeric_limits<double>::quiet_NaN();
394 if ( is3D() )
395 mZ = 0.;
396 else
397 mZ = std::numeric_limits<double>::quiet_NaN();
398
399 if ( isMeasure() )
400 mM = 0.;
401 else
402 mM = std::numeric_limits<double>::quiet_NaN();
403
404 clearCache();
405}
406
407
408/***************************************************************************
409 * This class is considered CRITICAL and any change MUST be accompanied with
410 * full unit tests.
411 * See details in QEP #17
412 ****************************************************************************/
413
415{
416 clearCache();
417 if ( transformZ )
418 {
419 ct.transformInPlace( mX, mY, mZ, d );
420 }
421 else
422 {
423 double z = 0.0;
424 ct.transformInPlace( mX, mY, z, d );
425 }
426}
427
429{
431
432 cs.append( QgsRingSequence() );
433 cs.back().append( QgsPointSequence() << QgsPoint( *this ) );
434
435 return cs;
436}
437
439{
440 return 1;
441}
442
444{
445 if ( id.vertex != 0 )
446 return -1;
447 else
448 return 0;
449}
450
452{
453 return nullptr;
454}
455
457{
458 return true;
459}
460
461bool QgsPoint::insertVertex( QgsVertexId position, const QgsPoint &vertex )
462{
463 Q_UNUSED( position )
464 Q_UNUSED( vertex )
465 return false;
466}
467
468/***************************************************************************
469 * This class is considered CRITICAL and any change MUST be accompanied with
470 * full unit tests.
471 * See details in QEP #17
472 ****************************************************************************/
473
474bool QgsPoint::moveVertex( QgsVertexId position, const QgsPoint &newPos )
475{
476 Q_UNUSED( position )
477 clearCache();
478 mX = newPos.mX;
479 mY = newPos.mY;
480 if ( is3D() && newPos.is3D() )
481 {
482 mZ = newPos.mZ;
483 }
484 if ( isMeasure() && newPos.isMeasure() )
485 {
486 mM = newPos.mM;
487 }
488 return true;
489}
490
492{
493 Q_UNUSED( position )
494 return false;
495}
496
497double QgsPoint::closestSegment( const QgsPoint &pt, QgsPoint &segmentPt, QgsVertexId &vertexAfter, int *leftOf, double epsilon ) const
498{
499 Q_UNUSED( pt )
500 Q_UNUSED( segmentPt )
501 Q_UNUSED( vertexAfter )
502 if ( leftOf )
503 *leftOf = 0;
504 Q_UNUSED( epsilon )
505 return -1; // no segments - return error
506}
507
508bool QgsPoint::nextVertex( QgsVertexId &id, QgsPoint &vertex ) const
509{
510 if ( id.vertex < 0 )
511 {
512 id.vertex = 0;
513 if ( id.part < 0 )
514 {
515 id.part = 0;
516 }
517 if ( id.ring < 0 )
518 {
519 id.ring = 0;
520 }
521 vertex = *this;
522 return true;
523 }
524 else
525 {
526 return false;
527 }
528}
529
531{
532 previousVertex = QgsVertexId();
534}
535
536double QgsPoint::vertexAngle( QgsVertexId vertex ) const
537{
538 Q_UNUSED( vertex )
539 return 0.0;
540}
541
542int QgsPoint::vertexCount( int, int ) const
543{
544 return 1;
545}
546
547int QgsPoint::ringCount( int ) const
548{
549 return 1;
550}
551
553{
554 return 1;
555}
556
558{
559 return *this;
560}
561
563{
564 return clone();
565}
566
568{
569 return 0.0;
570}
571
572bool QgsPoint::boundingBoxIntersects( const QgsRectangle &rectangle ) const
573{
574 return rectangle.contains( mX, mY );
575}
576
578{
579 return box3d.contains( mX, mY, mZ );
580}
581
582/***************************************************************************
583 * This class is considered CRITICAL and any change MUST be accompanied with
584 * full unit tests.
585 * See details in QEP #17
586 ****************************************************************************/
587
588bool QgsPoint::addZValue( double zValue )
589{
591 return false;
592
594 mZ = zValue;
595 clearCache();
596 return true;
597}
598
599bool QgsPoint::addMValue( double mValue )
600{
602 return false;
603
605 mM = mValue;
606 clearCache();
607 return true;
608}
609
610void QgsPoint::transform( const QTransform &t, double zTranslate, double zScale, double mTranslate, double mScale )
611{
612 clearCache();
613 qreal x, y;
614 t.map( mX, mY, &x, &y );
615 mX = x;
616 mY = y;
617
618 if ( is3D() )
619 {
620 mZ = mZ * zScale + zTranslate;
621 }
622 if ( isMeasure() )
623 {
624 mM = mM * mScale + mTranslate;
625 }
626}
627
628
630{
631 if ( !is3D() )
632 return false;
633
635 mZ = std::numeric_limits<double>::quiet_NaN();
636 clearCache();
637 return true;
638}
639
641{
642 if ( !isMeasure() )
643 return false;
644
646 mM = std::numeric_limits<double>::quiet_NaN();
647 clearCache();
648 return true;
649}
650
652{
653 std::swap( mX, mY );
654 clearCache();
655}
656
658{
659 if ( type == mWkbType )
660 return true;
661
662 clearCache();
663
664 switch ( type )
665 {
667 mZ = std::numeric_limits<double>::quiet_NaN();
668 mM = std::numeric_limits<double>::quiet_NaN();
669 mWkbType = type;
670 return true;
673 mM = std::numeric_limits<double>::quiet_NaN();
674 mWkbType = type;
675 return true;
677 mZ = std::numeric_limits<double>::quiet_NaN();
678 mWkbType = type;
679 return true;
681 mWkbType = type;
682 return true;
683 default:
684 break;
685 }
686
687 return false;
688}
689
691{
692 if ( !transformer )
693 return false;
694
695 const bool res = transformer->transformPoint( mX, mY, mZ, mM );
696 clearCache();
697 return res;
698}
699
700void QgsPoint::filterVertices( const std::function<bool( const QgsPoint & )> & )
701{
702 // no meaning for points
703}
704
705void QgsPoint::transformVertices( const std::function<QgsPoint( const QgsPoint & )> &transform )
706{
707 const QgsPoint res = transform( *this );
708 mX = res.x();
709 mY = res.y();
710 if ( is3D() )
711 mZ = res.z();
712 if ( isMeasure() )
713 mM = res.m();
714 clearCache();
715}
716
717double QgsPoint::azimuth( const QgsPoint &other ) const
718{
719 return QgsGeometryUtilsBase::azimuth( mX, mY, other.x(), other.y() );
720}
721
722double QgsPoint::inclination( const QgsPoint &other ) const
723{
724 const double distance = distance3D( other );
725 if ( qgsDoubleNear( distance, 0.0 ) )
726 {
727 return 90.0;
728 }
729 const double dz = other.z() - mZ;
730
731 return ( std::acos( dz / distance ) * 180.0 / M_PI );
732}
733
735{
736 Qgis::WkbType pType = mWkbType;
737 const double radsXy = azimuth * M_PI / 180.0;
738 double dx = 0.0, dy = 0.0, dz = 0.0;
739
740 inclination = std::fmod( inclination, 360.0 );
741
742 if ( !qgsDoubleNear( inclination, 90.0 ) )
743 pType = QgsWkbTypes::addZ( pType );
744
745 if ( !is3D() && qgsDoubleNear( inclination, 90.0 ) )
746 {
747 dx = distance * std::sin( radsXy );
748 dy = distance * std::cos( radsXy );
749 }
750 else
751 {
752 const double radsZ = inclination * M_PI / 180.0;
753 dx = distance * std::sin( radsZ ) * std::sin( radsXy );
754 dy = distance * std::sin( radsZ ) * std::cos( radsXy );
755 dz = distance * std::cos( radsZ );
756 }
757
758 return QgsPoint( mX + dx, mY + dy, mZ + dz, mM, pType );
759}
760
762{
763 // nothing to do
764}
765
767{
768 return std::isnan( mX ) || std::isnan( mY );
769}
770
772{
773 return QgsBox3D( mX, mY, mZ, mX, mY, mZ );
774}
775
777{
778 return u"Point"_s;
779}
780
782{
783 return 0;
784}
785
787{
788 return 1;
789}
790
792{
793 Q_ASSERT( index == 0 );
794 return *this;
795}
796
798{
799 const double nan = std::numeric_limits<double>::quiet_NaN();
800 return new QgsPoint( nan, nan, nan, nan, mWkbType );
801}
802
804{
805 const QgsPoint *otherPoint = qgsgeometry_cast< const QgsPoint * >( other );
806 if ( !otherPoint )
807 return -1;
808
809 if ( mX < otherPoint->mX )
810 {
811 return -1;
812 }
813 else if ( mX > otherPoint->mX )
814 {
815 return 1;
816 }
817
818 if ( mY < otherPoint->mY )
819 {
820 return -1;
821 }
822 else if ( mY > otherPoint->mY )
823 {
824 return 1;
825 }
826
827 if ( is3D() && !otherPoint->is3D() )
828 return 1;
829 else if ( !is3D() && otherPoint->is3D() )
830 return -1;
831 else if ( is3D() && otherPoint->is3D() )
832 {
833 if ( mZ < otherPoint->mZ )
834 {
835 return -1;
836 }
837 else if ( mZ > otherPoint->mZ )
838 {
839 return 1;
840 }
841 }
842
843 if ( isMeasure() && !otherPoint->isMeasure() )
844 return 1;
845 else if ( !isMeasure() && otherPoint->isMeasure() )
846 return -1;
847 else if ( isMeasure() && otherPoint->isMeasure() )
848 {
849 if ( mM < otherPoint->mM )
850 {
851 return -1;
852 }
853 else if ( mM > otherPoint->mM )
854 {
855 return 1;
856 }
857 }
858
859 return 0;
860}
QFlags< GeometryValidityFlag > GeometryValidityFlags
Geometry validity flags.
Definition qgis.h:2155
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:2764
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:771
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:700
double inclination(const QgsPoint &other) const
Calculates Cartesian inclination between this point and other one (starting from zenith = 0 to nadir ...
Definition qgspoint.cpp:722
QgsCoordinateSequence coordinateSequence() const override
Retrieves the sequence of geometries, rings and nodes.
Definition qgspoint.cpp:428
double vertexAngle(QgsVertexId vertex) const override
Angle undefined.
Definition qgspoint.cpp:536
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:599
QPainterPath asQPainterPath() const override
Returns the geometry represented as a QPainterPath.
Definition qgspoint.cpp:386
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:391
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:572
bool dropMValue() override
Drops any measure values which exist in the geometry.
Definition qgspoint.cpp:640
bool insertVertex(QgsVertexId position, const QgsPoint &vertex) override
Inserts a vertex into the geometry.
Definition qgspoint.cpp:461
double azimuth(const QgsPoint &other) const
Calculates Cartesian azimuth between this point and other one (clockwise in degree,...
Definition qgspoint.cpp:717
void adjacentVertices(QgsVertexId vertex, QgsVertexId &previousVertex, QgsVertexId &nextVertex) const override
Returns the vertices adjacent to a specified vertex within a geometry.
Definition qgspoint.cpp:530
bool addZValue(double zValue=0) override
Adds a z-dimension to the geometry, initialized to a preset value.
Definition qgspoint.cpp:588
QgsAbstractGeometry * boundary() const override
Returns the closure of the combinatorial boundary of the geometry (ie the topological boundary of the...
Definition qgspoint.cpp:451
void draw(QPainter &p) const override
Draws the geometry using the specified QPainter.
Definition qgspoint.cpp:381
QgsPoint * toCurveType() const override
Returns the geometry converted to the more generic curve type.
Definition qgspoint.cpp:562
QgsPoint * simplifyByDistance(double tolerance) const override
Simplifies the geometry by applying the Douglas Peucker simplification by distance algorithm.
Definition qgspoint.cpp:163
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:791
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:456
int dimension() const override
Returns the inherent dimension of the geometry.
Definition qgspoint.cpp:781
QgsPoint * clone() const override
Clones the geometry by performing a deep copy.
Definition qgspoint.cpp:138
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:497
int ringCount(int=0) const override
Returns the number of rings of which this geometry is built.
Definition qgspoint.cpp:547
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:557
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:797
bool moveVertex(QgsVertexId position, const QgsPoint &newPos) override
Moves a vertex within the geometry.
Definition qgspoint.cpp:474
void normalize() final
Reorganizes the geometry into a normalized form (or "canonical" form).
Definition qgspoint.cpp:761
bool deleteVertex(QgsVertexId position) override
Deletes a vertex within the geometry.
Definition qgspoint.cpp:491
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:705
bool convertTo(Qgis::WkbType type) override
Converts the geometry to a specified type.
Definition qgspoint.cpp:657
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:803
int vertexNumberFromVertexId(QgsVertexId id) const override
Returns the vertex number corresponding to a vertex id.
Definition qgspoint.cpp:443
int childCount() const override
Returns number of child geometries (for geometries with child geometries) or child points (for geomet...
Definition qgspoint.cpp:786
bool isEmpty() const override
Returns true if the geometry is empty.
Definition qgspoint.cpp:766
json asJsonObject(int precision=17) const override
Returns a json object representation of the geometry.
Definition qgspoint.cpp:358
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:414
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:542
int nCoordinates() const override
Returns the number of nodes contained in the geometry.
Definition qgspoint.cpp:438
void swapXy() override
Swaps the x and y coordinates from the geometry.
Definition qgspoint.cpp:651
QString geometryType() const override
Returns a unique string representing the geometry type.
Definition qgspoint.cpp:776
double segmentLength(QgsVertexId startVertex) const override
Returns the length of the segment of the geometry which begins at startVertex.
Definition qgspoint.cpp:567
bool dropZValue() override
Drops any z-dimensions which exist in the geometry.
Definition qgspoint.cpp:629
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:734
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:508
int partCount() const override
Returns count of parts contained in the geometry.
Definition qgspoint.cpp:552
QString asKml(int precision=17) const override
Returns a KML representation of the geometry.
Definition qgspoint.cpp:376
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:6893
double qgsRound(double number, int places)
Returns a double number, rounded (as close as possible) to the specified number of places.
Definition qgis.h:7015
bool qgsDoubleNear(double a, double b, double epsilon=4 *std::numeric_limits< double >::epsilon())
Compare two doubles (but allow some difference).
Definition qgis.h:6975
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:34