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