@@ -128,6 +128,8 @@ bool QgsGeometryCollection::insertGeometry( QgsAbstractGeometry *g, int index )
128
128
return false ;
129
129
}
130
130
131
+ index = std::min ( mGeometries .count (), index );
132
+
131
133
mGeometries .insert ( index , g );
132
134
clearCache (); // set bounding box invalid
133
135
return true ;
@@ -183,17 +185,6 @@ void QgsGeometryCollection::transform( const QTransform &t )
183
185
clearCache (); // set bounding box invalid
184
186
}
185
187
186
- #if 0
187
- void QgsGeometryCollection::clip( const QgsRectangle &rect )
188
- {
189
- QVector< QgsAbstractGeometry * >::iterator it = mGeometries.begin();
190
- for ( ; it != mGeometries.end(); ++it )
191
- {
192
- ( *it )->clip( rect );
193
- }
194
- }
195
- #endif
196
-
197
188
void QgsGeometryCollection::draw ( QPainter &p ) const
198
189
{
199
190
QVector< QgsAbstractGeometry * >::const_iterator it = mGeometries .constBegin ();
@@ -210,7 +201,11 @@ bool QgsGeometryCollection::fromWkb( QgsConstWkbPtr &wkbPtr )
210
201
return false ;
211
202
}
212
203
213
- mWkbType = wkbPtr.readHeader ();
204
+ QgsWkbTypes::Type wkbType = wkbPtr.readHeader ();
205
+ if ( QgsWkbTypes::flatType ( wkbType ) != QgsWkbTypes::flatType ( mWkbType ) )
206
+ return false ;
207
+
208
+ mWkbType = wkbType;
214
209
215
210
int nGeometries = 0 ;
216
211
wkbPtr >> nGeometries;
@@ -419,6 +414,9 @@ bool QgsGeometryCollection::nextVertex( QgsVertexId &id, QgsPoint &vertex ) cons
419
414
return false ;
420
415
}
421
416
417
+ if ( id.part >= mGeometries .count () )
418
+ return false ;
419
+
422
420
QgsAbstractGeometry *geom = mGeometries .at ( id.part );
423
421
if ( geom->nextVertex ( id, vertex ) )
424
422
{
@@ -451,7 +449,7 @@ bool QgsGeometryCollection::insertVertex( QgsVertexId position, const QgsPoint &
451
449
452
450
bool QgsGeometryCollection::moveVertex ( QgsVertexId position, const QgsPoint &newPos )
453
451
{
454
- if ( position.part >= mGeometries .size () )
452
+ if ( position.part < 0 || position. part >= mGeometries .size () )
455
453
{
456
454
return false ;
457
455
}
@@ -466,7 +464,7 @@ bool QgsGeometryCollection::moveVertex( QgsVertexId position, const QgsPoint &ne
466
464
467
465
bool QgsGeometryCollection::deleteVertex ( QgsVertexId position )
468
466
{
469
- if ( position.part >= mGeometries .size () )
467
+ if ( position.part < 0 || position. part >= mGeometries .size () )
470
468
{
471
469
return false ;
472
470
}
@@ -615,7 +613,7 @@ QgsAbstractGeometry *QgsGeometryCollection::segmentize( double tolerance, Segmen
615
613
616
614
double QgsGeometryCollection::vertexAngle ( QgsVertexId vertex ) const
617
615
{
618
- if ( vertex.part >= mGeometries .size () )
616
+ if ( vertex.part < 0 || vertex. part >= mGeometries .size () )
619
617
{
620
618
return 0.0 ;
621
619
}
@@ -631,11 +629,21 @@ double QgsGeometryCollection::vertexAngle( QgsVertexId vertex ) const
631
629
632
630
int QgsGeometryCollection::vertexCount ( int part, int ring ) const
633
631
{
632
+ if ( part < 0 || part >= mGeometries .size () )
633
+ {
634
+ return 0 ;
635
+ }
636
+
634
637
return mGeometries [part]->vertexCount ( 0 , ring );
635
638
}
636
639
637
640
int QgsGeometryCollection::ringCount ( int part ) const
638
641
{
642
+ if ( part < 0 || part >= mGeometries .size () )
643
+ {
644
+ return 0 ;
645
+ }
646
+
639
647
return mGeometries [part]->ringCount ();
640
648
}
641
649
@@ -682,7 +690,7 @@ bool QgsGeometryCollection::addMValue( double mValue )
682
690
683
691
bool QgsGeometryCollection::dropZValue ()
684
692
{
685
- if ( !is3D () )
693
+ if ( mWkbType != QgsWkbTypes::GeometryCollection && !is3D () )
686
694
return false ;
687
695
688
696
mWkbType = QgsWkbTypes::dropZ ( mWkbType );
@@ -696,7 +704,7 @@ bool QgsGeometryCollection::dropZValue()
696
704
697
705
bool QgsGeometryCollection::dropMValue ()
698
706
{
699
- if ( !isMeasure () )
707
+ if ( mWkbType != QgsWkbTypes::GeometryCollection && !isMeasure () )
700
708
return false ;
701
709
702
710
mWkbType = QgsWkbTypes::dropM ( mWkbType );
0 commit comments