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