QGIS API Documentation  3.0.2-Girona (307d082)
qgsgeometrycollection.cpp
Go to the documentation of this file.
1 /***************************************************************************
2  qgsgeometrycollection.cpp
3  -------------------------------------------------------------------
4 Date : 28 Oct 2014
5 Copyright : (C) 2014 by Marco Hugentobler
6 email : marco.hugentobler at sourcepole dot com
7  ***************************************************************************
8  * *
9  * This program is free software; you can redistribute it and/or modify *
10  * it under the terms of the GNU General Public License as published by *
11  * the Free Software Foundation; either version 2 of the License, or *
12  * (at your option) any later version. *
13  * *
14  ***************************************************************************/
15 
16 #include "qgsgeometrycollection.h"
17 #include "qgsapplication.h"
18 #include "qgsgeometryfactory.h"
19 #include "qgsgeometryutils.h"
20 #include "qgscircularstring.h"
21 #include "qgscompoundcurve.h"
22 #include "qgslinestring.h"
23 #include "qgsmultilinestring.h"
24 #include "qgspoint.h"
25 #include "qgsmultipoint.h"
26 #include "qgspolygon.h"
27 #include "qgsmultipolygon.h"
28 #include "qgswkbptr.h"
29 #include <memory>
30 
32 {
34 }
35 
37 {
38  int nGeoms = c.mGeometries.size();
39  mGeometries.resize( nGeoms );
40  for ( int i = 0; i < nGeoms; ++i )
41  {
42  mGeometries[i] = c.mGeometries.at( i )->clone();
43  }
44 }
45 
47 {
48  if ( &c != this )
49  {
50  clearCache();
52  int nGeoms = c.mGeometries.size();
53  mGeometries.resize( nGeoms );
54  for ( int i = 0; i < nGeoms; ++i )
55  {
56  mGeometries[i] = c.mGeometries.at( i )->clone();
57  }
58  }
59  return *this;
60 }
61 
63 {
64  clear();
65 }
66 
68 {
69  const QgsGeometryCollection *otherCollection = qgsgeometry_cast< const QgsGeometryCollection * >( &other );
70  if ( !otherCollection )
71  return false;
72 
73  if ( mWkbType != otherCollection->mWkbType )
74  return false;
75 
76  if ( mGeometries.count() != otherCollection->mGeometries.count() )
77  return false;
78 
79  for ( int i = 0; i < mGeometries.count(); ++i )
80  {
81  if ( mGeometries.at( i ) != otherCollection->mGeometries.at( i ) )
82  return false;
83  }
84 
85  return true;
86 }
87 
89 {
90  return !operator==( other );
91 }
92 
94 {
95  auto result = qgis::make_unique< QgsGeometryCollection >();
96  result->mWkbType = mWkbType;
97  return result.release();
98 }
99 
101 {
102  return new QgsGeometryCollection( *this );
103 }
104 
106 {
107  qDeleteAll( mGeometries );
108  mGeometries.clear();
109  clearCache(); //set bounding box invalid
110 }
111 
112 QgsGeometryCollection *QgsGeometryCollection::snappedToGrid( double hSpacing, double vSpacing, double dSpacing, double mSpacing ) const
113 {
114  std::unique_ptr<QgsGeometryCollection> result;
115 
116  for ( auto geom : mGeometries )
117  {
118  std::unique_ptr<QgsAbstractGeometry> gridified { geom->snappedToGrid( hSpacing, vSpacing, dSpacing, mSpacing ) };
119  if ( gridified )
120  {
121  if ( !result )
122  result = std::unique_ptr<QgsGeometryCollection> { createEmptyWithSameType() };
123 
124  result->mGeometries.append( gridified.release() );
125  }
126  }
127 
128  return result.release();
129 }
130 
131 bool QgsGeometryCollection::removeDuplicateNodes( double epsilon, bool useZValues )
132 {
133  bool result = false;
134  for ( QgsAbstractGeometry *geom : qgis::as_const( mGeometries ) )
135  {
136  result = result || geom->removeDuplicateNodes( epsilon, useZValues );
137  }
138  return result;
139 }
140 
142 {
143  return nullptr;
144 }
145 
147 {
148  if ( vertex.part < 0 || vertex.part >= mGeometries.count() )
149  {
150  previousVertex = QgsVertexId();
151  nextVertex = QgsVertexId();
152  return;
153  }
154 
155  mGeometries.at( vertex.part )->adjacentVertices( vertex, previousVertex, nextVertex );
156 }
157 
159 {
160  if ( id.part < 0 || id.part >= mGeometries.count() )
161  return -1;
162 
163  int number = 0;
164  int part = 0;
165  for ( QgsAbstractGeometry *geometry : mGeometries )
166  {
167  if ( part == id.part )
168  {
169  int partNumber = geometry->vertexNumberFromVertexId( QgsVertexId( 0, id.ring, id.vertex ) );
170  if ( partNumber == -1 )
171  return -1;
172  return number + partNumber;
173  }
174  else
175  {
176  number += geometry->nCoordinates();
177  }
178 
179  part++;
180  }
181  return -1; // should not happen
182 }
183 
185 {
186  return mGeometries.size();
187 }
188 
190 {
191  return mGeometries.value( n );
192 }
193 
195 {
196  clearCache();
197  return mGeometries.value( n );
198 }
199 
201 {
202  if ( mGeometries.isEmpty() )
203  return true;
204 
205  for ( QgsAbstractGeometry *geometry : mGeometries )
206  {
207  if ( !geometry->isEmpty() )
208  return false;
209  }
210  return true;
211 }
212 
214 {
215  if ( !g )
216  {
217  return false;
218  }
219 
220  mGeometries.append( g );
221  clearCache(); //set bounding box invalid
222  return true;
223 }
224 
226 {
227  if ( !g )
228  {
229  return false;
230  }
231 
232  index = std::min( mGeometries.count(), index );
233 
234  mGeometries.insert( index, g );
235  clearCache(); //set bounding box invalid
236  return true;
237 }
238 
240 {
241  if ( nr >= mGeometries.size() || nr < 0 )
242  {
243  return false;
244  }
245  delete mGeometries.at( nr );
246  mGeometries.remove( nr );
247  clearCache(); //set bounding box invalid
248  return true;
249 }
250 
252 {
253  int maxDim = 0;
254  QVector< QgsAbstractGeometry * >::const_iterator it = mGeometries.constBegin();
255  for ( ; it != mGeometries.constEnd(); ++it )
256  {
257  int dim = ( *it )->dimension();
258  if ( dim > maxDim )
259  {
260  maxDim = dim;
261  }
262  }
263  return maxDim;
264 }
265 
267 {
268  return QStringLiteral( "GeometryCollection" );
269 }
270 
272 {
273  for ( QgsAbstractGeometry *g : qgis::as_const( mGeometries ) )
274  {
275  g->transform( ct, d, transformZ );
276  }
277  clearCache(); //set bounding box invalid
278 }
279 
280 void QgsGeometryCollection::transform( const QTransform &t, double zTranslate, double zScale, double mTranslate, double mScale )
281 {
282  for ( QgsAbstractGeometry *g : qgis::as_const( mGeometries ) )
283  {
284  g->transform( t, zTranslate, zScale, mTranslate, mScale );
285  }
286  clearCache(); //set bounding box invalid
287 }
288 
289 void QgsGeometryCollection::draw( QPainter &p ) const
290 {
291  QVector< QgsAbstractGeometry * >::const_iterator it = mGeometries.constBegin();
292  for ( ; it != mGeometries.constEnd(); ++it )
293  {
294  ( *it )->draw( p );
295  }
296 }
297 
299 {
300  if ( !wkbPtr )
301  {
302  return false;
303  }
304 
307  return false;
308 
309  mWkbType = wkbType;
310 
311  int nGeometries = 0;
312  wkbPtr >> nGeometries;
313 
314  QVector<QgsAbstractGeometry *> geometryListBackup = mGeometries;
315  mGeometries.clear();
316  for ( int i = 0; i < nGeometries; ++i )
317  {
318  std::unique_ptr< QgsAbstractGeometry > geom( QgsGeometryFactory::geomFromWkb( wkbPtr ) ); // also updates wkbPtr
319  if ( geom )
320  {
321  if ( !addGeometry( geom.release() ) )
322  {
323  qDeleteAll( mGeometries );
324  mGeometries = geometryListBackup;
325  return false;
326  }
327  }
328  }
329  qDeleteAll( geometryListBackup );
330 
331  clearCache(); //set bounding box invalid
332 
333  return true;
334 }
335 
336 bool QgsGeometryCollection::fromWkt( const QString &wkt )
337 {
338  return fromCollectionWkt( wkt, QVector<QgsAbstractGeometry *>() << new QgsPoint << new QgsLineString << new QgsPolygon
339  << new QgsCircularString << new QgsCompoundCurve
340  << new QgsCurvePolygon
341  << new QgsMultiPoint << new QgsMultiLineString
343  << new QgsMultiCurve << new QgsMultiSurface, QStringLiteral( "GeometryCollection" ) );
344 }
345 
347 {
348  int binarySize = sizeof( char ) + sizeof( quint32 ) + sizeof( quint32 );
349  QVector<QByteArray> wkbForGeometries;
350  for ( const QgsAbstractGeometry *geom : mGeometries )
351  {
352  if ( geom )
353  {
354  QByteArray wkb( geom->asWkb() );
355  binarySize += wkb.length();
356  wkbForGeometries << wkb;
357  }
358  }
359 
360  QByteArray wkbArray;
361  wkbArray.resize( binarySize );
362  QgsWkbPtr wkb( wkbArray );
363  wkb << static_cast<char>( QgsApplication::endian() );
364  wkb << static_cast<quint32>( wkbType() );
365  wkb << static_cast<quint32>( wkbForGeometries.count() );
366  for ( const QByteArray &wkbForGeometry : qgis::as_const( wkbForGeometries ) )
367  {
368  wkb << wkbForGeometry;
369  }
370  return wkbArray;
371 }
372 
373 QString QgsGeometryCollection::asWkt( int precision ) const
374 {
375  QString wkt = wktTypeStr() + " (";
376  for ( const QgsAbstractGeometry *geom : mGeometries )
377  {
378  QString childWkt = geom->asWkt( precision );
379  if ( wktOmitChildType() )
380  {
381  childWkt = childWkt.mid( childWkt.indexOf( '(' ) );
382  }
383  wkt += childWkt + ',';
384  }
385  if ( wkt.endsWith( ',' ) )
386  {
387  wkt.chop( 1 ); // Remove last ','
388  }
389  wkt += ')';
390  return wkt;
391 }
392 
393 QDomElement QgsGeometryCollection::asGml2( QDomDocument &doc, int precision, const QString &ns ) const
394 {
395  QDomElement elemMultiGeometry = doc.createElementNS( ns, QStringLiteral( "MultiGeometry" ) );
396  for ( const QgsAbstractGeometry *geom : mGeometries )
397  {
398  QDomElement elemGeometryMember = doc.createElementNS( ns, QStringLiteral( "geometryMember" ) );
399  elemGeometryMember.appendChild( geom->asGml2( doc, precision, ns ) );
400  elemMultiGeometry.appendChild( elemGeometryMember );
401  }
402  return elemMultiGeometry;
403 }
404 
405 QDomElement QgsGeometryCollection::asGml3( QDomDocument &doc, int precision, const QString &ns ) const
406 {
407  QDomElement elemMultiGeometry = doc.createElementNS( ns, QStringLiteral( "MultiGeometry" ) );
408  for ( const QgsAbstractGeometry *geom : mGeometries )
409  {
410  QDomElement elemGeometryMember = doc.createElementNS( ns, QStringLiteral( "geometryMember" ) );
411  elemGeometryMember.appendChild( geom->asGml3( doc, precision, ns ) );
412  elemMultiGeometry.appendChild( elemGeometryMember );
413  }
414  return elemMultiGeometry;
415 }
416 
417 QString QgsGeometryCollection::asJson( int precision ) const
418 {
419  QString json = QStringLiteral( "{\"type\": \"GeometryCollection\", \"geometries\": [" );
420  for ( const QgsAbstractGeometry *geom : mGeometries )
421  {
422  json += geom->asJson( precision ) + ", ";
423  }
424  if ( json.endsWith( QLatin1String( ", " ) ) )
425  {
426  json.chop( 2 ); // Remove last ", "
427  }
428  json += QLatin1String( "] }" );
429  return json;
430 }
431 
433 {
434  if ( mBoundingBox.isNull() )
435  {
436  mBoundingBox = calculateBoundingBox();
437  }
438  return mBoundingBox;
439 }
440 
442 {
443  if ( mGeometries.empty() )
444  {
445  return QgsRectangle();
446  }
447 
448  QgsRectangle bbox = mGeometries.at( 0 )->boundingBox();
449  for ( int i = 1; i < mGeometries.size(); ++i )
450  {
451  QgsRectangle geomBox = mGeometries.at( i )->boundingBox();
452  bbox.combineExtentWith( geomBox );
453  }
454  return bbox;
455 }
456 
458 {
459  mBoundingBox = QgsRectangle();
461 }
462 
464 {
465  QgsCoordinateSequence sequence;
466  QVector< QgsAbstractGeometry * >::const_iterator geomIt = mGeometries.constBegin();
467  for ( ; geomIt != mGeometries.constEnd(); ++geomIt )
468  {
469  QgsCoordinateSequence geomCoords = ( *geomIt )->coordinateSequence();
470 
471  QgsCoordinateSequence::const_iterator cIt = geomCoords.constBegin();
472  for ( ; cIt != geomCoords.constEnd(); ++cIt )
473  {
474  sequence.push_back( *cIt );
475  }
476  }
477 
478  return sequence;
479 }
480 
482 {
483  int count = 0;
484 
485  QVector< QgsAbstractGeometry * >::const_iterator geomIt = mGeometries.constBegin();
486  for ( ; geomIt != mGeometries.constEnd(); ++geomIt )
487  {
488  count += ( *geomIt )->nCoordinates();
489  }
490 
491  return count;
492 }
493 
494 double QgsGeometryCollection::closestSegment( const QgsPoint &pt, QgsPoint &segmentPt, QgsVertexId &vertexAfter, int *leftOf, double epsilon ) const
495 {
496  return QgsGeometryUtils::closestSegmentFromComponents( mGeometries, QgsGeometryUtils::Part, pt, segmentPt, vertexAfter, leftOf, epsilon );
497 }
498 
500 {
501  if ( id.part < 0 )
502  {
503  id.part = 0;
504  id.ring = -1;
505  id.vertex = -1;
506  }
507  if ( mGeometries.isEmpty() )
508  {
509  return false;
510  }
511 
512  if ( id.part >= mGeometries.count() )
513  return false;
514 
515  QgsAbstractGeometry *geom = mGeometries.at( id.part );
516  if ( geom->nextVertex( id, vertex ) )
517  {
518  return true;
519  }
520  if ( ( id.part + 1 ) >= numGeometries() )
521  {
522  return false;
523  }
524  ++id.part;
525  id.ring = -1;
526  id.vertex = -1;
527  return mGeometries.at( id.part )->nextVertex( id, vertex );
528 }
529 
531 {
532  if ( position.part >= mGeometries.size() )
533  {
534  return false;
535  }
536 
537  bool success = mGeometries.at( position.part )->insertVertex( position, vertex );
538  if ( success )
539  {
540  clearCache(); //set bounding box invalid
541  }
542  return success;
543 }
544 
546 {
547  if ( position.part < 0 || position.part >= mGeometries.size() )
548  {
549  return false;
550  }
551 
552  bool success = mGeometries.at( position.part )->moveVertex( position, newPos );
553  if ( success )
554  {
555  clearCache(); //set bounding box invalid
556  }
557  return success;
558 }
559 
561 {
562  if ( position.part < 0 || position.part >= mGeometries.size() )
563  {
564  return false;
565  }
566 
567  QgsAbstractGeometry *geom = mGeometries.at( position.part );
568  if ( !geom )
569  {
570  return false;
571  }
572 
573  bool success = geom->deleteVertex( position );
574 
575  //remove geometry if no vertices left
576  if ( geom->isEmpty() )
577  {
578  removeGeometry( position.part );
579  }
580 
581  if ( success )
582  {
583  clearCache(); //set bounding box invalid
584  }
585  return success;
586 }
587 
589 {
590  double length = 0.0;
591  QVector< QgsAbstractGeometry * >::const_iterator geomIt = mGeometries.constBegin();
592  for ( ; geomIt != mGeometries.constEnd(); ++geomIt )
593  {
594  length += ( *geomIt )->length();
595  }
596  return length;
597 }
598 
600 {
601  double area = 0.0;
602  QVector< QgsAbstractGeometry * >::const_iterator geomIt = mGeometries.constBegin();
603  for ( ; geomIt != mGeometries.constEnd(); ++geomIt )
604  {
605  area += ( *geomIt )->area();
606  }
607  return area;
608 }
609 
611 {
612  double perimeter = 0.0;
613  QVector< QgsAbstractGeometry * >::const_iterator geomIt = mGeometries.constBegin();
614  for ( ; geomIt != mGeometries.constEnd(); ++geomIt )
615  {
616  perimeter += ( *geomIt )->perimeter();
617  }
618  return perimeter;
619 }
620 
621 bool QgsGeometryCollection::fromCollectionWkt( const QString &wkt, const QVector<QgsAbstractGeometry *> &subtypes, const QString &defaultChildWkbType )
622 {
623  clear();
624 
625  QPair<QgsWkbTypes::Type, QString> parts = QgsGeometryUtils::wktReadBlock( wkt );
626 
627  if ( QgsWkbTypes::flatType( parts.first ) != QgsWkbTypes::flatType( wkbType() ) )
628  {
629  qDeleteAll( subtypes );
630  return false;
631  }
632  mWkbType = parts.first;
633 
634  QString defChildWkbType = QStringLiteral( "%1%2%3 " ).arg( defaultChildWkbType, is3D() ? "Z" : "", isMeasure() ? "M" : "" );
635 
636  const QStringList blocks = QgsGeometryUtils::wktGetChildBlocks( parts.second, defChildWkbType );
637  for ( const QString &childWkt : blocks )
638  {
639  QPair<QgsWkbTypes::Type, QString> childParts = QgsGeometryUtils::wktReadBlock( childWkt );
640 
641  bool success = false;
642  for ( const QgsAbstractGeometry *geom : subtypes )
643  {
644  if ( QgsWkbTypes::flatType( childParts.first ) == QgsWkbTypes::flatType( geom->wkbType() ) )
645  {
646  mGeometries.append( geom->clone() );
647  if ( mGeometries.back()->fromWkt( childWkt ) )
648  {
649  success = true;
650  break;
651  }
652  }
653  }
654  if ( !success )
655  {
656  clear();
657  qDeleteAll( subtypes );
658  return false;
659  }
660  }
661  qDeleteAll( subtypes );
662 
663  //scan through geometries and check if dimensionality of geometries is different to collection.
664  //if so, update the type dimensionality of the collection to match
665  bool hasZ = false;
666  bool hasM = false;
667  for ( QgsAbstractGeometry *geom : qgis::as_const( mGeometries ) )
668  {
669  hasZ = hasZ || geom->is3D();
670  hasM = hasM || geom->isMeasure();
671  if ( hasZ && hasM )
672  break;
673  }
674  if ( hasZ )
675  addZValue( 0 );
676  if ( hasM )
677  addMValue( 0 );
678 
679  return true;
680 }
681 
683 {
684  QVector< QgsAbstractGeometry * >::const_iterator it = mGeometries.constBegin();
685  for ( ; it != mGeometries.constEnd(); ++it )
686  {
687  if ( ( *it )->hasCurvedSegments() )
688  {
689  return true;
690  }
691  }
692  return false;
693 }
694 
696 {
697  std::unique_ptr< QgsAbstractGeometry > geom( QgsGeometryFactory::geomFromWkbType( mWkbType ) );
698  QgsGeometryCollection *geomCollection = qgsgeometry_cast<QgsGeometryCollection *>( geom.get() );
699  if ( !geomCollection )
700  {
701  return clone();
702  }
703 
704  QVector< QgsAbstractGeometry * >::const_iterator geomIt = mGeometries.constBegin();
705  for ( ; geomIt != mGeometries.constEnd(); ++geomIt )
706  {
707  geomCollection->addGeometry( ( *geomIt )->segmentize( tolerance, toleranceType ) );
708  }
709  return geom.release();
710 }
711 
713 {
714  if ( vertex.part < 0 || vertex.part >= mGeometries.size() )
715  {
716  return 0.0;
717  }
718 
719  QgsAbstractGeometry *geom = mGeometries[vertex.part];
720  if ( !geom )
721  {
722  return 0.0;
723  }
724 
725  return geom->vertexAngle( vertex );
726 }
727 
729 {
730  if ( startVertex.part < 0 || startVertex.part >= mGeometries.size() )
731  {
732  return 0.0;
733  }
734 
735  const QgsAbstractGeometry *geom = mGeometries[startVertex.part];
736  if ( !geom )
737  {
738  return 0.0;
739  }
740 
741  return geom->segmentLength( startVertex );
742 }
743 
744 int QgsGeometryCollection::vertexCount( int part, int ring ) const
745 {
746  if ( part < 0 || part >= mGeometries.size() )
747  {
748  return 0;
749  }
750 
751  return mGeometries[part]->vertexCount( 0, ring );
752 }
753 
754 int QgsGeometryCollection::ringCount( int part ) const
755 {
756  if ( part < 0 || part >= mGeometries.size() )
757  {
758  return 0;
759  }
760 
761  return mGeometries[part]->ringCount();
762 }
763 
765 {
766  return mGeometries.size();
767 }
768 
770 {
771  return mGeometries[id.part]->vertexAt( id );
772 }
773 
774 bool QgsGeometryCollection::addZValue( double zValue )
775 {
776  if ( QgsWkbTypes::hasZ( mWkbType ) )
777  return false;
778 
780 
781  for ( QgsAbstractGeometry *geom : qgis::as_const( mGeometries ) )
782  {
783  geom->addZValue( zValue );
784  }
785  clearCache();
786  return true;
787 }
788 
789 bool QgsGeometryCollection::addMValue( double mValue )
790 {
791  if ( QgsWkbTypes::hasM( mWkbType ) )
792  return false;
793 
795 
796  for ( QgsAbstractGeometry *geom : qgis::as_const( mGeometries ) )
797  {
798  geom->addMValue( mValue );
799  }
800  clearCache();
801  return true;
802 }
803 
804 
806 {
808  return false;
809 
811  for ( QgsAbstractGeometry *geom : qgis::as_const( mGeometries ) )
812  {
813  geom->dropZValue();
814  }
815  clearCache();
816  return true;
817 }
818 
820 {
822  return false;
823 
825  for ( QgsAbstractGeometry *geom : qgis::as_const( mGeometries ) )
826  {
827  geom->dropMValue();
828  }
829  clearCache();
830  return true;
831 }
832 
834 {
835  std::unique_ptr< QgsGeometryCollection > newCollection( new QgsGeometryCollection() );
836  for ( QgsAbstractGeometry *geom : mGeometries )
837  {
838  newCollection->addGeometry( geom->toCurveType() );
839  }
840  return newCollection.release();
841 }
842 
844 {
845  return false;
846 }
847 
849 {
850  return mGeometries.count();
851 }
852 
854 {
855  if ( index < 0 || index > mGeometries.count() )
856  return nullptr;
857  return mGeometries.at( index );
858 }
bool isMeasure() const
Returns true if the geometry contains m values.
static std::unique_ptr< QgsAbstractGeometry > geomFromWkb(QgsConstWkbPtr &wkb)
Construct geometry from a WKB string.
QDomElement asGml2(QDomDocument &doc, int precision=17, const QString &ns="gml") const override
Returns a GML2 representation of the geometry.
virtual bool removeGeometry(int nr)
Removes a geometry from the collection.
bool nextVertex(QgsVertexId &id, QgsPoint &vertex) const override
Returns next vertex id and coordinates.
bool dropZValue() override
Drops any z-dimensions which exist in the geometry.
A rectangle specified with double values.
Definition: qgsrectangle.h:39
bool operator!=(const QgsAbstractGeometry &other) const override
virtual bool isEmpty() const
Returns true if the geometry is empty.
static std::unique_ptr< QgsAbstractGeometry > geomFromWkbType(QgsWkbTypes::Type t)
Return empty geometry from wkb type.
virtual bool deleteVertex(QgsVertexId position)=0
Deletes a vertex within the geometry.
bool fromWkb(QgsConstWkbPtr &wkb) override
Sets the geometry from a WKB string.
bool operator==(const QgsAbstractGeometry &other) const override
void clear() override
Clears the geometry, ie reset it to a null geometry.
bool addZValue(double zValue=0) override
Adds a z-dimension to the geometry, initialized to a preset value.
QgsAbstractGeometry & operator=(const QgsAbstractGeometry &geom)
Multi point geometry collection.
Definition: qgsmultipoint.h:29
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 (...
QgsGeometryCollection * 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...
QVector< QgsRingSequence > QgsCoordinateSequence
bool fromWkt(const QString &wkt) override
Sets the geometry from a WKT string.
TransformDirection
Enum used to indicate the direction (forward or inverse) of the transform.
bool hasCurvedSegments() const override
Returns true if the geometry contains curved segments.
virtual double vertexAngle(QgsVertexId vertex) const =0
Returns approximate angle at a vertex.
Multi line string geometry collection.
Curve polygon geometry type.
double closestSegment(const QgsPoint &pt, QgsPoint &segmentPt, QgsVertexId &vertexAfter, int *leftOf=nullptr, double epsilon=4 *DBL_EPSILON) const override
Searches for the closest segment of the geometry to a given point.
bool insertVertex(QgsVertexId position, const QgsPoint &vertex) override
Inserts a vertex into the geometry.
QgsAbstractGeometry * boundary() const override
Returns the closure of the combinatorial boundary of the geometry (ie the topological boundary of the...
virtual bool wktOmitChildType() const
Returns whether child type names are omitted from Wkt representations of the collection.
SegmentationToleranceType
Segmentation tolerance as maximum angle or maximum difference between approximation and circle...
double segmentLength(QgsVertexId startVertex) const override
Returns the length of the segment of the geometry which begins at startVertex.
QgsGeometryCollection & operator=(const QgsGeometryCollection &c)
virtual bool nextVertex(QgsVertexId &id, QgsPoint &vertex) const =0
Returns next vertex id and coordinates.
bool removeDuplicateNodes(double epsilon=4 *DBL_EPSILON, bool useZValues=false) override
Removes duplicate nodes from the geometry, wherever removing the nodes does not result in a degenerat...
bool dropMValue() override
Drops any measure values which exist in the geometry.
static endian_t endian()
Returns whether this machine uses big or little endian.
static bool hasZ(Type type)
Tests whether a WKB type contains the z-dimension.
Definition: qgswkbtypes.h:768
static QStringList wktGetChildBlocks(const QString &wkt, const QString &defaultType=QString())
Parses a WKT string and returns of list of blocks contained in the WKT.
static Type dropM(Type type)
Drops the m dimension (if present) for a WKB type and returns the new type.
Definition: qgswkbtypes.h:938
Multi surface geometry collection.
double length() const override
Returns the length of the geometry.
QString asJson(int precision=17) const override
Returns a GeoJSON representation of the geometry.
QgsWkbTypes::Type mWkbType
virtual bool insertGeometry(QgsAbstractGeometry *g, int index)
Inserts a geometry before a specified index and takes ownership.
QString wktTypeStr() const
Returns the WKT type string of the geometry.
bool isEmpty() const override
Returns true if the geometry is empty.
void adjacentVertices(QgsVertexId vertex, QgsVertexId &previousVertex, QgsVertexId &nextVertex) const override
Returns the vertices adjacent to a specified vertex within a geometry.
int nCoordinates() const override
Returns the number of nodes contained in the geometry.
Type
The WKB type describes the number of dimensions a geometry has.
Definition: qgswkbtypes.h:67
bool addMValue(double mValue=0) override
Adds a measure to the geometry, initialized to a preset value.
QDomElement asGml3(QDomDocument &doc, int precision=17, const QString &ns="gml") const override
Returns a GML3 representation of the geometry.
virtual void clearCache() const
Clears any cached parameters associated with the geometry, e.g., bounding boxes.
virtual double segmentLength(QgsVertexId startVertex) const =0
Returns the length of the segment of the geometry which begins at startVertex.
static Type addM(Type type)
Adds the m dimension to a WKB type and returns the new type.
Definition: qgswkbtypes.h:889
int dimension() const override
Returns the inherent dimension of the geometry.
Utility class for identifying a unique vertex within a geometry.
Geometry collection.
QString asWkt(int precision=17) const override
Returns a WKT representation of the geometry.
QgsGeometryCollection * createEmptyWithSameType() const override
Creates a new geometry with the same class and same WKB type as the original and transfers ownership...
double area() const override
Returns the area of the geometry.
QgsAbstractGeometry * childGeometry(int index) const override
Returns pointer to child geometry (for geometries with child geometries - i.e.
static Type addZ(Type type)
Adds the z dimension to a WKB type and returns the new type.
Definition: qgswkbtypes.h:864
T qgsgeometry_cast(const QgsAbstractGeometry *geom)
int childCount() const override
Returns number of child geometries (for geometries with child geometries) or child points (for geomet...
Multi curve geometry collection.
Definition: qgsmulticurve.h:29
QgsAbstractGeometry * segmentize(double tolerance=M_PI_2/90, SegmentationToleranceType toleranceType=MaximumAngle) const override
Returns a geometry without curves.
QString geometryType() const override
Returns a unique string representing the geometry type.
QByteArray asWkb() const override
Returns a WKB representation of the geometry.
void transform(const QgsCoordinateTransform &ct, QgsCoordinateTransform::TransformDirection d=QgsCoordinateTransform::ForwardTransform, bool transformZ=false) override
Transforms the geometry using a coordinate transform.
bool deleteVertex(QgsVertexId position) override
Deletes a vertex within the geometry.
Abstract base class for all geometries.
void clearCache() const override
Clears any cached parameters associated with the geometry, e.g., bounding boxes.
QgsWkbTypes::Type wkbType() const
Returns the WKB type of the geometry.
int vertexNumberFromVertexId(QgsVertexId id) const override
Returns the vertex number corresponding to a vertex id.
Point geometry type, with support for z-dimension and m-values.
Definition: qgspoint.h:37
bool fromCollectionWkt(const QString &wkt, const QVector< QgsAbstractGeometry *> &subtypes, const QString &defaultChildWkbType=QString())
Reads a collection from a WKT string.
int numGeometries() const
Returns the number of geometries within the collection.
void combineExtentWith(const QgsRectangle &rect)
Expand the rectangle so that covers both the original rectangle and the given rectangle.
int partCount() const override
Returns count of parts contained in the geometry.
QVector< QgsAbstractGeometry *> mGeometries
static Type dropZ(Type type)
Drops the z dimension (if present) for a WKB type and returns the new type.
Definition: qgswkbtypes.h:920
Multi polygon geometry collection.
const QgsAbstractGeometry * geometryN(int n) const
Returns a const reference to a geometry from within the collection.
QgsPoint vertexAt(QgsVertexId id) const override
Returns the point corresponding to a specified vertex id.
QgsRectangle boundingBox() const override
Returns the minimal bounding box for the geometry.
Line string geometry type, with support for z-dimension and m-values.
Definition: qgslinestring.h:41
QgsGeometryCollection * toCurveType() const override
Returns the geometry converted to the more generic curve type.
QgsCoordinateSequence coordinateSequence() const override
Retrieves the sequence of geometries, rings and nodes.
bool moveVertex(QgsVertexId position, const QgsPoint &newPos) override
Moves a vertex within the geometry.
bool isNull() const
Test if the rectangle is null (all coordinates zero or after call to setMinimal()).
Class for doing transforms between two map coordinate systems.
double perimeter() const override
Returns the perimeter of the geometry.
static bool hasM(Type type)
Tests whether a WKB type contains m values.
Definition: qgswkbtypes.h:818
Compound curve geometry type.
Circular string geometry type.
QgsGeometryCollection * clone() const override
Clones the geometry by performing a deep copy.
Polygon geometry type.
Definition: qgspolygon.h:31
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
static double closestSegmentFromComponents(T &container, ComponentType ctype, const QgsPoint &pt, QgsPoint &segmentPt, QgsVertexId &vertexAfter, int *leftOf, double epsilon)
int vertexCount(int part=0, int ring=0) const override
Returns the number of vertices of which this geometry is built.
void draw(QPainter &p) const override
Draws the geometry using the specified QPainter.
virtual bool addGeometry(QgsAbstractGeometry *g)
Adds a geometry and takes ownership. Returns true in case of success.
double vertexAngle(QgsVertexId vertex) const override
Returns approximate angle at a vertex.
QgsRectangle calculateBoundingBox() const override
Default calculator for the minimal bounding box for the geometry.
int ringCount(int part=0) const override
Returns the number of rings of which this geometry is built.