QGIS API Documentation  2.99.0-Master (f1c3692)
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 QgsPoint &pt ) const
95 {
96  const QgsWkbTypes::Type type = wkbType();
97 
98  bool equal = pt.wkbType() == type;
99  equal &= qgsDoubleNear( pt.x(), mX, 1E-8 );
100  equal &= qgsDoubleNear( pt.y(), mY, 1E-8 );
101  if ( QgsWkbTypes::hasZ( type ) )
102  equal &= qgsDoubleNear( pt.z(), mZ, 1E-8 ) || ( std::isnan( pt.z() ) && std::isnan( mZ ) );
103  if ( QgsWkbTypes::hasM( type ) )
104  equal &= qgsDoubleNear( pt.m(), mM, 1E-8 ) || ( std::isnan( pt.m() ) && std::isnan( mM ) );
105 
106  return equal;
107 }
108 
109 bool QgsPoint::operator!=( const QgsPoint &pt ) const
110 {
111  return !operator==( pt );
112 }
113 
115 {
116  return new QgsPoint( *this );
117 }
118 
119 QgsPoint *QgsPoint::snappedToGrid( double hSpacing, double vSpacing, double dSpacing, double mSpacing ) const
120 {
121  // helper function
122  auto gridifyValue = []( double value, double spacing, bool extraCondition = true ) -> double
123  {
124  if ( spacing > 0 && extraCondition )
125  return std::round( value / spacing ) * spacing;
126  else
127  return value;
128  };
129 
130  // Get the new values
131  auto x = gridifyValue( mX, hSpacing );
132  auto y = gridifyValue( mY, vSpacing );
133  auto z = gridifyValue( mZ, dSpacing, QgsWkbTypes::hasZ( mWkbType ) );
134  auto m = gridifyValue( mM, mSpacing, QgsWkbTypes::hasM( mWkbType ) );
135 
136  // return the new object
137  return new QgsPoint( mWkbType, x, y, z, m );
138 }
139 
141 {
142  QgsWkbTypes::Type type = wkbPtr.readHeader();
143  if ( QgsWkbTypes::flatType( type ) != QgsWkbTypes::Point )
144  {
145  clear();
146  return false;
147  }
148  mWkbType = type;
149 
150  wkbPtr >> mX;
151  wkbPtr >> mY;
152  if ( is3D() )
153  wkbPtr >> mZ;
154  if ( isMeasure() )
155  wkbPtr >> mM;
156 
157  clearCache();
158 
159  return true;
160 }
161 
162 /***************************************************************************
163  * This class is considered CRITICAL and any change MUST be accompanied with
164  * full unit tests.
165  * See details in QEP #17
166  ****************************************************************************/
167 
168 bool QgsPoint::fromWkt( const QString &wkt )
169 {
170  clear();
171 
172  QPair<QgsWkbTypes::Type, QString> parts = QgsGeometryUtils::wktReadBlock( wkt );
173 
174  if ( QgsWkbTypes::flatType( parts.first ) != QgsWkbTypes::Point )
175  return false;
176  mWkbType = parts.first;
177 
178  QRegularExpression rx( QStringLiteral( "\\s" ) );
179  QStringList coordinates = parts.second.split( rx, QString::SkipEmptyParts );
180  if ( coordinates.size() < 2 )
181  {
182  clear();
183  return false;
184  }
185  else if ( coordinates.size() == 3 && !is3D() && !isMeasure() )
186  {
187  // 3 dimensional coordinates, but not specifically marked as such. We allow this
188  // anyway and upgrade geometry to have Z dimension
190  }
191  else if ( coordinates.size() >= 4 && ( !is3D() || !isMeasure() ) )
192  {
193  // 4 (or more) dimensional coordinates, but not specifically marked as such. We allow this
194  // anyway and upgrade geometry to have Z&M dimensions
197  }
198 
199  int idx = 0;
200  mX = coordinates[idx++].toDouble();
201  mY = coordinates[idx++].toDouble();
202  if ( is3D() && coordinates.length() > 2 )
203  mZ = coordinates[idx++].toDouble();
204  if ( isMeasure() && coordinates.length() > 2 + is3D() )
205  mM = coordinates[idx++].toDouble();
206 
207  return true;
208 }
209 
210 /***************************************************************************
211  * This class is considered CRITICAL and any change MUST be accompanied with
212  * full unit tests.
213  * See details in QEP #17
214  ****************************************************************************/
215 
216 QByteArray QgsPoint::asWkb() const
217 {
218  int binarySize = sizeof( char ) + sizeof( quint32 );
219  binarySize += ( 2 + is3D() + isMeasure() ) * sizeof( double );
220 
221  QByteArray wkbArray;
222  wkbArray.resize( binarySize );
223  QgsWkbPtr wkb( wkbArray );
224  wkb << static_cast<char>( QgsApplication::endian() );
225  wkb << static_cast<quint32>( wkbType() );
226  wkb << mX << mY;
227  if ( is3D() )
228  {
229  wkb << mZ;
230  }
231  if ( isMeasure() )
232  {
233  wkb << mM;
234  }
235  return wkbArray;
236 }
237 
238 QString QgsPoint::asWkt( int precision ) const
239 {
240  QString wkt = wktTypeStr() + " (";
241  wkt += qgsDoubleToString( mX, precision ) + ' ' + qgsDoubleToString( mY, precision );
242  if ( is3D() )
243  wkt += ' ' + qgsDoubleToString( mZ, precision );
244  if ( isMeasure() )
245  wkt += ' ' + qgsDoubleToString( mM, precision );
246  wkt += ')';
247  return wkt;
248 }
249 
250 QDomElement QgsPoint::asGml2( QDomDocument &doc, int precision, const QString &ns ) const
251 {
252  QDomElement elemPoint = doc.createElementNS( ns, QStringLiteral( "Point" ) );
253  QDomElement elemCoordinates = doc.createElementNS( ns, QStringLiteral( "coordinates" ) );
254 
255  // coordinate separator
256  QString cs = QStringLiteral( "," );
257  // tupel separator
258  QString ts = QStringLiteral( " " );
259 
260  elemCoordinates.setAttribute( QStringLiteral( "cs" ), cs );
261  elemCoordinates.setAttribute( QStringLiteral( "ts" ), ts );
262 
263  QString strCoordinates = qgsDoubleToString( mX, precision ) + cs + qgsDoubleToString( mY, precision );
264  elemCoordinates.appendChild( doc.createTextNode( strCoordinates ) );
265  elemPoint.appendChild( elemCoordinates );
266  return elemPoint;
267 }
268 
269 QDomElement QgsPoint::asGml3( QDomDocument &doc, int precision, const QString &ns ) const
270 {
271  QDomElement elemPoint = doc.createElementNS( ns, QStringLiteral( "Point" ) );
272  QDomElement elemPosList = doc.createElementNS( ns, QStringLiteral( "pos" ) );
273  elemPosList.setAttribute( QStringLiteral( "srsDimension" ), is3D() ? 3 : 2 );
274  QString strCoordinates = qgsDoubleToString( mX, precision ) + ' ' + qgsDoubleToString( mY, precision );
275  if ( is3D() )
276  strCoordinates += ' ' + qgsDoubleToString( mZ, precision );
277 
278  elemPosList.appendChild( doc.createTextNode( strCoordinates ) );
279  elemPoint.appendChild( elemPosList );
280  return elemPoint;
281 }
282 
283 /***************************************************************************
284  * This class is considered CRITICAL and any change MUST be accompanied with
285  * full unit tests.
286  * See details in QEP #17
287  ****************************************************************************/
288 
289 QString QgsPoint::asJson( int precision ) const
290 {
291  return "{\"type\": \"Point\", \"coordinates\": ["
292  + qgsDoubleToString( mX, precision ) + ", " + qgsDoubleToString( mY, precision )
293  + "]}";
294 }
295 
296 void QgsPoint::draw( QPainter &p ) const
297 {
298  p.drawRect( QRectF( mX - 2, mY - 2, 4, 4 ) );
299 }
300 
302 {
303  mX = mY = 0.;
304  if ( is3D() )
305  mZ = 0.;
306  else
307  mZ = std::numeric_limits<double>::quiet_NaN();
308 
309  if ( isMeasure() )
310  mM = 0.;
311  else
312  mM = std::numeric_limits<double>::quiet_NaN();
313 
314  clearCache();
315 }
316 
318 {
319  clearCache();
320  if ( transformZ )
321  {
322  ct.transformInPlace( mX, mY, mZ, d );
323  }
324  else
325  {
326  double z = 0.0;
327  ct.transformInPlace( mX, mY, z, d );
328  }
329 }
330 
332 {
334 
335  cs.append( QgsRingSequence() );
336  cs.back().append( QgsPointSequence() << QgsPoint( *this ) );
337 
338  return cs;
339 }
340 
342 {
343  return 1;
344 }
345 
347 {
348  if ( id.vertex != 0 )
349  return -1;
350  else
351  return 0;
352 }
353 
355 {
356  return nullptr;
357 }
358 
359 bool QgsPoint::insertVertex( QgsVertexId position, const QgsPoint &vertex )
360 {
361  Q_UNUSED( position );
362  Q_UNUSED( vertex );
363  return false;
364 }
365 
366 /***************************************************************************
367  * This class is considered CRITICAL and any change MUST be accompanied with
368  * full unit tests.
369  * See details in QEP #17
370  ****************************************************************************/
371 
372 bool QgsPoint::moveVertex( QgsVertexId position, const QgsPoint &newPos )
373 {
374  Q_UNUSED( position );
375  clearCache();
376  mX = newPos.mX;
377  mY = newPos.mY;
378  if ( is3D() && newPos.is3D() )
379  {
380  mZ = newPos.mZ;
381  }
382  if ( isMeasure() && newPos.isMeasure() )
383  {
384  mM = newPos.mM;
385  }
386  return true;
387 }
388 
390 {
391  Q_UNUSED( position );
392  return false;
393 }
394 
395 double QgsPoint::closestSegment( const QgsPoint &pt, QgsPoint &segmentPt, QgsVertexId &vertexAfter, bool *leftOf, double epsilon ) const
396 {
397  Q_UNUSED( pt );
398  Q_UNUSED( segmentPt );
399  Q_UNUSED( vertexAfter );
400  Q_UNUSED( leftOf );
401  Q_UNUSED( epsilon );
402  return -1; // no segments - return error
403 }
404 
405 bool QgsPoint::nextVertex( QgsVertexId &id, QgsPoint &vertex ) const
406 {
407  if ( id.vertex < 0 )
408  {
409  id.vertex = 0;
410  if ( id.part < 0 )
411  {
412  id.part = 0;
413  }
414  if ( id.ring < 0 )
415  {
416  id.ring = 0;
417  }
418  vertex = *this;
419  return true;
420  }
421  else
422  {
423  return false;
424  }
425 }
426 
428 {
429  previousVertex = QgsVertexId();
430  nextVertex = QgsVertexId();
431 }
432 
433 double QgsPoint::vertexAngle( QgsVertexId vertex ) const
434 {
435  Q_UNUSED( vertex );
436  return 0.0;
437 }
438 
439 int QgsPoint::vertexCount( int, int ) const
440 {
441  return 1;
442 }
443 
444 int QgsPoint::ringCount( int ) const
445 {
446  return 1;
447 }
448 
450 {
451  return 1;
452 }
453 
455 {
456  return *this;
457 }
458 
460 {
461  return clone();
462 }
463 
465 {
466  return 0.0;
467 }
468 
469 /***************************************************************************
470  * This class is considered CRITICAL and any change MUST be accompanied with
471  * full unit tests.
472  * See details in QEP #17
473  ****************************************************************************/
474 
475 bool QgsPoint::addZValue( double zValue )
476 {
477  if ( QgsWkbTypes::hasZ( mWkbType ) )
478  return false;
479 
481  mZ = zValue;
482  clearCache();
483  return true;
484 }
485 
486 bool QgsPoint::addMValue( double mValue )
487 {
488  if ( QgsWkbTypes::hasM( mWkbType ) )
489  return false;
490 
492  mM = mValue;
493  clearCache();
494  return true;
495 }
496 
497 void QgsPoint::transform( const QTransform &t )
498 {
499  clearCache();
500  qreal x, y;
501  t.map( mX, mY, &x, &y );
502  mX = x;
503  mY = y;
504 }
505 
506 
508 {
509  if ( !is3D() )
510  return false;
511 
513  mZ = std::numeric_limits<double>::quiet_NaN();
514  clearCache();
515  return true;
516 }
517 
519 {
520  if ( !isMeasure() )
521  return false;
522 
524  mM = std::numeric_limits<double>::quiet_NaN();
525  clearCache();
526  return true;
527 }
528 
530 {
531  if ( type == mWkbType )
532  return true;
533 
534  clearCache();
535 
536  switch ( type )
537  {
538  case QgsWkbTypes::Point:
539  mZ = std::numeric_limits<double>::quiet_NaN();
540  mM = std::numeric_limits<double>::quiet_NaN();
541  mWkbType = type;
542  return true;
543  case QgsWkbTypes::PointZ:
545  mM = std::numeric_limits<double>::quiet_NaN();
546  mWkbType = type;
547  return true;
548  case QgsWkbTypes::PointM:
549  mZ = std::numeric_limits<double>::quiet_NaN();
550  mWkbType = type;
551  return true;
553  mWkbType = type;
554  return true;
555  default:
556  break;
557  }
558 
559  return false;
560 }
561 
562 
563 QPointF QgsPoint::toQPointF() const
564 {
565  return QPointF( mX, mY );
566 }
567 
568 double QgsPoint::distance( double x, double y ) const
569 {
570  return std::sqrt( ( mX - x ) * ( mX - x ) + ( mY - y ) * ( mY - y ) );
571 }
572 
573 double QgsPoint::distance( const QgsPoint &other ) const
574 {
575  return std::sqrt( ( mX - other.x() ) * ( mX - other.x() ) + ( mY - other.y() ) * ( mY - other.y() ) );
576 }
577 
578 double QgsPoint::distanceSquared( double x, double y ) const
579 {
580  return ( mX - x ) * ( mX - x ) + ( mY - y ) * ( mY - y );
581 }
582 
583 double QgsPoint::distanceSquared( const QgsPoint &other ) const
584 {
585  return ( mX - other.x() ) * ( mX - other.x() ) + ( mY - other.y() ) * ( mY - other.y() );
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 }
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:354
void draw(QPainter &p) const override
Draws the geometry using the specified QPainter.
Definition: qgspoint.cpp:296
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:464
int nCoordinates() const override
Returns the number of nodes contained in the geometry.
Definition: qgspoint.cpp:341
bool addZValue(double zValue=0) override
Adds a z-dimension to the geometry, initialized to a preset value.
Definition: qgspoint.cpp:475
QPointF toQPointF() const
Returns the point as a QPointF.
Definition: qgspoint.cpp:563
bool fromWkb(QgsConstWkbPtr &wkb) override
Sets the geometry from a WKB string.
Definition: qgspoint.cpp:140
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:459
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:433
double distance(double x, double y) const
Returns the distance between this point and a specified x, y coordinate.
Definition: qgspoint.cpp:568
double azimuth(const QgsPoint &other) const
Calculates azimuth between this point and other one (clockwise in degree, starting from north) ...
Definition: qgspoint.cpp:624
A class to represent a 2D point.
Definition: qgspointxy.h:43
TransformDirection
Enum used to indicate the direction (forward or inverse) of the transform.
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:289
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
QDomElement asGml2(QDomDocument &doc, int precision=17, const QString &ns="gml") const override
Returns a GML2 representation of the geometry.
Definition: qgspoint.cpp:250
void clear() override
Clears the geometry, ie reset it to a null geometry.
Definition: qgspoint.cpp:301
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:227
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:454
bool operator!=(const QgsPoint &pt) const
Definition: qgspoint.cpp:109
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:507
bool moveVertex(QgsVertexId position, const QgsPoint &newPos) override
Moves a vertex within the geometry.
Definition: qgspoint.cpp:372
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:359
bool dropMValue() override
Drops any measure values which exist in the geometry.
Definition: qgspoint.cpp:518
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.
QString qgsDoubleToString(double a, int precision=17)
Returns a string representation of a double.
Definition: qgis.h:213
QString asWkt(int precision=17) const override
Returns a WKT representation of the geometry.
Definition: qgspoint.cpp:238
static Type addZ(Type type)
Adds the z dimension to a WKB type and returns the new type.
Definition: qgswkbtypes.h:864
QgsPoint * clone() const override
Clones the geometry by performing a deep copy.
Definition: qgspoint.cpp:114
double closestSegment(const QgsPoint &pt, QgsPoint &segmentPt, QgsVertexId &vertexAfter, bool *leftOf=nullptr, double epsilon=4 *DBL_EPSILON) const override
Searches for the closest segment of the geometry to a given point.
Definition: qgspoint.cpp:395
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:158
Abstract base class for all geometries.
bool nextVertex(QgsVertexId &id, QgsPoint &vertex) const override
Returns next vertex id and coordinates.
Definition: qgspoint.cpp:405
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
void adjacentVertices(QgsVertexId vertex, QgsVertexId &previousVertex, QgsVertexId &nextVertex) const override
Returns the vertices adjacent to a specified vertex within a geometry.
Definition: qgspoint.cpp:427
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:643
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:444
int vertexCount(int=0, int=0) const override
Returns the number of vertices of which this geometry is built.
Definition: qgspoint.cpp:439
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:449
bool operator==(const QgsPoint &pt) const
Definition: qgspoint.cpp:94
QDomElement asGml3(QDomDocument &doc, int precision=17, const QString &ns="gml") const override
Returns a GML3 representation of the geometry.
Definition: qgspoint.cpp:269
bool fromWkt(const QString &wkt) override
Sets the geometry from a WKT string.
Definition: qgspoint.cpp:168
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:920
QByteArray asWkb() const override
Returns a WKB representation of the geometry.
Definition: qgspoint.cpp:216
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:529
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:486
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:331
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:680
QgsPoint childPoint(int index) const override
Returns point at index (for geometries without child geometries - i.e.
Definition: qgspoint.cpp:695
bool deleteVertex(QgsVertexId position) override
Deletes a vertex within the geometry.
Definition: qgspoint.cpp:389
int childCount() const override
Returns number of child geometries (for geometries with child geometries) or child points (for geomet...
Definition: qgspoint.cpp:690
double distanceSquared(double x, double y) const
Returns the squared distance between this point a specified x, y coordinate.
Definition: qgspoint.cpp:578
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:317
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
double x() const
Returns the point&#39;s x-coordinate.
Definition: qgspoint.h:128
virtual 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:119
int vertexNumberFromVertexId(QgsVertexId id) const override
Returns the vertex number corresponding to a vertex id.
Definition: qgspoint.cpp:346
double m
Definition: qgspoint.h:44
double x
Definition: qgspoint.h:41