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