QGIS API Documentation  3.10.0-A Coruña (6c816b4204)
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  // tupel 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 void QgsPoint::draw( QPainter &p ) const
310 {
311  p.drawRect( QRectF( mX - 2, mY - 2, 4, 4 ) );
312 }
313 
315 {
316  mX = mY = std::numeric_limits<double>::quiet_NaN();
317  if ( is3D() )
318  mZ = 0.;
319  else
320  mZ = std::numeric_limits<double>::quiet_NaN();
321 
322  if ( isMeasure() )
323  mM = 0.;
324  else
325  mM = std::numeric_limits<double>::quiet_NaN();
326 
327  clearCache();
328 }
329 
330 
331 /***************************************************************************
332  * This class is considered CRITICAL and any change MUST be accompanied with
333  * full unit tests.
334  * See details in QEP #17
335  ****************************************************************************/
336 
338 {
339  clearCache();
340  if ( transformZ )
341  {
342  ct.transformInPlace( mX, mY, mZ, d );
343  }
344  else
345  {
346  double z = 0.0;
347  ct.transformInPlace( mX, mY, z, d );
348  }
349 }
350 
352 {
354 
355  cs.append( QgsRingSequence() );
356  cs.back().append( QgsPointSequence() << QgsPoint( *this ) );
357 
358  return cs;
359 }
360 
362 {
363  return 1;
364 }
365 
367 {
368  if ( id.vertex != 0 )
369  return -1;
370  else
371  return 0;
372 }
373 
375 {
376  return nullptr;
377 }
378 
379 bool QgsPoint::isValid( QString &, int ) const
380 {
381  return true;
382 }
383 
384 bool QgsPoint::insertVertex( QgsVertexId position, const QgsPoint &vertex )
385 {
386  Q_UNUSED( position )
387  Q_UNUSED( vertex )
388  return false;
389 }
390 
391 /***************************************************************************
392  * This class is considered CRITICAL and any change MUST be accompanied with
393  * full unit tests.
394  * See details in QEP #17
395  ****************************************************************************/
396 
397 bool QgsPoint::moveVertex( QgsVertexId position, const QgsPoint &newPos )
398 {
399  Q_UNUSED( position )
400  clearCache();
401  mX = newPos.mX;
402  mY = newPos.mY;
403  if ( is3D() && newPos.is3D() )
404  {
405  mZ = newPos.mZ;
406  }
407  if ( isMeasure() && newPos.isMeasure() )
408  {
409  mM = newPos.mM;
410  }
411  return true;
412 }
413 
415 {
416  Q_UNUSED( position )
417  return false;
418 }
419 
420 double QgsPoint::closestSegment( const QgsPoint &pt, QgsPoint &segmentPt, QgsVertexId &vertexAfter, int *leftOf, double epsilon ) const
421 {
422  Q_UNUSED( pt )
423  Q_UNUSED( segmentPt )
424  Q_UNUSED( vertexAfter )
425  if ( leftOf )
426  *leftOf = 0;
427  Q_UNUSED( epsilon )
428  return -1; // no segments - return error
429 }
430 
431 bool QgsPoint::nextVertex( QgsVertexId &id, QgsPoint &vertex ) const
432 {
433  if ( id.vertex < 0 )
434  {
435  id.vertex = 0;
436  if ( id.part < 0 )
437  {
438  id.part = 0;
439  }
440  if ( id.ring < 0 )
441  {
442  id.ring = 0;
443  }
444  vertex = *this;
445  return true;
446  }
447  else
448  {
449  return false;
450  }
451 }
452 
454 {
455  previousVertex = QgsVertexId();
456  nextVertex = QgsVertexId();
457 }
458 
459 double QgsPoint::vertexAngle( QgsVertexId vertex ) const
460 {
461  Q_UNUSED( vertex )
462  return 0.0;
463 }
464 
465 int QgsPoint::vertexCount( int, int ) const
466 {
467  return 1;
468 }
469 
470 int QgsPoint::ringCount( int ) const
471 {
472  return 1;
473 }
474 
476 {
477  return 1;
478 }
479 
481 {
482  return *this;
483 }
484 
486 {
487  return clone();
488 }
489 
491 {
492  return 0.0;
493 }
494 
495 /***************************************************************************
496  * This class is considered CRITICAL and any change MUST be accompanied with
497  * full unit tests.
498  * See details in QEP #17
499  ****************************************************************************/
500 
501 bool QgsPoint::addZValue( double zValue )
502 {
503  if ( QgsWkbTypes::hasZ( mWkbType ) )
504  return false;
505 
507  mZ = zValue;
508  clearCache();
509  return true;
510 }
511 
512 bool QgsPoint::addMValue( double mValue )
513 {
514  if ( QgsWkbTypes::hasM( mWkbType ) )
515  return false;
516 
518  mM = mValue;
519  clearCache();
520  return true;
521 }
522 
523 void QgsPoint::transform( const QTransform &t, double zTranslate, double zScale, double mTranslate, double mScale )
524 {
525  clearCache();
526  qreal x, y;
527  t.map( mX, mY, &x, &y );
528  mX = x;
529  mY = y;
530 
531  if ( is3D() )
532  {
533  mZ = mZ * zScale + zTranslate;
534  }
535  if ( isMeasure() )
536  {
537  mM = mM * mScale + mTranslate;
538  }
539 }
540 
541 
543 {
544  if ( !is3D() )
545  return false;
546 
548  mZ = std::numeric_limits<double>::quiet_NaN();
549  clearCache();
550  return true;
551 }
552 
554 {
555  if ( !isMeasure() )
556  return false;
557 
559  mM = std::numeric_limits<double>::quiet_NaN();
560  clearCache();
561  return true;
562 }
563 
565 {
566  std::swap( mX, mY );
567  clearCache();
568 }
569 
571 {
572  if ( type == mWkbType )
573  return true;
574 
575  clearCache();
576 
577  switch ( type )
578  {
579  case QgsWkbTypes::Point:
580  mZ = std::numeric_limits<double>::quiet_NaN();
581  mM = std::numeric_limits<double>::quiet_NaN();
582  mWkbType = type;
583  return true;
584  case QgsWkbTypes::PointZ:
586  mM = std::numeric_limits<double>::quiet_NaN();
587  mWkbType = type;
588  return true;
589  case QgsWkbTypes::PointM:
590  mZ = std::numeric_limits<double>::quiet_NaN();
591  mWkbType = type;
592  return true;
594  mWkbType = type;
595  return true;
596  default:
597  break;
598  }
599 
600  return false;
601 }
602 
603 void QgsPoint::filterVertices( const std::function<bool ( const QgsPoint & )> & )
604 {
605  // no meaning for points
606 }
607 
608 void QgsPoint::transformVertices( const std::function<QgsPoint( const QgsPoint & )> &transform )
609 {
610  QgsPoint res = transform( *this );
611  mX = res.x();
612  mY = res.y();
613  if ( is3D() )
614  mZ = res.z();
615  if ( isMeasure() )
616  mM = res.m();
617  clearCache();
618 }
619 
620 double QgsPoint::distance3D( double x, double y, double z ) const
621 {
622  double zDistSquared = 0.0;
623  if ( is3D() || !std::isnan( z ) )
624  zDistSquared = ( mZ - z ) * ( mZ - z );
625 
626  return std::sqrt( ( mX - x ) * ( mX - x ) + ( mY - y ) * ( mY - y ) + zDistSquared );
627 }
628 
629 double QgsPoint::distance3D( const QgsPoint &other ) const
630 {
631  double zDistSquared = 0.0;
632  if ( is3D() || other.is3D() )
633  zDistSquared = ( mZ - other.z() ) * ( mZ - other.z() );
634 
635  return std::sqrt( ( mX - other.x() ) * ( mX - other.x() ) + ( mY - other.y() ) * ( mY - other.y() ) + zDistSquared );
636 }
637 
638 double QgsPoint::distanceSquared3D( double x, double y, double z ) const
639 {
640  double zDistSquared = 0.0;
641  if ( is3D() || !std::isnan( z ) )
642  zDistSquared = ( mZ - z ) * ( mZ - z );
643 
644  return ( mX - x ) * ( mX - x ) + ( mY - y ) * ( mY - y ) + zDistSquared;
645 }
646 
647 double QgsPoint::distanceSquared3D( const QgsPoint &other ) const
648 {
649  double zDistSquared = 0.0;
650  if ( is3D() || other.is3D() )
651  zDistSquared = ( mZ - other.z() ) * ( mZ - other.z() );
652 
653  return ( mX - other.x() ) * ( mX - other.x() ) + ( mY - other.y() ) * ( mY - other.y() ) + zDistSquared;
654 }
655 
656 double QgsPoint::azimuth( const QgsPoint &other ) const
657 {
658  double dx = other.x() - mX;
659  double dy = other.y() - mY;
660  return ( std::atan2( dx, dy ) * 180.0 / M_PI );
661 }
662 
663 double QgsPoint::inclination( const QgsPoint &other ) const
664 {
665  double distance = distance3D( other );
666  if ( qgsDoubleNear( distance, 0.0 ) )
667  {
668  return 90.0;
669  }
670  double dz = other.z() - mZ;
671 
672  return ( std::acos( dz / distance ) * 180.0 / M_PI );
673 }
674 
675 QgsPoint QgsPoint::project( double distance, double azimuth, double inclination ) const
676 {
677  QgsWkbTypes::Type pType = mWkbType;
678  double radsXy = azimuth * M_PI / 180.0;
679  double dx = 0.0, dy = 0.0, dz = 0.0;
680 
681  inclination = std::fmod( inclination, 360.0 );
682 
683  if ( !qgsDoubleNear( inclination, 90.0 ) )
684  pType = QgsWkbTypes::addZ( pType );
685 
686  if ( !is3D() && qgsDoubleNear( inclination, 90.0 ) )
687  {
688  dx = distance * std::sin( radsXy );
689  dy = distance * std::cos( radsXy );
690  }
691  else
692  {
693  double radsZ = inclination * M_PI / 180.0;
694  dx = distance * std::sin( radsZ ) * std::sin( radsXy );
695  dy = distance * std::sin( radsZ ) * std::cos( radsXy );
696  dz = distance * std::cos( radsZ );
697  }
698 
699  return QgsPoint( mX + dx, mY + dy, mZ + dz, mM, pType );
700 }
701 
702 bool QgsPoint::isEmpty() const
703 {
704  return std::isnan( mX ) || std::isnan( mY );
705 }
706 
708 {
709  return QgsRectangle( mX, mY, mX, mY );
710 }
711 
712 QString QgsPoint::geometryType() const
713 {
714  return QStringLiteral( "Point" );
715 }
716 
718 {
719  return 0;
720 }
721 
723 {
724  return 1;
725 }
726 
727 QgsPoint QgsPoint::childPoint( int index ) const
728 {
729  Q_ASSERT( index == 0 );
730  return *this;
731 }
732 
734 {
735  double nan = std::numeric_limits<double>::quiet_NaN();
736  return new QgsPoint( nan, nan, nan, nan, mWkbType );
737 }
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:564
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:420
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:374
void draw(QPainter &p) const override
Draws the geometry using the specified QPainter.
Definition: qgspoint.cpp:309
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:490
int nCoordinates() const override
Returns the number of nodes contained in the geometry.
Definition: qgspoint.cpp:361
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:608
bool addZValue(double zValue=0) override
Adds a z-dimension to the geometry, initialized to a preset value.
Definition: qgspoint.cpp:501
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:717
QgsRectangle boundingBox() const override
Returns the minimal bounding box for the geometry.
Definition: qgspoint.cpp:707
QVector< QgsRingSequence > QgsCoordinateSequence
QgsPoint * toCurveType() const override
Returns the geometry converted to the more generic curve type.
Definition: qgspoint.cpp:485
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:459
double distance(double x, double y) const
Returns the Cartesian 2D distance between this point and a specified x, y coordinate.
Definition: qgspoint.h:325
double azimuth(const QgsPoint &other) const
Calculates Cartesian azimuth between this point and other one (clockwise in degree, starting from north)
Definition: qgspoint.cpp:656
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:280
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:603
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:379
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:663
void clear() override
Clears the geometry, ie reset it to a null geometry.
Definition: qgspoint.cpp:314
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:480
QgsWkbTypes::Type mWkbType
double y() const
Returns the point&#39;s y-coordinate.
Definition: qgspoint.h:205
bool dropZValue() override
Drops any z-dimensions which exist in the geometry.
Definition: qgspoint.cpp:542
bool moveVertex(QgsVertexId position, const QgsPoint &newPos) override
Moves a vertex within the geometry.
Definition: qgspoint.cpp:397
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:384
bool dropMValue() override
Drops any measure values which exist in the geometry.
Definition: qgspoint.cpp:553
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:240
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:733
double & rx()
Returns a reference to the x-coordinate of this point.
Definition: qgspoint.h:228
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:431
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:638
void adjacentVertices(QgsVertexId vertex, QgsVertexId &previousVertex, QgsVertexId &nextVertex) const override
Returns the vertices adjacent to a specified vertex within a geometry.
Definition: qgspoint.cpp:453
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:675
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:470
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:465
QVector< QgsPoint > QgsPointSequence
double m() const
Returns the point&#39;s m value.
Definition: qgspoint.h:219
QVector< QgsPointSequence > QgsRingSequence
int partCount() const override
Returns count of parts contained in the geometry.
Definition: qgspoint.cpp:475
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:702
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:328
bool convertTo(QgsWkbTypes::Type type) override
Converts the geometry to a specified type.
Definition: qgspoint.cpp:570
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:512
double z
Definition: qgspoint.h:43
double z() const
Returns the point&#39;s z-coordinate.
Definition: qgspoint.h:212
QgsCoordinateSequence coordinateSequence() const override
Retrieves the sequence of geometries, rings and nodes.
Definition: qgspoint.cpp:351
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:712
QgsPoint childPoint(int index) const override
Returns point at index (for geometries without child geometries - i.e.
Definition: qgspoint.cpp:727
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:414
int childCount() const override
Returns number of child geometries (for geometries with child geometries) or child points (for geomet...
Definition: qgspoint.cpp:722
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:337
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;. Negativ values mean left a...
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:620
double x() const
Returns the point&#39;s x-coordinate.
Definition: qgspoint.h:198
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:366
double m
Definition: qgspoint.h:44
double x
Definition: qgspoint.h:41