Rename QgsGeometry::geometry as QgsGeometry::get()

Because feature.geometry().geometry() is confusing, and impossible
to search for in python code (e.g. is input.geometry() a QgsGeometry
or a QgsAbstractGeometry?)

But more importantantly: also add a const version
QgsGeometry::constGet(). The non-const
version is slow, since it now forces a detach to avoid corrupting
geometries (since QgsGeometry is shared, it's not safe to directly
access its primitive QgsAbstractGeometry and start messing with
it without first detaching). This is a big risk in the 2.x API
which could potentially corrupt feature geometries with unexpected
outcomes.

Update all uses to constGet where possible.
This commit is contained in:
Nyall Dawson 2017-10-13 12:17:30 +10:00
parent a89dfde91b
commit 70361063d8
83 changed files with 417 additions and 357 deletions

View File

@ -269,7 +269,7 @@ class QgsAbstractGeometry
:rtype: bool
%End
virtual void adjacentVertices( QgsVertexId vertex, QgsVertexId &previousVertex /Out/, QgsVertexId &nextVertex /Out/ ) = 0;
virtual void adjacentVertices( QgsVertexId vertex, QgsVertexId &previousVertex /Out/, QgsVertexId &nextVertex /Out/ ) const = 0;
%Docstring
Returns the vertices adjacent to a specified ``vertex`` within a geometry.
.. versionadded:: 3.0

View File

@ -102,7 +102,7 @@ class QgsCurve: QgsAbstractGeometry
virtual bool nextVertex( QgsVertexId &id, QgsPoint &vertex /Out/ ) const;
virtual void adjacentVertices( QgsVertexId vertex, QgsVertexId &previousVertex /Out/, QgsVertexId &nextVertex /Out/ );
virtual void adjacentVertices( QgsVertexId vertex, QgsVertexId &previousVertex /Out/, QgsVertexId &nextVertex /Out/ ) const;
virtual int vertexNumberFromVertexId( QgsVertexId id ) const;

View File

@ -152,7 +152,7 @@ Adds an interior ring to the geometry (takes ownership)
virtual bool nextVertex( QgsVertexId &id, QgsPoint &vertex /Out/ ) const;
virtual void adjacentVertices( QgsVertexId vertex, QgsVertexId &previousVertex /Out/, QgsVertexId &nextVertex /Out/ );
virtual void adjacentVertices( QgsVertexId vertex, QgsVertexId &previousVertex /Out/, QgsVertexId &nextVertex /Out/ ) const;
virtual bool hasCurvedSegments() const;

View File

@ -84,19 +84,50 @@ Copy constructor will prompt a deep copy of the object
~QgsGeometry();
QgsAbstractGeometry *geometry() const;
const QgsAbstractGeometry *constGet() const;
%Docstring
Returns the underlying geometry store.
.. versionadded:: 2.10
.. seealso:: setGeometry
Returns a non-modifiable (const) reference to the underlying abstract geometry primitive.
This is much faster then calling the non-const get() method.
.. note::
In QGIS 2.x this method was named geometry().
.. versionadded:: 3.0
.. seealso:: primitive()
.. seealso:: set()
:rtype: QgsAbstractGeometry
%End
void setGeometry( QgsAbstractGeometry *geometry /Transfer/ );
QgsAbstractGeometry *get();
%Docstring
Returns a modifiable (non-const) reference to the underlying abstract geometry primitive.
This method can be slow to call, as it may trigger a detachment of the geometry
and a deep copy. Where possible, use constGet() instead.
.. note::
In QGIS 2.x this method was named geometry().
.. versionadded:: 3.0
.. seealso:: constGet()
.. seealso:: set()
:rtype: QgsAbstractGeometry
%End
void set( QgsAbstractGeometry *geometry /Transfer/ );
%Docstring
Sets the underlying geometry store. Ownership of geometry is transferred.
.. versionadded:: 2.10
.. seealso:: geometry
.. note::
In QGIS 2.x this method was named setGeometry().
.. versionadded:: 3.0
.. seealso:: get()
.. seealso:: constGet()
%End
bool isNull() const;

View File

@ -53,7 +53,7 @@ class QgsGeometryCollection: QgsAbstractGeometry
virtual QgsAbstractGeometry *boundary() const /Factory/;
virtual void adjacentVertices( QgsVertexId vertex, QgsVertexId &previousVertex /Out/, QgsVertexId &nextVertex /Out/ );
virtual void adjacentVertices( QgsVertexId vertex, QgsVertexId &previousVertex /Out/, QgsVertexId &nextVertex /Out/ ) const;
virtual int vertexNumberFromVertexId( QgsVertexId id ) const;

View File

@ -380,7 +380,7 @@ class QgsPoint: QgsAbstractGeometry
virtual bool nextVertex( QgsVertexId &id, QgsPoint &vertex /Out/ ) const;
virtual void adjacentVertices( QgsVertexId vertex, QgsVertexId &previousVertex /Out/, QgsVertexId &nextVertex /Out/ );
virtual void adjacentVertices( QgsVertexId vertex, QgsVertexId &previousVertex /Out/, QgsVertexId &nextVertex /Out/ ) const;
virtual double vertexAngle( QgsVertexId vertex ) const;

View File

@ -165,9 +165,9 @@ void QgsVectorLayerDirector::makeGraph( QgsGraphBuilderInterface *builder, const
}
QgsMultiPolyline mpl;
if ( QgsWkbTypes::flatType( feature.geometry().geometry()->wkbType() ) == QgsWkbTypes::MultiLineString )
if ( QgsWkbTypes::flatType( feature.geometry().wkbType() ) == QgsWkbTypes::MultiLineString )
mpl = feature.geometry().asMultiPolyline();
else if ( QgsWkbTypes::flatType( feature.geometry().geometry()->wkbType() ) == QgsWkbTypes::LineString )
else if ( QgsWkbTypes::flatType( feature.geometry().wkbType() ) == QgsWkbTypes::LineString )
mpl.push_back( feature.geometry().asPolyline() );
QgsMultiPolyline::iterator mplIt;
@ -308,9 +308,9 @@ void QgsVectorLayerDirector::makeGraph( QgsGraphBuilderInterface *builder, const
// begin features segments and add arc to the Graph;
QgsMultiPolyline mpl;
if ( QgsWkbTypes::flatType( feature.geometry().geometry()->wkbType() ) == QgsWkbTypes::MultiLineString )
if ( QgsWkbTypes::flatType( feature.geometry().wkbType() ) == QgsWkbTypes::MultiLineString )
mpl = feature.geometry().asMultiPolyline();
else if ( QgsWkbTypes::flatType( feature.geometry().geometry()->wkbType() ) == QgsWkbTypes::LineString )
else if ( QgsWkbTypes::flatType( feature.geometry().wkbType() ) == QgsWkbTypes::LineString )
mpl.push_back( feature.geometry().asPolyline() );
QgsMultiPolyline::iterator mplIt;

View File

@ -97,7 +97,7 @@ QgsFeature QgsBoundaryAlgorithm::processFeature( const QgsFeature &feature, QgsP
if ( feature.hasGeometry() )
{
QgsGeometry inputGeometry = feature.geometry();
QgsGeometry outputGeometry = QgsGeometry( inputGeometry.geometry()->boundary() );
QgsGeometry outputGeometry = QgsGeometry( inputGeometry.constGet()->boundary() );
if ( !outputGeometry )
{
feedback->reportError( QObject::tr( "No boundary for feature %1 (possibly a closed linestring?)'" ).arg( feature.id() ) );

View File

@ -109,7 +109,7 @@ QVariantMap QgsClipAlgorithm::processAlgorithm( const QVariantMap &parameters, Q
}
// use prepared geometries for faster intersection tests
std::unique_ptr< QgsGeometryEngine > engine( QgsGeometry::createGeometryEngine( combinedClipGeom.geometry() ) );
std::unique_ptr< QgsGeometryEngine > engine( QgsGeometry::createGeometryEngine( combinedClipGeom.constGet() ) );
engine->prepareGeometry();
QgsFeatureIds testedFeatureIds;
@ -154,15 +154,15 @@ QVariantMap QgsClipAlgorithm::processAlgorithm( const QVariantMap &parameters, Q
}
testedFeatureIds.insert( inputFeature.id() );
if ( !engine->intersects( inputFeature.geometry().geometry() ) )
if ( !engine->intersects( inputFeature.geometry().constGet() ) )
continue;
QgsGeometry newGeometry;
if ( !engine->contains( inputFeature.geometry().geometry() ) )
if ( !engine->contains( inputFeature.geometry().constGet() ) )
{
QgsGeometry currentGeometry = inputFeature.geometry();
newGeometry = combinedClipGeom.intersection( currentGeometry );
if ( newGeometry.wkbType() == QgsWkbTypes::Unknown || QgsWkbTypes::flatType( newGeometry.geometry()->wkbType() ) == QgsWkbTypes::GeometryCollection )
if ( newGeometry.wkbType() == QgsWkbTypes::Unknown || QgsWkbTypes::flatType( newGeometry.wkbType() ) == QgsWkbTypes::GeometryCollection )
{
QgsGeometry intCom = inputFeature.geometry().combine( newGeometry );
QgsGeometry intSym = inputFeature.geometry().symDifference( newGeometry );

View File

@ -76,8 +76,8 @@ QgsFeature QgsConvexHullAlgorithm::processFeature( const QgsFeature &feature, Qg
if ( outputGeometry )
{
QgsAttributes attrs = f.attributes();
attrs << outputGeometry.geometry()->area()
<< outputGeometry.geometry()->perimeter();
attrs << outputGeometry.constGet()->area()
<< outputGeometry.constGet()->perimeter();
f.setAttributes( attrs );
}
}

View File

@ -82,7 +82,7 @@ QgsFeature QgsDropMZValuesAlgorithm::processFeature( const QgsFeature &feature,
QgsFeature f = feature;
if ( f.hasGeometry() )
{
std::unique_ptr< QgsAbstractGeometry > newGeom( f.geometry().geometry()->clone() );
std::unique_ptr< QgsAbstractGeometry > newGeom( f.geometry().constGet()->clone() );
if ( mDropM )
newGeom->dropMValue();
if ( mDropZ )

View File

@ -136,7 +136,7 @@ void QgsLocationBasedAlgorithm::process( QgsFeatureSource *targetSource,
if ( !engine )
{
engine.reset( QgsGeometry::createGeometryEngine( f.geometry().geometry() ) );
engine.reset( QgsGeometry::createGeometryEngine( f.geometry().constGet() ) );
engine->prepareGeometry();
}
@ -146,31 +146,31 @@ void QgsLocationBasedAlgorithm::process( QgsFeatureSource *targetSource,
switch ( predicate )
{
case Intersects:
isMatch = engine->intersects( testFeature.geometry().geometry() );
isMatch = engine->intersects( testFeature.geometry().constGet() );
break;
case Contains:
isMatch = engine->contains( testFeature.geometry().geometry() );
isMatch = engine->contains( testFeature.geometry().constGet() );
break;
case Disjoint:
if ( engine->intersects( testFeature.geometry().geometry() ) )
if ( engine->intersects( testFeature.geometry().constGet() ) )
{
disjointSet.remove( testFeature.id() );
}
break;
case IsEqual:
isMatch = engine->isEqual( testFeature.geometry().geometry() );
isMatch = engine->isEqual( testFeature.geometry().constGet() );
break;
case Touches:
isMatch = engine->touches( testFeature.geometry().geometry() );
isMatch = engine->touches( testFeature.geometry().constGet() );
break;
case Overlaps:
isMatch = engine->overlaps( testFeature.geometry().geometry() );
isMatch = engine->overlaps( testFeature.geometry().constGet() );
break;
case Within:
isMatch = engine->within( testFeature.geometry().geometry() );
isMatch = engine->within( testFeature.geometry().constGet() );
break;
case Crosses:
isMatch = engine->crosses( testFeature.geometry().geometry() );
isMatch = engine->crosses( testFeature.geometry().constGet() );
break;
}
if ( isMatch )

View File

@ -83,7 +83,7 @@ QgsFeature QgsFixGeometriesAlgorithm::processFeature( const QgsFeature &feature,
}
if ( outputGeometry.wkbType() == QgsWkbTypes::Unknown ||
QgsWkbTypes::flatType( outputGeometry.geometry()->wkbType() ) == QgsWkbTypes::GeometryCollection )
QgsWkbTypes::flatType( outputGeometry.wkbType() ) == QgsWkbTypes::GeometryCollection )
{
// keep only the parts of the geometry collection with correct type
const QList< QgsGeometry > tmpGeometries = outputGeometry.asGeometryCollection();

View File

@ -177,9 +177,9 @@ QVariantMap QgsJoinWithLinesAlgorithm::processAlgorithm( const QVariantMap &para
{
QgsPoint p;
if ( feature.geometry().type() == QgsWkbTypes::PointGeometry && !feature.geometry().isMultipart() )
p = *static_cast< QgsPoint *>( feature.geometry().geometry() );
p = *static_cast< const QgsPoint *>( feature.geometry().constGet() );
else
p = *static_cast< QgsPoint *>( feature.geometry().pointOnSurface().geometry() );
p = *static_cast< const QgsPoint *>( feature.geometry().pointOnSurface().constGet() );
if ( hasZ && !p.is3D() )
p.addZValue( 0 );
if ( hasM && !p.isMeasure() )

View File

@ -161,7 +161,7 @@ QVariantMap QgsLineIntersectionAlgorithm::processAlgorithm( const QVariantMap &p
if ( !lines.empty() )
{
// use prepared geometries for faster intersection tests
std::unique_ptr< QgsGeometryEngine > engine( QgsGeometry::createGeometryEngine( inGeom.geometry() ) );
std::unique_ptr< QgsGeometryEngine > engine( QgsGeometry::createGeometryEngine( inGeom.constGet() ) );
engine->prepareGeometry();
QgsFeatureRequest request = QgsFeatureRequest().setFilterFids( lines );
@ -178,7 +178,7 @@ QVariantMap QgsLineIntersectionAlgorithm::processAlgorithm( const QVariantMap &p
}
QgsGeometry tmpGeom = inFeatureB.geometry();
if ( engine->intersects( tmpGeom.geometry() ) )
if ( engine->intersects( tmpGeom.constGet() ) )
{
QgsMultiPoint points;
QgsGeometry intersectGeom = inGeom.intersection( tmpGeom );

View File

@ -164,7 +164,7 @@ QVariantMap QgsMeanCoordinatesAlgorithm::processAlgorithm( const QVariantMap &pa
QgsVertexId vid;
QgsPoint pt;
const QgsAbstractGeometry *g = feat.geometry().geometry();
const QgsAbstractGeometry *g = feat.geometry().constGet();
// NOTE - should this be including the duplicate nodes for closed rings? currently it is,
// but I suspect that the expected behavior would be to NOT include these
while ( g->nextVertex( vid, pt ) )

View File

@ -140,11 +140,11 @@ QVariantMap QgsSplitWithLinesAlgorithm::processAlgorithm( const QVariantMap &par
QgsGeometry splitGeom = splitGeoms.value( line );
if ( !engine )
{
engine.reset( QgsGeometry::createGeometryEngine( inGeom.geometry() ) );
engine.reset( QgsGeometry::createGeometryEngine( inGeom.constGet() ) );
engine->prepareGeometry();
}
if ( engine->intersects( splitGeom.geometry() ) )
if ( engine->intersects( splitGeom.constGet() ) )
{
QList< QgsGeometry > splitGeomParts = splitGeom.asGeometryCollection();
splittingLines.append( splitGeomParts );
@ -159,7 +159,7 @@ QVariantMap QgsSplitWithLinesAlgorithm::processAlgorithm( const QVariantMap &par
QList< QgsGeometry > outGeoms;
// use prepared geometries for faster intersection tests
std::unique_ptr< QgsGeometryEngine > splitGeomEngine( QgsGeometry::createGeometryEngine( splitGeom.geometry() ) );
std::unique_ptr< QgsGeometryEngine > splitGeomEngine( QgsGeometry::createGeometryEngine( splitGeom.constGet() ) );
splitGeomEngine->prepareGeometry();
while ( !inGeoms.empty() )
{
@ -172,12 +172,12 @@ QVariantMap QgsSplitWithLinesAlgorithm::processAlgorithm( const QVariantMap &par
if ( !inGeom )
continue;
if ( splitGeomEngine->intersects( inGeom.geometry() ) )
if ( splitGeomEngine->intersects( inGeom.constGet() ) )
{
QgsGeometry before = inGeom;
if ( splitterPList.empty() )
{
const QgsCoordinateSequence sequence = splitGeom.geometry()->coordinateSequence();
const QgsCoordinateSequence sequence = splitGeom.constGet()->coordinateSequence();
for ( const QgsRingSequence &part : sequence )
{
for ( const QgsPointSequence &ring : part )
@ -237,12 +237,12 @@ QVariantMap QgsSplitWithLinesAlgorithm::processAlgorithm( const QVariantMap &par
bool passed = true;
if ( QgsWkbTypes::geometryType( aGeom.wkbType() ) == QgsWkbTypes::LineGeometry )
{
int numPoints = aGeom.geometry()->nCoordinates();
int numPoints = aGeom.constGet()->nCoordinates();
if ( numPoints <= 2 )
{
if ( numPoints == 2 )
passed = !static_cast< QgsCurve * >( aGeom.geometry() )->isClosed(); // tests if vertex 0 = vertex 1
passed = !static_cast< const QgsCurve * >( aGeom.constGet() )->isClosed(); // tests if vertex 0 = vertex 1
else
passed = false; // sometimes splitting results in lines of zero length
}

View File

@ -132,7 +132,7 @@ QVariantMap QgsTransectAlgorithm::processAlgorithm( const QVariantMap &parameter
QgsGeometry inputGeometry = feat.geometry();
inputGeometry.convertToMultiType();
const QgsMultiLineString *multiLine = static_cast< QgsMultiLineString * >( inputGeometry.geometry() );
const QgsMultiLineString *multiLine = static_cast< const QgsMultiLineString * >( inputGeometry.constGet() );
for ( int id = 0; id < multiLine->numGeometries(); ++id )
{
const QgsLineString *line = static_cast< const QgsLineString * >( multiLine->geometryN( id ) );

View File

@ -109,7 +109,7 @@ void QgsFeaturePool::updateFeature( QgsFeature &feature )
get( feature.id(), origFeature );
QgsGeometryMap geometryMap;
geometryMap.insert( feature.id(), QgsGeometry( feature.geometry().geometry()->clone() ) );
geometryMap.insert( feature.id(), QgsGeometry( feature.geometry().constGet()->clone() ) );
QgsChangedAttributesMap changedAttributesMap;
QgsAttributeMap attribMap;
for ( int i = 0, n = feature.attributes().size(); i < n; ++i )

View File

@ -73,7 +73,7 @@ void QgsGeometryAngleCheck::fixError( QgsGeometryCheckError *error, int method,
return;
}
QgsGeometry featureGeometry = feature.geometry();
QgsAbstractGeometry *geometry = featureGeometry.geometry();
QgsAbstractGeometry *geometry = featureGeometry.get();
QgsVertexId vidx = error->vidx();
// Check if point still exists

View File

@ -49,7 +49,7 @@ void QgsGeometryAreaCheck::fixError( QgsGeometryCheckError *error, int method, c
}
double layerToMapUnits = featurePool->getLayerToMapUnits();
QgsGeometry g = feature.geometry();
QgsAbstractGeometry *geom = g.geometry();
const QgsAbstractGeometry *geom = g.constGet();
QgsVertexId vidx = error->vidx();
// Check if polygon still exists
@ -111,7 +111,7 @@ bool QgsGeometryAreaCheck::mergeWithNeighbor( const QString &layerId, QgsFeature
int mergePartIdx = -1;
bool matchFound = false;
QgsGeometry featureGeometry = feature.geometry();
QgsAbstractGeometry *geom = featureGeometry.geometry();
const QgsAbstractGeometry *geom = featureGeometry.constGet();
// Search for touching neighboring geometries
for ( QgsFeatureId testId : featurePool->getIntersects( featureGeometry.boundingBox() ) )
@ -122,7 +122,7 @@ bool QgsGeometryAreaCheck::mergeWithNeighbor( const QString &layerId, QgsFeature
continue;
}
QgsGeometry testFeatureGeom = testFeature.geometry();
QgsAbstractGeometry *testGeom = testFeatureGeom.geometry();
const QgsAbstractGeometry *testGeom = testFeatureGeom.constGet();
for ( int testPartIdx = 0, nTestParts = testGeom->partCount(); testPartIdx < nTestParts; ++testPartIdx )
{
if ( testId == feature.id() && testPartIdx == partIdx )
@ -141,8 +141,8 @@ bool QgsGeometryAreaCheck::mergeWithNeighbor( const QString &layerId, QgsFeature
}
else
{
if ( dynamic_cast<QgsGeometryCollection *>( testGeom ) )
val = static_cast<QgsGeometryCollection *>( testGeom )->geometryN( testPartIdx )->area();
if ( dynamic_cast<const QgsGeometryCollection *>( testGeom ) )
val = static_cast<const QgsGeometryCollection *>( testGeom )->geometryN( testPartIdx )->area();
else
val = testGeom->area();
}
@ -178,7 +178,7 @@ bool QgsGeometryAreaCheck::mergeWithNeighbor( const QString &layerId, QgsFeature
// Merge geometries
QgsGeometry mergeFeatureGeom = mergeFeature.geometry();
QgsAbstractGeometry *mergeGeom = mergeFeatureGeom.geometry();
const QgsAbstractGeometry *mergeGeom = mergeFeatureGeom.constGet();
QSharedPointer<QgsGeometryEngine> geomEngine = QgsGeometryCheckerUtils::createGeomEngine( QgsGeometryCheckerUtils::getGeomPart( mergeGeom, mergePartIdx ), mContext->reducedTolerance );
QgsAbstractGeometry *combinedGeom = geomEngine->combine( QgsGeometryCheckerUtils::getGeomPart( geom, partIdx ), &errMsg );
if ( !combinedGeom || combinedGeom->isEmpty() || !QgsWkbTypes::isSingleType( combinedGeom->wkbType() ) )

View File

@ -157,10 +157,9 @@ void QgsGeometryCheck::replaceFeatureGeometryPart( const QString &layerId, QgsFe
{
QgsFeaturePool *featurePool = mContext->featurePools[layerId];
QgsGeometry featureGeom = feature.geometry();
QgsAbstractGeometry *geom = featureGeom.geometry();
if ( dynamic_cast<QgsGeometryCollection *>( geom ) )
QgsAbstractGeometry *geom = featureGeom.get();
if ( QgsGeometryCollection *geomCollection = dynamic_cast< QgsGeometryCollection *>( geom ) )
{
QgsGeometryCollection *geomCollection = static_cast<QgsGeometryCollection *>( geom );
geomCollection->removeGeometry( partIdx );
geomCollection->addGeometry( newPartGeom );
changes[layerId][feature.id()].append( Change( ChangePart, ChangeRemoved, QgsVertexId( partIdx ) ) );
@ -179,7 +178,7 @@ void QgsGeometryCheck::deleteFeatureGeometryPart( const QString &layerId, QgsFea
{
QgsFeaturePool *featurePool = mContext->featurePools[layerId];
QgsGeometry featureGeom = feature.geometry();
QgsAbstractGeometry *geom = featureGeom.geometry();
QgsAbstractGeometry *geom = featureGeom.get();
if ( dynamic_cast<QgsGeometryCollection *>( geom ) )
{
static_cast<QgsGeometryCollection *>( geom )->removeGeometry( partIdx );
@ -206,7 +205,7 @@ void QgsGeometryCheck::deleteFeatureGeometryRing( const QString &layerId, QgsFea
{
QgsFeaturePool *featurePool = mContext->featurePools[layerId];
QgsGeometry featureGeom = feature.geometry();
QgsAbstractGeometry *partGeom = QgsGeometryCheckerUtils::getGeomPart( featureGeom.geometry(), partIdx );
QgsAbstractGeometry *partGeom = QgsGeometryCheckerUtils::getGeomPart( featureGeom.get(), partIdx );
if ( dynamic_cast<QgsCurvePolygon *>( partGeom ) )
{
// If we delete the exterior ring of a polygon, it makes no sense to keep the interiors

View File

@ -31,7 +31,7 @@ namespace QgsGeometryCheckerUtils
, mFeature( feature )
, mMapCrs( useMapCrs )
{
mGeometry = feature.geometry().geometry()->clone();
mGeometry = feature.geometry().constGet()->clone();
if ( useMapCrs && !mFeaturePool->getLayerToMapTransform().isShortCircuited() )
{
mGeometry->transform( mFeaturePool->getLayerToMapTransform() );
@ -124,7 +124,7 @@ namespace QgsGeometryCheckerUtils
if ( mParent->mProgressCounter )
mParent->mProgressCounter->fetchAndAddRelaxed( 1 );
QgsFeature feature;
if ( featurePool->get( *mFeatureIt, feature ) && feature.geometry() && feature.geometry().geometry() )
if ( featurePool->get( *mFeatureIt, feature ) && feature.geometry() && feature.geometry().constGet() )
{
delete mCurrentFeature;
mCurrentFeature = new LayerFeature( mParent->mFeaturePools[*mLayerIt], feature, mParent->mUseMapCrs );

View File

@ -47,7 +47,7 @@ void QgsGeometryDegeneratePolygonCheck::fixError( QgsGeometryCheckError *error,
return;
}
QgsGeometry featureGeometry = feature.geometry();
QgsAbstractGeometry *geom = featureGeometry.geometry();
const QgsAbstractGeometry *geom = featureGeometry.constGet();
QgsVertexId vidx = error->vidx();
// Check if ring still exists

View File

@ -55,7 +55,7 @@ void QgsGeometryDuplicateNodesCheck::fixError( QgsGeometryCheckError *error, int
return;
}
QgsGeometry featureGeom = feature.geometry();
QgsAbstractGeometry *geom = featureGeom.geometry();
QgsAbstractGeometry *geom = featureGeom.get();
QgsVertexId vidx = error->vidx();
// Check if point still exists

View File

@ -74,7 +74,7 @@ void QgsGeometryFollowBoundariesCheck::collectErrors( QList<QgsGeometryCheckErro
QgsFeature refFeature;
while ( refFeatureIt.nextFeature( refFeature ) )
{
QgsAbstractGeometry *refGeom = refFeature.geometry().geometry();
const QgsAbstractGeometry *refGeom = refFeature.geometry().constGet();
QSharedPointer<QgsGeometryEngine> refgeomEngine = QgsGeometryCheckerUtils::createGeomEngine( refGeom, mContext->tolerance );
QScopedPointer<QgsAbstractGeometry> reducedRefGeom( refgeomEngine->buffer( -mContext->tolerance, 0 ) );
if ( !( geomEngine->contains( reducedRefGeom.data() ) || geomEngine->disjoint( reducedRefGeom.data() ) ) )

View File

@ -168,7 +168,7 @@ bool QgsGeometryGapCheck::mergeWithNeighbor( QgsGeometryGapCheckError *err, Chan
continue;
}
QgsGeometry featureGeom = testFeature.geometry();
QgsAbstractGeometry *testGeom = featureGeom.geometry();
const QgsAbstractGeometry *testGeom = featureGeom.constGet();
for ( int iPart = 0, nParts = testGeom->partCount(); iPart < nParts; ++iPart )
{
double len = QgsGeometryCheckerUtils::sharedEdgeLength( errLayerGeom, QgsGeometryCheckerUtils::getGeomPart( testGeom, iPart ), mContext->reducedTolerance );
@ -194,7 +194,7 @@ bool QgsGeometryGapCheck::mergeWithNeighbor( QgsGeometryGapCheckError *err, Chan
QgsAbstractGeometry *errLayerGeom = errGeometry->clone();
errLayerGeom->transform( featurePool->getLayerToMapTransform(), QgsCoordinateTransform::ReverseTransform );
QgsGeometry mergeFeatureGeom = mergeFeature.geometry();
QgsAbstractGeometry *mergeGeom = mergeFeatureGeom.geometry();
const QgsAbstractGeometry *mergeGeom = mergeFeatureGeom.constGet();
QSharedPointer<QgsGeometryEngine> geomEngine = QgsGeometryCheckerUtils::createGeomEngine( errLayerGeom, mContext->reducedTolerance );
QgsAbstractGeometry *combinedGeom = geomEngine->combine( QgsGeometryCheckerUtils::getGeomPart( mergeGeom, mergePartIdx ), &errMsg );
delete errLayerGeom;

View File

@ -53,7 +53,7 @@ void QgsGeometryHoleCheck::fixError( QgsGeometryCheckError *error, int method, c
return;
}
QgsGeometry featureGeom = feature.geometry();
QgsAbstractGeometry *geom = featureGeom.geometry();
const QgsAbstractGeometry *geom = featureGeom.constGet();
QgsVertexId vidx = error->vidx();
// Check if ring still exists

View File

@ -41,7 +41,7 @@ void QgsGeometryMultipartCheck::fixError( QgsGeometryCheckError *error, int meth
return;
}
QgsGeometry featureGeom = feature.geometry();
QgsAbstractGeometry *geom = featureGeom.geometry();
const QgsAbstractGeometry *geom = featureGeom.constGet();
// Check if error still applies
if ( geom->partCount() > 1 || !QgsWkbTypes::isMultiType( geom->wkbType() ) )

View File

@ -65,7 +65,7 @@ void QgsGeometrySegmentLengthCheck::fixError( QgsGeometryCheckError *error, int
}
QgsGeometry featureGeom = feature.geometry();
QgsAbstractGeometry *geom = featureGeom.geometry();
const QgsAbstractGeometry *geom = featureGeom.constGet();
QgsVertexId vidx = error->vidx();
// Check if point still exists

View File

@ -90,7 +90,7 @@ void QgsGeometrySelfIntersectionCheck::fixError( QgsGeometryCheckError *error, i
return;
}
QgsGeometry featureGeom = feature.geometry();
QgsAbstractGeometry *geom = featureGeom.geometry();
QgsAbstractGeometry *geom = featureGeom.get();
QgsVertexId vidx = error->vidx();
// Check if ring still exists

View File

@ -48,7 +48,7 @@ void QgsGeometryTypeCheck::fixError( QgsGeometryCheckError *error, int method, c
return;
}
QgsGeometry featureGeom = feature.geometry();
QgsAbstractGeometry *geom = featureGeom.geometry();
const QgsAbstractGeometry *geom = featureGeom.constGet();
// Check if error still applies
QgsWkbTypes::Type type = QgsWkbTypes::flatType( geom->wkbType() );

View File

@ -505,17 +505,17 @@ QgsGeometry QgsGeometrySnapper::snapGeometry( const QgsGeometry &geometry, doubl
( mode == EndPointPreferClosest || mode == EndPointPreferNodes || mode == EndPointToEndPoint ) )
return geometry;
QgsPoint center = qgsgeometry_cast< const QgsPoint * >( geometry.geometry() ) ? *static_cast< const QgsPoint * >( geometry.geometry() ) :
QgsPoint( geometry.geometry()->boundingBox().center() );
QgsPoint center = qgsgeometry_cast< const QgsPoint * >( geometry.constGet() ) ? *static_cast< const QgsPoint * >( geometry.constGet() ) :
QgsPoint( geometry.constGet()->boundingBox().center() );
QgsSnapIndex refSnapIndex( center, 10 * snapTolerance );
Q_FOREACH ( const QgsGeometry &geom, referenceGeometries )
{
refSnapIndex.addGeometry( geom.geometry() );
refSnapIndex.addGeometry( geom.constGet() );
}
// Snap geometries
QgsAbstractGeometry *subjGeom = geometry.geometry()->clone();
QgsAbstractGeometry *subjGeom = geometry.constGet()->clone();
QList < QList< QList<PointFlag> > > subjPointFlags;
// Pass 1: snap vertices of subject geometry to reference vertices
@ -619,16 +619,16 @@ QgsGeometry QgsGeometrySnapper::snapGeometry( const QgsGeometry &geometry, doubl
// Pass 2: add missing vertices to subject geometry
Q_FOREACH ( const QgsGeometry &refGeom, referenceGeometries )
{
for ( int iPart = 0, nParts = refGeom.geometry()->partCount(); iPart < nParts; ++iPart )
for ( int iPart = 0, nParts = refGeom.constGet()->partCount(); iPart < nParts; ++iPart )
{
for ( int iRing = 0, nRings = refGeom.geometry()->ringCount( iPart ); iRing < nRings; ++iRing )
for ( int iRing = 0, nRings = refGeom.constGet()->ringCount( iPart ); iRing < nRings; ++iRing )
{
for ( int iVert = 0, nVerts = polyLineSize( refGeom.geometry(), iPart, iRing ); iVert < nVerts; ++iVert )
for ( int iVert = 0, nVerts = polyLineSize( refGeom.constGet(), iPart, iRing ); iVert < nVerts; ++iVert )
{
QgsSnapIndex::PointSnapItem *snapPoint = nullptr;
QgsSnapIndex::SegmentSnapItem *snapSegment = nullptr;
QgsPoint point = refGeom.geometry()->vertexAt( QgsVertexId( iPart, iRing, iVert ) );
QgsPoint point = refGeom.constGet()->vertexAt( QgsVertexId( iPart, iRing, iVert ) );
if ( subjSnapIndex->getSnapItem( point, snapTolerance, &snapPoint, &snapSegment ) )
{
// Snap to segment, unless a subject point was already snapped to the reference point

View File

@ -2672,7 +2672,7 @@ bool QgsDwgImporter::expandInserts( QString &error )
continue;
}
QByteArray wkb = g.geometry()->asWkb();
QByteArray wkb = g.constGet()->asWkb();
if ( OGR_G_CreateFromWkb( ( unsigned char * ) wkb.constData(), nullptr, &ogrG, wkb.size() ) != OGRERR_NONE )
{
QgsDebugMsg( QString( "%1/%2: could not create ogr geometry" ).arg( name ).arg( fid ) );

View File

@ -54,12 +54,12 @@ uint qHash( const Vertex &v )
//! Find out whether vertex at the given index is an endpoint (assuming linear geometry)
static bool isEndpointAtVertexIndex( const QgsGeometry &geom, int vertexIndex )
{
QgsAbstractGeometry *g = geom.geometry();
if ( QgsCurve *curve = dynamic_cast<QgsCurve *>( g ) )
const QgsAbstractGeometry *g = geom.constGet();
if ( const QgsCurve *curve = qgsgeometry_cast< const QgsCurve *>( g ) )
{
return vertexIndex == 0 || vertexIndex == curve->numPoints() - 1;
}
else if ( QgsMultiCurve *multiCurve = dynamic_cast<QgsMultiCurve *>( g ) )
else if ( const QgsMultiCurve *multiCurve = qgsgeometry_cast<const QgsMultiCurve *>( g ) )
{
for ( int i = 0; i < multiCurve->numGeometries(); ++i )
{
@ -83,17 +83,17 @@ static bool isEndpointAtVertexIndex( const QgsGeometry &geom, int vertexIndex )
//! Return index of vertex adjacent to the given endpoint. Assuming linear geometries.
int adjacentVertexIndexToEndpoint( const QgsGeometry &geom, int vertexIndex )
{
QgsAbstractGeometry *g = geom.geometry();
if ( QgsCurve *curve = dynamic_cast<QgsCurve *>( g ) )
const QgsAbstractGeometry *g = geom.constGet();
if ( const QgsCurve *curve = qgsgeometry_cast<const QgsCurve *>( g ) )
{
return vertexIndex == 0 ? 1 : curve->numPoints() - 2;
}
else if ( QgsMultiCurve *multiCurve = dynamic_cast<QgsMultiCurve *>( g ) )
else if ( const QgsMultiCurve *multiCurve = qgsgeometry_cast<const QgsMultiCurve *>( g ) )
{
int offset = 0;
for ( int i = 0; i < multiCurve->numGeometries(); ++i )
{
QgsCurve *part = qgsgeometry_cast<QgsCurve *>( multiCurve->geometryN( i ) );
const QgsCurve *part = qgsgeometry_cast<const QgsCurve *>( multiCurve->geometryN( i ) );
Q_ASSERT( part );
if ( vertexIndex < part->numPoints() )
return vertexIndex == 0 ? offset + 1 : offset + part->numPoints() - 2;
@ -125,7 +125,7 @@ static QgsGeometry geometryToMultiPoint( const QgsGeometry &geom )
{
QgsMultiPointV2 *multiPoint = new QgsMultiPointV2();
QgsGeometry outputGeom( multiPoint );
QgsAbstractGeometry *g = geom.geometry();
const QgsAbstractGeometry *g = geom.constGet();
for ( int i = 0; i < g->partCount(); ++i )
for ( int j = 0; j < g->ringCount( i ); ++j )
for ( int k = 0; k < g->vertexCount( i, j ); ++k )
@ -180,7 +180,7 @@ class MatchCollectingFilter : public QgsPointLocator::MatchFilter
QgsGeometry matchGeom = nodetool->cachedGeometry( match.layer(), match.featureId() );
QgsVertexId vid;
QgsPoint pt;
while ( matchGeom.geometry()->nextVertex( vid, pt ) )
while ( matchGeom.constGet()->nextVertex( vid, pt ) )
{
int vindex = matchGeom.vertexNrFromVertexId( vid );
if ( pt.x() == match.point().x() && pt.y() == match.point().y() && vindex != match.vertexIndex() )
@ -435,7 +435,7 @@ void QgsNodeTool::cadCanvasReleaseEvent( QgsMapMouseEvent *e )
while ( fi.nextFeature( f ) )
{
QgsGeometry g = f.geometry();
for ( int i = 0; i < g.geometry()->nCoordinates(); ++i )
for ( int i = 0; i < g.constGet()->nCoordinates(); ++i )
{
QgsPointXY pt = g.vertexAt( i );
if ( layerRect.contains( pt ) )
@ -828,8 +828,8 @@ void QgsNodeTool::mouseMoveNotDragging( QgsMapMouseEvent *e )
QgsGeometry geom = cachedGeometry( m.layer(), m.featureId() );
mFeatureBandMarkers->setToGeometry( geometryToMultiPoint( geom ), m.layer() );
mFeatureBandMarkers->setVisible( true );
if ( QgsWkbTypes::isCurvedType( geom.geometry()->wkbType() ) )
geom = QgsGeometry( geom.geometry()->segmentize() );
if ( QgsWkbTypes::isCurvedType( geom.wkbType() ) )
geom = QgsGeometry( geom.constGet()->segmentize() );
mFeatureBand->setToGeometry( geom, m.layer() );
mFeatureBand->setVisible( true );
mFeatureBandLayer = m.layer();
@ -994,7 +994,7 @@ void QgsNodeTool::deleteNodeEditorSelection()
if ( mSelectedFeature->geometry()->type() == QgsWkbTypes::LineGeometry )
{
// for lines we don't wrap around vertex selection when deleting nodes from end of line
nextVertexToSelect = std::min( nextVertexToSelect, mSelectedFeature->geometry()->geometry()->nCoordinates() - 1 );
nextVertexToSelect = std::min( nextVertexToSelect, mSelectedFeature->geometry()->constGet()->nCoordinates() - 1 );
}
_safeSelectVertex( *mSelectedFeature, nextVertexToSelect );
@ -1398,7 +1398,7 @@ void QgsNodeTool::moveVertex( const QgsPointXY &mapPoint, const QgsPointLocator:
return;
}
QgsAbstractGeometry *geomTmp = geom.geometry()->clone();
QgsAbstractGeometry *geomTmp = geom.constGet()->clone();
// add/move vertex
if ( addingVertex )
@ -1425,7 +1425,7 @@ void QgsNodeTool::moveVertex( const QgsPointXY &mapPoint, const QgsPointLocator:
}
}
geom.setGeometry( geomTmp );
geom.set( geomTmp );
NodeEdits edits; // dict { layer : { fid : geom } }
edits[dragLayer][dragFid] = geom;
@ -1582,7 +1582,7 @@ void QgsNodeTool::deleteVertex()
QgsVertexId vid;
if ( geom.vertexIdFromVertexNr( vertexIds[i], vid ) )
{
int ringVertexCount = geom.geometry()->vertexCount( vid.part, vid.ring );
int ringVertexCount = geom.constGet()->vertexCount( vid.part, vid.ring );
if ( vid.vertex == ringVertexCount - 1 )
{
// this is the last vertex of the ring - remove the first vertex from the list

View File

@ -274,7 +274,7 @@ void QgsSelectedFeature::createVertexMap()
return;
}
const QgsAbstractGeometry *geom = mGeometry->geometry();
const QgsAbstractGeometry *geom = mGeometry->constGet();
if ( !geom )
{
return;

View File

@ -154,7 +154,7 @@ void QgsMapToolAddPart::cadCanvasReleaseEvent( QgsMapMouseEvent *e )
QgsGeometry *geom = new QgsGeometry( cp );
geom->avoidIntersections( QgsProject::instance()->avoidIntersectionsLayers() );
const QgsCurvePolygon *cpGeom = qgsgeometry_cast<const QgsCurvePolygon *>( geom->geometry() );
const QgsCurvePolygon *cpGeom = qgsgeometry_cast<const QgsCurvePolygon *>( geom->constGet() );
if ( !cpGeom )
{
stopCapturing();

View File

@ -83,7 +83,7 @@ void QgsSelectByFormDialog::zoomToFeatures( const QString &filter )
while ( features.nextFeature( feat ) )
{
QgsGeometry geom = feat.geometry();
if ( geom.isNull() || geom.geometry()->isEmpty() )
if ( geom.isNull() || geom.constGet()->isEmpty() )
continue;
QgsRectangle r = mMapCanvas->mapSettings().layerExtentToOutputExtent( mLayer, geom.boundingBox() );

View File

@ -3677,7 +3677,7 @@ void QgsDxfExport::addFeature( QgsSymbolRenderContext &ctx, const QgsCoordinateT
if ( !fet->hasGeometry() )
return;
std::unique_ptr<QgsAbstractGeometry> geom( fet->geometry().geometry()->clone() );
std::unique_ptr<QgsAbstractGeometry> geom( fet->geometry().constGet()->clone() );
if ( ct.isValid() )
{
geom->transform( ct );

View File

@ -780,7 +780,7 @@ QString QgsExpression::formatPreviewString( const QVariant &value )
if ( geom.isNull() )
return tr( "<i>&lt;empty geometry&gt;</i>" );
else
return tr( "<i>&lt;geometry: %1&gt;</i>" ).arg( QgsWkbTypes::displayString( geom.geometry()->wkbType() ) );
return tr( "<i>&lt;geometry: %1&gt;</i>" ).arg( QgsWkbTypes::displayString( geom.constGet()->wkbType() ) );
}
else if ( !value.isValid() )
{

View File

@ -1632,7 +1632,7 @@ static QVariant fcnGeomZ( const QVariantList &values, const QgsExpressionContext
//if single point, return the point's z coordinate
if ( geom.type() == QgsWkbTypes::PointGeometry && !geom.isMultipart() )
{
QgsPoint *point = qgsgeometry_cast< QgsPoint * >( geom.geometry() );
const QgsPoint *point = qgsgeometry_cast< const QgsPoint * >( geom.constGet() );
if ( point )
return point->z();
}
@ -1649,7 +1649,7 @@ static QVariant fcnGeomM( const QVariantList &values, const QgsExpressionContext
//if single point, return the point's m value
if ( geom.type() == QgsWkbTypes::PointGeometry && !geom.isMultipart() )
{
QgsPoint *point = qgsgeometry_cast< QgsPoint * >( geom.geometry() );
const QgsPoint *point = qgsgeometry_cast< const QgsPoint * >( geom.constGet() );
if ( point )
return point->m();
}
@ -1674,7 +1674,7 @@ static QVariant fcnPointN( const QVariantList &values, const QgsExpressionContex
return QVariant();
}
QgsPoint point = geom.geometry()->vertexAt( vId );
QgsPoint point = geom.constGet()->vertexAt( vId );
return QVariant::fromValue( QgsGeometry( new QgsPoint( point ) ) );
}
@ -1691,7 +1691,7 @@ static QVariant fcnStartPoint( const QVariantList &values, const QgsExpressionCo
return QVariant();
}
QgsPoint point = geom.geometry()->vertexAt( vId );
QgsPoint point = geom.constGet()->vertexAt( vId );
return QVariant::fromValue( QgsGeometry( new QgsPoint( point ) ) );
}
@ -1703,12 +1703,12 @@ static QVariant fcnEndPoint( const QVariantList &values, const QgsExpressionCont
return QVariant();
QgsVertexId vId;
if ( !geom.vertexIdFromVertexNr( geom.geometry()->nCoordinates() - 1, vId ) )
if ( !geom.vertexIdFromVertexNr( geom.constGet()->nCoordinates() - 1, vId ) )
{
return QVariant();
}
QgsPoint point = geom.geometry()->vertexAt( vId );
QgsPoint point = geom.constGet()->vertexAt( vId );
return QVariant::fromValue( QgsGeometry( new QgsPoint( point ) ) );
}
@ -1727,7 +1727,7 @@ static QVariant fcnNodesToPoints( const QVariantList &values, const QgsExpressio
QgsMultiPointV2 *mp = new QgsMultiPointV2();
const QgsCoordinateSequence sequence = geom.geometry()->coordinateSequence();
const QgsCoordinateSequence sequence = geom.constGet()->coordinateSequence();
for ( const QgsRingSequence &part : sequence )
{
for ( const QgsPointSequence &ring : part )
@ -1755,7 +1755,7 @@ static QVariant fcnSegmentsToLines( const QVariantList &values, const QgsExpress
if ( geom.isNull() )
return QVariant();
const QList< QgsLineString * > linesToProcess = QgsGeometryUtils::extractLineStrings( geom.geometry() );
const QList< QgsLineString * > linesToProcess = QgsGeometryUtils::extractLineStrings( geom.constGet() );
//OK, now we have a complete list of segmentized lines from the geometry
QgsMultiLineString *ml = new QgsMultiLineString();
@ -1782,7 +1782,7 @@ static QVariant fcnInteriorRingN( const QVariantList &values, const QgsExpressio
if ( geom.isNull() )
return QVariant();
QgsCurvePolygon *curvePolygon = qgsgeometry_cast< QgsCurvePolygon * >( geom.geometry() );
const QgsCurvePolygon *curvePolygon = qgsgeometry_cast< const QgsCurvePolygon * >( geom.constGet() );
if ( !curvePolygon )
return QVariant();
@ -1804,7 +1804,7 @@ static QVariant fcnGeometryN( const QVariantList &values, const QgsExpressionCon
if ( geom.isNull() )
return QVariant();
QgsGeometryCollection *collection = qgsgeometry_cast< QgsGeometryCollection * >( geom.geometry() );
const QgsGeometryCollection *collection = qgsgeometry_cast< const QgsGeometryCollection * >( geom.constGet() );
if ( !collection )
return QVariant();
@ -1826,7 +1826,7 @@ static QVariant fcnBoundary( const QVariantList &values, const QgsExpressionCont
if ( geom.isNull() )
return QVariant();
QgsAbstractGeometry *boundary = geom.geometry()->boundary();
QgsAbstractGeometry *boundary = geom.constGet()->boundary();
if ( !boundary )
return QVariant();
@ -1951,7 +1951,7 @@ static QVariant fcnMakeLine( const QVariantList &values, const QgsExpressionCont
if ( geom.type() != QgsWkbTypes::PointGeometry || geom.isMultipart() )
continue;
QgsPoint *point = qgsgeometry_cast< QgsPoint * >( geom.geometry() );
const QgsPoint *point = qgsgeometry_cast< const QgsPoint * >( geom.constGet() );
if ( !point )
continue;
@ -1974,7 +1974,7 @@ static QVariant fcnMakePolygon( const QVariantList &values, const QgsExpressionC
return QVariant();
QgsPolygonV2 *polygon = new QgsPolygonV2();
polygon->setExteriorRing( qgsgeometry_cast< QgsCurve * >( outerRing.geometry()->clone() ) );
polygon->setExteriorRing( qgsgeometry_cast< QgsCurve * >( outerRing.constGet()->clone() ) );
for ( int i = 1; i < values.count(); ++i )
{
@ -1985,7 +1985,7 @@ static QVariant fcnMakePolygon( const QVariantList &values, const QgsExpressionC
if ( ringGeom.type() != QgsWkbTypes::LineGeometry || ringGeom.isMultipart() || ringGeom.isNull() )
continue;
polygon->addInteriorRing( qgsgeometry_cast< QgsCurve * >( ringGeom.geometry()->clone() ) );
polygon->addInteriorRing( qgsgeometry_cast< QgsCurve * >( ringGeom.constGet()->clone() ) );
}
return QVariant::fromValue( QgsGeometry( polygon ) );
@ -2006,7 +2006,7 @@ static QVariant fcnMakeTriangle( const QVariantList &values, const QgsExpression
if ( geom.type() != QgsWkbTypes::PointGeometry || geom.isMultipart() )
return QVariant();
QgsPoint *point = qgsgeometry_cast< QgsPoint * >( geom.geometry() );
const QgsPoint *point = qgsgeometry_cast< const QgsPoint * >( geom.constGet() );
if ( !point )
return QVariant();
@ -2035,7 +2035,7 @@ static QVariant fcnMakeCircle( const QVariantList &values, const QgsExpressionCo
parent->setEvalErrorString( QObject::tr( "Segment must be greater than 2" ) );
return QVariant();
}
QgsPoint *point = qgsgeometry_cast< QgsPoint * >( geom.geometry() );
const QgsPoint *point = qgsgeometry_cast< const QgsPoint * >( geom.constGet() );
QgsCircle circ( *point, radius );
return QVariant::fromValue( QgsGeometry( circ.toPolygon( segment ) ) );
}
@ -2058,7 +2058,7 @@ static QVariant fcnMakeEllipse( const QVariantList &values, const QgsExpressionC
parent->setEvalErrorString( QObject::tr( "Segment must be greater than 2" ) );
return QVariant();
}
QgsPoint *point = qgsgeometry_cast< QgsPoint * >( geom.geometry() );
const QgsPoint *point = qgsgeometry_cast< const QgsPoint * >( geom.constGet() );
QgsEllipse elp( *point, majorAxis, minorAxis, azimuth );
return QVariant::fromValue( QgsGeometry( elp.toPolygon( segment ) ) );
}
@ -2093,8 +2093,8 @@ static QVariant fcnMakeRegularPolygon( const QVariantList &values, const QgsExpr
parent->setEvalErrorString( QObject::tr( "Option can be 0 (inscribed) or 1 (circumscribed)" ) );
return QVariant();
}
QgsPoint *center = qgsgeometry_cast< QgsPoint * >( pt1.geometry() );
QgsPoint *corner = qgsgeometry_cast< QgsPoint * >( pt2.geometry() );
const QgsPoint *center = qgsgeometry_cast< const QgsPoint * >( pt1.constGet() );
const QgsPoint *corner = qgsgeometry_cast< const QgsPoint * >( pt2.constGet() );
QgsRegularPolygon rp = QgsRegularPolygon( *center, *corner, nbEdges, option );
@ -2112,9 +2112,9 @@ static QVariant pointAt( const QVariantList &values, const QgsExpressionContext
if ( idx < 0 )
{
idx += g.geometry()->nCoordinates();
idx += g.constGet()->nCoordinates();
}
if ( idx < 0 || idx >= g.geometry()->nCoordinates() )
if ( idx < 0 || idx >= g.constGet()->nCoordinates() )
{
parent->setEvalErrorString( QObject::tr( "Index is out of range" ) );
return QVariant();
@ -2221,7 +2221,7 @@ static QVariant fcnGeomPerimeter( const QVariantList &, const QgsExpressionConte
}
else
{
return f.geometry().isNull() ? QVariant( 0 ) : QVariant( f.geometry().geometry()->perimeter() );
return f.geometry().isNull() ? QVariant( 0 ) : QVariant( f.geometry().constGet()->perimeter() );
}
}
@ -2239,7 +2239,7 @@ static QVariant fcnPerimeter( const QVariantList &values, const QgsExpressionCon
static QVariant fcnGeomNumPoints( const QVariantList &values, const QgsExpressionContext *, QgsExpression *parent, const QgsExpressionNodeFunction * )
{
QgsGeometry geom = QgsExpressionUtils::getGeometry( values.at( 0 ), parent );
return QVariant( geom.isNull() ? 0 : geom.geometry()->nCoordinates() );
return QVariant( geom.isNull() ? 0 : geom.constGet()->nCoordinates() );
}
static QVariant fcnGeomNumGeometries( const QVariantList &values, const QgsExpressionContext *, QgsExpression *parent, const QgsExpressionNodeFunction * )
@ -2248,7 +2248,7 @@ static QVariant fcnGeomNumGeometries( const QVariantList &values, const QgsExpre
if ( geom.isNull() )
return QVariant();
return QVariant( geom.geometry()->partCount() );
return QVariant( geom.constGet()->partCount() );
}
static QVariant fcnGeomNumInteriorRings( const QVariantList &values, const QgsExpressionContext *, QgsExpression *parent, const QgsExpressionNodeFunction * )
@ -2258,17 +2258,17 @@ static QVariant fcnGeomNumInteriorRings( const QVariantList &values, const QgsEx
if ( geom.isNull() )
return QVariant();
QgsCurvePolygon *curvePolygon = qgsgeometry_cast< QgsCurvePolygon * >( geom.geometry() );
const QgsCurvePolygon *curvePolygon = qgsgeometry_cast< const QgsCurvePolygon * >( geom.constGet() );
if ( curvePolygon )
return QVariant( curvePolygon->numInteriorRings() );
QgsGeometryCollection *collection = qgsgeometry_cast< QgsGeometryCollection * >( geom.geometry() );
const QgsGeometryCollection *collection = qgsgeometry_cast< const QgsGeometryCollection * >( geom.constGet() );
if ( collection )
{
//find first CurvePolygon in collection
for ( int i = 0; i < collection->numGeometries(); ++i )
{
curvePolygon = qgsgeometry_cast< QgsCurvePolygon *>( collection->geometryN( i ) );
curvePolygon = qgsgeometry_cast< const QgsCurvePolygon *>( collection->geometryN( i ) );
if ( !curvePolygon )
continue;
@ -2286,13 +2286,13 @@ static QVariant fcnGeomNumRings( const QVariantList &values, const QgsExpression
if ( geom.isNull() )
return QVariant();
QgsCurvePolygon *curvePolygon = qgsgeometry_cast< QgsCurvePolygon * >( geom.geometry() );
const QgsCurvePolygon *curvePolygon = qgsgeometry_cast< const QgsCurvePolygon * >( geom.constGet() );
if ( curvePolygon )
return QVariant( curvePolygon->ringCount() );
bool foundPoly = false;
int ringCount = 0;
QgsGeometryCollection *collection = qgsgeometry_cast< QgsGeometryCollection * >( geom.geometry() );
const QgsGeometryCollection *collection = qgsgeometry_cast< const QgsGeometryCollection * >( geom.constGet() );
if ( collection )
{
//find CurvePolygons in collection
@ -2363,7 +2363,7 @@ static QVariant fcnIsClosed( const QVariantList &values, const QgsExpressionCont
if ( fGeom.isNull() )
return QVariant();
QgsCurve *curve = qgsgeometry_cast< QgsCurve * >( fGeom.geometry() );
const QgsCurve *curve = qgsgeometry_cast< const QgsCurve * >( fGeom.constGet() );
if ( !curve )
return QVariant();
@ -2381,19 +2381,19 @@ static QVariant fcnRelate( const QVariantList &values, const QgsExpressionContex
if ( fGeom.isNull() || sGeom.isNull() )
return QVariant();
std::unique_ptr<QgsGeometryEngine> engine( QgsGeometry::createGeometryEngine( fGeom.geometry() ) );
std::unique_ptr<QgsGeometryEngine> engine( QgsGeometry::createGeometryEngine( fGeom.constGet() ) );
if ( values.length() == 2 )
{
//two geometry arguments, return relation
QString result = engine->relate( sGeom.geometry() );
QString result = engine->relate( sGeom.constGet() );
return QVariant::fromValue( result );
}
else
{
//three arguments, test pattern
QString pattern = QgsExpressionUtils::getStringValue( values.at( 2 ), parent );
bool result = engine->relatePattern( sGeom.geometry(), pattern );
bool result = engine->relatePattern( sGeom.constGet(), pattern );
return QVariant::fromValue( result );
}
}
@ -2578,7 +2578,7 @@ static QVariant fcnReverse( const QVariantList &values, const QgsExpressionConte
if ( fGeom.isNull() )
return QVariant();
QgsCurve *curve = qgsgeometry_cast< QgsCurve * >( fGeom.geometry() );
const QgsCurve *curve = qgsgeometry_cast<const QgsCurve * >( fGeom.constGet() );
if ( !curve )
return QVariant();
@ -2593,7 +2593,7 @@ static QVariant fcnExteriorRing( const QVariantList &values, const QgsExpression
if ( fGeom.isNull() )
return QVariant();
QgsCurvePolygon *curvePolygon = qgsgeometry_cast< QgsCurvePolygon * >( fGeom.geometry() );
const QgsCurvePolygon *curvePolygon = qgsgeometry_cast< const QgsCurvePolygon * >( fGeom.constGet() );
if ( !curvePolygon || !curvePolygon->exteriorRing() )
return QVariant();
@ -2677,8 +2677,8 @@ static QVariant fcnAzimuth( const QVariantList &values, const QgsExpressionConte
QgsGeometry fGeom1 = QgsExpressionUtils::getGeometry( values.at( 0 ), parent );
QgsGeometry fGeom2 = QgsExpressionUtils::getGeometry( values.at( 1 ), parent );
const QgsPoint *pt1 = qgsgeometry_cast<const QgsPoint *>( fGeom1.geometry() );
const QgsPoint *pt2 = qgsgeometry_cast<const QgsPoint *>( fGeom2.geometry() );
const QgsPoint *pt1 = qgsgeometry_cast<const QgsPoint *>( fGeom1.constGet() );
const QgsPoint *pt2 = qgsgeometry_cast<const QgsPoint *>( fGeom2.constGet() );
if ( !pt1 || !pt2 )
{
@ -2749,7 +2749,7 @@ static QVariant fcnProject( const QVariantList &values, const QgsExpressionConte
double azimuth = QgsExpressionUtils::getDoubleValue( values.at( 2 ), parent );
double inclination = QgsExpressionUtils::getDoubleValue( values.at( 3 ), parent );
const QgsPoint *p = static_cast<const QgsPoint *>( geom.geometry() );
const QgsPoint *p = static_cast<const QgsPoint *>( geom.constGet() );
QgsPoint newPoint = p->project( distance, 180.0 * azimuth / M_PI, 180.0 * inclination / M_PI );
return QVariant::fromValue( QgsGeometry( new QgsPoint( newPoint ) ) );
@ -2760,8 +2760,8 @@ static QVariant fcnInclination( const QVariantList &values, const QgsExpressionC
QgsGeometry fGeom1 = QgsExpressionUtils::getGeometry( values.at( 0 ), parent );
QgsGeometry fGeom2 = QgsExpressionUtils::getGeometry( values.at( 1 ), parent );
const QgsPoint *pt1 = qgsgeometry_cast<const QgsPoint *>( fGeom1.geometry() );
const QgsPoint *pt2 = qgsgeometry_cast<const QgsPoint *>( fGeom2.geometry() );
const QgsPoint *pt1 = qgsgeometry_cast<const QgsPoint *>( fGeom1.constGet() );
const QgsPoint *pt2 = qgsgeometry_cast<const QgsPoint *>( fGeom2.constGet() );
if ( ( fGeom1.type() != QgsWkbTypes::PointGeometry ) || ( fGeom2.type() != QgsWkbTypes::PointGeometry ) ||
!pt1 || !pt2 )
@ -2785,7 +2785,7 @@ static QVariant fcnExtrude( const QVariantList &values, const QgsExpressionConte
QgsGeometry geom = fGeom.extrude( x, y );
QVariant result = geom.geometry() ? QVariant::fromValue( geom ) : QVariant();
QVariant result = geom.constGet() ? QVariant::fromValue( geom ) : QVariant();
return result;
}
@ -2829,7 +2829,7 @@ static QVariant fcnOrderParts( const QVariantList &values, const QgsExpressionCo
unconstedContext = new QgsExpressionContext();
}
QgsGeometryCollection *collection = qgsgeometry_cast<QgsGeometryCollection *>( fGeom.geometry() );
const QgsGeometryCollection *collection = qgsgeometry_cast<const QgsGeometryCollection *>( fGeom.constGet() );
Q_ASSERT( collection ); // Should have failed the multipart check above
QgsFeatureRequest::OrderBy orderBy;
@ -2846,7 +2846,7 @@ static QVariant fcnOrderParts( const QVariantList &values, const QgsExpressionCo
sorter.sortFeatures( partFeatures, unconstedContext );
QgsGeometryCollection *orderedGeom = qgsgeometry_cast<QgsGeometryCollection *>( fGeom.geometry()->clone() );
QgsGeometryCollection *orderedGeom = qgsgeometry_cast<QgsGeometryCollection *>( fGeom.constGet()->clone() );
Q_ASSERT( orderedGeom );
@ -2855,7 +2855,7 @@ static QVariant fcnOrderParts( const QVariantList &values, const QgsExpressionCo
for ( const QgsFeature &feature : qgis::as_const( partFeatures ) )
{
orderedGeom->addGeometry( feature.geometry().geometry()->clone() );
orderedGeom->addGeometry( feature.geometry().constGet()->clone() );
}
QVariant result = QVariant::fromValue( QgsGeometry( orderedGeom ) );

View File

@ -298,7 +298,7 @@ class CORE_EXPORT QgsAbstractGeometry
* Returns the vertices adjacent to a specified \a vertex within a geometry.
* \since QGIS 3.0
*/
virtual void adjacentVertices( QgsVertexId vertex, QgsVertexId &previousVertex SIP_OUT, QgsVertexId &nextVertex SIP_OUT ) = 0;
virtual void adjacentVertices( QgsVertexId vertex, QgsVertexId &previousVertex SIP_OUT, QgsVertexId &nextVertex SIP_OUT ) const = 0;
/**
* Retrieves the sequence of geometries, rings and nodes.

View File

@ -78,7 +78,7 @@ bool QgsCurve::nextVertex( QgsVertexId &id, QgsPoint &vertex ) const
return pointAt( id.vertex, vertex, id.type );
}
void QgsCurve::adjacentVertices( QgsVertexId vertex, QgsVertexId &previousVertex, QgsVertexId &nextVertex )
void QgsCurve::adjacentVertices( QgsVertexId vertex, QgsVertexId &previousVertex, QgsVertexId &nextVertex ) const
{
int n = numPoints();
if ( vertex.vertex < 0 || vertex.vertex >= n )

View File

@ -103,7 +103,7 @@ class CORE_EXPORT QgsCurve: public QgsAbstractGeometry
QgsCoordinateSequence coordinateSequence() const override;
bool nextVertex( QgsVertexId &id, QgsPoint &vertex SIP_OUT ) const override;
void adjacentVertices( QgsVertexId vertex, QgsVertexId &previousVertex SIP_OUT, QgsVertexId &nextVertex SIP_OUT ) override;
void adjacentVertices( QgsVertexId vertex, QgsVertexId &previousVertex SIP_OUT, QgsVertexId &nextVertex SIP_OUT ) const override;
int vertexNumberFromVertexId( QgsVertexId id ) const override;
/**

View File

@ -844,7 +844,7 @@ void ringAdjacentVertices( const QgsCurve *curve, QgsVertexId vertex, QgsVertexI
}
}
void QgsCurvePolygon::adjacentVertices( QgsVertexId vertex, QgsVertexId &previousVertex, QgsVertexId &nextVertex )
void QgsCurvePolygon::adjacentVertices( QgsVertexId vertex, QgsVertexId &previousVertex, QgsVertexId &nextVertex ) const
{
if ( !mExteriorRing || vertex.ring < 0 || vertex.ring >= 1 + mInteriorRings.size() )
{

View File

@ -123,7 +123,7 @@ class CORE_EXPORT QgsCurvePolygon: public QgsSurface
double closestSegment( const QgsPoint &pt, QgsPoint &segmentPt SIP_OUT, QgsVertexId &vertexAfter SIP_OUT, bool *leftOf SIP_OUT = nullptr, double epsilon = 4 * DBL_EPSILON ) const override;
bool nextVertex( QgsVertexId &id, QgsPoint &vertex SIP_OUT ) const override;
void adjacentVertices( QgsVertexId vertex, QgsVertexId &previousVertex SIP_OUT, QgsVertexId &nextVertex SIP_OUT ) override;
void adjacentVertices( QgsVertexId vertex, QgsVertexId &previousVertex SIP_OUT, QgsVertexId &nextVertex SIP_OUT ) const override;
bool hasCurvedSegments() const override;
/**

View File

@ -120,12 +120,18 @@ void QgsGeometry::reset( std::unique_ptr<QgsAbstractGeometry> newGeometry )
d->geometry = std::move( newGeometry );
}
QgsAbstractGeometry *QgsGeometry::geometry() const
const QgsAbstractGeometry *QgsGeometry::constGet() const
{
return d->geometry.get();
}
void QgsGeometry::setGeometry( QgsAbstractGeometry *geometry )
QgsAbstractGeometry *QgsGeometry::get()
{
detach();
return d->geometry.get();
}
void QgsGeometry::set( QgsAbstractGeometry *geometry )
{
if ( d->geometry.get() == geometry )
{
@ -872,7 +878,7 @@ int QgsGeometry::makeDifferenceInPlace( const QgsGeometry &other )
QgsGeos geos( d->geometry.get() );
mLastError.clear();
std::unique_ptr< QgsAbstractGeometry > diffGeom( geos.intersection( other.geometry(), &mLastError ) );
std::unique_ptr< QgsAbstractGeometry > diffGeom( geos.intersection( other.constGet(), &mLastError ) );
if ( !diffGeom )
{
return 1;
@ -892,7 +898,7 @@ QgsGeometry QgsGeometry::makeDifference( const QgsGeometry &other ) const
QgsGeos geos( d->geometry.get() );
mLastError.clear();
std::unique_ptr< QgsAbstractGeometry > diffGeom( geos.intersection( other.geometry(), &mLastError ) );
std::unique_ptr< QgsAbstractGeometry > diffGeom( geos.intersection( other.constGet(), &mLastError ) );
if ( !diffGeom )
{
QgsGeometry result;
@ -932,10 +938,10 @@ QgsGeometry QgsGeometry::orientedMinimumBoundingBox( double &area, double &angle
QgsPoint pt1;
QgsPoint pt2;
// get first point
hull.geometry()->nextVertex( vertexId, pt0 );
hull.constGet()->nextVertex( vertexId, pt0 );
pt1 = pt0;
double prevAngle = 0.0;
while ( hull.geometry()->nextVertex( vertexId, pt2 ) )
while ( hull.constGet()->nextVertex( vertexId, pt2 ) )
{
double currentAngle = QgsGeometryUtils::lineAngle( pt1.x(), pt1.y(), pt2.x(), pt2.y() );
double rotateAngle = 180.0 / M_PI * ( currentAngle - prevAngle );
@ -945,9 +951,9 @@ QgsGeometry QgsGeometry::orientedMinimumBoundingBox( double &area, double &angle
t.rotate( rotateAngle );
t.translate( -pt0.x(), -pt0.y() );
hull.geometry()->transform( t );
hull.get()->transform( t );
QgsRectangle bounds = hull.geometry()->boundingBox();
QgsRectangle bounds = hull.constGet()->boundingBox();
double currentArea = bounds.width() * bounds.height();
if ( currentArea < area )
{
@ -1047,7 +1053,7 @@ QgsGeometry QgsGeometry::minimalEnclosingCircle( QgsPointXY &center, double &rad
center = QgsPointXY( circ.center() );
radius = circ.radius();
QgsGeometry geom;
geom.setGeometry( circ.toPolygon( segments ) );
geom.set( circ.toPolygon( segments ) );
return geom;
}
@ -1816,7 +1822,7 @@ QgsGeometry QgsGeometry::voronoiDiagram( const QgsGeometry &extent, double toler
QgsGeos geos( d->geometry.get() );
mLastError.clear();
QgsGeometry result = geos.voronoiDiagram( extent.geometry(), tolerance, edgesOnly, &mLastError );
QgsGeometry result = geos.voronoiDiagram( extent.constGet(), tolerance, edgesOnly, &mLastError );
result.mLastError = mLastError;
return result;
}
@ -1873,7 +1879,7 @@ QgsGeometry QgsGeometry::interpolate( double distance ) const
if ( type() == QgsWkbTypes::PolygonGeometry )
line = QgsGeometry( d->geometry->boundary() );
QgsGeos geos( line.geometry() );
QgsGeos geos( line.constGet() );
mLastError.clear();
std::unique_ptr< QgsAbstractGeometry > result( geos.interpolate( distance, &mLastError ) );
if ( !result )
@ -1918,7 +1924,7 @@ double QgsGeometry::interpolateAngle( double distance ) const
QgsVertexId previous;
QgsVertexId next;
if ( !QgsGeometryUtils::verticesAtDistance( *segmentized.geometry(), distance, previous, next ) )
if ( !QgsGeometryUtils::verticesAtDistance( *segmentized.constGet(), distance, previous, next ) )
return 0.0;
if ( previous == next )
@ -1927,33 +1933,33 @@ double QgsGeometry::interpolateAngle( double distance ) const
QgsVertexId v2 = previous;
QgsVertexId v1;
QgsVertexId v3;
segmentized.geometry()->adjacentVertices( v2, v1, v3 );
segmentized.constGet()->adjacentVertices( v2, v1, v3 );
if ( v1.isValid() && v3.isValid() )
{
QgsPoint p1 = segmentized.geometry()->vertexAt( v1 );
QgsPoint p2 = segmentized.geometry()->vertexAt( v2 );
QgsPoint p3 = segmentized.geometry()->vertexAt( v3 );
QgsPoint p1 = segmentized.constGet()->vertexAt( v1 );
QgsPoint p2 = segmentized.constGet()->vertexAt( v2 );
QgsPoint p3 = segmentized.constGet()->vertexAt( v3 );
double angle1 = QgsGeometryUtils::lineAngle( p1.x(), p1.y(), p2.x(), p2.y() );
double angle2 = QgsGeometryUtils::lineAngle( p2.x(), p2.y(), p3.x(), p3.y() );
return QgsGeometryUtils::averageAngle( angle1, angle2 );
}
else if ( v3.isValid() )
{
QgsPoint p1 = segmentized.geometry()->vertexAt( v2 );
QgsPoint p2 = segmentized.geometry()->vertexAt( v3 );
QgsPoint p1 = segmentized.constGet()->vertexAt( v2 );
QgsPoint p2 = segmentized.constGet()->vertexAt( v3 );
return QgsGeometryUtils::lineAngle( p1.x(), p1.y(), p2.x(), p2.y() );
}
else
{
QgsPoint p1 = segmentized.geometry()->vertexAt( v1 );
QgsPoint p2 = segmentized.geometry()->vertexAt( v2 );
QgsPoint p1 = segmentized.constGet()->vertexAt( v1 );
QgsPoint p2 = segmentized.constGet()->vertexAt( v2 );
return QgsGeometryUtils::lineAngle( p1.x(), p1.y(), p2.x(), p2.y() );
}
}
else
{
QgsPoint p1 = segmentized.geometry()->vertexAt( previous );
QgsPoint p2 = segmentized.geometry()->vertexAt( next );
QgsPoint p1 = segmentized.constGet()->vertexAt( previous );
QgsPoint p2 = segmentized.constGet()->vertexAt( next );
return QgsGeometryUtils::lineAngle( p1.x(), p1.y(), p2.x(), p2.y() );
}
}
@ -2152,7 +2158,7 @@ bool QgsGeometry::deletePart( int partNum )
if ( !isMultipart() && partNum < 1 )
{
setGeometry( nullptr );
set( nullptr );
return true;
}
@ -2250,7 +2256,7 @@ QgsGeometry QgsGeometry::polygonize( const QList<QgsGeometry> &geometryList )
{
if ( !( g.isNull() ) )
{
geomV2List.append( g.geometry() );
geomV2List.append( g.constGet() );
}
}
@ -3107,7 +3113,7 @@ QDataStream &operator>>( QDataStream &in, QgsGeometry &geometry )
in >> byteArray;
if ( byteArray.isEmpty() )
{
geometry.setGeometry( nullptr );
geometry.set( nullptr );
return in;
}

View File

@ -164,18 +164,42 @@ class CORE_EXPORT QgsGeometry
~QgsGeometry();
/**
* Returns the underlying geometry store.
* \since QGIS 2.10
* \see setGeometry
* Returns a non-modifiable (const) reference to the underlying abstract geometry primitive.
*
* This is much faster then calling the non-const get() method.
*
* \note In QGIS 2.x this method was named geometry().
*
* \since QGIS 3.0
* \see primitive()
* \see set()
*/
QgsAbstractGeometry *geometry() const;
const QgsAbstractGeometry *constGet() const;
/**
* Returns a modifiable (non-const) reference to the underlying abstract geometry primitive.
*
* This method can be slow to call, as it may trigger a detachment of the geometry
* and a deep copy. Where possible, use constGet() instead.
*
* \note In QGIS 2.x this method was named geometry().
*
* \since QGIS 3.0
* \see constGet()
* \see set()
*/
QgsAbstractGeometry *get();
/**
* Sets the underlying geometry store. Ownership of geometry is transferred.
* \since QGIS 2.10
* \see geometry
*
* \note In QGIS 2.x this method was named setGeometry().
*
* \since QGIS 3.0
* \see get()
* \see constGet()
*/
void setGeometry( QgsAbstractGeometry *geometry SIP_TRANSFER );
void set( QgsAbstractGeometry *geometry SIP_TRANSFER );
/**
* Returns true if the geometry is null (ie, contains no underlying geometry

View File

@ -80,7 +80,7 @@ QgsAbstractGeometry *QgsGeometryCollection::boundary() const
return nullptr;
}
void QgsGeometryCollection::adjacentVertices( QgsVertexId vertex, QgsVertexId &previousVertex, QgsVertexId &nextVertex )
void QgsGeometryCollection::adjacentVertices( QgsVertexId vertex, QgsVertexId &previousVertex, QgsVertexId &nextVertex ) const
{
if ( vertex.part < 0 || vertex.part >= mGeometries.count() )
{

View File

@ -65,7 +65,7 @@ class CORE_EXPORT QgsGeometryCollection: public QgsAbstractGeometry
QString geometryType() const override;
void clear() override;
QgsAbstractGeometry *boundary() const override SIP_FACTORY;
void adjacentVertices( QgsVertexId vertex, QgsVertexId &previousVertex SIP_OUT, QgsVertexId &nextVertex SIP_OUT ) override;
void adjacentVertices( QgsVertexId vertex, QgsVertexId &previousVertex SIP_OUT, QgsVertexId &nextVertex SIP_OUT ) const override;
int vertexNumberFromVertexId( QgsVertexId id ) const override;
//! Adds a geometry and takes ownership. Returns true in case of success.

View File

@ -341,7 +341,7 @@ QgsAbstractGeometry *QgsGeos::combine( const QList<QgsGeometry> &geomList, QStri
if ( !g )
continue;
geosGeometries << asGeos( g.geometry(), mPrecision ).release();
geosGeometries << asGeos( g.constGet(), mPrecision ).release();
}
geos::unique_ptr geomUnion;
@ -2043,7 +2043,7 @@ QgsGeometry QgsGeos::closestPoint( const QgsGeometry &other, QString *errorMsg )
return QgsGeometry();
}
geos::unique_ptr otherGeom( asGeos( other.geometry(), mPrecision ) );
geos::unique_ptr otherGeom( asGeos( other.constGet(), mPrecision ) );
if ( !otherGeom )
{
return QgsGeometry();
@ -2077,7 +2077,7 @@ QgsGeometry QgsGeos::shortestLine( const QgsGeometry &other, QString *errorMsg )
return QgsGeometry();
}
geos::unique_ptr otherGeom( asGeos( other.geometry(), mPrecision ) );
geos::unique_ptr otherGeom( asGeos( other.constGet(), mPrecision ) );
if ( !otherGeom )
{
return QgsGeometry();

View File

@ -29,7 +29,7 @@
#include <queue>
QgsInternalGeometryEngine::QgsInternalGeometryEngine( const QgsGeometry &geometry )
: mGeometry( geometry.geometry() )
: mGeometry( geometry.constGet() )
{
}

View File

@ -401,7 +401,7 @@ bool QgsPoint::nextVertex( QgsVertexId &id, QgsPoint &vertex ) const
}
}
void QgsPoint::adjacentVertices( QgsVertexId, QgsVertexId &previousVertex, QgsVertexId &nextVertex )
void QgsPoint::adjacentVertices( QgsVertexId, QgsVertexId &previousVertex, QgsVertexId &nextVertex ) const
{
previousVertex = QgsVertexId();
nextVertex = QgsVertexId();

View File

@ -415,7 +415,7 @@ class CORE_EXPORT QgsPoint: public QgsAbstractGeometry
double closestSegment( const QgsPoint &pt, QgsPoint &segmentPt SIP_OUT, QgsVertexId &vertexAfter SIP_OUT, bool *leftOf SIP_OUT = nullptr, double epsilon = 4 * DBL_EPSILON ) const override;
bool nextVertex( QgsVertexId &id, QgsPoint &vertex SIP_OUT ) const override;
void adjacentVertices( QgsVertexId vertex, QgsVertexId &previousVertex SIP_OUT, QgsVertexId &nextVertex SIP_OUT ) override;
void adjacentVertices( QgsVertexId vertex, QgsVertexId &previousVertex SIP_OUT, QgsVertexId &nextVertex SIP_OUT ) const override;
/**
* Angle undefined. Always returns 0.0

View File

@ -52,7 +52,7 @@ QgsMemoryFeatureIterator::QgsMemoryFeatureIterator( QgsMemoryFeatureSource *sour
if ( !mFilterRect.isNull() && mRequest.flags() & QgsFeatureRequest::ExactIntersect )
{
mSelectRectGeom = QgsGeometry::fromRect( mFilterRect );
mSelectRectEngine.reset( QgsGeometry::createGeometryEngine( mSelectRectGeom.geometry() ) );
mSelectRectEngine.reset( QgsGeometry::createGeometryEngine( mSelectRectGeom.constGet() ) );
mSelectRectEngine->prepareGeometry();
}
@ -111,7 +111,7 @@ bool QgsMemoryFeatureIterator::nextFeatureUsingList( QgsFeature &feature )
if ( !mFilterRect.isNull() && mRequest.flags() & QgsFeatureRequest::ExactIntersect )
{
// do exact check in case we're doing intersection
if ( mSource->mFeatures.value( *mFeatureIdListIterator ).hasGeometry() && mSelectRectEngine->intersects( mSource->mFeatures.value( *mFeatureIdListIterator ).geometry().geometry() ) )
if ( mSource->mFeatures.value( *mFeatureIdListIterator ).hasGeometry() && mSelectRectEngine->intersects( mSource->mFeatures.value( *mFeatureIdListIterator ).geometry().constGet() ) )
hasFeature = true;
}
else
@ -166,7 +166,7 @@ bool QgsMemoryFeatureIterator::nextFeatureTraverseAll( QgsFeature &feature )
if ( mRequest.flags() & QgsFeatureRequest::ExactIntersect )
{
// using exact test when checking for intersection
if ( mSelectIterator->hasGeometry() && mSelectRectEngine->intersects( mSelectIterator->geometry().geometry() ) )
if ( mSelectIterator->hasGeometry() && mSelectRectEngine->intersects( mSelectIterator->geometry().constGet() ) )
hasFeature = true;
}
else

View File

@ -180,7 +180,7 @@ double QgsDistanceArea::measureArea( const QgsGeometry &geometry ) const
if ( geometry.isNull() )
return 0.0;
const QgsAbstractGeometry *geomV2 = geometry.geometry();
const QgsAbstractGeometry *geomV2 = geometry.constGet();
return measure( geomV2, Area );
}
@ -189,7 +189,7 @@ double QgsDistanceArea::measureLength( const QgsGeometry &geometry ) const
if ( geometry.isNull() )
return 0.0;
const QgsAbstractGeometry *geomV2 = geometry.geometry();
const QgsAbstractGeometry *geomV2 = geometry.constGet();
return measure( geomV2, Length );
}
@ -198,7 +198,7 @@ double QgsDistanceArea::measurePerimeter( const QgsGeometry &geometry ) const
if ( geometry.isNull() )
return 0.0;
const QgsAbstractGeometry *geomV2 = geometry.geometry();
const QgsAbstractGeometry *geomV2 = geometry.constGet();
if ( !geomV2 || geomV2->dimension() < 2 )
{
return 0.0;

View File

@ -93,7 +93,7 @@ QString QgsJsonExporter::exportFeature( const QgsFeature &feature, const QVarian
}
QgsRectangle box = geom.boundingBox();
if ( QgsWkbTypes::flatType( geom.geometry()->wkbType() ) != QgsWkbTypes::Point )
if ( QgsWkbTypes::flatType( geom.wkbType() ) != QgsWkbTypes::Point )
{
s += QStringLiteral( " \"bbox\":[%1, %2, %3, %4],\n" ).arg( qgsDoubleToString( box.xMinimum(), mPrecision ),
qgsDoubleToString( box.yMinimum(), mPrecision ),

View File

@ -133,7 +133,7 @@ void QgsMapHitTest::runHitTestLayer( QgsVectorLayer *vl, SymbolSet &usedSymbols,
else
{
request.setFilterRect( transformedPolygon.boundingBox() );
polygonEngine.reset( QgsGeometry::createGeometryEngine( transformedPolygon.geometry() ) );
polygonEngine.reset( QgsGeometry::createGeometryEngine( transformedPolygon.constGet() ) );
polygonEngine->prepareGeometry();
}
}
@ -155,7 +155,7 @@ void QgsMapHitTest::runHitTestLayer( QgsVectorLayer *vl, SymbolSet &usedSymbols,
// filter out elements outside of the polygon
if ( f.geometry() && polygonEngine )
{
if ( !polygonEngine->intersects( f.geometry().geometry() ) )
if ( !polygonEngine->intersects( f.geometry().constGet() ) )
{
continue;
}

View File

@ -269,11 +269,11 @@ QgsGeometry QgsMapToPixelSimplifier::simplifyGeometry(
{
const QgsPolygonV2 &srcPolygon = dynamic_cast<const QgsPolygonV2 &>( geometry );
std::unique_ptr<QgsPolygonV2> polygon( new QgsPolygonV2() );
polygon->setExteriorRing( qgsgeometry_cast<QgsCurve *>( simplifyGeometry( simplifyFlags, simplifyAlgorithm, srcPolygon.exteriorRing()->wkbType(), *srcPolygon.exteriorRing(), envelope, map2pixelTol, true ).geometry()->clone() ) );
polygon->setExteriorRing( qgsgeometry_cast<QgsCurve *>( simplifyGeometry( simplifyFlags, simplifyAlgorithm, srcPolygon.exteriorRing()->wkbType(), *srcPolygon.exteriorRing(), envelope, map2pixelTol, true ).constGet()->clone() ) );
for ( int i = 0; i < srcPolygon.numInteriorRings(); ++i )
{
const QgsCurve *sub = srcPolygon.interiorRing( i );
polygon->addInteriorRing( qgsgeometry_cast<QgsCurve *>( simplifyGeometry( simplifyFlags, simplifyAlgorithm, sub->wkbType(), *sub, envelope, map2pixelTol, true ).geometry()->clone() ) );
polygon->addInteriorRing( qgsgeometry_cast<QgsCurve *>( simplifyGeometry( simplifyFlags, simplifyAlgorithm, sub->wkbType(), *sub, envelope, map2pixelTol, true ).constGet()->clone() ) );
}
return QgsGeometry( polygon.release() );
}
@ -285,7 +285,7 @@ QgsGeometry QgsMapToPixelSimplifier::simplifyGeometry(
for ( int i = 0; i < numGeoms; ++i )
{
const QgsAbstractGeometry *sub = srcCollection.geometryN( i );
collection->addGeometry( simplifyGeometry( simplifyFlags, simplifyAlgorithm, sub->wkbType(), *sub, envelope, map2pixelTol, false ).geometry()->clone() );
collection->addGeometry( simplifyGeometry( simplifyFlags, simplifyAlgorithm, sub->wkbType(), *sub, envelope, map2pixelTol, false ).constGet()->clone() );
}
return QgsGeometry( collection.release() );
}
@ -320,7 +320,7 @@ QgsGeometry QgsMapToPixelSimplifier::simplify( const QgsGeometry &geometry ) con
}
const bool isaLinearRing = flatType == QgsWkbTypes::Polygon;
const int numPoints = geometry.geometry()->nCoordinates();
const int numPoints = geometry.constGet()->nCoordinates();
if ( numPoints <= ( isaLinearRing ? 6 : 3 ) )
{
@ -335,5 +335,5 @@ QgsGeometry QgsMapToPixelSimplifier::simplify( const QgsGeometry &geometry ) con
return geometry;
}
return simplifyGeometry( mSimplifyFlags, mSimplifyAlgorithm, geometry.wkbType(), *geometry.geometry(), envelope, mTolerance, false );
return simplifyGeometry( mSimplifyFlags, mSimplifyAlgorithm, geometry.wkbType(), *geometry.constGet(), envelope, mTolerance, false );
}

View File

@ -1494,7 +1494,7 @@ void QgsPalLayerSettings::registerFeature( QgsFeature &f, QgsRenderContext &cont
if ( ( geom.type() == QgsWkbTypes::PolygonGeometry )
&& ( placement == Line || placement == PerimeterCurved ) )
{
geom = QgsGeometry( geom.geometry()->boundary() );
geom = QgsGeometry( geom.constGet()->boundary() );
}
GEOSGeometry *geos_geom_clone = nullptr;
@ -1779,8 +1779,8 @@ void QgsPalLayerSettings::registerFeature( QgsFeature &f, QgsRenderContext &cont
if ( QgsPalLabeling::geometryRequiresPreparation( ddPoint, context, ct ) )
{
ddPoint = QgsPalLabeling::prepareGeometry( ddPoint, context, ct );
xPos = static_cast< QgsPoint * >( ddPoint.geometry() )->x();
yPos = static_cast< QgsPoint * >( ddPoint.geometry() )->y();
xPos = static_cast< const QgsPoint * >( ddPoint.constGet() )->x();
yPos = static_cast< const QgsPoint * >( ddPoint.constGet() )->y();
}
xPos += xdiff;

View File

@ -414,16 +414,16 @@ void extractLinework( const QgsGeometry &g, QgsMultiPolyline &mpl )
QgsGeometry geom = g;
// segmentize curved geometries - we will use noding algorithm from GEOS
// to find all intersections a bit later (so we need them segmentized anyway)
if ( QgsWkbTypes::isCurvedType( g.geometry()->wkbType() ) )
if ( QgsWkbTypes::isCurvedType( g.wkbType() ) )
{
QgsAbstractGeometry *segmentizedGeomV2 = g.geometry()->segmentize();
QgsAbstractGeometry *segmentizedGeomV2 = g.constGet()->segmentize();
if ( !segmentizedGeomV2 )
return;
geom = QgsGeometry( segmentizedGeomV2 );
}
switch ( QgsWkbTypes::flatType( geom.geometry()->wkbType() ) )
switch ( QgsWkbTypes::flatType( geom.wkbType() ) )
{
case QgsWkbTypes::LineString:
mpl << geom.asPolyline();

View File

@ -692,7 +692,7 @@ QgsGeometry QgsVectorDataProvider::convertToProviderType( const QgsGeometry &geo
return QgsGeometry();
}
QgsAbstractGeometry *geometry = geom.geometry();
const QgsAbstractGeometry *geometry = geom.constGet();
if ( !geometry )
{
return QgsGeometry();

View File

@ -2109,13 +2109,13 @@ OGRFeatureH QgsVectorFileWriter::createFeature( const QgsFeature &feature )
QgsGeometry geom = feature.geometry();
// turn single geometry to multi geometry if needed
if ( QgsWkbTypes::flatType( geom.geometry()->wkbType() ) != QgsWkbTypes::flatType( mWkbType ) &&
QgsWkbTypes::flatType( geom.geometry()->wkbType() ) == QgsWkbTypes::flatType( QgsWkbTypes::singleType( mWkbType ) ) )
if ( QgsWkbTypes::flatType( geom.wkbType() ) != QgsWkbTypes::flatType( mWkbType ) &&
QgsWkbTypes::flatType( geom.wkbType() ) == QgsWkbTypes::flatType( QgsWkbTypes::singleType( mWkbType ) ) )
{
geom.convertToMultiType();
}
if ( geom.geometry()->wkbType() != mWkbType )
if ( geom.wkbType() != mWkbType )
{
OGRGeometryH mGeom2 = nullptr;
@ -2127,10 +2127,10 @@ OGRFeatureH QgsVectorFileWriter::createFeature( const QgsFeature &feature )
//so the exported WKB has a different type to what the OGRGeometry is expecting.
//possibly this is handled already in OGR, but it should be fixed regardless by actually converting
//geom to the correct WKB type
QgsWkbTypes::Type wkbType = geom.geometry()->wkbType();
QgsWkbTypes::Type wkbType = geom.wkbType();
if ( wkbType >= QgsWkbTypes::PointZ && wkbType <= QgsWkbTypes::MultiPolygonZ )
{
QgsWkbTypes::Type wkbType25d = static_cast<QgsWkbTypes::Type>( geom.geometry()->wkbType() - QgsWkbTypes::PointZ + QgsWkbTypes::Point25D );
QgsWkbTypes::Type wkbType25d = static_cast<QgsWkbTypes::Type>( geom.wkbType() - QgsWkbTypes::PointZ + QgsWkbTypes::Point25D );
mGeom2 = createEmptyGeometry( wkbType25d );
}
}
@ -2145,7 +2145,7 @@ OGRFeatureH QgsVectorFileWriter::createFeature( const QgsFeature &feature )
//
// Btw. OGRGeometry must be exactly of the type of the geometry which it will receive
// i.e. Polygons can't be imported to OGRMultiPolygon
mGeom2 = createEmptyGeometry( geom.geometry()->wkbType() );
mGeom2 = createEmptyGeometry( geom.wkbType() );
}
if ( !mGeom2 )
@ -2431,7 +2431,7 @@ QgsVectorFileWriter::writeAsVectorFormat( QgsVectorLayer *layer,
}
}
if ( fet.hasGeometry() && QgsWkbTypes::isMultiType( fet.geometry().geometry()->wkbType() ) )
if ( fet.hasGeometry() && QgsWkbTypes::isMultiType( fet.geometry().wkbType() ) )
{
destWkbType = QgsWkbTypes::multiType( destWkbType );
break;
@ -2526,7 +2526,7 @@ QgsVectorFileWriter::writeAsVectorFormat( QgsVectorLayer *layer,
req.setFilterRect( filterRect );
}
filterRectGeometry = QgsGeometry::fromRect( options.filterExtent );
filterRectEngine.reset( QgsGeometry::createGeometryEngine( filterRectGeometry.geometry() ) );
filterRectEngine.reset( QgsGeometry::createGeometryEngine( filterRectGeometry.constGet() ) );
filterRectEngine->prepareGeometry();
}
@ -2613,7 +2613,7 @@ QgsVectorFileWriter::writeAsVectorFormat( QgsVectorLayer *layer,
}
}
if ( fet.hasGeometry() && filterRectEngine && !filterRectEngine->intersects( fet.geometry().geometry() ) )
if ( fet.hasGeometry() && filterRectEngine && !filterRectEngine->intersects( fet.geometry().constGet() ) )
continue;
if ( attributes.empty() && options.skipAttributeCreation )

View File

@ -105,10 +105,10 @@ QgsVectorLayer::EditResult QgsVectorLayerEditUtils::deleteVertex( QgsFeatureId f
if ( !geometry.deleteVertex( vertex ) )
return QgsVectorLayer::EditFailed;
if ( geometry.geometry() && geometry.geometry()->nCoordinates() == 0 )
if ( geometry.constGet() && geometry.constGet()->nCoordinates() == 0 )
{
//last vertex deleted, set geometry to null
geometry.setGeometry( nullptr );
geometry.set( nullptr );
}
mLayer->editBuffer()->changeGeometry( featureId, geometry );

View File

@ -266,16 +266,16 @@ QgsGeometry QgsVectorLayerLabelProvider::getPointObstacleGeometry( QgsFeature &f
if ( !fet.hasGeometry() || fet.geometry().type() != QgsWkbTypes::PointGeometry )
return QgsGeometry();
bool isMultiPoint = fet.geometry().geometry()->nCoordinates() > 1;
bool isMultiPoint = fet.geometry().constGet()->nCoordinates() > 1;
QgsAbstractGeometry *obstacleGeom = nullptr;
if ( isMultiPoint )
obstacleGeom = new QgsMultiPolygonV2();
// for each point
for ( int i = 0; i < fet.geometry().geometry()->nCoordinates(); ++i )
for ( int i = 0; i < fet.geometry().constGet()->nCoordinates(); ++i )
{
QRectF bounds;
QgsPoint p = fet.geometry().geometry()->vertexAt( QgsVertexId( i, 0, 0 ) );
QgsPoint p = fet.geometry().constGet()->vertexAt( QgsVertexId( i, 0, 0 ) );
double x = p.x();
double y = p.y();
double z = 0; // dummy variable for coordinate transforms

View File

@ -3415,8 +3415,8 @@ void QgsCentroidFillSymbolLayer::renderPolygon( const QPolygonF &points, QList<Q
if ( context.geometryPartCount() > 1 )
{
QgsGeometry geom = feature->geometry();
const QgsGeometryCollection *geomCollection = static_cast<const QgsGeometryCollection *>( geom.geometry() );
const QgsGeometry geom = feature->geometry();
const QgsGeometryCollection *geomCollection = static_cast<const QgsGeometryCollection *>( geom.constGet() );
double area = 0;
double areaBiggest = 0;

View File

@ -285,7 +285,7 @@ void QgsInvertedPolygonRenderer::stopRender( QgsRenderContext &context )
Q_FOREACH ( const QgsGeometry &geom, cit.geometries )
{
QgsMultiPolygon multi;
QgsWkbTypes::Type type = QgsWkbTypes::flatType( geom.geometry()->wkbType() );
QgsWkbTypes::Type type = QgsWkbTypes::flatType( geom.constGet()->wkbType() );
if ( ( type == QgsWkbTypes::Polygon ) || ( type == QgsWkbTypes::CurvePolygon ) )
{

View File

@ -142,7 +142,7 @@ void QgsPointDistanceRenderer::drawGroup( const ClusteredGroup &group, QgsRender
QgsMultiPointV2 *groupMultiPoint = new QgsMultiPointV2();
Q_FOREACH ( const GroupedFeature &f, group )
{
groupMultiPoint->addGeometry( f.feature.geometry().geometry()->clone() );
groupMultiPoint->addGeometry( f.feature.geometry().constGet()->clone() );
}
QgsGeometry groupGeom( groupMultiPoint );
QgsGeometry centroid = groupGeom.centroid();

View File

@ -674,7 +674,7 @@ class ExpressionContextScopePopper
void QgsSymbol::renderFeature( const QgsFeature &feature, QgsRenderContext &context, int layer, bool selected, bool drawVertexMarker, int currentVertexMarkerType, int currentVertexMarkerSize )
{
QgsGeometry geom = feature.geometry();
const QgsGeometry geom = feature.geometry();
if ( geom.isNull() )
{
return;
@ -682,14 +682,14 @@ void QgsSymbol::renderFeature( const QgsFeature &feature, QgsRenderContext &cont
QgsGeometry segmentizedGeometry = geom;
bool usingSegmentizedGeometry = false;
context.setGeometry( geom.geometry() );
context.setGeometry( geom.constGet() );
bool tileMapRendering = context.testFlag( QgsRenderContext::RenderMapTile );
//convert curve types to normal point/line/polygon ones
if ( QgsWkbTypes::isCurvedType( geom.geometry()->wkbType() ) )
if ( QgsWkbTypes::isCurvedType( geom.constGet()->wkbType() ) )
{
QgsAbstractGeometry *g = geom.geometry()->segmentize( context.segmentationTolerance(), context.segmentationToleranceType() );
QgsAbstractGeometry *g = geom.constGet()->segmentize( context.segmentationTolerance(), context.segmentationToleranceType() );
if ( !g )
{
return;
@ -698,7 +698,7 @@ void QgsSymbol::renderFeature( const QgsFeature &feature, QgsRenderContext &cont
usingSegmentizedGeometry = true;
}
mSymbolRenderContext->setGeometryPartCount( segmentizedGeometry.geometry()->partCount() );
mSymbolRenderContext->setGeometryPartCount( segmentizedGeometry.constGet()->partCount() );
mSymbolRenderContext->setGeometryPartNum( 1 );
ExpressionContextScopePopper scopePopper;
@ -729,7 +729,7 @@ void QgsSymbol::renderFeature( const QgsFeature &feature, QgsRenderContext &cont
segmentizedGeometry = simplifier.simplify( segmentizedGeometry );
}
switch ( QgsWkbTypes::flatType( segmentizedGeometry.geometry()->wkbType() ) )
switch ( QgsWkbTypes::flatType( segmentizedGeometry.constGet()->wkbType() ) )
{
case QgsWkbTypes::Point:
{
@ -739,7 +739,7 @@ void QgsSymbol::renderFeature( const QgsFeature &feature, QgsRenderContext &cont
break;
}
const QgsPoint *point = static_cast< const QgsPoint * >( segmentizedGeometry.geometry() );
const QgsPoint *point = static_cast< const QgsPoint * >( segmentizedGeometry.constGet() );
const QPointF pt = _getPoint( context, *point );
static_cast<QgsMarkerSymbol *>( this )->renderPoint( pt, &feature, context, layer, selected );
@ -764,7 +764,7 @@ void QgsSymbol::renderFeature( const QgsFeature &feature, QgsRenderContext &cont
QgsDebugMsg( "linestring can be drawn only with line symbol!" );
break;
}
const QgsCurve &curve = dynamic_cast<const QgsCurve &>( *segmentizedGeometry.geometry() );
const QgsCurve &curve = dynamic_cast<const QgsCurve &>( *segmentizedGeometry.constGet() );
const QPolygonF pts = _getLineString( context, curve, !tileMapRendering && clipFeaturesToExtent() );
static_cast<QgsLineSymbol *>( this )->renderPolyline( pts, &feature, context, layer, selected );
@ -784,7 +784,7 @@ void QgsSymbol::renderFeature( const QgsFeature &feature, QgsRenderContext &cont
QgsDebugMsg( "polygon can be drawn only with fill symbol!" );
break;
}
const QgsPolygonV2 &polygon = dynamic_cast<const QgsPolygonV2 &>( *segmentizedGeometry.geometry() );
const QgsPolygonV2 &polygon = dynamic_cast<const QgsPolygonV2 &>( *segmentizedGeometry.constGet() );
if ( !polygon.exteriorRing() )
{
QgsDebugMsg( "cannot render polygon with no exterior ring" );
@ -813,7 +813,7 @@ void QgsSymbol::renderFeature( const QgsFeature &feature, QgsRenderContext &cont
break;
}
const QgsMultiPointV2 &mp = static_cast< const QgsMultiPointV2 & >( *segmentizedGeometry.geometry() );
const QgsMultiPointV2 &mp = static_cast< const QgsMultiPointV2 & >( *segmentizedGeometry.constGet() );
if ( drawVertexMarker && !usingSegmentizedGeometry )
{
@ -846,7 +846,7 @@ void QgsSymbol::renderFeature( const QgsFeature &feature, QgsRenderContext &cont
break;
}
const QgsGeometryCollection &geomCollection = dynamic_cast<const QgsGeometryCollection &>( *segmentizedGeometry.geometry() );
const QgsGeometryCollection &geomCollection = dynamic_cast<const QgsGeometryCollection &>( *segmentizedGeometry.constGet() );
const unsigned int num = geomCollection.numGeometries();
for ( unsigned int i = 0; i < num; ++i )
@ -886,7 +886,7 @@ void QgsSymbol::renderFeature( const QgsFeature &feature, QgsRenderContext &cont
QPolygonF pts;
QList<QPolygonF> holes;
const QgsGeometryCollection &geomCollection = dynamic_cast<const QgsGeometryCollection &>( *segmentizedGeometry.geometry() );
const QgsGeometryCollection &geomCollection = dynamic_cast<const QgsGeometryCollection &>( *segmentizedGeometry.constGet() );
const unsigned int num = geomCollection.numGeometries();
// Sort components by approximate area (probably a bit faster than using
@ -939,7 +939,7 @@ void QgsSymbol::renderFeature( const QgsFeature &feature, QgsRenderContext &cont
}
case QgsWkbTypes::GeometryCollection:
{
const QgsGeometryCollection &geomCollection = dynamic_cast<const QgsGeometryCollection &>( *segmentizedGeometry.geometry() );
const QgsGeometryCollection &geomCollection = dynamic_cast<const QgsGeometryCollection &>( *segmentizedGeometry.constGet() );
if ( geomCollection.numGeometries() == 0 )
{
// skip noise from empty geometry collections from simplification
@ -951,7 +951,7 @@ void QgsSymbol::renderFeature( const QgsFeature &feature, QgsRenderContext &cont
default:
QgsDebugMsg( QString( "feature %1: unsupported wkb type %2/%3 for rendering" )
.arg( feature.id() )
.arg( QgsWkbTypes::displayString( geom.geometry()->wkbType() ) )
.arg( QgsWkbTypes::displayString( geom.constGet()->wkbType() ) )
.arg( geom.wkbType(), 0, 16 ) );
}
@ -973,7 +973,7 @@ void QgsSymbol::renderFeature( const QgsFeature &feature, QgsRenderContext &cont
QgsVertexId vertexId;
double x, y, z;
QPointF mapPoint;
while ( geom.geometry()->nextVertex( vertexId, vertexPoint ) )
while ( geom.constGet()->nextVertex( vertexId, vertexPoint ) )
{
//transform
x = vertexPoint.x();

View File

@ -146,7 +146,7 @@ void QgsExpressionSelectionDialog::mButtonZoomToFeatures_clicked()
while ( features.nextFeature( feat ) )
{
QgsGeometry geom = feat.geometry();
if ( geom.isNull() || geom.geometry()->isEmpty() )
if ( geom.isNull() || geom.constGet()->isEmpty() )
continue;
QgsRectangle r = mMapCanvas->mapSettings().layerExtentToOutputExtent( mLayer, geom.boundingBox() );

View File

@ -1018,7 +1018,7 @@ bool QgsMapCanvas::boundingBoxOfFeatureIds( const QgsFeatureIds &ids, QgsVectorL
{
errorMsg = tr( "Feature does not have a geometry" );
}
else if ( geom.geometry()->isEmpty() )
else if ( geom.constGet()->isEmpty() )
{
errorMsg = tr( "Feature geometry is empty" );
}

View File

@ -419,7 +419,7 @@ int QgsMapToolCapture::fetchLayerPoint( const QgsPointLocator::Match &match, Qgs
QgsVertexId vId;
if ( !f.geometry().vertexIdFromVertexNr( match.vertexIndex(), vId ) )
return 2;
layerPoint = f.geometry().geometry()->vertexAt( vId );
layerPoint = f.geometry().constGet()->vertexAt( vId );
return 0;
}
else

View File

@ -376,14 +376,14 @@ QMap< QString, QString > QgsMapToolIdentify::featureDerivedAttributes( QgsFeatur
if ( feature->hasGeometry() )
{
geometryType = feature->geometry().type();
wkbType = feature->geometry().geometry()->wkbType();
wkbType = feature->geometry().wkbType();
//find closest vertex to clicked point
closestPoint = QgsGeometryUtils::closestVertex( *feature->geometry().geometry(), QgsPoint( layerPoint.x(), layerPoint.y() ), vId );
closestPoint = QgsGeometryUtils::closestVertex( *feature->geometry().constGet(), QgsPoint( layerPoint.x(), layerPoint.y() ), vId );
}
if ( QgsWkbTypes::isMultiType( wkbType ) )
{
QString str = QLocale::system().toString( static_cast<const QgsGeometryCollection *>( feature->geometry().geometry() )->numGeometries() );
QString str = QLocale::system().toString( static_cast<const QgsGeometryCollection *>( feature->geometry().constGet() )->numGeometries() );
derivedAttributes.insert( tr( "Parts" ), str );
str = QLocale::system().toString( vId.part + 1 );
derivedAttributes.insert( tr( "Part number" ), str );
@ -396,7 +396,7 @@ QMap< QString, QString > QgsMapToolIdentify::featureDerivedAttributes( QgsFeatur
QString str = formatDistance( dist );
derivedAttributes.insert( tr( "Length" ), str );
const QgsCurve *curve = qgsgeometry_cast< const QgsCurve * >( feature->geometry().geometry() );
const QgsCurve *curve = qgsgeometry_cast< const QgsCurve * >( feature->geometry().constGet() );
if ( curve )
{
str = QLocale::system().toString( curve->nCoordinates() );
@ -431,11 +431,11 @@ QMap< QString, QString > QgsMapToolIdentify::featureDerivedAttributes( QgsFeatur
str = formatDistance( perimeter );
derivedAttributes.insert( tr( "Perimeter" ), str );
str = QLocale::system().toString( feature->geometry().geometry()->nCoordinates() );
str = QLocale::system().toString( feature->geometry().constGet()->nCoordinates() );
derivedAttributes.insert( tr( "Vertices" ), str );
//add details of closest vertex to identify point
closestVertexAttributes( *feature->geometry().geometry(), vId, layer, derivedAttributes );
closestVertexAttributes( *feature->geometry().constGet(), vId, layer, derivedAttributes );
}
else if ( geometryType == QgsWkbTypes::PointGeometry &&
QgsWkbTypes::flatType( wkbType ) == QgsWkbTypes::Point )
@ -449,12 +449,12 @@ QMap< QString, QString > QgsMapToolIdentify::featureDerivedAttributes( QgsFeatur
if ( QgsWkbTypes::hasZ( wkbType ) )
{
str = QLocale::system().toString( static_cast<const QgsPoint *>( feature->geometry().geometry() )->z(), 'g', 10 );
str = QLocale::system().toString( static_cast<const QgsPoint *>( feature->geometry().constGet() )->z(), 'g', 10 );
derivedAttributes.insert( QStringLiteral( "Z" ), str );
}
if ( QgsWkbTypes::hasM( wkbType ) )
{
str = QLocale::system().toString( static_cast<const QgsPoint *>( feature->geometry().geometry() )->m(), 'g', 10 );
str = QLocale::system().toString( static_cast<const QgsPoint *>( feature->geometry().constGet() )->m(), 'g', 10 );
derivedAttributes.insert( QStringLiteral( "M" ), str );
}
}

View File

@ -1206,7 +1206,7 @@ void QgsGrassProvider::onFeatureAdded( QgsFeatureId fid )
}
QgsFeature feature = mEditBuffer->addedFeatures().value( fid );
QgsGeometry featureGeometry = feature.geometry();
geometry = featureGeometry.geometry();
geometry = featureGeometry.constGet();
if ( !geometry )
{
QgsDebugMsg( "geometry is null" );
@ -1222,7 +1222,7 @@ void QgsGrassProvider::onFeatureAdded( QgsFeatureId fid )
if ( wkbType == QgsWkbTypes::Polygon )
{
QgsGeometry addedFeatureGeom = addedFeatures[fid].geometry();
const QgsPolygonV2 *polygon = dynamic_cast<const QgsPolygonV2 *>( addedFeatureGeom.geometry() );
const QgsPolygonV2 *polygon = dynamic_cast<const QgsPolygonV2 *>( addedFeatureGeom.constGet() );
if ( polygon )
{
QgsLineString *lineString = polygon->exteriorRing()->curveToLine();
@ -1662,7 +1662,7 @@ void QgsGrassProvider::onGeometryChanged( QgsFeatureId fid, const QgsGeometry &g
}
}
setPoints( mPoints, geom.geometry() );
setPoints( mPoints, geom.constGet() );
mLayer->map()->lockReadWrite();
// Vect_rewrite_line may delete/write the line with a new id

View File

@ -1254,7 +1254,7 @@ namespace QgsWfs
}
else
{
QgsAbstractGeometry *abstractGeom = geom.geometry();
const QgsAbstractGeometry *abstractGeom = geom.constGet();
if ( abstractGeom )
{
gmlElem = abstractGeom->asGML2( doc, prec, "http://www.opengis.net/gml" );
@ -1355,7 +1355,7 @@ namespace QgsWfs
}
else
{
QgsAbstractGeometry *abstractGeom = geom.geometry();
const QgsAbstractGeometry *abstractGeom = geom.constGet();
if ( abstractGeom )
{
gmlElem = abstractGeom->asGML3( doc, prec, "http://www.opengis.net/gml" );

View File

@ -1613,13 +1613,13 @@ namespace QgsWms
if ( segmentizeWktGeometry )
{
QgsAbstractGeometry *abstractGeom = geom.geometry();
const QgsAbstractGeometry *abstractGeom = geom.constGet();
if ( abstractGeom )
{
if ( QgsWkbTypes::isCurvedType( abstractGeom->wkbType() ) )
{
QgsAbstractGeometry *segmentizedGeom = abstractGeom->segmentize();
geom.setGeometry( segmentizedGeom );
geom.set( segmentizedGeom );
}
}
}

View File

@ -1911,7 +1911,7 @@ void TestQgsProcessing::parameterExtent()
QGSCOMPARENEAR( ext.yMinimum(), 30.151856, 0.01 );
QGSCOMPARENEAR( ext.yMaximum(), 30.257289, 0.01 );
QgsGeometry gExt = QgsProcessingParameters::parameterAsExtentGeometry( def.get(), params, context, QgsCoordinateReferenceSystem( "EPSG:4326" ) );
QCOMPARE( gExt.geometry()->vertexCount(), 85 );
QCOMPARE( gExt.constGet()->vertexCount(), 85 );
ext = gExt.boundingBox();
QGSCOMPARENEAR( ext.xMinimum(), 17.924273, 0.01 );
QGSCOMPARENEAR( ext.xMaximum(), 18.045658, 0.01 );
@ -1948,7 +1948,7 @@ void TestQgsProcessing::parameterExtent()
QGSCOMPARENEAR( ext.yMinimum(), 244963, 100 );
QGSCOMPARENEAR( ext.yMaximum(), 490287, 100 );
gExt = QgsProcessingParameters::parameterAsExtentGeometry( def.get(), params, context, QgsCoordinateReferenceSystem( "EPSG:3785" ) );
QCOMPARE( gExt.geometry()->vertexCount(), 85 );
QCOMPARE( gExt.constGet()->vertexCount(), 85 );
ext = gExt.boundingBox();
QGSCOMPARENEAR( ext.xMinimum(), 122451, 100 );
QGSCOMPARENEAR( ext.xMaximum(), 367354, 100 );
@ -1998,7 +1998,7 @@ void TestQgsProcessing::parameterExtent()
// as reprojected geometry
gExt = QgsProcessingParameters::parameterAsExtentGeometry( def.get(), params, context, QgsCoordinateReferenceSystem( "EPSG:3785" ) );
QCOMPARE( gExt.geometry()->vertexCount(), 85 );
QCOMPARE( gExt.constGet()->vertexCount(), 85 );
ext = gExt.boundingBox();
QGSCOMPARENEAR( ext.xMinimum(), 122451, 100 );
QGSCOMPARENEAR( ext.xMaximum(), 367354, 100 );

View File

@ -205,14 +205,14 @@ void TestQgisAppClipboard::pasteWkt()
QgsFeatureList features = mQgisApp->clipboard()->copyOf();
QCOMPARE( features.length(), 2 );
QVERIFY( features.at( 0 ).hasGeometry() && !features.at( 0 ).geometry().isNull() );
QCOMPARE( features.at( 0 ).geometry().geometry()->wkbType(), QgsWkbTypes::Point );
QCOMPARE( features.at( 0 ).geometry().constGet()->wkbType(), QgsWkbTypes::Point );
QgsGeometry featureGeom = features.at( 0 ).geometry();
const QgsPoint *point = dynamic_cast< QgsPoint * >( featureGeom.geometry() );
const QgsPoint *point = dynamic_cast< const QgsPoint * >( featureGeom.constGet() );
QCOMPARE( point->x(), 125.0 );
QCOMPARE( point->y(), 10.0 );
QVERIFY( features.at( 1 ).hasGeometry() && !features.at( 1 ).geometry().isNull() );
QCOMPARE( features.at( 1 ).geometry().geometry()->wkbType(), QgsWkbTypes::Point );
point = dynamic_cast< QgsPoint * >( features.at( 1 ).geometry().geometry() );
QCOMPARE( features.at( 1 ).geometry().constGet()->wkbType(), QgsWkbTypes::Point );
point = dynamic_cast< const QgsPoint * >( features.at( 1 ).geometry().constGet() );
QCOMPARE( point->x(), 111.0 );
QCOMPARE( point->y(), 30.0 );
@ -224,15 +224,15 @@ void TestQgisAppClipboard::pasteWkt()
QCOMPARE( features.length(), 2 );
QVERIFY( features.at( 0 ).hasGeometry() && !features.at( 0 ).geometry().isNull() );
QCOMPARE( features.at( 0 ).geometry().geometry()->wkbType(), QgsWkbTypes::Point );
QCOMPARE( features.at( 0 ).geometry().constGet()->wkbType(), QgsWkbTypes::Point );
featureGeom = features.at( 0 ).geometry();
point = dynamic_cast< QgsPoint * >( featureGeom.geometry() );
point = dynamic_cast< const QgsPoint * >( featureGeom.constGet() );
QCOMPARE( point->x(), 111.0 );
QCOMPARE( point->y(), 30.0 );
QVERIFY( features.at( 1 ).hasGeometry() && !features.at( 1 ).geometry().isNull() );
QCOMPARE( features.at( 1 ).geometry().geometry()->wkbType(), QgsWkbTypes::Point );
point = dynamic_cast< QgsPoint * >( features.at( 1 ).geometry().geometry() );
QCOMPARE( features.at( 1 ).geometry().constGet()->wkbType(), QgsWkbTypes::Point );
point = dynamic_cast< const QgsPoint * >( features.at( 1 ).geometry().constGet() );
QCOMPARE( point->x(), 125.0 );
QCOMPARE( point->y(), 10.0 );
@ -251,9 +251,9 @@ void TestQgisAppClipboard::pasteGeoJson()
QgsFeatureList features = mQgisApp->clipboard()->copyOf( fields );
QCOMPARE( features.length(), 1 );
QVERIFY( features.at( 0 ).hasGeometry() && !features.at( 0 ).geometry().isNull() );
QCOMPARE( features.at( 0 ).geometry().geometry()->wkbType(), QgsWkbTypes::Point );
QCOMPARE( features.at( 0 ).geometry().constGet()->wkbType(), QgsWkbTypes::Point );
QgsGeometry featureGeom = features.at( 0 ).geometry();
const QgsPoint *point = dynamic_cast< QgsPoint * >( featureGeom.geometry() );
const QgsPoint *point = dynamic_cast< const QgsPoint * >( featureGeom.constGet() );
QCOMPARE( point->x(), 125.0 );
QCOMPARE( point->y(), 10.0 );
QCOMPARE( features.at( 0 ).attribute( "name" ).toString(), QString( "Dinagat Islands" ) );

View File

@ -116,7 +116,7 @@ void TestQgsConnectionPool::layersFromSameDatasetGPX()
for ( int i = 0, n = layer1Features.count(); i < n; ++i )
{
QgsGeometry featureGeom = layer1Features[i].geometry();
const QgsPoint *geom = dynamic_cast<const QgsPoint *>( featureGeom.geometry() );
const QgsPoint *geom = dynamic_cast<const QgsPoint *>( featureGeom.constGet() );
QVERIFY( geom );
QVERIFY( qFuzzyCompare( geom->x(), i ) );
QVERIFY( qFuzzyCompare( geom->y(), i ) );
@ -124,7 +124,7 @@ void TestQgsConnectionPool::layersFromSameDatasetGPX()
for ( int i = 0, n = layer2Features.count(); i < n; ++i )
{
QgsGeometry featureGeom = layer2Features[i].geometry();
const QgsLineString *geom = dynamic_cast<const QgsLineString *>( featureGeom.geometry() );
const QgsLineString *geom = dynamic_cast<const QgsLineString *>( featureGeom.constGet() );
QVERIFY( geom );
int nVtx = geom->vertexCount();
QVERIFY( nVtx == nRoutePts );

View File

@ -322,74 +322,74 @@ void TestQgsGeometry::copy()
{
//create a point geometry
QgsGeometry original( new QgsPoint( 1.0, 2.0 ) );
QCOMPARE( original.geometry()->vertexAt( QgsVertexId( 0, 0, 0 ) ).x(), 1.0 );
QCOMPARE( original.geometry()->vertexAt( QgsVertexId( 0, 0, 0 ) ).y(), 2.0 );
QCOMPARE( original.constGet()->vertexAt( QgsVertexId( 0, 0, 0 ) ).x(), 1.0 );
QCOMPARE( original.constGet()->vertexAt( QgsVertexId( 0, 0, 0 ) ).y(), 2.0 );
//implicitly shared copy
QgsGeometry copy( original );
QCOMPARE( copy.geometry()->vertexAt( QgsVertexId( 0, 0, 0 ) ).x(), 1.0 );
QCOMPARE( copy.geometry()->vertexAt( QgsVertexId( 0, 0, 0 ) ).y(), 2.0 );
QCOMPARE( copy.constGet()->vertexAt( QgsVertexId( 0, 0, 0 ) ).x(), 1.0 );
QCOMPARE( copy.constGet()->vertexAt( QgsVertexId( 0, 0, 0 ) ).y(), 2.0 );
//trigger a detach
copy.setGeometry( new QgsPoint( 3.0, 4.0 ) );
QCOMPARE( copy.geometry()->vertexAt( QgsVertexId( 0, 0, 0 ) ).x(), 3.0 );
QCOMPARE( copy.geometry()->vertexAt( QgsVertexId( 0, 0, 0 ) ).y(), 4.0 );
copy.set( new QgsPoint( 3.0, 4.0 ) );
QCOMPARE( copy.constGet()->vertexAt( QgsVertexId( 0, 0, 0 ) ).x(), 3.0 );
QCOMPARE( copy.constGet()->vertexAt( QgsVertexId( 0, 0, 0 ) ).y(), 4.0 );
//make sure original was untouched
QCOMPARE( original.geometry()->vertexAt( QgsVertexId( 0, 0, 0 ) ).x(), 1.0 );
QCOMPARE( original.geometry()->vertexAt( QgsVertexId( 0, 0, 0 ) ).y(), 2.0 );
QCOMPARE( original.constGet()->vertexAt( QgsVertexId( 0, 0, 0 ) ).x(), 1.0 );
QCOMPARE( original.constGet()->vertexAt( QgsVertexId( 0, 0, 0 ) ).y(), 2.0 );
}
void TestQgsGeometry::assignment()
{
//create a point geometry
QgsGeometry original( new QgsPoint( 1.0, 2.0 ) );
QCOMPARE( original.geometry()->vertexAt( QgsVertexId( 0, 0, 0 ) ).x(), 1.0 );
QCOMPARE( original.geometry()->vertexAt( QgsVertexId( 0, 0, 0 ) ).y(), 2.0 );
QCOMPARE( original.constGet()->vertexAt( QgsVertexId( 0, 0, 0 ) ).x(), 1.0 );
QCOMPARE( original.constGet()->vertexAt( QgsVertexId( 0, 0, 0 ) ).y(), 2.0 );
//assign to implicitly shared copy
QgsGeometry copy;
copy = original;
QCOMPARE( copy.geometry()->vertexAt( QgsVertexId( 0, 0, 0 ) ).x(), 1.0 );
QCOMPARE( copy.geometry()->vertexAt( QgsVertexId( 0, 0, 0 ) ).y(), 2.0 );
QCOMPARE( copy.constGet()->vertexAt( QgsVertexId( 0, 0, 0 ) ).x(), 1.0 );
QCOMPARE( copy.constGet()->vertexAt( QgsVertexId( 0, 0, 0 ) ).y(), 2.0 );
//trigger a detach
copy.setGeometry( new QgsPoint( 3.0, 4.0 ) );
QCOMPARE( copy.geometry()->vertexAt( QgsVertexId( 0, 0, 0 ) ).x(), 3.0 );
QCOMPARE( copy.geometry()->vertexAt( QgsVertexId( 0, 0, 0 ) ).y(), 4.0 );
copy.set( new QgsPoint( 3.0, 4.0 ) );
QCOMPARE( copy.constGet()->vertexAt( QgsVertexId( 0, 0, 0 ) ).x(), 3.0 );
QCOMPARE( copy.constGet()->vertexAt( QgsVertexId( 0, 0, 0 ) ).y(), 4.0 );
//make sure original was untouched
QCOMPARE( original.geometry()->vertexAt( QgsVertexId( 0, 0, 0 ) ).x(), 1.0 );
QCOMPARE( original.geometry()->vertexAt( QgsVertexId( 0, 0, 0 ) ).y(), 2.0 );
QCOMPARE( original.constGet()->vertexAt( QgsVertexId( 0, 0, 0 ) ).x(), 1.0 );
QCOMPARE( original.constGet()->vertexAt( QgsVertexId( 0, 0, 0 ) ).y(), 2.0 );
}
void TestQgsGeometry::asVariant()
{
//create a point geometry
QgsGeometry original( new QgsPoint( 1.0, 2.0 ) );
QCOMPARE( original.geometry()->vertexAt( QgsVertexId( 0, 0, 0 ) ).x(), 1.0 );
QCOMPARE( original.geometry()->vertexAt( QgsVertexId( 0, 0, 0 ) ).y(), 2.0 );
QCOMPARE( original.constGet()->vertexAt( QgsVertexId( 0, 0, 0 ) ).x(), 1.0 );
QCOMPARE( original.constGet()->vertexAt( QgsVertexId( 0, 0, 0 ) ).y(), 2.0 );
//convert to and from a QVariant
QVariant var = QVariant::fromValue( original );
QVERIFY( var.isValid() );
QgsGeometry fromVar = qvariant_cast<QgsGeometry>( var );
QCOMPARE( fromVar.geometry()->vertexAt( QgsVertexId( 0, 0, 0 ) ).x(), 1.0 );
QCOMPARE( fromVar.geometry()->vertexAt( QgsVertexId( 0, 0, 0 ) ).y(), 2.0 );
QCOMPARE( fromVar.constGet()->vertexAt( QgsVertexId( 0, 0, 0 ) ).x(), 1.0 );
QCOMPARE( fromVar.constGet()->vertexAt( QgsVertexId( 0, 0, 0 ) ).y(), 2.0 );
//also check copying variant
QVariant var2 = var;
QVERIFY( var2.isValid() );
QgsGeometry fromVar2 = qvariant_cast<QgsGeometry>( var2 );
QCOMPARE( fromVar2.geometry()->vertexAt( QgsVertexId( 0, 0, 0 ) ).x(), 1.0 );
QCOMPARE( fromVar2.geometry()->vertexAt( QgsVertexId( 0, 0, 0 ) ).y(), 2.0 );
QCOMPARE( fromVar2.constGet()->vertexAt( QgsVertexId( 0, 0, 0 ) ).x(), 1.0 );
QCOMPARE( fromVar2.constGet()->vertexAt( QgsVertexId( 0, 0, 0 ) ).y(), 2.0 );
//modify original and check detachment
original.setGeometry( new QgsPoint( 3.0, 4.0 ) );
original.set( new QgsPoint( 3.0, 4.0 ) );
QgsGeometry fromVar3 = qvariant_cast<QgsGeometry>( var );
QCOMPARE( fromVar3.geometry()->vertexAt( QgsVertexId( 0, 0, 0 ) ).x(), 1.0 );
QCOMPARE( fromVar3.geometry()->vertexAt( QgsVertexId( 0, 0, 0 ) ).y(), 2.0 );
QCOMPARE( fromVar3.constGet()->vertexAt( QgsVertexId( 0, 0, 0 ) ).x(), 1.0 );
QCOMPARE( fromVar3.constGet()->vertexAt( QgsVertexId( 0, 0, 0 ) ).y(), 2.0 );
}
void TestQgsGeometry::isEmpty()
@ -397,10 +397,10 @@ void TestQgsGeometry::isEmpty()
QgsGeometry geom;
QVERIFY( geom.isNull() );
geom.setGeometry( new QgsPoint( 1.0, 2.0 ) );
geom.set( new QgsPoint( 1.0, 2.0 ) );
QVERIFY( !geom.isNull() );
geom.setGeometry( 0 );
geom.set( 0 );
QVERIFY( geom.isNull() );
QgsGeometryCollection collection;
@ -412,10 +412,10 @@ void TestQgsGeometry::operatorBool()
QgsGeometry geom;
QVERIFY( !geom );
geom.setGeometry( new QgsPoint( 1.0, 2.0 ) );
geom.set( new QgsPoint( 1.0, 2.0 ) );
QVERIFY( geom );
geom.setGeometry( 0 );
geom.set( 0 );
QVERIFY( !geom );
}
@ -15099,10 +15099,10 @@ void TestQgsGeometry::intersectionCheck1()
{
QVERIFY( mpPolygonGeometryA.intersects( mpPolygonGeometryB ) );
std::unique_ptr< QgsGeometryEngine > engine( QgsGeometry::createGeometryEngine( mpPolygonGeometryA.geometry() ) );
QVERIFY( engine->intersects( mpPolygonGeometryB.geometry() ) );
std::unique_ptr< QgsGeometryEngine > engine( QgsGeometry::createGeometryEngine( mpPolygonGeometryA.constGet() ) );
QVERIFY( engine->intersects( mpPolygonGeometryB.constGet() ) );
engine->prepareGeometry();
QVERIFY( engine->intersects( mpPolygonGeometryB.geometry() ) );
QVERIFY( engine->intersects( mpPolygonGeometryB.constGet() ) );
// should be a single polygon as A intersect B
QgsGeometry mypIntersectionGeometry = mpPolygonGeometryA.intersection( mpPolygonGeometryB );
@ -15389,7 +15389,7 @@ void TestQgsGeometry::dataStream()
ds.device()->seek( 0 );
ds >> resultGeometry;
QCOMPARE( geom.geometry()->asWkt(), resultGeometry.geometry()->asWkt() );
QCOMPARE( geom.constGet()->asWkt(), resultGeometry.constGet()->asWkt() );
//also test with geometry without data
std::unique_ptr<QgsGeometry> emptyGeom( new QgsGeometry() );
@ -15863,7 +15863,7 @@ void TestQgsGeometry::minimalEnclosingCircle()
result = geomTest.minimalEnclosingCircle( center, radius );
QCOMPARE( center, QgsPointXY( 5, 5 ) );
QCOMPARE( radius, 0.0 );
resultTest.setGeometry( QgsCircle( QgsPoint( center ), radius ).toPolygon( 36 ) );
resultTest.set( QgsCircle( QgsPoint( center ), radius ).toPolygon( 36 ) );
QCOMPARE( result, resultTest );
// case 2
@ -15871,35 +15871,35 @@ void TestQgsGeometry::minimalEnclosingCircle()
result = geomTest.minimalEnclosingCircle( center, radius );
QGSCOMPARENEARPOINT( center, QgsPointXY( 5, 6 ), 0.0001 );
QGSCOMPARENEAR( radius, sqrt( 2 ) * 2, 0.0001 );
resultTest.setGeometry( QgsCircle( QgsPoint( center ), radius ).toPolygon( 36 ) );
resultTest.set( QgsCircle( QgsPoint( center ), radius ).toPolygon( 36 ) );
QCOMPARE( result, resultTest );
geomTest = QgsGeometry::fromWkt( QStringLiteral( "LINESTRING( 0 5, 2 2, 0 -5, -1 -1 )" ) );
result = geomTest.minimalEnclosingCircle( center, radius );
QGSCOMPARENEARPOINT( center, QgsPointXY( 0, 0 ), 0.0001 );
QGSCOMPARENEAR( radius, 5, 0.0001 );
resultTest.setGeometry( QgsCircle( QgsPoint( center ), radius ).toPolygon( 36 ) );
resultTest.set( QgsCircle( QgsPoint( center ), radius ).toPolygon( 36 ) );
QCOMPARE( result, resultTest );
geomTest = QgsGeometry::fromWkt( QStringLiteral( "MULTIPOINT( 0 5, 2 2, 0 -5, -1 -1 )" ) );
result = geomTest.minimalEnclosingCircle( center, radius );
QGSCOMPARENEARPOINT( center, QgsPointXY( 0, 0 ), 0.0001 );
QGSCOMPARENEAR( radius, 5, 0.0001 );
resultTest.setGeometry( QgsCircle( QgsPoint( center ), radius ).toPolygon( 36 ) );
resultTest.set( QgsCircle( QgsPoint( center ), radius ).toPolygon( 36 ) );
QCOMPARE( result, resultTest );
geomTest = QgsGeometry::fromWkt( QStringLiteral( "POLYGON(( 0 5, 2 2, 0 -5, -1 -1 ))" ) );
result = geomTest.minimalEnclosingCircle( center, radius );
QGSCOMPARENEARPOINT( center, QgsPointXY( 0, 0 ), 0.0001 );
QGSCOMPARENEAR( radius, 5, 0.0001 );
resultTest.setGeometry( QgsCircle( QgsPoint( center ), radius ).toPolygon( 36 ) );
resultTest.set( QgsCircle( QgsPoint( center ), radius ).toPolygon( 36 ) );
QCOMPARE( result, resultTest );
geomTest = QgsGeometry::fromWkt( QStringLiteral( "MULTIPOINT( 0 5, 0 -5, 0 0 )" ) );
result = geomTest.minimalEnclosingCircle( center, radius );
QGSCOMPARENEARPOINT( center, QgsPointXY( 0, 0 ), 0.0001 );
QGSCOMPARENEAR( radius, 5, 0.0001 );
resultTest.setGeometry( QgsCircle( QgsPoint( center ), radius ).toPolygon( 36 ) );
resultTest.set( QgsCircle( QgsPoint( center ), radius ).toPolygon( 36 ) );
QCOMPARE( result, resultTest );
// case 3
@ -15907,7 +15907,7 @@ void TestQgsGeometry::minimalEnclosingCircle()
result = geomTest.minimalEnclosingCircle( center, radius );
QGSCOMPARENEARPOINT( center, QgsPointXY( 0.8333, 0.8333 ), 0.0001 );
QGSCOMPARENEAR( radius, 5.8926, 0.0001 );
resultTest.setGeometry( QgsCircle( QgsPoint( center ), radius ).toPolygon( 36 ) );
resultTest.set( QgsCircle( QgsPoint( center ), radius ).toPolygon( 36 ) );
QCOMPARE( result, resultTest );
}

View File

@ -97,8 +97,8 @@ void TestQgsOgrUtils::ogrGeometryToQgsGeometry()
QgsGeometry geom = QgsOgrUtils::ogrGeometryToQgsGeometry( ogrGeom );
QVERIFY( !geom.isNull() );
QCOMPARE( geom.geometry()->wkbType(), QgsWkbTypes::LineString );
QCOMPARE( geom.geometry()->nCoordinates(), 71 );
QCOMPARE( geom.constGet()->wkbType(), QgsWkbTypes::LineString );
QCOMPARE( geom.constGet()->nCoordinates(), 71 );
OGR_F_Destroy( oFeat );
OGR_DS_Destroy( hDS );
@ -124,8 +124,8 @@ void TestQgsOgrUtils::readOgrFeatureGeometry()
QgsOgrUtils::readOgrFeatureGeometry( oFeat, f );
QVERIFY( f.hasGeometry() );
QCOMPARE( f.geometry().geometry()->wkbType(), QgsWkbTypes::LineString );
QCOMPARE( f.geometry().geometry()->nCoordinates(), 71 );
QCOMPARE( f.geometry().constGet()->wkbType(), QgsWkbTypes::LineString );
QCOMPARE( f.geometry().constGet()->nCoordinates(), 71 );
OGR_F_Destroy( oFeat );
OGR_DS_Destroy( hDS );
@ -273,8 +273,8 @@ void TestQgsOgrUtils::readOgrFeature()
QCOMPARE( f.attribute( "datetime_field" ), QVariant( QDateTime( QDate( 2005, 3, 5 ), QTime( 6, 45, 0 ) ) ) );
QCOMPARE( f.attribute( "string_field" ), QVariant( "a string" ) );
QVERIFY( f.hasGeometry() );
QCOMPARE( f.geometry().geometry()->wkbType(), QgsWkbTypes::LineString );
QCOMPARE( f.geometry().geometry()->nCoordinates(), 71 );
QCOMPARE( f.geometry().constGet()->wkbType(), QgsWkbTypes::LineString );
QCOMPARE( f.geometry().constGet()->nCoordinates(), 71 );
OGR_F_Destroy( oFeat );
OGR_DS_Destroy( hDS );
@ -331,9 +331,9 @@ void TestQgsOgrUtils::stringToFeatureList()
features = QgsOgrUtils::stringToFeatureList( QStringLiteral( "{\n\"type\": \"Feature\",\"geometry\": {\"type\": \"Point\",\"coordinates\": [125, 10]},\"properties\": {\"name\": \"Dinagat Islands\"}}" ), fields, QTextCodec::codecForName( "System" ) );
QCOMPARE( features.length(), 1 );
QVERIFY( features.at( 0 ).hasGeometry() && !features.at( 0 ).geometry().isNull() );
QCOMPARE( features.at( 0 ).geometry().geometry()->wkbType(), QgsWkbTypes::Point );
QCOMPARE( features.at( 0 ).geometry().constGet()->wkbType(), QgsWkbTypes::Point );
QgsGeometry featureGeom = features.at( 0 ).geometry();
const QgsPoint *point = dynamic_cast< QgsPoint * >( featureGeom.geometry() );
const QgsPoint *point = dynamic_cast< const QgsPoint * >( featureGeom.constGet() );
QCOMPARE( point->x(), 125.0 );
QCOMPARE( point->y(), 10.0 );
QCOMPARE( features.at( 0 ).attribute( "name" ).toString(), QString( "Dinagat Islands" ) );
@ -343,16 +343,16 @@ void TestQgsOgrUtils::stringToFeatureList()
" {\n\"type\": \"Feature\",\"geometry\": {\"type\": \"Point\",\"coordinates\": [110, 20]},\"properties\": {\"name\": \"Henry Gale Island\"}}]}", fields, QTextCodec::codecForName( "System" ) );
QCOMPARE( features.length(), 2 );
QVERIFY( features.at( 0 ).hasGeometry() && !features.at( 0 ).geometry().isNull() );
QCOMPARE( features.at( 0 ).geometry().geometry()->wkbType(), QgsWkbTypes::Point );
QCOMPARE( features.at( 0 ).geometry().constGet()->wkbType(), QgsWkbTypes::Point );
featureGeom = features.at( 0 ).geometry();
point = dynamic_cast< QgsPoint * >( featureGeom.geometry() );
point = dynamic_cast< const QgsPoint * >( featureGeom.constGet() );
QCOMPARE( point->x(), 125.0 );
QCOMPARE( point->y(), 10.0 );
QCOMPARE( features.at( 0 ).attribute( "name" ).toString(), QString( "Dinagat Islands" ) );
QVERIFY( features.at( 1 ).hasGeometry() && !features.at( 1 ).geometry().isNull() );
QCOMPARE( features.at( 1 ).geometry().geometry()->wkbType(), QgsWkbTypes::Point );
QCOMPARE( features.at( 1 ).geometry().constGet()->wkbType(), QgsWkbTypes::Point );
featureGeom = features.at( 1 ).geometry();
point = dynamic_cast< QgsPoint * >( featureGeom.geometry() );
point = dynamic_cast< const QgsPoint * >( featureGeom.constGet() );
QCOMPARE( point->x(), 110.0 );
QCOMPARE( point->y(), 20.0 );
QCOMPARE( features.at( 1 ).attribute( "name" ).toString(), QString( "Henry Gale Island" ) );

View File

@ -286,7 +286,7 @@ class TestQgsPointLocator : public QObject
QgsVectorLayer *vlEmptyGeom = new QgsVectorLayer( QStringLiteral( "Polygon" ), QStringLiteral( "x" ), QStringLiteral( "memory" ) );
QgsFeature ff( 0 );
QgsGeometry g;
g.setGeometry( new QgsPolygonV2() );
g.set( new QgsPolygonV2() );
ff.setGeometry( g );
QgsFeatureList flist;
flist << ff;

View File

@ -141,21 +141,21 @@ void TestQgsGeometryChecks::testAngleCheck()
int n1, n2;
context->featurePools[errs1[0]->layerId()]->get( errs1[0]->featureId(), f );
n1 = f.geometry().geometry()->vertexCount( errs1[0]->vidx().part, errs1[0]->vidx().ring );
n1 = f.geometry().constGet()->vertexCount( errs1[0]->vidx().part, errs1[0]->vidx().ring );
QVERIFY( fixCheckError( errs1[0],
QgsGeometryAngleCheck::DeleteNode, QgsGeometryCheckError::StatusFixed,
{{errs1[0]->layerId(), errs1[0]->featureId(), QgsGeometryCheck::ChangeNode, QgsGeometryCheck::ChangeRemoved, errs1[0]->vidx()}} ) );
context->featurePools[errs1[0]->layerId()]->get( errs1[0]->featureId(), f );
n2 = f.geometry().geometry()->vertexCount( errs1[0]->vidx().part, errs1[0]->vidx().ring );
n2 = f.geometry().constGet()->vertexCount( errs1[0]->vidx().part, errs1[0]->vidx().ring );
QCOMPARE( n1, n2 + 1 );
context->featurePools[errs2[0]->layerId()]->get( errs2[0]->featureId(), f );
n1 = f.geometry().geometry()->vertexCount( errs2[0]->vidx().part, errs2[0]->vidx().ring );
n1 = f.geometry().constGet()->vertexCount( errs2[0]->vidx().part, errs2[0]->vidx().ring );
QVERIFY( fixCheckError( errs2[0],
QgsGeometryAngleCheck::DeleteNode, QgsGeometryCheckError::StatusFixed,
{{errs2[0]->layerId(), errs2[0]->featureId(), QgsGeometryCheck::ChangeNode, QgsGeometryCheck::ChangeRemoved, errs2[0]->vidx()}} ) );
context->featurePools[errs2[0]->layerId()]->get( errs2[0]->featureId(), f );
n2 = f.geometry().geometry()->vertexCount( errs2[0]->vidx().part, errs2[0]->vidx().ring );
n2 = f.geometry().constGet()->vertexCount( errs2[0]->vidx().part, errs2[0]->vidx().ring );
QCOMPARE( n1, n2 + 1 );
// Test change tracking
@ -455,12 +455,12 @@ void TestQgsGeometryChecks::testDuplicateNodesCheck()
QgsFeature f;
context->featurePools[errs1[0]->layerId()]->get( errs1[0]->featureId(), f );
int n1 = f.geometry().geometry()->vertexCount( errs1[0]->vidx().part, errs1[0]->vidx().ring );
int n1 = f.geometry().constGet()->vertexCount( errs1[0]->vidx().part, errs1[0]->vidx().ring );
QVERIFY( fixCheckError( errs1[0],
QgsGeometryDuplicateNodesCheck::RemoveDuplicates, QgsGeometryCheckError::StatusFixed,
{{errs1[0]->layerId(), errs1[0]->featureId(), QgsGeometryCheck::ChangeNode, QgsGeometryCheck::ChangeRemoved, errs1[0]->vidx()}} ) );
context->featurePools[errs1[0]->layerId()]->get( errs1[0]->featureId(), f );
int n2 = f.geometry().geometry()->vertexCount( errs1[0]->vidx().part, errs1[0]->vidx().ring );
int n2 = f.geometry().constGet()->vertexCount( errs1[0]->vidx().part, errs1[0]->vidx().ring );
QCOMPARE( n1, n2 + 1 );
cleanupTestContext( context );
@ -562,7 +562,7 @@ void TestQgsGeometryChecks::testHoleCheck()
{errs1[0]->layerId(), errs1[0]->featureId(), QgsGeometryCheck::ChangeRing, QgsGeometryCheck::ChangeRemoved, QgsVertexId( 0, 1 )}
} ) );
context->featurePools[errs1[0]->layerId()]->get( errs1[0]->featureId(), f );
QVERIFY( f.geometry().geometry()->ringCount( 0 ) == 1 );
QVERIFY( f.geometry().constGet()->ringCount( 0 ) == 1 );
cleanupTestContext( context );
}
@ -867,11 +867,11 @@ void TestQgsGeometryChecks::testSelfIntersectionCheck()
{errs1[0]->layerId(), nextId, QgsGeometryCheck::ChangeFeature, QgsGeometryCheck::ChangeAdded, QgsVertexId()}
} ) );
context->featurePools[errs1[0]->layerId()]->get( errs1[0]->featureId(), f );
QCOMPARE( f.geometry().geometry()->partCount(), 1 );
QCOMPARE( f.geometry().geometry()->vertexCount(), 4 );
QCOMPARE( f.geometry().constGet()->partCount(), 1 );
QCOMPARE( f.geometry().constGet()->vertexCount(), 4 );
context->featurePools[errs1[0]->layerId()]->get( nextId, f );
QCOMPARE( f.geometry().geometry()->partCount(), 1 );
QCOMPARE( f.geometry().geometry()->vertexCount(), 6 );
QCOMPARE( f.geometry().constGet()->partCount(), 1 );
QCOMPARE( f.geometry().constGet()->vertexCount(), 6 );
QVERIFY( fixCheckError( errs2[0],
QgsGeometrySelfIntersectionCheck::ToMultiObject, QgsGeometryCheckError::StatusFixed,
@ -881,9 +881,9 @@ void TestQgsGeometryChecks::testSelfIntersectionCheck()
{errs2[0]->layerId(), errs2[0]->featureId(), QgsGeometryCheck::ChangePart, QgsGeometryCheck::ChangeAdded, QgsVertexId( 1 )}
} ) );
context->featurePools[errs2[0]->layerId()]->get( errs2[0]->featureId(), f );
QCOMPARE( f.geometry().geometry()->partCount(), 2 );
QCOMPARE( f.geometry().geometry()->vertexCount( 0 ), 4 );
QCOMPARE( f.geometry().geometry()->vertexCount( 1 ), 5 );
QCOMPARE( f.geometry().constGet()->partCount(), 2 );
QCOMPARE( f.geometry().constGet()->vertexCount( 0 ), 4 );
QCOMPARE( f.geometry().constGet()->vertexCount( 1 ), 5 );
nextId = context->featurePools[errs3[0]->layerId()]->getLayer()->featureCount();
QVERIFY( fixCheckError( errs3[0],
@ -893,11 +893,11 @@ void TestQgsGeometryChecks::testSelfIntersectionCheck()
{errs3[0]->layerId(), nextId, QgsGeometryCheck::ChangeFeature, QgsGeometryCheck::ChangeAdded, QgsVertexId()}
} ) );
context->featurePools[errs3[0]->layerId()]->get( errs3[0]->featureId(), f );
QCOMPARE( f.geometry().geometry()->partCount(), 1 );
QCOMPARE( f.geometry().geometry()->vertexCount(), 6 );
QCOMPARE( f.geometry().constGet()->partCount(), 1 );
QCOMPARE( f.geometry().constGet()->vertexCount(), 6 );
context->featurePools[errs3[0]->layerId()]->get( nextId, f );
QCOMPARE( f.geometry().geometry()->partCount(), 1 );
QCOMPARE( f.geometry().geometry()->vertexCount(), 4 );
QCOMPARE( f.geometry().constGet()->partCount(), 1 );
QCOMPARE( f.geometry().constGet()->vertexCount(), 4 );
QVERIFY( fixCheckError( errs4[0],
QgsGeometrySelfIntersectionCheck::ToMultiObject, QgsGeometryCheckError::StatusFixed,
@ -907,12 +907,12 @@ void TestQgsGeometryChecks::testSelfIntersectionCheck()
{errs4[0]->layerId(), errs4[0]->featureId(), QgsGeometryCheck::ChangePart, QgsGeometryCheck::ChangeAdded, QgsVertexId( 1 )}
} ) );
context->featurePools[errs4[0]->layerId()]->get( errs4[0]->featureId(), f );
QCOMPARE( f.geometry().geometry()->partCount(), 2 );
QCOMPARE( f.geometry().geometry()->ringCount( 0 ), 1 );
QCOMPARE( f.geometry().geometry()->vertexCount( 0, 0 ), 5 );
QCOMPARE( f.geometry().geometry()->ringCount( 1 ), 2 );
QCOMPARE( f.geometry().geometry()->vertexCount( 1, 0 ), 5 );
QCOMPARE( f.geometry().geometry()->vertexCount( 1, 1 ), 5 );
QCOMPARE( f.geometry().constGet()->partCount(), 2 );
QCOMPARE( f.geometry().constGet()->ringCount( 0 ), 1 );
QCOMPARE( f.geometry().constGet()->vertexCount( 0, 0 ), 5 );
QCOMPARE( f.geometry().constGet()->ringCount( 1 ), 2 );
QCOMPARE( f.geometry().constGet()->vertexCount( 1, 0 ), 5 );
QCOMPARE( f.geometry().constGet()->vertexCount( 1, 1 ), 5 );
// Test change tracking
QgsGeometrySelfIntersectionCheckError *err = static_cast<QgsGeometrySelfIntersectionCheckError *>( errs4[0] );