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