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