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