QGIS API Documentation  2.14.0-Essen
qgscompoundcurvev2.cpp
Go to the documentation of this file.
1 /***************************************************************************
2  qgscompoundcurvev2.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 #include "qgscompoundcurvev2.h"
19 #include "qgsapplication.h"
20 #include "qgscircularstringv2.h"
21 #include "qgsgeometryutils.h"
22 #include "qgslinestringv2.h"
23 #include "qgswkbptr.h"
24 #include <QPainter>
25 #include <QPainterPath>
26 
27 
29 {
30 
31 }
32 
34 {
35  clear();
36 }
37 
38 bool QgsCompoundCurveV2::operator==( const QgsCurveV2& other ) const
39 {
40  const QgsCompoundCurveV2* otherCurve = dynamic_cast< const QgsCompoundCurveV2* >( &other );
41  if ( !otherCurve )
42  return false;
43 
44  return *otherCurve == *this;
45 }
46 
47 bool QgsCompoundCurveV2::operator!=( const QgsCurveV2& other ) const
48 {
49  return !operator==( other );
50 }
51 
53 {
54  Q_FOREACH ( const QgsCurveV2* c, curve.mCurves )
55  {
56  mCurves.append( static_cast<QgsCurveV2*>( c->clone() ) );
57  }
58 }
59 
61 {
62  if ( &curve != this )
63  {
64  clearCache();
65  QgsCurveV2::operator=( curve );
66  Q_FOREACH ( const QgsCurveV2* c, curve.mCurves )
67  {
68  mCurves.append( static_cast<QgsCurveV2*>( c->clone() ) );
69  }
70  }
71  return *this;
72 }
73 
75 {
76  return new QgsCompoundCurveV2( *this );
77 }
78 
80 {
81  qDeleteAll( mCurves );
82  mCurves.clear();
84  clearCache();
85 }
86 
88 {
89  if ( mCurves.size() < 1 )
90  {
91  return QgsRectangle();
92  }
93 
94  QgsRectangle bbox = mCurves.at( 0 )->boundingBox();
95  for ( int i = 1; i < mCurves.size(); ++i )
96  {
97  QgsRectangle curveBox = mCurves.at( i )->boundingBox();
98  bbox.combineExtentWith( &curveBox );
99  }
100  return bbox;
101 }
102 
104 {
105  clear();
106  if ( !wkbPtr )
107  {
108  return false;
109  }
110 
111  QgsWKBTypes::Type type = wkbPtr.readHeader();
113  {
114  return false;
115  }
116  mWkbType = type;
117 
118  int nCurves;
119  wkbPtr >> nCurves;
120  QgsCurveV2* currentCurve = nullptr;
121  int currentCurveSize = 0;
122  for ( int i = 0; i < nCurves; ++i )
123  {
124  QgsWKBTypes::Type curveType = wkbPtr.readHeader();
125  wkbPtr -= 1 + sizeof( int );
126  if ( QgsWKBTypes::flatType( curveType ) == QgsWKBTypes::LineString )
127  {
128  currentCurve = new QgsLineStringV2();
129  }
130  else if ( QgsWKBTypes::flatType( curveType ) == QgsWKBTypes::CircularString )
131  {
132  currentCurve = new QgsCircularStringV2();
133  }
134  else
135  {
136  return false;
137  }
138  currentCurve->fromWkb( wkbPtr );
139  currentCurveSize = currentCurve->wkbSize();
140  mCurves.append( currentCurve );
141  wkbPtr += currentCurveSize;
142  }
143  return true;
144 }
145 
147 {
148  clear();
149 
151 
152  if ( QgsWKBTypes::flatType( parts.first ) != QgsWKBTypes::parseType( geometryType() ) )
153  return false;
154  mWkbType = parts.first;
155 
156  QString defaultChildWkbType = QString( "LineString%1%2" ).arg( is3D() ? "Z" : "", isMeasure() ? "M" : "" );
157 
158  Q_FOREACH ( const QString& childWkt, QgsGeometryUtils::wktGetChildBlocks( parts.second, defaultChildWkbType ) )
159  {
161 
162  if ( QgsWKBTypes::flatType( childParts.first ) == QgsWKBTypes::LineString )
163  mCurves.append( new QgsLineStringV2() );
164  else if ( QgsWKBTypes::flatType( childParts.first ) == QgsWKBTypes::CircularString )
165  mCurves.append( new QgsCircularStringV2() );
166  else
167  {
168  clear();
169  return false;
170  }
171  if ( !mCurves.back()->fromWkt( childWkt ) )
172  {
173  clear();
174  return false;
175  }
176  }
177 
178  //scan through curves and check if dimensionality of curves is different to compound curve.
179  //if so, update the type dimensionality of the compound curve to match
180  bool hasZ = false;
181  bool hasM = false;
182  Q_FOREACH ( const QgsCurveV2* curve, mCurves )
183  {
184  hasZ = hasZ || curve->is3D();
185  hasM = hasM || curve->isMeasure();
186  if ( hasZ && hasM )
187  break;
188  }
189  if ( hasZ )
190  addZValue( 0 );
191  if ( hasM )
192  addMValue( 0 );
193 
194  return true;
195 }
196 
198 {
199  int size = sizeof( char ) + sizeof( quint32 ) + sizeof( quint32 );
200  Q_FOREACH ( const QgsCurveV2 *curve, mCurves )
201  {
202  size += curve->wkbSize();
203  }
204  return size;
205 }
206 
207 unsigned char* QgsCompoundCurveV2::asWkb( int& binarySize ) const
208 {
209  binarySize = wkbSize();
210  unsigned char* geomPtr = new unsigned char[binarySize];
211  QgsWkbPtr wkb( geomPtr, binarySize );
212  wkb << static_cast<char>( QgsApplication::endian() );
213  wkb << static_cast<quint32>( wkbType() );
214  wkb << static_cast<quint32>( mCurves.size() );
215  Q_FOREACH ( const QgsCurveV2* curve, mCurves )
216  {
217  int curveWkbLen = 0;
218  unsigned char* curveWkb = curve->asWkb( curveWkbLen );
219  memcpy( wkb, curveWkb, curveWkbLen );
220  wkb += curveWkbLen;
221  delete[] curveWkb;
222  }
223  return geomPtr;
224 }
225 
226 QString QgsCompoundCurveV2::asWkt( int precision ) const
227 {
228  QString wkt = wktTypeStr() + " (";
229  Q_FOREACH ( const QgsCurveV2* curve, mCurves )
230  {
231  QString childWkt = curve->asWkt( precision );
232  if ( dynamic_cast<const QgsLineStringV2*>( curve ) )
233  {
234  // Type names of linear geometries are omitted
235  childWkt = childWkt.mid( childWkt.indexOf( '(' ) );
236  }
237  wkt += childWkt + ',';
238  }
239  if ( wkt.endsWith( ',' ) )
240  {
241  wkt.chop( 1 );
242  }
243  wkt += ')';
244  return wkt;
245 }
246 
247 QDomElement QgsCompoundCurveV2::asGML2( QDomDocument& doc, int precision, const QString& ns ) const
248 {
249  // GML2 does not support curves
250  QgsLineStringV2* line = curveToLine();
251  QDomElement gml = line->asGML2( doc, precision, ns );
252  delete line;
253  return gml;
254 }
255 
256 QDomElement QgsCompoundCurveV2::asGML3( QDomDocument& doc, int precision, const QString& ns ) const
257 {
258  QDomElement elemCurve = doc.createElementNS( ns, "Curve" );
259 
260  QDomElement elemSegments = doc.createElementNS( ns, "segments" );
261 
262  Q_FOREACH ( const QgsCurveV2* curve, mCurves )
263  {
264  if ( dynamic_cast<const QgsLineStringV2*>( curve ) )
265  {
266  QgsPointSequenceV2 pts;
267  curve->points( pts );
268 
269  QDomElement elemLineStringSegment = doc.createElementNS( ns, "LineStringSegment" );
270  elemLineStringSegment.appendChild( QgsGeometryUtils::pointsToGML3( pts, doc, precision, ns, is3D() ) );
271  elemSegments.appendChild( elemLineStringSegment );
272  }
273  else if ( dynamic_cast<const QgsCircularStringV2*>( curve ) )
274  {
275  QgsPointSequenceV2 pts;
276  curve->points( pts );
277 
278  QDomElement elemArcString = doc.createElementNS( ns, "ArcString" );
279  elemArcString.appendChild( QgsGeometryUtils::pointsToGML3( pts, doc, precision, ns, is3D() ) );
280  elemSegments.appendChild( elemArcString );
281  }
282  }
283  elemCurve.appendChild( elemSegments );
284  return elemCurve;
285 }
286 
287 QString QgsCompoundCurveV2::asJSON( int precision ) const
288 {
289  // GeoJSON does not support curves
290  QgsLineStringV2* line = curveToLine();
291  QString json = line->asJSON( precision );
292  delete line;
293  return json;
294 }
295 
297 {
298  double length = 0;
300  for ( ; curveIt != mCurves.constEnd(); ++curveIt )
301  {
302  length += ( *curveIt )->length();
303  }
304  return length;
305 }
306 
308 {
309  if ( mCurves.size() < 1 )
310  {
311  return QgsPointV2();
312  }
313  return mCurves.at( 0 )->startPoint();
314 }
315 
317 {
318  if ( mCurves.size() < 1 )
319  {
320  return QgsPointV2();
321  }
322  return mCurves.at( mCurves.size() - 1 )->endPoint();
323 }
324 
326 {
327  pts.clear();
328  if ( mCurves.size() < 1 )
329  {
330  return;
331  }
332 
333  mCurves[0]->points( pts );
334  for ( int i = 1; i < mCurves.size(); ++i )
335  {
336  QgsPointSequenceV2 pList;
337  mCurves[i]->points( pList );
338  pList.removeFirst(); //first vertex already added in previous line
339  pts.append( pList );
340  }
341 }
342 
344 {
345  int nPoints = 0;
346  int nCurves = mCurves.size();
347  if ( nCurves < 1 )
348  {
349  return 0;
350  }
351 
352  for ( int i = 0; i < nCurves; ++i )
353  {
354  nPoints += mCurves.at( i )->numPoints() - 1; //last vertex is equal to first of next section
355  }
356  nPoints += 1; //last vertex was removed above
357  return nPoints;
358 }
359 
361 {
363  QgsLineStringV2* line = new QgsLineStringV2();
364  QgsLineStringV2* currentLine = nullptr;
365  for ( ; curveIt != mCurves.constEnd(); ++curveIt )
366  {
367  currentLine = ( *curveIt )->curveToLine();
368  line->append( currentLine );
369  delete currentLine;
370  }
371  return line;
372 }
373 
375 {
376  if ( i >= mCurves.size() )
377  {
378  return nullptr;
379  }
380  return mCurves.at( i );
381 }
382 
384 {
385  if ( c )
386  {
387  mCurves.append( c );
388 
390  {
392  }
393  clearCache();
394  }
395 }
396 
398 {
399  if ( mCurves.size() - 1 < i )
400  {
401  return;
402  }
403 
404  delete( mCurves.at( i ) );
405  mCurves.removeAt( i );
406  clearCache();
407 }
408 
410 {
412  {
414  }
415 
416  //is last curve QgsLineStringV2
417  QgsCurveV2* lastCurve = nullptr;
418  if ( !mCurves.isEmpty() )
419  {
420  lastCurve = mCurves.at( mCurves.size() - 1 );
421  }
422 
423  QgsLineStringV2* line = nullptr;
424  if ( !lastCurve || lastCurve->geometryType() != "LineString" )
425  {
426  line = new QgsLineStringV2();
427  mCurves.append( line );
428  if ( lastCurve )
429  {
430  line->addVertex( lastCurve->endPoint() );
431  }
432  lastCurve = line;
433  }
434  else //create new QgsLineStringV2* with point in it
435  {
436  line = static_cast<QgsLineStringV2*>( lastCurve );
437  }
438  line->addVertex( pt );
439  clearCache();
440 }
441 
443 {
445  for ( ; it != mCurves.constEnd(); ++it )
446  {
447  ( *it )->draw( p );
448  }
449 }
450 
452 {
453  Q_FOREACH ( QgsCurveV2* curve, mCurves )
454  {
455  curve->transform( ct, d );
456  }
457  clearCache();
458 }
459 
461 {
462  Q_FOREACH ( QgsCurveV2* curve, mCurves )
463  {
464  curve->transform( t );
465  }
466  clearCache();
467 }
468 
470 {
471  QPainterPath pp;
473  for ( ; it != mCurves.constEnd(); ++it )
474  {
475  ( *it )->addToPainterPath( pp );
476  }
477  path.addPath( pp );
478 }
479 
481 {
482  QPainterPath pp;
484  for ( ; it != mCurves.constEnd(); ++it )
485  {
486  ( *it )->addToPainterPath( pp );
487  }
488  p.drawPath( pp );
489 }
490 
492 {
493  QList< QPair<int, QgsVertexId> > curveIds = curveVertexId( position );
494  if ( curveIds.size() < 1 )
495  {
496  return false;
497  }
498  int curveId = curveIds.at( 0 ).first;
499  if ( curveId >= mCurves.size() )
500  {
501  return false;
502  }
503 
504  bool success = mCurves.at( curveId )->insertVertex( curveIds.at( 0 ).second, vertex );
505  if ( success )
506  {
507  clearCache(); //bbox changed
508  }
509  return success;
510 }
511 
513 {
514  QList< QPair<int, QgsVertexId> > curveIds = curveVertexId( position );
515  QList< QPair<int, QgsVertexId> >::const_iterator idIt = curveIds.constBegin();
516  for ( ; idIt != curveIds.constEnd(); ++idIt )
517  {
518  mCurves.at( idIt->first )->moveVertex( idIt->second, newPos );
519  }
520 
521  bool success = !curveIds.isEmpty();
522  if ( success )
523  {
524  clearCache(); //bbox changed
525  }
526  return success;
527 }
528 
530 {
531  QList< QPair<int, QgsVertexId> > curveIds = curveVertexId( position );
532  QList< QPair<int, QgsVertexId> >::const_iterator idIt = curveIds.constBegin();
533  for ( ; idIt != curveIds.constEnd(); ++idIt )
534  {
535  mCurves.at( idIt->first )->deleteVertex( idIt->second );
536  }
537 
538  bool success = !curveIds.isEmpty();
539  if ( success )
540  {
541  clearCache(); //bbox changed
542  }
543  return success;
544 }
545 
546 QList< QPair<int, QgsVertexId> > QgsCompoundCurveV2::curveVertexId( QgsVertexId id ) const
547 {
549 
550  int currentVertexIndex = 0;
551  for ( int i = 0; i < mCurves.size(); ++i )
552  {
553  int increment = mCurves.at( i )->numPoints() - 1;
554  if ( id.vertex >= currentVertexIndex && id.vertex <= currentVertexIndex + increment )
555  {
556  int curveVertexId = id.vertex - currentVertexIndex;
557  QgsVertexId vid;
558  vid.part = 0;
559  vid.ring = 0;
560  vid.vertex = curveVertexId;
561  curveIds.append( qMakePair( i, vid ) );
562  if ( curveVertexId == increment && i < ( mCurves.size() - 1 ) ) //add first vertex of next curve
563  {
564  vid.vertex = 0;
565  curveIds.append( qMakePair( i + 1, vid ) );
566  }
567  }
568  currentVertexIndex += increment;
569  }
570 
571  return curveIds;
572 }
573 
574 double QgsCompoundCurveV2::closestSegment( const QgsPointV2& pt, QgsPointV2& segmentPt, QgsVertexId& vertexAfter, bool* leftOf, double epsilon ) const
575 {
576  return QgsGeometryUtils::closestSegmentFromComponents( mCurves, QgsGeometryUtils::VERTEX, pt, segmentPt, vertexAfter, leftOf, epsilon );
577 }
578 
580 {
581  int currentVertexId = 0;
582  for ( int j = 0; j < mCurves.size(); ++j )
583  {
584  int nCurvePoints = mCurves.at( j )->numPoints();
585  if (( node - currentVertexId ) < nCurvePoints )
586  {
587  return ( mCurves.at( j )->pointAt( node - currentVertexId, point, type ) );
588  }
589  currentVertexId += ( nCurvePoints - 1 );
590  }
591  return false;
592 }
593 
594 void QgsCompoundCurveV2::sumUpArea( double& sum ) const
595 {
597  for ( ; curveIt != mCurves.constEnd(); ++curveIt )
598  {
599  ( *curveIt )->sumUpArea( sum );
600  }
601 }
602 
604 {
605  if ( numPoints() < 1 || isClosed() )
606  {
607  return;
608  }
609  addVertex( startPoint() );
610 }
611 
613 {
615  for ( ; curveIt != mCurves.constEnd(); ++curveIt )
616  {
617  if (( *curveIt )->hasCurvedSegments() )
618  {
619  return true;
620  }
621  }
622  return false;
623 }
624 
626 {
627  QList< QPair<int, QgsVertexId> > curveIds = curveVertexId( vertex );
628  if ( curveIds.size() == 1 )
629  {
630  QgsCurveV2* curve = mCurves[curveIds.at( 0 ).first];
631  return curve->vertexAngle( curveIds.at( 0 ).second );
632  }
633  else if ( curveIds.size() > 1 )
634  {
635  QgsCurveV2* curve1 = mCurves[curveIds.at( 0 ).first];
636  QgsCurveV2* curve2 = mCurves[curveIds.at( 1 ).first];
637  double angle1 = curve1->vertexAngle( curveIds.at( 0 ).second );
638  double angle2 = curve2->vertexAngle( curveIds.at( 1 ).second );
639  return QgsGeometryUtils::averageAngle( angle1, angle2 );
640  }
641  else
642  {
643  return 0.0;
644  }
645 }
646 
648 {
650  Q_FOREACH ( QgsCurveV2* curve, mCurves )
651  {
652  QgsCurveV2* reversedCurve = curve->reversed();
653  clone->addCurve( reversedCurve );
654  }
655  return clone;
656 }
657 
658 bool QgsCompoundCurveV2::addZValue( double zValue )
659 {
660  if ( QgsWKBTypes::hasZ( mWkbType ) )
661  return false;
662 
664 
665  Q_FOREACH ( QgsCurveV2* curve, mCurves )
666  {
667  curve->addZValue( zValue );
668  }
669  clearCache();
670  return true;
671 }
672 
673 bool QgsCompoundCurveV2::addMValue( double mValue )
674 {
675  if ( QgsWKBTypes::hasM( mWkbType ) )
676  return false;
677 
679 
680  Q_FOREACH ( QgsCurveV2* curve, mCurves )
681  {
682  curve->addMValue( mValue );
683  }
684  clearCache();
685  return true;
686 }
687 
689 {
690  if ( !QgsWKBTypes::hasZ( mWkbType ) )
691  return false;
692 
694  Q_FOREACH ( QgsCurveV2* curve, mCurves )
695  {
696  curve->dropZValue();
697  }
698  clearCache();
699  return true;
700 }
701 
703 {
704  if ( !QgsWKBTypes::hasM( mWkbType ) )
705  return false;
706 
708  Q_FOREACH ( QgsCurveV2* curve, mCurves )
709  {
710  curve->dropMValue();
711  }
712  clearCache();
713  return true;
714 }
715 
virtual QgsCompoundCurveV2 * reversed() const override
Returns a reversed copy of the curve, where the direction of the curve has been flipped.
virtual bool deleteVertex(QgsVertexId position) override
Deletes a vertex within the geometry.
void addPath(const QPainterPath &path)
void clear()
int indexOf(QChar ch, int from, Qt::CaseSensitivity cs) const
QgsWKBTypes::Type wkbType() const
Returns the WKB type of the geometry.
A rectangle specified with double values.
Definition: qgsrectangle.h:35
QDomElement asGML2(QDomDocument &doc, int precision=17, const QString &ns="gml") const override
Returns a GML2 representation of the geometry.
virtual bool dropMValue()=0
Drops any measure values which exist in the geometry.
virtual QgsLineStringV2 * curveToLine() const override
Returns a new line string geometry corresponding to a segmentized approximation of the curve...
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 (...
void close()
Appends first point if not already closed.
virtual QgsAbstractGeometryV2 & operator=(const QgsAbstractGeometryV2 &geom)
QDomNode appendChild(const QDomNode &newChild)
bool hasCurvedSegments() const override
Returns true if the geometry contains curved segments.
static double averageAngle(double x1, double y1, double x2, double y2, double x3, double y3)
Angle between two linear segments.
static Type addZ(Type type)
Adds the z dimension to a WKB type and returns the new type.
Definition: qgswkbtypes.h:746
static bool hasM(Type type)
Tests whether a WKB type contains m values.
Definition: qgswkbtypes.h:703
Circular string geometry type.
virtual QgsPointV2 endPoint() const override
Returns the end point of the curve.
double vertexAngle(QgsVertexId vertex) const override
Returns approximate rotation angle for a vertex.
virtual QgsPointV2 startPoint() const override
Returns the starting point of the curve.
void removeFirst()
void transform(const QgsCoordinateTransform &ct, QgsCoordinateTransform::TransformDirection d=QgsCoordinateTransform::ForwardTransform) override
Transforms the geometry using a coordinate transform.
TransformDirection
Enum used to indicate the direction (forward or inverse) of the transform.
const T & at(int i) const
void removeAt(int i)
QDomElement asGML2(QDomDocument &doc, int precision=17, const QString &ns="gml") const override
Returns a GML2 representation of the geometry.
virtual bool insertVertex(QgsVertexId position, const QgsPointV2 &vertex) override
Inserts a vertex into the geometry.
static QStringList wktGetChildBlocks(const QString &wkt, const QString &defaultType="")
Parses a WKT string and returns of list of blocks contained in the WKT.
unsigned char * asWkb(int &binarySize) const override
Returns a WKB representation of the geometry.
virtual bool operator==(const QgsCurveV2 &other) const override
static double closestSegmentFromComponents(T &container, componentType ctype, const QgsPointV2 &pt, QgsPointV2 &segmentPt, QgsVertexId &vertexAfter, bool *leftOf, double epsilon)
virtual QgsRectangle calculateBoundingBox() const override
Default calculator for the minimal bounding box for the geometry.
virtual bool dropZValue()=0
Drops any z-dimensions which exist in the geometry.
void append(const QgsLineStringV2 *line)
Appends the contents of another line string to the end of this line string.
void sumUpArea(double &sum) const override
Calculates the area of the curve.
QDomElement createElementNS(const QString &nsURI, const QString &qName)
static bool hasZ(Type type)
Tests whether a WKB type contains the z-dimension.
Definition: qgswkbtypes.h:656
virtual QgsCurveV2 * clone() const override=0
Clones the geometry by performing a deep copy.
void chop(int n)
void addToPainterPath(QPainterPath &path) const override
Adds a curve to a painter path.
static endian_t endian()
Returns whether this machine uses big or little endian.
QString wktTypeStr() const
Returns the WKT type string of the geometry.
virtual int wkbSize() const =0
Returns the size of the WKB representation of the geometry.
QgsCompoundCurveV2 & operator=(const QgsCompoundCurveV2 &curve)
void removeCurve(int i)
Removes a curve from the geometry.
int size() const
virtual bool addMValue(double mValue=0)=0
Adds a measure to the geometry, initialized to a preset value.
virtual QgsLineStringV2 * curveToLine() const override
Returns a new line string geometry corresponding to a segmentized approximation of the curve...
QgsWKBTypes::Type readHeader() const
Definition: qgswkbptr.cpp:37
bool is3D() const
Returns true if the geometry is 3D and contains a z-value.
void combineExtentWith(QgsRectangle *rect)
expand the rectangle so that covers both the original rectangle and the given rectangle ...
void append(const T &value)
static Type dropZ(Type type)
Drops the z dimension (if present) for a WKB type and returns the new type.
Definition: qgswkbtypes.h:800
virtual bool operator!=(const QgsCurveV2 &other) const override
static Type addM(Type type)
Adds the m dimension to a WKB type and returns the new type.
Definition: qgswkbtypes.h:770
virtual QgsCurveV2 * reversed() const =0
Returns a reversed copy of the curve, where the direction of the curve has been flipped.
virtual void clearCache() const override
Clears any cached parameters associated with the geometry, eg bounding boxes.
Definition: qgscurvev2.h:116
Utility class for identifying a unique vertex within a geometry.
bool isMeasure() const
Returns true if the geometry contains m values.
void drawAsPolygon(QPainter &p) const override
Draws the curve as a polygon on the specified QPainter.
Line string geometry type, with support for z-dimension and m-values.
virtual bool fromWkb(QgsConstWkbPtr wkb)=0
Sets the geometry from a WKB string.
void draw(QPainter &p) const override
Draws the geometry using the specified QPainter.
virtual QString geometryType() const override
Returns a unique string representing the geometry type.
void addVertex(const QgsPointV2 &pt)
Adds a vertex to the end of the geometry.
Point geometry type, with support for z-dimension and m-values.
Definition: qgspointv2.h:34
bool isEmpty() const
QString asJSON(int precision=17) const override
Returns a GeoJSON representation of the geometry.
QString asWkt(int precision=17) const override
Returns a WKT representation of the geometry.
virtual bool fromWkb(QgsConstWkbPtr wkb) override
Sets the geometry from a WKB string.
virtual unsigned char * asWkb(int &binarySize) const =0
Returns a WKB representation of the geometry.
bool endsWith(const QString &s, Qt::CaseSensitivity cs) const
virtual void transform(const QgsCoordinateTransform &ct, QgsCoordinateTransform::TransformDirection d=QgsCoordinateTransform::ForwardTransform)=0
Transforms the geometry using a coordinate transform.
const QgsCurveV2 * curveAt(int i) const
Returns the curve at the specified index.
void setZMTypeFromSubGeometry(const QgsAbstractGeometryV2 *subggeom, QgsWKBTypes::Type baseGeomType)
Updates the geometry type based on whether sub geometries contain z or m values.
virtual bool addZValue(double zValue=0)=0
Adds a z-dimension to the geometry, initialized to a preset value.
virtual bool addMValue(double mValue=0) override
Adds a measure to the geometry, initialized to a preset value.
T & first()
virtual bool dropZValue() override
Drops any z-dimensions which exist in the geometry.
virtual bool dropMValue() override
Drops any measure values which exist in the geometry.
QString asJSON(int precision=17) const override
Returns a GeoJSON representation of the geometry.
static QDomElement pointsToGML3(const QgsPointSequenceV2 &points, QDomDocument &doc, int precision, const QString &ns, bool is3D)
Returns a gml::posList DOM element.
Compound curve geometry type.
virtual void points(QgsPointSequenceV2 &pts) const override
Returns a list of points within the curve.
virtual QString geometryType() const =0
Returns a unique string representing the geometry type.
virtual double vertexAngle(QgsVertexId vertex) const =0
Returns approximate angle at a vertex.
static Type dropM(Type type)
Drops the m dimension (if present) for a WKB type and returns the new type.
Definition: qgswkbtypes.h:817
void addCurve(QgsCurveV2 *c)
Adds a curve to the geometr (takes ownership)
void addVertex(const QgsPointV2 &pt)
Adds a new vertex to the end of the line string.
virtual QgsPointV2 endPoint() const =0
Returns the end point of the curve.
QString mid(int position, int n) const
void drawPath(const QPainterPath &path)
virtual bool fromWkt(const QString &wkt) override
Sets the geometry from a WKT string.
virtual QgsCompoundCurveV2 * clone() const override
Clones the geometry by performing a deep copy.
virtual bool isClosed() const
Returns true if the curve is closed.
Definition: qgscurvev2.cpp:27
bool pointAt(int node, QgsPointV2 &point, QgsVertexId::VertexType &type) const override
Returns the point and vertex id of a point within the curve.
int wkbSize() const override
Returns the size of the WKB representation of the geometry.
Class for doing transforms between two map coordinate systems.
virtual QString asWkt(int precision=17) const =0
Returns a WKT representation of the geometry.
virtual double closestSegment(const QgsPointV2 &pt, QgsPointV2 &segmentPt, QgsVertexId &vertexAfter, bool *leftOf, double epsilon) const override
Searches for the closest segment of the geometry to a given point.
static Type flatType(Type type)
Returns the flat type for a WKB type.
Definition: qgswkbtypes.h:366
static Type parseType(const QString &wktStr)
Attempts to extract the WKB type from a WKT string.
Definition: qgswkbtypes.cpp:32
double ANALYSIS_EXPORT leftOf(Point3D *thepoint, Point3D *p1, Point3D *p2)
Returns whether &#39;thepoint&#39; is left or right of the line from &#39;p1&#39; to &#39;p2&#39;.
const_iterator constEnd() const
const_iterator constBegin() const
Abstract base class for curved geometry type.
Definition: qgscurvev2.h:32
QString arg(qlonglong a, int fieldWidth, int base, const QChar &fillChar) const
virtual int numPoints() const override
Returns the number of points in the curve.
QDomElement asGML3(QDomDocument &doc, int precision=17, const QString &ns="gml") const override
Returns a GML3 representation of the geometry.
virtual double length() const override
Returns the length of the geometry.
T & back()
virtual void points(QgsPointSequenceV2 &pt) const =0
Returns a list of points within the curve.
int nCurves() const
Returns the number of curves in the geometry.
virtual void clear() override
Clears the geometry, ie reset it to a null geometry.
virtual bool addZValue(double zValue=0) override
Adds a z-dimension to the geometry, initialized to a preset value.
virtual bool moveVertex(QgsVertexId position, const QgsPointV2 &newPos) override
Moves a vertex within the geometry.