Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Fix bugs related to adding and removing geometry parts
  • Loading branch information
mhugent committed Jun 7, 2015
1 parent faf3bcd commit 624d142
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 22 deletions.
2 changes: 1 addition & 1 deletion python/core/geometry/qgsgeometry.sip
Expand Up @@ -260,7 +260,7 @@ class QgsGeometry
/**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
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
@return 0 in case of success, 1 if not a multipolygon, 2 if ring is not a valid geometry, 3 if new polygon ring
Expand Down
51 changes: 31 additions & 20 deletions src/core/geometry/qgsgeometry.cpp
Expand Up @@ -315,7 +315,11 @@ QGis::GeometryType QgsGeometry::type() 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 )
Expand Down Expand Up @@ -538,13 +542,29 @@ int QgsGeometry::addRing( QgsCurveV2* ring )

int QgsGeometry::addPart( const QList<QgsPoint> &points, QGis::GeometryType geomType )
{
Q_UNUSED( geomType );
if ( !d || !d->geometry )
if ( !d )
{
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() )
{
Expand All @@ -564,14 +584,12 @@ int QgsGeometry::addPart( const QList<QgsPoint> &points, QGis::GeometryType geom
ringLine->setPoints( partPoints );
partGeom = ringLine;
}
removeWkbGeos();
return addPart( dynamic_cast<QgsCurveV2*>( partGeom ) );
return addPart( partGeom );
}

int QgsGeometry::addPart( QgsCurveV2* part )
int QgsGeometry::addPart( QgsAbstractGeometryV2* part )
{
detach( true );

removeWkbGeos();
return QgsGeometryEditUtils::addPart( d->geometry, part );
}
Expand All @@ -583,15 +601,7 @@ int QgsGeometry::addPart( const QgsGeometry *newPart )
return 1;
}

detach( true );

QgsAbstractGeometryV2* g = d->geometry->clone();
QgsCurveV2* curve = dynamic_cast<QgsCurveV2*>( g );
if ( !curve )
{
delete g; return 1;
}
return addPart( curve );
return addPart( newPart->d->geometry->clone() );
}

int QgsGeometry::addPart( GEOSGeometry *newPart )
Expand Down Expand Up @@ -1435,8 +1445,9 @@ bool QgsGeometry::deletePart( int partNum )
}

detach( true );

return QgsGeometryEditUtils::deletePart( d->geometry, partNum );
bool ok = QgsGeometryEditUtils::deletePart( d->geometry, partNum );
removeWkbGeos();
return ok;
}

int QgsGeometry::avoidIntersections( QMap<QgsVectorLayer*, QSet< QgsFeatureId > > ignoreFeatures )
Expand Down
2 changes: 1 addition & 1 deletion src/core/geometry/qgsgeometry.h
Expand Up @@ -308,7 +308,7 @@ class CORE_EXPORT QgsGeometry
/**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
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
@return 0 in case of success, 1 if not a multipolygon, 2 if ring is not a valid geometry, 3 if new polygon ring
Expand Down

0 comments on commit 624d142

Please sign in to comment.