Skip to content
Permalink
Browse files

Convert more calls to qgsgeometry_cast

  • Loading branch information
m-kuhn committed Aug 13, 2017
1 parent d9ad859 commit dba8cc0f6c0628c7e89e099a915d7620a374339f
@@ -332,9 +332,9 @@ void QgsSnapIndex::addGeometry( const QgsAbstractGeometry *geom )
{
int nVerts = geom->vertexCount( iPart, iRing );

if ( dynamic_cast< const QgsSurface * >( geom ) )
if ( qgsgeometry_cast< const QgsSurface * >( geom ) )
nVerts--;
else if ( const QgsCurve *curve = dynamic_cast< const QgsCurve * >( geom ) )
else if ( const QgsCurve *curve = qgsgeometry_cast< const QgsCurve * >( geom ) )
{
if ( curve->isClosed() )
nVerts--;
@@ -510,7 +510,7 @@ QgsGeometry QgsGeometrySnapper::snapGeometry( const QgsGeometry &geometry, doubl
( mode == EndPointPreferClosest || mode == EndPointPreferNodes || mode == EndPointToEndPoint ) )
return geometry;

QgsPoint center = dynamic_cast< const QgsPoint * >( geometry.geometry() ) ? *static_cast< const QgsPoint * >( geometry.geometry() ) :
QgsPoint center = qgsgeometry_cast< const QgsPoint * >( geometry.geometry() ) ? *static_cast< const QgsPoint * >( geometry.geometry() ) :
QgsPoint( geometry.geometry()->boundingBox().center() );

QgsSnapIndex refSnapIndex( center, 10 * snapTolerance );
@@ -607,7 +607,7 @@ QgsGeometry QgsGeometrySnapper::snapGeometry( const QgsGeometry &geometry, doubl
}

//nothing more to do for points
if ( dynamic_cast< const QgsPoint * >( subjGeom ) )
if ( qgsgeometry_cast< const QgsPoint * >( subjGeom ) )
return QgsGeometry( subjGeom );
//or for end point snapping
if ( mode == EndPointPreferClosest || mode == EndPointPreferNodes || mode == EndPointToEndPoint )
@@ -715,7 +715,7 @@ int QgsGeometrySnapper::polyLineSize( const QgsAbstractGeometry *geom, int iPart
{
int nVerts = geom->vertexCount( iPart, iRing );

if ( dynamic_cast< const QgsSurface * >( geom ) )
if ( qgsgeometry_cast< const QgsSurface * >( geom ) )
{
QgsPoint front = geom->vertexAt( QgsVertexId( iPart, iRing, 0 ) );
QgsPoint back = geom->vertexAt( QgsVertexId( iPart, iRing, nVerts - 1 ) );
@@ -63,7 +63,7 @@ static bool isEndpointAtVertexIndex( const QgsGeometry &geom, int vertexIndex )
{
for ( int i = 0; i < multiCurve->numGeometries(); ++i )
{
QgsCurve *part = dynamic_cast<QgsCurve *>( multiCurve->geometryN( i ) );
QgsCurve *part = qgsgeometry_cast<QgsCurve *>( multiCurve->geometryN( i ) );
Q_ASSERT( part );
if ( vertexIndex < part->numPoints() )
return vertexIndex == 0 || vertexIndex == part->numPoints() - 1;
@@ -93,7 +93,7 @@ int adjacentVertexIndexToEndpoint( const QgsGeometry &geom, int vertexIndex )
int offset = 0;
for ( int i = 0; i < multiCurve->numGeometries(); ++i )
{
QgsCurve *part = dynamic_cast<QgsCurve *>( multiCurve->geometryN( i ) );
QgsCurve *part = qgsgeometry_cast<QgsCurve *>( multiCurve->geometryN( i ) );
Q_ASSERT( part );
if ( vertexIndex < part->numPoints() )
return vertexIndex == 0 ? offset + 1 : offset + part->numPoints() - 2;
@@ -155,7 +155,7 @@ void QgsMapToolAddPart::cadCanvasReleaseEvent( QgsMapMouseEvent *e )
QgsGeometry *geom = new QgsGeometry( cp );
geom->avoidIntersections( QgsProject::instance()->avoidIntersectionsLayers() );

const QgsCurvePolygon *cpGeom = dynamic_cast<const QgsCurvePolygon *>( geom->geometry() );
const QgsCurvePolygon *cpGeom = qgsgeometry_cast<const QgsCurvePolygon *>( geom->geometry() );
if ( !cpGeom )
{
stopCapturing();
@@ -1620,7 +1620,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 = dynamic_cast< QgsPoint * >( geom.geometry() );
QgsPoint *point = qgsgeometry_cast< QgsPoint * >( geom.geometry() );
if ( point )
return point->z();
}
@@ -1637,7 +1637,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 = dynamic_cast< QgsPoint * >( geom.geometry() );
QgsPoint *point = qgsgeometry_cast< QgsPoint * >( geom.geometry() );
if ( point )
return point->m();
}
@@ -1769,7 +1769,7 @@ static QVariant fcnInteriorRingN( const QVariantList &values, const QgsExpressio
if ( geom.isNull() )
return QVariant();

QgsCurvePolygon *curvePolygon = dynamic_cast< QgsCurvePolygon * >( geom.geometry() );
QgsCurvePolygon *curvePolygon = qgsgeometry_cast< QgsCurvePolygon * >( geom.geometry() );
if ( !curvePolygon )
return QVariant();

@@ -1791,7 +1791,7 @@ static QVariant fcnGeometryN( const QVariantList &values, const QgsExpressionCon
if ( geom.isNull() )
return QVariant();

QgsGeometryCollection *collection = dynamic_cast< QgsGeometryCollection * >( geom.geometry() );
QgsGeometryCollection *collection = qgsgeometry_cast< QgsGeometryCollection * >( geom.geometry() );
if ( !collection )
return QVariant();

@@ -1938,7 +1938,7 @@ static QVariant fcnMakeLine( const QVariantList &values, const QgsExpressionCont
if ( geom.type() != QgsWkbTypes::PointGeometry || geom.isMultipart() )
continue;

QgsPoint *point = dynamic_cast< QgsPoint * >( geom.geometry() );
QgsPoint *point = qgsgeometry_cast< QgsPoint * >( geom.geometry() );
if ( !point )
continue;

@@ -1961,7 +1961,7 @@ static QVariant fcnMakePolygon( const QVariantList &values, const QgsExpressionC
return QVariant();

QgsPolygonV2 *polygon = new QgsPolygonV2();
polygon->setExteriorRing( dynamic_cast< QgsCurve * >( outerRing.geometry()->clone() ) );
polygon->setExteriorRing( qgsgeometry_cast< QgsCurve * >( outerRing.geometry()->clone() ) );

for ( int i = 1; i < values.count(); ++i )
{
@@ -1972,7 +1972,7 @@ static QVariant fcnMakePolygon( const QVariantList &values, const QgsExpressionC
if ( ringGeom.type() != QgsWkbTypes::LineGeometry || ringGeom.isMultipart() || ringGeom.isNull() )
continue;

polygon->addInteriorRing( dynamic_cast< QgsCurve * >( ringGeom.geometry()->clone() ) );
polygon->addInteriorRing( qgsgeometry_cast< QgsCurve * >( ringGeom.geometry()->clone() ) );
}

return QVariant::fromValue( QgsGeometry( polygon ) );
@@ -1993,7 +1993,7 @@ static QVariant fcnMakeTriangle( const QVariantList &values, const QgsExpression
if ( geom.type() != QgsWkbTypes::PointGeometry || geom.isMultipart() )
return QVariant();

QgsPoint *point = dynamic_cast< QgsPoint * >( geom.geometry() );
QgsPoint *point = qgsgeometry_cast< QgsPoint * >( geom.geometry() );
if ( !point )
return QVariant();

@@ -2022,7 +2022,7 @@ static QVariant fcnMakeCircle( const QVariantList &values, const QgsExpressionCo
parent->setEvalErrorString( QObject::tr( "Segment must be greater than 2" ) );
return QVariant();
}
QgsPoint *point = static_cast< QgsPoint * >( geom.geometry() );
QgsPoint *point = qgsgeometry_cast< QgsPoint * >( geom.geometry() );
QgsCircle circ( *point, radius );
return QVariant::fromValue( QgsGeometry( circ.toPolygon( segment ) ) );
}
@@ -2045,7 +2045,7 @@ static QVariant fcnMakeEllipse( const QVariantList &values, const QgsExpressionC
parent->setEvalErrorString( QObject::tr( "Segment must be greater than 2" ) );
return QVariant();
}
QgsPoint *point = static_cast< QgsPoint * >( geom.geometry() );
QgsPoint *point = qgsgeometry_cast< QgsPoint * >( geom.geometry() );
QgsEllipse elp( *point, majorAxis, minorAxis, azimuth );
return QVariant::fromValue( QgsGeometry( elp.toPolygon( segment ) ) );
}
@@ -2080,8 +2080,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 = static_cast< QgsPoint * >( pt1.geometry() );
QgsPoint *corner = static_cast< QgsPoint * >( pt2.geometry() );
QgsPoint *center = qgsgeometry_cast< QgsPoint * >( pt1.geometry() );
QgsPoint *corner = qgsgeometry_cast< QgsPoint * >( pt2.geometry() );

QgsRegularPolygon rp = QgsRegularPolygon( *center, *corner, nbEdges, option );

@@ -2245,17 +2245,17 @@ static QVariant fcnGeomNumInteriorRings( const QVariantList &values, const QgsEx
if ( geom.isNull() )
return QVariant();

QgsCurvePolygon *curvePolygon = dynamic_cast< QgsCurvePolygon * >( geom.geometry() );
QgsCurvePolygon *curvePolygon = qgsgeometry_cast< QgsCurvePolygon * >( geom.geometry() );
if ( curvePolygon )
return QVariant( curvePolygon->numInteriorRings() );

QgsGeometryCollection *collection = dynamic_cast< QgsGeometryCollection * >( geom.geometry() );
QgsGeometryCollection *collection = qgsgeometry_cast< QgsGeometryCollection * >( geom.geometry() );
if ( collection )
{
//find first CurvePolygon in collection
for ( int i = 0; i < collection->numGeometries(); ++i )
{
curvePolygon = dynamic_cast< QgsCurvePolygon *>( collection->geometryN( i ) );
curvePolygon = qgsgeometry_cast< QgsCurvePolygon *>( collection->geometryN( i ) );
if ( !curvePolygon )
continue;

@@ -2273,19 +2273,19 @@ static QVariant fcnGeomNumRings( const QVariantList &values, const QgsExpression
if ( geom.isNull() )
return QVariant();

QgsCurvePolygon *curvePolygon = dynamic_cast< QgsCurvePolygon * >( geom.geometry() );
QgsCurvePolygon *curvePolygon = qgsgeometry_cast< QgsCurvePolygon * >( geom.geometry() );
if ( curvePolygon )
return QVariant( curvePolygon->ringCount() );

bool foundPoly = false;
int ringCount = 0;
QgsGeometryCollection *collection = dynamic_cast< QgsGeometryCollection * >( geom.geometry() );
QgsGeometryCollection *collection = qgsgeometry_cast< QgsGeometryCollection * >( geom.geometry() );
if ( collection )
{
//find CurvePolygons in collection
for ( int i = 0; i < collection->numGeometries(); ++i )
{
curvePolygon = dynamic_cast< QgsCurvePolygon *>( collection->geometryN( i ) );
curvePolygon = qgsgeometry_cast< QgsCurvePolygon *>( collection->geometryN( i ) );
if ( !curvePolygon )
continue;

@@ -2350,7 +2350,7 @@ static QVariant fcnIsClosed( const QVariantList &values, const QgsExpressionCont
if ( fGeom.isNull() )
return QVariant();

QgsCurve *curve = dynamic_cast< QgsCurve * >( fGeom.geometry() );
QgsCurve *curve = qgsgeometry_cast< QgsCurve * >( fGeom.geometry() );
if ( !curve )
return QVariant();

@@ -2544,7 +2544,7 @@ static QVariant fcnReverse( const QVariantList &values, const QgsExpressionConte
if ( fGeom.isNull() )
return QVariant();

QgsCurve *curve = dynamic_cast< QgsCurve * >( fGeom.geometry() );
QgsCurve *curve = qgsgeometry_cast< QgsCurve * >( fGeom.geometry() );
if ( !curve )
return QVariant();

@@ -2559,7 +2559,7 @@ static QVariant fcnExteriorRing( const QVariantList &values, const QgsExpression
if ( fGeom.isNull() )
return QVariant();

QgsCurvePolygon *curvePolygon = dynamic_cast< QgsCurvePolygon * >( fGeom.geometry() );
QgsCurvePolygon *curvePolygon = qgsgeometry_cast< QgsCurvePolygon * >( fGeom.geometry() );
if ( !curvePolygon || !curvePolygon->exteriorRing() )
return QVariant();

@@ -2622,8 +2622,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 = dynamic_cast<const QgsPoint *>( fGeom1.geometry() );
const QgsPoint *pt2 = dynamic_cast<const QgsPoint *>( fGeom2.geometry() );
const QgsPoint *pt1 = qgsgeometry_cast<const QgsPoint *>( fGeom1.geometry() );
const QgsPoint *pt2 = qgsgeometry_cast<const QgsPoint *>( fGeom2.geometry() );

if ( !pt1 || !pt2 )
{
@@ -2705,8 +2705,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 = dynamic_cast<const QgsPoint *>( fGeom1.geometry() );
const QgsPoint *pt2 = dynamic_cast<const QgsPoint *>( fGeom2.geometry() );
const QgsPoint *pt1 = qgsgeometry_cast<const QgsPoint *>( fGeom1.geometry() );
const QgsPoint *pt2 = qgsgeometry_cast<const QgsPoint *>( fGeom2.geometry() );

if ( ( fGeom1.type() != QgsWkbTypes::PointGeometry ) || ( fGeom2.type() != QgsWkbTypes::PointGeometry ) ||
!pt1 || !pt2 )
@@ -2774,7 +2774,7 @@ static QVariant fcnOrderParts( const QVariantList &values, const QgsExpressionCo
unconstedContext = new QgsExpressionContext();
}

QgsGeometryCollection *collection = dynamic_cast<QgsGeometryCollection *>( fGeom.geometry() );
QgsGeometryCollection *collection = qgsgeometry_cast<QgsGeometryCollection *>( fGeom.geometry() );
Q_ASSERT( collection ); // Should have failed the multipart check above

QgsFeatureRequest::OrderBy orderBy;
@@ -2791,7 +2791,7 @@ static QVariant fcnOrderParts( const QVariantList &values, const QgsExpressionCo

sorter.sortFeatures( partFeatures, unconstedContext );

QgsGeometryCollection *orderedGeom = dynamic_cast<QgsGeometryCollection *>( fGeom.geometry()->clone() );
QgsGeometryCollection *orderedGeom = qgsgeometry_cast<QgsGeometryCollection *>( fGeom.geometry()->clone() );

Q_ASSERT( orderedGeom );

@@ -598,7 +598,7 @@ bool QgsGeometryCollection::hasCurvedSegments() const
QgsAbstractGeometry *QgsGeometryCollection::segmentize( double tolerance, SegmentationToleranceType toleranceType ) const
{
QgsAbstractGeometry *geom = QgsGeometryFactory::geomFromWkbType( mWkbType );
QgsGeometryCollection *geomCollection = dynamic_cast<QgsGeometryCollection *>( geom );
QgsGeometryCollection *geomCollection = qgsgeometry_cast<QgsGeometryCollection *>( geom );
if ( !geomCollection )
{
delete geom;
@@ -34,8 +34,8 @@ int QgsGeometryEditUtils::addRing( QgsAbstractGeometry *geom, QgsCurve *ring )
}

QList< QgsCurvePolygon * > polygonList;
QgsCurvePolygon *curvePoly = dynamic_cast< QgsCurvePolygon * >( geom );
QgsGeometryCollection *multiGeom = dynamic_cast< QgsGeometryCollection * >( geom );
QgsCurvePolygon *curvePoly = qgsgeometry_cast< QgsCurvePolygon * >( geom );
QgsGeometryCollection *multiGeom = qgsgeometry_cast< QgsGeometryCollection * >( geom );
if ( curvePoly )
{
polygonList.append( curvePoly );
@@ -45,7 +45,7 @@ int QgsGeometryEditUtils::addRing( QgsAbstractGeometry *geom, QgsCurve *ring )
polygonList.reserve( multiGeom->numGeometries() );
for ( int i = 0; i < multiGeom->numGeometries(); ++i )
{
polygonList.append( dynamic_cast< QgsCurvePolygon * >( multiGeom->geometryN( i ) ) );
polygonList.append( qgsgeometry_cast< QgsCurvePolygon * >( multiGeom->geometryN( i ) ) );
}
}
else
@@ -113,7 +113,7 @@ int QgsGeometryEditUtils::addPart( QgsAbstractGeometry *geom, QgsAbstractGeometr
}

//multitype?
QgsGeometryCollection *geomCollection = dynamic_cast<QgsGeometryCollection *>( geom );
QgsGeometryCollection *geomCollection = qgsgeometry_cast<QgsGeometryCollection *>( geom );
if ( !geomCollection )
{
return 1;
@@ -188,7 +188,7 @@ bool QgsGeometryEditUtils::deleteRing( QgsAbstractGeometry *geom, int ringNum, i
}

QgsAbstractGeometry *g = geom;
QgsGeometryCollection *c = dynamic_cast<QgsGeometryCollection *>( geom );
QgsGeometryCollection *c = qgsgeometry_cast<QgsGeometryCollection *>( geom );
if ( c )
{
g = c->geometryN( partNum );
@@ -215,7 +215,7 @@ bool QgsGeometryEditUtils::deletePart( QgsAbstractGeometry *geom, int partNum )
return false;
}

QgsGeometryCollection *c = dynamic_cast<QgsGeometryCollection *>( geom );
QgsGeometryCollection *c = qgsgeometry_cast<QgsGeometryCollection *>( geom );
if ( !c )
{
return false;
@@ -357,18 +357,18 @@ static bool lwgeom_make_geos_friendly( QgsAbstractGeometry &geom )

case QgsWkbTypes::LineString:
// lines need at least 2 points
return lwline_make_geos_friendly( dynamic_cast<QgsLineString &>( geom ) );
return lwline_make_geos_friendly( qgsgeometry_cast<QgsLineString &>( geom ) );
break;

case QgsWkbTypes::Polygon:
// polygons need all rings closed and with npoints > 3
return lwpoly_make_geos_friendly( dynamic_cast<QgsPolygonV2 &>( geom ) );
return lwpoly_make_geos_friendly( qgsgeometry_cast<QgsPolygonV2 &>( geom ) );
break;

case QgsWkbTypes::MultiLineString:
case QgsWkbTypes::MultiPolygon:
case QgsWkbTypes::GeometryCollection:
return lwcollection_make_geos_friendly( dynamic_cast<QgsGeometryCollection &>( geom ) );
return lwcollection_make_geos_friendly( qgsgeometry_cast<QgsGeometryCollection &>( geom ) );
break;

default:
@@ -666,7 +666,7 @@ GEOSGeometry *QgsGeos::linePointDifference( GEOSGeometry *GEOSsplitPoint ) const
QgsMultiCurve *multiCurve = nullptr;
if ( type == GEOS_MULTILINESTRING )
{
multiCurve = dynamic_cast<QgsMultiCurve *>( mGeometry->clone() );
multiCurve = qgsgeometry_cast<QgsMultiCurve *>( mGeometry->clone() );
}
else if ( type == GEOS_LINESTRING )
{
@@ -685,7 +685,7 @@ GEOSGeometry *QgsGeos::linePointDifference( GEOSGeometry *GEOSsplitPoint ) const


QgsAbstractGeometry *splitGeom = fromGeos( GEOSsplitPoint );
QgsPoint *splitPoint = dynamic_cast<QgsPoint *>( splitGeom );
QgsPoint *splitPoint = qgsgeometry_cast<QgsPoint *>( splitGeom );
if ( !splitPoint )
{
delete splitGeom;
@@ -697,7 +697,7 @@ GEOSGeometry *QgsGeos::linePointDifference( GEOSGeometry *GEOSsplitPoint ) const
//For each part
for ( int i = 0; i < multiCurve->numGeometries(); ++i )
{
const QgsLineString *line = dynamic_cast<const QgsLineString *>( multiCurve->geometryN( i ) );
const QgsLineString *line = qgsgeometry_cast<const QgsLineString *>( multiCurve->geometryN( i ) );
if ( line )
{
//For each segment
@@ -1254,7 +1254,7 @@ GEOSGeometry *QgsGeos::asGeos( const QgsAbstractGeometry *geom, double precision
}
}

const QgsGeometryCollection *c = dynamic_cast<const QgsGeometryCollection *>( geom );
const QgsGeometryCollection *c = qgsgeometry_cast<const QgsGeometryCollection *>( geom );
if ( !c )
return nullptr;

0 comments on commit dba8cc0

Please sign in to comment.
You can’t perform that action at this time.