Skip to content

Commit

Permalink
Ensure distance area is always correctly used in processing
Browse files Browse the repository at this point in the history
  • Loading branch information
nyalldawson committed Jul 15, 2017
1 parent bbe466f commit 8af7318
Show file tree
Hide file tree
Showing 6 changed files with 22 additions and 2 deletions.
6 changes: 5 additions & 1 deletion python/plugins/processing/algs/qgis/PointDistance.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@

from qgis.PyQt.QtGui import QIcon

from qgis.core import QgsFeatureRequest, QgsDistanceArea, QgsFeatureSink, QgsProcessingUtils
from qgis.core import QgsFeatureRequest, QgsProject, QgsDistanceArea, QgsFeatureSink, QgsProcessingUtils

from processing.algs.qgis.QgisAlgorithm import QgisAlgorithm
from processing.core.parameters import ParameterNumber
Expand Down Expand Up @@ -134,6 +134,8 @@ def linearMatrix(self, context, inLayer, inField, targetLayer, targetField,
outIdx = targetLayer.fields().lookupField(targetField)

distArea = QgsDistanceArea()
distArea.setSourceCrs(inLayer.crs())
distArea.setEllipsoid(QgsProject.instance().ellipsoid())

features = QgsProcessingUtils.getFeatures(inLayer, context)
total = 100.0 / inLayer.featureCount() if inLayer.featureCount() else 0
Expand Down Expand Up @@ -172,6 +174,8 @@ def regularMatrix(self, context, inLayer, inField, targetLayer, targetField,
inIdx = inLayer.fields().lookupField(inField)

distArea = QgsDistanceArea()
distArea.setSourceCrs(inLayer.sourceCrs())
distArea.setEllipsoid(QgsProject.instance().ellipsoid())

first = True
features = QgsProcessingUtils.getFeatures(inLayer, context)
Expand Down
3 changes: 3 additions & 0 deletions python/plugins/processing/algs/qgis/PointsToPaths.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
QgsField,
QgsGeometry,
QgsDistanceArea,
QgsProject,
QgsWkbTypes,
QgsProcessingUtils)

Expand Down Expand Up @@ -120,6 +121,8 @@ def processAlgorithm(self, parameters, context, feedback):
feedback.setProgress(0)

da = QgsDistanceArea()
da.setSourceCrs(layer.sourceCrs())
da.setEllipsoid(QgsProject.instance().ellipsoid())

current = 0
total = 100.0 / len(points) if points else 1
Expand Down
4 changes: 4 additions & 0 deletions python/plugins/processing/algs/qgis/RandomPointsAlongLines.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@
QgsFeature,
QgsPointXY,
QgsMessageLog,
QgsProject,
QgsProcessingUtils)

from processing.algs.qgis.QgisAlgorithm import QgisAlgorithm
Expand Down Expand Up @@ -97,6 +98,9 @@ def processAlgorithm(self, parameters, context, feedback):
points = dict()

da = QgsDistanceArea()
da.setSourceCrs(layer.sourceCrs())
da.setEllipsoid(QgsProject.instance().ellipsoid())

request = QgsFeatureRequest()

random.seed()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,8 @@
from qgis.core import (QgsFields, QgsFeatureSink, QgsField, QgsDistanceArea, QgsGeometry, QgsWkbTypes,
QgsSpatialIndex, QgsPointXY, QgsFeature,
QgsMessageLog,
QgsProcessingUtils)
QgsProcessingUtils,
QgsProject)

from processing.algs.qgis.QgisAlgorithm import QgisAlgorithm
from processing.core.parameters import ParameterVector
Expand Down Expand Up @@ -94,6 +95,8 @@ def processAlgorithm(self, parameters, context, feedback):
writer = self.getOutputFromName(self.OUTPUT).getVectorWriter(fields, QgsWkbTypes.Point, layer.crs(), context)

da = QgsDistanceArea()
da.setSourceCrs(layer.sourceCrs())
da.setEllipsoid(QgsProject.instance().ellipsoid())

features = QgsProcessingUtils.getFeatures(layer, context)
for current, f in enumerate(features):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
from qgis.core import (QgsFields, QgsFeatureSink, QgsField, QgsFeature, QgsPointXY, QgsWkbTypes,
QgsGeometry, QgsSpatialIndex, QgsDistanceArea,
QgsMessageLog,
QgsProject,
QgsProcessingUtils)

from processing.algs.qgis.QgisAlgorithm import QgisAlgorithm
Expand Down Expand Up @@ -95,6 +96,8 @@ def processAlgorithm(self, parameters, context, feedback):
writer = self.getOutputFromName(self.OUTPUT).getVectorWriter(fields, QgsWkbTypes.Point, layer.crs(), context)

da = QgsDistanceArea()
da.setSourceCrs(layer.sourceCrs())
da.setEllipsoid(QgsProject.instance().ellipsoid())

features = QgsProcessingUtils.getFeatures(layer, context)
for current, f in enumerate(features):
Expand Down
3 changes: 3 additions & 0 deletions python/plugins/processing/algs/qgis/SumLines.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
QgsGeometry,
QgsFeatureRequest,
QgsDistanceArea,
QgsProject,
QgsProcessing,
QgsProcessingParameterString,
QgsProcessingParameterFeatureSource,
Expand Down Expand Up @@ -103,6 +104,8 @@ def processAlgorithm(self, parameters, context, feedback):
QgsFeatureRequest().setSubsetOfAttributes([]).setDestinationCrs(poly_source.sourceCrs())))

distArea = QgsDistanceArea()
distArea.setSourceCrs(poly_source.sourceCrs())
distArea.setEllipsoid(QgsProject.instance().ellipsoid())

features = poly_source.getFeatures()
total = 100.0 / poly_source.featureCount() if poly_source.featureCount() else 0
Expand Down

0 comments on commit 8af7318

Please sign in to comment.