bool QgsGeometryEditUtils::deletePart( QgsAbstractGeometryV2* geom, int partNum ) { if ( !geom ) { return false; } QgsGeometryCollectionV2* c = dynamic_cast<QgsGeometryCollectionV2*>( geom ); if ( !c ) { return false; } return c->removeGeometry( partNum ); }
void QgsGeometryCheck::replaceFeatureGeometryPart( QgsFeature& feature, int partIdx, QgsAbstractGeometryV2* newPartGeom, Changes& changes ) const { QgsAbstractGeometryV2* geom = feature.geometry()->geometry(); if ( dynamic_cast<QgsGeometryCollectionV2*>( geom ) ) { QgsGeometryCollectionV2* GeomCollection = static_cast<QgsGeometryCollectionV2*>( geom ); GeomCollection->removeGeometry( partIdx ); GeomCollection->addGeometry( newPartGeom ); changes[feature.id()].append( Change( ChangeFeature, ChangeRemoved, QgsVertexId( partIdx ) ) ); changes[feature.id()].append( Change( ChangeFeature, ChangeAdded, QgsVertexId( GeomCollection->partCount() - 1 ) ) ); } else { feature.setGeometry( new QgsGeometry( newPartGeom ) ); changes[feature.id()].append( Change( ChangeFeature, ChangeChanged ) ); } mFeaturePool->updateFeature( feature ); }
int QgsGeometryEditUtils::addPart( QgsAbstractGeometryV2* geom, QgsAbstractGeometryV2* part ) { if ( !geom ) { return 1; } if ( !part ) { return 2; } //multitype? QgsGeometryCollectionV2* geomCollection = dynamic_cast<QgsGeometryCollectionV2*>( geom ); if ( !geomCollection ) { return 1; } bool added = false; if ( QgsWKBTypes::flatType( geom->wkbType() ) == QgsWKBTypes::MultiSurface || QgsWKBTypes::flatType( geom->wkbType() ) == QgsWKBTypes::MultiPolygon ) { QgsCurveV2* curve = dynamic_cast<QgsCurveV2*>( part ); if ( curve && curve->isClosed() && curve->numPoints() >= 4 ) { QgsCurvePolygonV2 *poly = nullptr; if ( QgsWKBTypes::flatType( curve->wkbType() ) == QgsWKBTypes::LineString ) { poly = new QgsPolygonV2(); } else { poly = new QgsCurvePolygonV2(); } poly->setExteriorRing( curve ); added = geomCollection->addGeometry( poly ); } else if ( QgsWKBTypes::flatType( part->wkbType() ) == QgsWKBTypes::Polygon ) { added = geomCollection->addGeometry( part ); } else if ( QgsWKBTypes::flatType( part->wkbType() ) == QgsWKBTypes::MultiPolygon ) { QgsGeometryCollectionV2 *parts = static_cast<QgsGeometryCollectionV2*>( part ); int i; int n = geomCollection->numGeometries(); for ( i = 0; i < parts->numGeometries() && geomCollection->addGeometry( parts->geometryN( i )->clone() ); i++ ) ; added = i == parts->numGeometries(); if ( !added ) { while ( geomCollection->numGeometries() > n ) geomCollection->removeGeometry( n ); delete part; return 2; } delete part; } else { delete part; return 2; } } else { added = geomCollection->addGeometry( part ); } return added ? 0 : 2; }