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