Fix bugs related to adding and removing geometry parts

This commit is contained in:
Marco Hugentobler 2015-06-07 11:07:50 +02:00
parent faf3bcd0d6
commit 624d142ec4
3 changed files with 33 additions and 22 deletions

View File

@ -260,7 +260,7 @@ class QgsGeometry
/**Adds a new part to this geometry (takes ownership) /**Adds a new part to this geometry (takes ownership)
@return 0 in case of success, 1 if not a multipolygon, 2 if ring is not a valid geometry, 3 if new polygon ring @return 0 in case of success, 1 if not a multipolygon, 2 if ring is not a valid geometry, 3 if new polygon ring
not disjoint with existing polygons of the feature*/ not disjoint with existing polygons of the feature*/
int addPart( QgsCurveV2* part /Transfer/ ); int addPart( QgsAbstractGeometryV2* part /Transfer/ );
/**Adds a new island polygon to a multipolygon feature /**Adds a new island polygon to a multipolygon feature
@return 0 in case of success, 1 if not a multipolygon, 2 if ring is not a valid geometry, 3 if new polygon ring @return 0 in case of success, 1 if not a multipolygon, 2 if ring is not a valid geometry, 3 if new polygon ring

View File

@ -315,7 +315,11 @@ QGis::GeometryType QgsGeometry::type() const
bool QgsGeometry::isMultipart() const bool QgsGeometry::isMultipart() const
{ {
return QGis::isMultiType( wkbType() ); if ( !d || !d->geometry )
{
return false;
}
return QgsWKBTypes::isMultiType( d->geometry->wkbType() );
} }
void QgsGeometry::fromGeos( GEOSGeometry *geos ) void QgsGeometry::fromGeos( GEOSGeometry *geos )
@ -538,13 +542,29 @@ int QgsGeometry::addRing( QgsCurveV2* ring )
int QgsGeometry::addPart( const QList<QgsPoint> &points, QGis::GeometryType geomType ) int QgsGeometry::addPart( const QList<QgsPoint> &points, QGis::GeometryType geomType )
{ {
Q_UNUSED( geomType ); if ( !d )
if ( !d || !d->geometry )
{ {
return 2; return 1;
} }
detach( true ); if ( !d->geometry )
{
detach( false );
switch ( geomType )
{
case QGis::Point:
d->geometry = new QgsMultiPointV2();
break;
case QGis::Line:
d->geometry = new QgsMultiLineStringV2();
break;
case QGis::Polygon:
d->geometry = new QgsMultiPolygonV2();
break;
default:
return 1;
}
}
if ( !isMultipart() ) if ( !isMultipart() )
{ {
@ -564,14 +584,12 @@ int QgsGeometry::addPart( const QList<QgsPoint> &points, QGis::GeometryType geom
ringLine->setPoints( partPoints ); ringLine->setPoints( partPoints );
partGeom = ringLine; partGeom = ringLine;
} }
removeWkbGeos(); return addPart( partGeom );
return addPart( dynamic_cast<QgsCurveV2*>( partGeom ) );
} }
int QgsGeometry::addPart( QgsCurveV2* part ) int QgsGeometry::addPart( QgsAbstractGeometryV2* part )
{ {
detach( true ); detach( true );
removeWkbGeos(); removeWkbGeos();
return QgsGeometryEditUtils::addPart( d->geometry, part ); return QgsGeometryEditUtils::addPart( d->geometry, part );
} }
@ -583,15 +601,7 @@ int QgsGeometry::addPart( const QgsGeometry *newPart )
return 1; return 1;
} }
detach( true ); return addPart( newPart->d->geometry->clone() );
QgsAbstractGeometryV2* g = d->geometry->clone();
QgsCurveV2* curve = dynamic_cast<QgsCurveV2*>( g );
if ( !curve )
{
delete g; return 1;
}
return addPart( curve );
} }
int QgsGeometry::addPart( GEOSGeometry *newPart ) int QgsGeometry::addPart( GEOSGeometry *newPart )
@ -1435,8 +1445,9 @@ bool QgsGeometry::deletePart( int partNum )
} }
detach( true ); detach( true );
bool ok = QgsGeometryEditUtils::deletePart( d->geometry, partNum );
return QgsGeometryEditUtils::deletePart( d->geometry, partNum ); removeWkbGeos();
return ok;
} }
int QgsGeometry::avoidIntersections( QMap<QgsVectorLayer*, QSet< QgsFeatureId > > ignoreFeatures ) int QgsGeometry::avoidIntersections( QMap<QgsVectorLayer*, QSet< QgsFeatureId > > ignoreFeatures )

View File

@ -308,7 +308,7 @@ class CORE_EXPORT QgsGeometry
/**Adds a new part to this geometry (takes ownership) /**Adds a new part to this geometry (takes ownership)
@return 0 in case of success, 1 if not a multipolygon, 2 if ring is not a valid geometry, 3 if new polygon ring @return 0 in case of success, 1 if not a multipolygon, 2 if ring is not a valid geometry, 3 if new polygon ring
not disjoint with existing polygons of the feature*/ not disjoint with existing polygons of the feature*/
int addPart( QgsCurveV2* part ); int addPart( QgsAbstractGeometryV2* part );
/**Adds a new island polygon to a multipolygon feature /**Adds a new island polygon to a multipolygon feature
@return 0 in case of success, 1 if not a multipolygon, 2 if ring is not a valid geometry, 3 if new polygon ring @return 0 in case of success, 1 if not a multipolygon, 2 if ring is not a valid geometry, 3 if new polygon ring