Skip to content
Permalink
Browse files

Use direct getters for ellipsoid/units in processing algs

Refs #37988
  • Loading branch information
nyalldawson committed Jul 29, 2020
1 parent 03854a4 commit b40bfbbf4cd1d2ad00636b7bf0eb437a3fa037a3
@@ -138,7 +138,7 @@ def processAlgorithm(self, parameters, context, feedback):
self.distance_area = QgsDistanceArea()
if method == 2:
self.distance_area.setSourceCrs(source.sourceCrs(), context.transformContext())
self.distance_area.setEllipsoid(context.project().ellipsoid())
self.distance_area.setEllipsoid(context.ellipsoid())
elif method == 1:
coordTransform = QgsCoordinateTransform(source.sourceCrs(), context.project().crs(), context.project())

@@ -106,11 +106,11 @@ def processAlgorithm(self, parameters, context, feedback):
expression = QgsExpression(formula)
da = QgsDistanceArea()
da.setSourceCrs(source.sourceCrs(), context.transformContext())
da.setEllipsoid(context.project().ellipsoid())
da.setEllipsoid(context.ellipsoid())
expression.setGeomCalculator(da)

expression.setDistanceUnits(context.project().distanceUnits())
expression.setAreaUnits(context.project().areaUnits())
expression.setDistanceUnits(context.distanceUnit())
expression.setAreaUnits(context.areaUnit())

fields = source.fields()
field_index = fields.lookupField(field_name)
@@ -121,7 +121,7 @@ def processAlgorithm(self, parameters, context, feedback):

distance = QgsDistanceArea()
distance.setSourceCrs(point_source.sourceCrs(), context.transformContext())
distance.setEllipsoid(context.project().ellipsoid())
distance.setEllipsoid(context.ellipsoid())

# Scan source points, find nearest hub, and write to output file
features = point_source.getFeatures()
@@ -118,7 +118,7 @@ def processAlgorithm(self, parameters, context, feedback):

distance = QgsDistanceArea()
distance.setSourceCrs(point_source.sourceCrs(), context.transformContext())
distance.setEllipsoid(context.project().ellipsoid())
distance.setEllipsoid(context.ellipsoid())

# Scan source points, find nearest hub, and write to output file
features = point_source.getFeatures()
@@ -180,7 +180,7 @@ def linearMatrix(self, parameters, context, source, inField, target_source, targ

distArea = QgsDistanceArea()
distArea.setSourceCrs(source.sourceCrs(), context.transformContext())
distArea.setEllipsoid(context.project().ellipsoid())
distArea.setEllipsoid(context.ellipsoid())

features = source.getFeatures(QgsFeatureRequest().setSubsetOfAttributes([inIdx]))
total = 100.0 / source.featureCount() if source.featureCount() else 0
@@ -235,7 +235,7 @@ def regularMatrix(self, parameters, context, source, inField, target_source, tar

distArea = QgsDistanceArea()
distArea.setSourceCrs(source.sourceCrs(), context.transformContext())
distArea.setEllipsoid(context.project().ellipsoid())
distArea.setEllipsoid(context.ellipsoid())

inIdx = source.fields().lookupField(inField)
targetIdx = target_source.fields().lookupField(targetField)
@@ -156,7 +156,7 @@ def processAlgorithm(self, parameters, context, feedback):

da = QgsDistanceArea()
da.setSourceCrs(source.sourceCrs(), context.transformContext())
da.setEllipsoid(context.project().ellipsoid())
da.setEllipsoid(context.ellipsoid())

current = 0
total = 100.0 / len(points) if points else 1
@@ -110,7 +110,7 @@ def processAlgorithm(self, parameters, context, feedback):

da = QgsDistanceArea()
da.setSourceCrs(source.sourceCrs(), context.transformContext())
da.setEllipsoid(context.project().ellipsoid())
da.setEllipsoid(context.ellipsoid())

request = QgsFeatureRequest()

@@ -157,7 +157,7 @@ def processAlgorithm(self, parameters, context, feedback):

da = QgsDistanceArea()
da.setSourceCrs(source.sourceCrs(), context.transformContext())
da.setEllipsoid(context.project().ellipsoid())
da.setEllipsoid(context.ellipsoid())

total = 100.0 / source.featureCount() if source.featureCount() else 0
current_progress = 0
@@ -77,7 +77,7 @@ bool QgsAggregateAlgorithm::prepareAlgorithm( const QVariantMap &parameters, Qgs
mGroupBy = parameterAsExpression( parameters, QStringLiteral( "GROUP_BY" ), context );

mDa.setSourceCrs( mSource->sourceCrs(), context.transformContext() );
mDa.setEllipsoid( context.project()->ellipsoid() );
mDa.setEllipsoid( context.ellipsoid() );

mGroupByExpression = createExpression( mGroupBy, context );
mGeometryExpression = createExpression( QStringLiteral( "collect($geometry, %1)" ).arg( mGroupBy ), context );
@@ -278,8 +278,8 @@ QgsExpression QgsAggregateAlgorithm::createExpression( const QString &expression
{
QgsExpression expr( expressionString );
expr.setGeomCalculator( &mDa );
expr.setDistanceUnits( context.project()->distanceUnits() );
expr.setAreaUnits( context.project()->areaUnits() );
expr.setDistanceUnits( context.distanceUnit() );
expr.setAreaUnits( context.areaUnit() );
if ( expr.hasParserError() )
{
throw QgsProcessingException(
@@ -127,7 +127,7 @@ QVariantMap QgsCalculateVectorOverlapsAlgorithm::processAlgorithm( const QVarian

QgsDistanceArea da;
da.setSourceCrs( mCrs, context.transformContext() );
da.setEllipsoid( context.project()->ellipsoid() );
da.setEllipsoid( context.ellipsoid() );

// loop through input
double step = mInputCount > 0 ? 100.0 / mInputCount : 0;
@@ -143,7 +143,7 @@ QVariantMap QgsJoinWithLinesAlgorithm::processAlgorithm( const QVariantMap &para
const bool splitAntimeridian = parameterAsBoolean( parameters, QStringLiteral( "ANTIMERIDIAN_SPLIT" ), context );
QgsDistanceArea da;
da.setSourceCrs( hubSource->sourceCrs(), context.transformContext() );
da.setEllipsoid( context.project()->ellipsoid() );
da.setEllipsoid( context.ellipsoid() );

QgsFields hubOutFields;
QgsAttributeList hubFieldIndices;
@@ -91,14 +91,9 @@ bool QgsLineDensityAlgorithm::prepareAlgorithm( const QVariantMap &parameters, Q
mExtent = mSource->sourceExtent();
mCrs = mSource->sourceCrs();
mDa = QgsDistanceArea();

if ( context.project() )
{
mDa.setEllipsoid( context.project()->ellipsoid() );
}
mDa.setEllipsoid( context.ellipsoid() );
mDa.setSourceCrs( mCrs, context.transformContext() );


//get cell midpoint from top left cell
QgsPoint firstCellMidpoint = QgsPoint( mExtent.xMinimum() + ( mPixelSize / 2 ), mExtent.yMaximum() - ( mPixelSize / 2 ) );
QgsCircle searchCircle = QgsCircle( firstCellMidpoint, mSearchRadius );
@@ -90,7 +90,7 @@ QVariantMap QgsNearestNeighbourAnalysisAlgorithm::processAlgorithm( const QVaria
QgsSpatialIndex spatialIndex( *source, feedback, QgsSpatialIndex::FlagStoreFeatureGeometries );
QgsDistanceArea da;
da.setSourceCrs( source->sourceCrs(), context.transformContext() );
da.setEllipsoid( context.project()->ellipsoid() );
da.setEllipsoid( context.ellipsoid() );

double step = source->featureCount() ? 100.0 / source->featureCount() : 1;
QgsFeatureIterator it = source->getFeatures( QgsFeatureRequest().setSubsetOfAttributes( QList< int >() ) );
@@ -94,7 +94,7 @@ bool QgsRefactorFieldsAlgorithm::prepareAlgorithm( const QVariantMap &parameters
throw QgsProcessingException( invalidSourceError( parameters, QStringLiteral( "INPUT" ) ) );

mDa.setSourceCrs( source->sourceCrs(), context.transformContext() );
mDa.setEllipsoid( context.project()->ellipsoid() );
mDa.setEllipsoid( context.ellipsoid() );

mExpressionContext = createExpressionContext( parameters, context, source.get() );

@@ -118,11 +118,8 @@ bool QgsRefactorFieldsAlgorithm::prepareAlgorithm( const QVariantMap &parameters
{
QgsExpression expression( expressionString );
expression.setGeomCalculator( &mDa );
if ( context.project() )
{
expression.setDistanceUnits( context.project()->distanceUnits() );
expression.setAreaUnits( context.project()->areaUnits() );
}
expression.setDistanceUnits( context.distanceUnit() );
expression.setAreaUnits( context.areaUnit() );
if ( expression.hasParserError() )
{
throw QgsProcessingException( QObject::tr( "Parser error for field \"%1\" with expression \"%2\": %3" )
@@ -100,11 +100,7 @@ QgsCoordinateReferenceSystem QgsSplitGeometryAtAntimeridianAlgorithm::outputCrs(

bool QgsSplitGeometryAtAntimeridianAlgorithm::prepareAlgorithm( const QVariantMap &, QgsProcessingContext &context, QgsProcessingFeedback * )
{
if ( context.project() )
{
mDa.setEllipsoid( context.project()->ellipsoid() );
}

mDa.setEllipsoid( context.ellipsoid() );
mTransformContext = context.transformContext();
return true;
}
@@ -128,10 +128,7 @@ bool QgsSumLineLengthAlgorithm::prepareAlgorithm( const QVariantMap &parameters,
if ( mLinesSource->hasSpatialIndex() == QgsFeatureSource::SpatialIndexNotPresent )
feedback->reportError( QObject::tr( "No spatial index exists for lines layer, performance will be severely degraded" ) );

if ( context.project() )
{
mDa.setEllipsoid( context.project()->ellipsoid() );
}
mDa.setEllipsoid( context.ellipsoid() );
mTransformContext = context.transformContext();

return true;

0 comments on commit b40bfbb

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