QGIS API Documentation  2.14.16-Essen
qgscurvepolygonv2.cpp
Go to the documentation of this file.
1 /***************************************************************************
2  qgscurvepolygonv2.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 "qgscurvepolygonv2.h"
19 #include "qgsapplication.h"
20 #include "qgscircularstringv2.h"
21 #include "qgscompoundcurvev2.h"
22 #include "qgsgeometryutils.h"
23 #include "qgslinestringv2.h"
24 #include "qgspolygonv2.h"
25 #include "qgswkbptr.h"
26 #include <QPainter>
27 #include <QPainterPath>
28 
29 QgsCurvePolygonV2::QgsCurvePolygonV2(): QgsSurfaceV2(), mExteriorRing( nullptr )
30 {
31 
32 }
33 
35 {
36  clear();
37 }
38 
40 {
41  if ( p.mExteriorRing )
42  {
43  mExteriorRing = static_cast<QgsCurveV2*>( p.mExteriorRing->clone() );
44  }
45 
46  Q_FOREACH ( const QgsCurveV2* ring, p.mInteriorRings )
47  {
48  mInteriorRings.push_back( static_cast<QgsCurveV2*>( ring->clone() ) );
49  }
50 }
51 
53 {
54  if ( &p != this )
55  {
56  clearCache();
58  if ( p.mExteriorRing )
59  {
60  mExteriorRing = static_cast<QgsCurveV2*>( p.mExteriorRing->clone() );
61  }
62 
63  Q_FOREACH ( const QgsCurveV2* ring, p.mInteriorRings )
64  {
65  mInteriorRings.push_back( static_cast<QgsCurveV2*>( ring->clone() ) );
66  }
67  }
68  return *this;
69 }
70 
72 {
73  return new QgsCurvePolygonV2( *this );
74 }
75 
77 {
78  delete mExteriorRing;
79  mExteriorRing = nullptr;
80  qDeleteAll( mInteriorRings );
83  clearCache();
84 }
85 
86 
88 {
89  clear();
90  if ( !wkbPtr )
91  {
92  return false;
93  }
94 
95  QgsWKBTypes::Type type = wkbPtr.readHeader();
97  {
98  return false;
99  }
100  mWkbType = type;
101 
102  int nRings;
103  wkbPtr >> nRings;
104  QgsCurveV2* currentCurve = nullptr;
105  int currentCurveSize = 0;
106  for ( int i = 0; i < nRings; ++i )
107  {
108  QgsWKBTypes::Type curveType = wkbPtr.readHeader();
109  wkbPtr -= 1 + sizeof( int );
110  if ( curveType == QgsWKBTypes::LineString || curveType == QgsWKBTypes::LineStringZ || curveType == QgsWKBTypes::LineStringM ||
111  curveType == QgsWKBTypes::LineStringZM || curveType == QgsWKBTypes::LineString25D )
112  {
113  currentCurve = new QgsLineStringV2();
114  }
115  else if ( curveType == QgsWKBTypes::CircularString || curveType == QgsWKBTypes::CircularStringZ || curveType == QgsWKBTypes::CircularStringZM ||
116  curveType == QgsWKBTypes::CircularStringM )
117  {
118  currentCurve = new QgsCircularStringV2();
119  }
120  else if ( curveType == QgsWKBTypes::CompoundCurve || curveType == QgsWKBTypes::CompoundCurveZ || curveType == QgsWKBTypes::CompoundCurveZM )
121  {
122  currentCurve = new QgsCompoundCurveV2();
123  }
124  else
125  {
126  return false;
127  }
128  currentCurve->fromWkb( wkbPtr );
129  currentCurveSize = currentCurve->wkbSize();
130  if ( i == 0 )
131  {
132  mExteriorRing = currentCurve;
133  }
134  else
135  {
136  mInteriorRings.append( currentCurve );
137  }
138  wkbPtr += currentCurveSize;
139  }
140 
141  return true;
142 }
143 
145 {
146  clear();
147 
149 
150  if ( QgsWKBTypes::flatType( parts.first ) != QgsWKBTypes::parseType( geometryType() ) )
151  return false;
152 
153  mWkbType = parts.first;
154 
155  QString defaultChildWkbType = QString( "LineString%1%2" ).arg( is3D() ? "Z" : "", isMeasure() ? "M" : "" );
156 
157  Q_FOREACH ( const QString& childWkt, QgsGeometryUtils::wktGetChildBlocks( parts.second, defaultChildWkbType ) )
158  {
160 
161  QgsWKBTypes::Type flatCurveType = QgsWKBTypes::flatType( childParts.first );
162  if ( flatCurveType == QgsWKBTypes::LineString )
164  else if ( flatCurveType == QgsWKBTypes::CircularString )
166  else if ( flatCurveType == QgsWKBTypes::CompoundCurve )
168  else
169  {
170  clear();
171  return false;
172  }
173  if ( !mInteriorRings.back()->fromWkt( childWkt ) )
174  {
175  clear();
176  return false;
177  }
178  }
179 
180  if ( mInteriorRings.isEmpty() )
181  {
182  clear();
183  return false;
184  }
185 
188 
189  //scan through rings and check if dimensionality of rings is different to CurvePolygon.
190  //if so, update the type dimensionality of the CurvePolygon to match
191  bool hasZ = false;
192  bool hasM = false;
193  if ( mExteriorRing )
194  {
195  hasZ = hasZ || mExteriorRing->is3D();
196  hasM = hasM || mExteriorRing->isMeasure();
197  }
198  Q_FOREACH ( const QgsCurveV2* curve, mInteriorRings )
199  {
200  hasZ = hasZ || curve->is3D();
201  hasM = hasM || curve->isMeasure();
202  if ( hasZ && hasM )
203  break;
204  }
205  if ( hasZ )
206  addZValue( 0 );
207  if ( hasM )
208  addMValue( 0 );
209 
210  return true;
211 }
212 
214 {
215  if ( mExteriorRing )
216  {
217  return mExteriorRing->boundingBox();
218  }
219  return QgsRectangle();
220 }
221 
223 {
224  int size = sizeof( char ) + sizeof( quint32 ) + sizeof( quint32 );
225  if ( mExteriorRing )
226  {
227  size += mExteriorRing->wkbSize();
228  }
229  Q_FOREACH ( const QgsCurveV2* curve, mInteriorRings )
230  {
231  size += curve->wkbSize();
232  }
233  return size;
234 }
235 
236 unsigned char* QgsCurvePolygonV2::asWkb( int& binarySize ) const
237 {
238  binarySize = wkbSize();
239  unsigned char* geomPtr = new unsigned char[binarySize];
240  QgsWkbPtr wkbPtr( geomPtr, binarySize );
241  wkbPtr << static_cast<char>( QgsApplication::endian() );
242  wkbPtr << static_cast<quint32>( wkbType() );
243  wkbPtr << static_cast<quint32>(( nullptr != mExteriorRing ) + mInteriorRings.size() );
244  if ( mExteriorRing )
245  {
246  int curveWkbLen = 0;
247  unsigned char *ringWkb = mExteriorRing->asWkb( curveWkbLen );
248  memcpy( wkbPtr, ringWkb, curveWkbLen );
249  wkbPtr += curveWkbLen;
250  }
251  Q_FOREACH ( const QgsCurveV2* curve, mInteriorRings )
252  {
253  int curveWkbLen = 0;
254  unsigned char *ringWkb = curve->asWkb( curveWkbLen );
255  memcpy( wkbPtr, ringWkb, curveWkbLen );
256  wkbPtr += curveWkbLen;
257  }
258  return geomPtr;
259 }
260 
261 QString QgsCurvePolygonV2::asWkt( int precision ) const
262 {
263  QString wkt = wktTypeStr() + " (";
264  if ( mExteriorRing )
265  {
266  QString childWkt = mExteriorRing->asWkt( precision );
267  if ( dynamic_cast<QgsLineStringV2*>( mExteriorRing ) )
268  {
269  // Type names of linear geometries are omitted
270  childWkt = childWkt.mid( childWkt.indexOf( '(' ) );
271  }
272  wkt += childWkt + ',';
273  }
274  Q_FOREACH ( const QgsCurveV2* curve, mInteriorRings )
275  {
276  QString childWkt = curve->asWkt( precision );
277  if ( dynamic_cast<const QgsLineStringV2*>( curve ) )
278  {
279  // Type names of linear geometries are omitted
280  childWkt = childWkt.mid( childWkt.indexOf( '(' ) );
281  }
282  wkt += childWkt + ',';
283  }
284  if ( wkt.endsWith( ',' ) )
285  {
286  wkt.chop( 1 ); // Remove last ','
287  }
288  wkt += ')';
289  return wkt;
290 }
291 
292 QDomElement QgsCurvePolygonV2::asGML2( QDomDocument& doc, int precision, const QString& ns ) const
293 {
294  // GML2 does not support curves
295  QDomElement elemPolygon = doc.createElementNS( ns, "Polygon" );
296  QDomElement elemOuterBoundaryIs = doc.createElementNS( ns, "outerBoundaryIs" );
297  QgsLineStringV2* exteriorLineString = exteriorRing()->curveToLine();
298  QDomElement outerRing = exteriorLineString->asGML2( doc, precision, ns );
299  outerRing.toElement().setTagName( "LinearRing" );
300  elemOuterBoundaryIs.appendChild( outerRing );
301  delete exteriorLineString;
302  elemPolygon.appendChild( elemOuterBoundaryIs );
303  QDomElement elemInnerBoundaryIs = doc.createElementNS( ns, "innerBoundaryIs" );
304  for ( int i = 0, n = numInteriorRings(); i < n; ++i )
305  {
306  QgsLineStringV2* interiorLineString = interiorRing( i )->curveToLine();
307  QDomElement innerRing = interiorLineString->asGML2( doc, precision, ns );
308  innerRing.toElement().setTagName( "LinearRing" );
309  elemInnerBoundaryIs.appendChild( innerRing );
310  delete interiorLineString;
311  }
312  elemPolygon.appendChild( elemInnerBoundaryIs );
313  return elemPolygon;
314 }
315 
316 QDomElement QgsCurvePolygonV2::asGML3( QDomDocument& doc, int precision, const QString& ns ) const
317 {
318  QDomElement elemCurvePolygon = doc.createElementNS( ns, "Polygon" );
319  QDomElement elemExterior = doc.createElementNS( ns, "exterior" );
320  QDomElement outerRing = exteriorRing()->asGML2( doc, precision, ns );
321  outerRing.toElement().setTagName( "LinearRing" );
322  elemExterior.appendChild( outerRing );
323  elemCurvePolygon.appendChild( elemExterior );
324  QDomElement elemInterior = doc.createElementNS( ns, "interior" );
325  for ( int i = 0, n = numInteriorRings(); i < n; ++i )
326  {
327  QDomElement innerRing = interiorRing( i )->asGML2( doc, precision, ns );
328  innerRing.toElement().setTagName( "LinearRing" );
329  elemInterior.appendChild( innerRing );
330  }
331  elemCurvePolygon.appendChild( elemInterior );
332  return elemCurvePolygon;
333 }
334 
335 QString QgsCurvePolygonV2::asJSON( int precision ) const
336 {
337  // GeoJSON does not support curves
338  QString json = "{\"type\": \"Polygon\", \"coordinates\": [";
339 
340  QgsLineStringV2* exteriorLineString = exteriorRing()->curveToLine();
341  QgsPointSequenceV2 exteriorPts;
342  exteriorLineString->points( exteriorPts );
343  json += QgsGeometryUtils::pointsToJSON( exteriorPts, precision ) + ", ";
344  delete exteriorLineString;
345 
346  for ( int i = 0, n = numInteriorRings(); i < n; ++i )
347  {
348  QgsLineStringV2* interiorLineString = interiorRing( i )->curveToLine();
349  QgsPointSequenceV2 interiorPts;
350  interiorLineString->points( interiorPts );
351  json += QgsGeometryUtils::pointsToJSON( interiorPts, precision ) + ", ";
352  delete interiorLineString;
353  }
354  if ( json.endsWith( ", " ) )
355  {
356  json.chop( 2 ); // Remove last ", "
357  }
358  json += "] }";
359  return json;
360 }
361 
363 {
364  if ( !mExteriorRing )
365  {
366  return 0.0;
367  }
368 
369  double totalArea = 0.0;
370 
371  if ( mExteriorRing->isRing() )
372  {
373  double area = 0.0;
374  mExteriorRing->sumUpArea( area );
375  totalArea += qAbs( area );
376  }
377 
379  for ( ; ringIt != mInteriorRings.constEnd(); ++ringIt )
380  {
381  double area = 0.0;
382  if (( *ringIt )->isRing() )
383  {
384  ( *ringIt )->sumUpArea( area );
385  totalArea -= qAbs( area );
386  }
387  }
388  return totalArea;
389 }
390 
392 {
393  if ( !mExteriorRing )
394  return 0.0;
395 
396  //sum perimeter of rings
397  double perimeter = mExteriorRing->length();
399  for ( ; ringIt != mInteriorRings.constEnd(); ++ringIt )
400  {
401  perimeter += ( *ringIt )->length();
402  }
403  return perimeter;
404 }
405 
407 {
408  QgsPolygonV2* polygon = new QgsPolygonV2();
409  polygon->setExteriorRing( exteriorRing()->curveToLine() );
410  QList<QgsCurveV2*> interiors;
411  int n = numInteriorRings();
412  interiors.reserve( n );
413  for ( int i = 0; i < n; ++i )
414  {
415  interiors.append( interiorRing( i )->curveToLine() );
416  }
417  polygon->setInteriorRings( interiors );
418  return polygon;
419 }
420 
422 {
423  if ( !mExteriorRing )
424  {
425  return nullptr;
426  }
427 
428  QgsPolygonV2* poly = new QgsPolygonV2();
430 
431  QList<QgsCurveV2*> rings;
433  for ( ; it != mInteriorRings.constEnd(); ++it )
434  {
435  rings.push_back(( *it )->curveToLine() );
436  }
437  poly->setInteriorRings( rings );
438  return poly;
439 }
440 
442 {
443  return mInteriorRings.size();
444 }
445 
447 {
448  return mExteriorRing;
449 }
450 
452 {
453  if ( i < 0 || i >= mInteriorRings.size() )
454  {
455  return nullptr;
456  }
457  return mInteriorRings.at( i );
458 }
459 
461 {
462  if ( !ring )
463  {
464  return;
465  }
466  delete mExteriorRing;
467  mExteriorRing = ring;
468 
469  //set proper wkb type
470  if ( geometryType() == "Polygon" )
471  {
473  }
474  else if ( geometryType() == "CurvePolygon" )
475  {
477  }
478 
479  //match dimensionality for rings
480  Q_FOREACH ( QgsCurveV2* ring, mInteriorRings )
481  {
482  if ( is3D() )
483  ring->addZValue();
484  else
485  ring->dropZValue();
486 
487  if ( isMeasure() )
488  ring->addMValue();
489  else
490  ring->dropMValue();
491  }
492  clearCache();
493 }
494 
496 {
497  qDeleteAll( mInteriorRings );
499 
500  //add rings one-by-one, so that they can each be converted to the correct type for the CurvePolygon
501  Q_FOREACH ( QgsCurveV2* ring, rings )
502  {
503  addInteriorRing( ring );
504  }
505  clearCache();
506 }
507 
509 {
510  if ( !ring )
511  return;
512 
513  //ensure dimensionality of ring matches curve polygon
514  if ( !is3D() )
515  ring->dropZValue();
516  else if ( !ring->is3D() )
517  ring->addZValue();
518 
519  if ( !isMeasure() )
520  ring->dropMValue();
521  else if ( !ring->isMeasure() )
522  ring->addMValue();
523 
524  mInteriorRings.append( ring );
525  clearCache();
526 }
527 
529 {
530  if ( nr < 0 || nr >= mInteriorRings.size() )
531  {
532  return false;
533  }
534  delete mInteriorRings.takeAt( nr );
535  clearCache();
536  return true;
537 }
538 
540 {
541  if ( mInteriorRings.size() < 1 )
542  {
543  if ( mExteriorRing )
544  {
546  }
547  }
548  else
549  {
550  QPainterPath path;
552 
554  for ( ; it != mInteriorRings.constEnd(); ++it )
555  {
556  ( *it )->addToPainterPath( path );
557  }
558  p.drawPath( path );
559  }
560 }
561 
563 {
564  if ( mExteriorRing )
565  {
566  mExteriorRing->transform( ct, d );
567  }
568 
569  Q_FOREACH ( QgsCurveV2* curve, mInteriorRings )
570  {
571  curve->transform( ct, d );
572  }
573  clearCache();
574 }
575 
577 {
578  if ( mExteriorRing )
579  {
580  mExteriorRing->transform( t );
581  }
582 
583  Q_FOREACH ( QgsCurveV2* curve, mInteriorRings )
584  {
585  curve->transform( t );
586  }
587  clearCache();
588 }
589 
591 {
592  if ( !mCoordinateSequence.isEmpty() )
593  return mCoordinateSequence;
594 
596 
597  if ( mExteriorRing )
598  {
601  }
602 
604  for ( ; it != mInteriorRings.constEnd(); ++it )
605  {
607  ( *it )->points( mCoordinateSequence.back().back() );
608  }
609 
610  return mCoordinateSequence;
611 }
612 
614 {
615  if ( !mCoordinateSequence.isEmpty() )
617 
618  int count = 0;
619 
620  if ( mExteriorRing )
621  {
622  count += mExteriorRing->nCoordinates();
623  }
624 
626  for ( ; it != mInteriorRings.constEnd(); ++it )
627  {
628  count += ( *it )->nCoordinates();
629  }
630 
631  return count;
632 }
633 
634 double QgsCurvePolygonV2::closestSegment( const QgsPointV2& pt, QgsPointV2& segmentPt, QgsVertexId& vertexAfter, bool* leftOf, double epsilon ) const
635 {
636  if ( !mExteriorRing )
637  {
638  return -1;
639  }
640  QList<QgsCurveV2*> segmentList;
641  segmentList.append( mExteriorRing );
642  segmentList.append( mInteriorRings );
643  return QgsGeometryUtils::closestSegmentFromComponents( segmentList, QgsGeometryUtils::RING, pt, segmentPt, vertexAfter, leftOf, epsilon );
644 }
645 
647 {
648  if ( !mExteriorRing || vId.ring >= 1 + mInteriorRings.size() )
649  {
650  return false;
651  }
652 
653  if ( vId.ring < 0 )
654  {
655  vId.ring = 0;
656  vId.vertex = -1;
657  if ( vId.part < 0 )
658  {
659  vId.part = 0;
660  }
661  return mExteriorRing->nextVertex( vId, vertex );
662  }
663  else
664  {
665  QgsCurveV2* ring = vId.ring == 0 ? mExteriorRing : mInteriorRings[vId.ring - 1];
666 
667  if ( ring->nextVertex( vId, vertex ) )
668  {
669  return true;
670  }
671  ++vId.ring;
672  vId.vertex = -1;
673  if ( vId.ring >= 1 + mInteriorRings.size() )
674  {
675  return false;
676  }
677  ring = mInteriorRings[ vId.ring - 1 ];
678  return ring->nextVertex( vId, vertex );
679  }
680 }
681 
683 {
684  if ( !mExteriorRing || vId.ring < 0 || vId.ring >= 1 + mInteriorRings.size() )
685  {
686  return false;
687  }
688 
689  QgsCurveV2* ring = vId.ring == 0 ? mExteriorRing : mInteriorRings.at( vId.ring - 1 );
690  int n = ring->numPoints();
691  bool success = ring->insertVertex( QgsVertexId( 0, 0, vId.vertex ), vertex );
692  if ( !success )
693  {
694  return false;
695  }
696 
697  // If first or last vertex is inserted, re-sync the last/first vertex
698  if ( vId.vertex == 0 )
699  ring->moveVertex( QgsVertexId( 0, 0, n ), vertex );
700  else if ( vId.vertex == n )
701  ring->moveVertex( QgsVertexId( 0, 0, 0 ), vertex );
702 
703  clearCache();
704 
705  return true;
706 }
707 
709 {
710  if ( !mExteriorRing || vId.ring < 0 || vId.ring >= 1 + mInteriorRings.size() )
711  {
712  return false;
713  }
714 
715  QgsCurveV2* ring = vId.ring == 0 ? mExteriorRing : mInteriorRings.at( vId.ring - 1 );
716  int n = ring->numPoints();
717  bool success = ring->moveVertex( vId, newPos );
718  if ( success )
719  {
720  // If first or last vertex is moved, also move the last/first vertex
721  if ( vId.vertex == 0 )
722  ring->moveVertex( QgsVertexId( vId.part, vId.ring, n - 1 ), newPos );
723  else if ( vId.vertex == n - 1 )
724  ring->moveVertex( QgsVertexId( vId.part, vId.ring, 0 ), newPos );
725  clearCache();
726  }
727  return success;
728 }
729 
731 {
732  if ( !mExteriorRing || vId.ring < 0 || vId.ring >= 1 + mInteriorRings.size() )
733  {
734  return false;
735  }
736 
737  QgsCurveV2* ring = vId.ring == 0 ? mExteriorRing : mInteriorRings.at( vId.ring - 1 );
738  int n = ring->numPoints();
739  if ( n <= 4 )
740  {
741  //no points will be left in ring, so remove whole ring
742  if ( vId.ring == 0 )
743  {
744  delete mExteriorRing;
745  mExteriorRing = nullptr;
746  if ( !mInteriorRings.isEmpty() )
747  {
749  }
750  }
751  else
752  {
753  removeInteriorRing( vId.ring - 1 );
754  }
755  clearCache();
756  return true;
757  }
758 
759  bool success = ring->deleteVertex( vId );
760  if ( success )
761  {
762  // If first or last vertex is removed, re-sync the last/first vertex
763  if ( vId.vertex == 0 )
764  ring->moveVertex( QgsVertexId( 0, 0, n - 2 ), ring->vertexAt( QgsVertexId( 0, 0, 0 ) ) );
765  else if ( vId.vertex == n - 1 )
766  ring->moveVertex( QgsVertexId( 0, 0, 0 ), ring->vertexAt( QgsVertexId( 0, 0, n - 2 ) ) );
767  clearCache();
768  }
769  return success;
770 }
771 
773 {
775  {
776  return true;
777  }
778 
780  for ( ; it != mInteriorRings.constEnd(); ++it )
781  {
782  if (( *it )->hasCurvedSegments() )
783  {
784  return true;
785  }
786  }
787  return false;
788 }
789 
791 {
792  return toPolygon();
793 }
794 
796 {
797  if ( !mExteriorRing || vertex.ring < 0 || vertex.ring >= 1 + mInteriorRings.size() )
798  {
799  //makes no sense - conversion of false to double!
800  return false;
801  }
802 
803  QgsCurveV2* ring = vertex.ring == 0 ? mExteriorRing : mInteriorRings[vertex.ring - 1];
804  return ring->vertexAngle( vertex );
805 }
806 
807 int QgsCurvePolygonV2::vertexCount( int /*part*/, int ring ) const
808 {
809  return ring == 0 ? mExteriorRing->vertexCount() : mInteriorRings[ring - 1]->vertexCount();
810 }
811 
813 {
814  return id.ring == 0 ? mExteriorRing->vertexAt( id ) : mInteriorRings[id.ring - 1]->vertexAt( id );
815 }
816 
817 bool QgsCurvePolygonV2::addZValue( double zValue )
818 {
819  if ( QgsWKBTypes::hasZ( mWkbType ) )
820  return false;
821 
823 
824  if ( mExteriorRing )
825  mExteriorRing->addZValue( zValue );
826  Q_FOREACH ( QgsCurveV2* curve, mInteriorRings )
827  {
828  curve->addZValue( zValue );
829  }
830  clearCache();
831  return true;
832 }
833 
834 bool QgsCurvePolygonV2::addMValue( double mValue )
835 {
836  if ( QgsWKBTypes::hasM( mWkbType ) )
837  return false;
838 
840 
841  if ( mExteriorRing )
842  mExteriorRing->addMValue( mValue );
843  Q_FOREACH ( QgsCurveV2* curve, mInteriorRings )
844  {
845  curve->addMValue( mValue );
846  }
847  clearCache();
848  return true;
849 }
850 
852 {
853  if ( !is3D() )
854  return false;
855 
857  if ( mExteriorRing )
859  Q_FOREACH ( QgsCurveV2* curve, mInteriorRings )
860  {
861  curve->dropZValue();
862  }
863  clearCache();
864  return true;
865 }
866 
868 {
869  if ( !isMeasure() )
870  return false;
871 
873  if ( mExteriorRing )
875  Q_FOREACH ( QgsCurveV2* curve, mInteriorRings )
876  {
877  curve->dropMValue();
878  }
879  clearCache();
880  return true;
881 }
QString wktTypeStr() const
Returns the WKT type string of the geometry.
void clear()
bool removeInteriorRing(int nr)
Removes ring.
bool hasCurvedSegments() const override
Returns true if the geometry contains curved segments.
int indexOf(QChar ch, int from, Qt::CaseSensitivity cs) const
const QgsCurveV2 * exteriorRing() const
void setInteriorRings(const QList< QgsCurveV2 *> &rings)
Sets all interior rings (takes ownership)
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 bool addMValue(double mValue=0) override
Adds a measure to the geometry, initialized to a preset value.
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 (...
const QgsCurveV2 * interiorRing(int i) const
QDomElement asGML2(QDomDocument &doc, int precision=17, const QString &ns="gml") const override
Returns a GML2 representation of the geometry.
virtual QgsRectangle calculateBoundingBox() const override
Default calculator for the minimal bounding box for the geometry.
virtual QgsAbstractGeometryV2 & operator=(const QgsAbstractGeometryV2 &geom)
QDomNode appendChild(const QDomNode &newChild)
virtual void addInteriorRing(QgsCurveV2 *ring)
Adds an interior ring to the geometry (takes ownership)
void push_back(const T &value)
void clear() override
Clears the geometry, ie reset it to a null geometry.
void points(QgsPointSequenceV2 &pt) const override
Returns a list of points within the curve.
void setTagName(const QString &name)
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.
QgsPolygonV2 * surfaceToPolygon() const override
void reserve(int alloc)
virtual bool deleteVertex(QgsVertexId position) override
Deletes a vertex within the geometry.
void removeFirst()
virtual QgsCoordinateSequenceV2 coordinateSequence() const override
Retrieves the sequence of geometries, rings and nodes.
TransformDirection
Enum used to indicate the direction (forward or inverse) of the transform.
const T & at(int i) const
virtual bool hasCurvedSegments() const
Returns true if the geometry contains curved segments.
virtual void addToPainterPath(QPainterPath &path) const =0
Adds a curve to a painter path.
static QString pointsToJSON(const QgsPointSequenceV2 &points, int precision)
Returns a geoJSON coordinates string.
Abstract base class for all geometries.
double vertexAngle(QgsVertexId vertex) const override
Returns approximate rotation angle for a vertex.
static QStringList wktGetChildBlocks(const QString &wkt, const QString &defaultType="")
Parses a WKT string and returns of list of blocks contained in the WKT.
T takeAt(int i)
static double closestSegmentFromComponents(T &container, componentType ctype, const QgsPointV2 &pt, QgsPointV2 &segmentPt, QgsVertexId &vertexAfter, bool *leftOf, double epsilon)
virtual bool dropZValue()=0
Drops any z-dimensions which exist in the geometry.
virtual bool moveVertex(QgsVertexId position, const QgsPointV2 &newPos) override
Moves a vertex within the geometry.
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)
static endian_t endian()
Returns whether this machine uses big or little endian.
virtual bool isRing() const
Returns true if the curve is a ring.
Definition: qgscurvev2.cpp:40
virtual int wkbSize() const =0
Returns the size of the WKB representation of the geometry.
int size() const
virtual bool addMValue(double mValue=0)=0
Adds a measure to the geometry, initialized to a preset value.
virtual void clearCache() const override
Clears any cached parameters associated with the geometry, eg bounding boxes.
Definition: qgssurfacev2.h:45
QDomElement toElement() const
virtual int numPoints() const =0
Returns the number of points in the curve.
int wkbSize() const override
Returns the size of the WKB representation of the geometry.
Polygon geometry type.
Definition: qgspolygonv2.h:29
virtual bool dropMValue() override
Drops any measure values which exist in the geometry.
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 fromWkt(const QString &wkt) override
Sets the geometry from a WKT string.
virtual double perimeter() const override
Returns the perimeter of the geometry.
virtual QString geometryType() const override
Returns a unique string representing the geometry type.
static Type addM(Type type)
Adds the m dimension to a WKB type and returns the new type.
Definition: qgswkbtypes.h:770
virtual void setExteriorRing(QgsCurveV2 *ring) override
Sets the exterior ring of the polygon.
Utility class for identifying a unique vertex within a geometry.
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.
bool isMeasure() const
Returns true if the geometry contains m values.
Point geometry type, with support for z-dimension and m-values.
Definition: qgspointv2.h:34
bool isEmpty() const
QString asWkt(int precision=17) const override
Returns a WKT representation of the geometry.
QgsCurvePolygonV2 & operator=(const QgsCurvePolygonV2 &p)
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.
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.
void transform(const QgsCoordinateTransform &ct, QgsCoordinateTransform::TransformDirection d=QgsCoordinateTransform::ForwardTransform) override
Transforms the geometry using a coordinate transform.
virtual bool nextVertex(QgsVertexId &id, QgsPointV2 &vertex) const override
Returns next vertex id and coordinates.
Definition: qgscurvev2.cpp:57
virtual int vertexCount(int=0, int ring=0) const override
unsigned char * asWkb(int &binarySize) const override
Returns a WKB representation of the geometry.
virtual void draw(QPainter &p) const override
Draws the geometry using the specified QPainter.
virtual QgsCurvePolygonV2 * clone() const override
Clones the geometry by performing a deep copy.
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.
Compound curve geometry type.
QList< QgsPointSequenceV2 > QgsRingSequenceV2
QgsCoordinateSequenceV2 mCoordinateSequence
Definition: qgssurfacev2.h:47
virtual int nCoordinates() const
Returns the number of nodes contained in the geometry.
virtual void sumUpArea(double &sum) const =0
Sums up the area of the curve by iterating over the vertices (shoelace formula).
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
bool nextVertex(QgsVertexId &id, QgsPointV2 &vertex) const override
Returns next vertex id and coordinates.
QList< QgsCurveV2 * > mInteriorRings
virtual QgsLineStringV2 * curveToLine() const =0
Returns a new line string geometry corresponding to a segmentized approximation of the curve...
QString asJSON(int precision=17) const override
Returns a GeoJSON representation of the geometry.
virtual bool deleteVertex(QgsVertexId position)=0
Deletes a vertex within the geometry.
virtual bool insertVertex(QgsVertexId position, const QgsPointV2 &vertex) override
Inserts a vertex into the geometry.
QString mid(int position, int n) const
void drawPath(const QPainterPath &path)
virtual void setExteriorRing(QgsCurveV2 *ring)
Sets the exterior ring of the polygon.
T takeFirst()
virtual bool insertVertex(QgsVertexId position, const QgsPointV2 &vertex)=0
Inserts a vertex into the geometry.
QgsWKBTypes::Type wkbType() const
Returns the WKB type of the geometry.
virtual bool addZValue(double zValue=0) override
Adds a z-dimension to the geometry, initialized to a preset value.
virtual double length() const
Returns the length of the geometry.
virtual QgsPolygonV2 * toPolygon() const
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 int nCoordinates() const override
Returns the number of nodes contained in the geometry.
virtual bool fromWkb(QgsConstWkbPtr wkb) override
Sets the geometry from a WKB string.
static Type flatType(Type type)
Returns the flat type for a WKB type.
Definition: qgswkbtypes.h:366
virtual bool dropZValue() override
Drops any z-dimensions which exist in the geometry.
virtual void drawAsPolygon(QPainter &p) const =0
Draws the curve as a polygon on the specified QPainter.
static Type parseType(const QString &wktStr)
Attempts to extract the WKB type from a WKT string.
Definition: qgswkbtypes.cpp:32
QgsAbstractGeometryV2 * segmentize() const override
Returns a version of the geometry without curves.
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;.
virtual QgsPointV2 vertexAt(QgsVertexId id) const override
Returns the point corresponding to a specified vertex id.
Definition: qgscurvev2.cpp:87
Curve polygon geometry type.
QgsWKBTypes::Type readHeader() const
Definition: qgswkbptr.cpp:37
virtual QDomElement asGML2(QDomDocument &doc, int precision=17, const QString &ns="gml") const =0
Returns a GML2 representation of the geometry.
const_iterator constEnd() const
const_iterator constBegin() const
Abstract base class for curved geometry type.
Definition: qgscurvev2.h:32
virtual bool moveVertex(QgsVertexId position, const QgsPointV2 &newPos)=0
Moves a vertex within the geometry.
QString arg(qlonglong a, int fieldWidth, int base, const QChar &fillChar) const
QDomElement asGML3(QDomDocument &doc, int precision=17, const QString &ns="gml") const override
Returns a GML3 representation of the geometry.
T & back()
virtual void points(QgsPointSequenceV2 &pt) const =0
Returns a list of points within the curve.
virtual int vertexCount(int part=0, int ring=0) const override
Definition: qgscurvev2.h:106
virtual double area() const override
Returns the area of the geometry.
bool is3D() const
Returns true if the geometry is 3D and contains a z-value.
virtual QgsRectangle boundingBox() const override
Returns the minimal bounding box for the geometry.
Definition: qgscurvev2.cpp:95
QList< QgsPointV2 > QgsPointSequenceV2
virtual QgsPointV2 vertexAt(QgsVertexId id) const override
Returns the point corresponding to a specified vertex id.
QgsCurveV2 * mExteriorRing
int numInteriorRings() const