mirror of
https://github.com/qgis/QGIS.git
synced 2025-04-13 00:03:09 -04:00
[processing] remove Z/M addition from "random" algorithms
This commit is contained in:
parent
c7645a3884
commit
c440ade2d8
@ -34,7 +34,6 @@ from qgis.core import (QgsField,
|
||||
QgsFeature,
|
||||
QgsFields,
|
||||
QgsGeometry,
|
||||
QgsPoint,
|
||||
QgsPointXY,
|
||||
QgsWkbTypes,
|
||||
QgsSpatialIndex,
|
||||
@ -44,7 +43,6 @@ from qgis.core import (QgsField,
|
||||
QgsProcessing,
|
||||
QgsProcessingException,
|
||||
QgsProcessingParameterNumber,
|
||||
QgsProcessingParameterBoolean,
|
||||
QgsProcessingParameterFeatureSource,
|
||||
QgsProcessingParameterFeatureSink,
|
||||
QgsProcessingParameterDefinition)
|
||||
@ -58,8 +56,6 @@ class RandomPointsAlongLines(QgisAlgorithm):
|
||||
INPUT = 'INPUT'
|
||||
POINTS_NUMBER = 'POINTS_NUMBER'
|
||||
MIN_DISTANCE = 'MIN_DISTANCE'
|
||||
ADD_Z = 'ADD_Z'
|
||||
ADD_M = 'ADD_M'
|
||||
OUTPUT = 'OUTPUT'
|
||||
|
||||
def group(self):
|
||||
@ -80,17 +76,6 @@ class RandomPointsAlongLines(QgisAlgorithm):
|
||||
self.tr('Minimum distance between points'),
|
||||
QgsProcessingParameterNumber.Double,
|
||||
0, False, 0, 1000000000))
|
||||
params = []
|
||||
params.append(QgsProcessingParameterBoolean(self.ADD_Z,
|
||||
self.tr('Add Z coordinate'),
|
||||
False))
|
||||
params.append(QgsProcessingParameterBoolean(self.ADD_M,
|
||||
self.tr('Add M coordinate'),
|
||||
False))
|
||||
for p in params:
|
||||
p.setFlags(p.flags() | QgsProcessingParameterDefinition.FlagAdvanced)
|
||||
self.addParameter(p)
|
||||
|
||||
self.addParameter(QgsProcessingParameterFeatureSink(self.OUTPUT,
|
||||
self.tr('Random points'),
|
||||
type=QgsProcessing.TypeVectorPoint))
|
||||
@ -105,20 +90,12 @@ class RandomPointsAlongLines(QgisAlgorithm):
|
||||
source = self.parameterAsSource(parameters, self.INPUT, context)
|
||||
pointCount = self.parameterAsDouble(parameters, self.POINTS_NUMBER, context)
|
||||
minDistance = self.parameterAsDouble(parameters, self.MIN_DISTANCE, context)
|
||||
addZ = self.parameterAsBool(parameters, self.ADD_Z, context)
|
||||
addM = self.parameterAsBool(parameters, self.ADD_M, context)
|
||||
|
||||
fields = QgsFields()
|
||||
fields.append(QgsField('id', QVariant.Int, '', 10, 0))
|
||||
|
||||
wkbType = QgsWkbTypes.Point
|
||||
if addZ:
|
||||
wkbType = QgsWkbTypes.addZ(wkbType)
|
||||
if addM:
|
||||
wkbType = QgsWkbTypes.addM(wkbType)
|
||||
|
||||
(sink, dest_id) = self.parameterAsSink(parameters, self.OUTPUT, context,
|
||||
fields, wkbType, source.sourceCrs())
|
||||
fields, QgsWkbTypes.Point, source.sourceCrs())
|
||||
|
||||
nPoints = 0
|
||||
nIterations = 0
|
||||
@ -170,13 +147,8 @@ class RandomPointsAlongLines(QgisAlgorithm):
|
||||
ry = (startPoint.y() + d * endPoint.y()) / (1 + d)
|
||||
|
||||
# generate random point
|
||||
pnt = QgsPoint(rx, ry)
|
||||
p = QgsPointXY(rx, ry)
|
||||
if addZ:
|
||||
pnt.addZValue(0.0)
|
||||
if addM:
|
||||
pnt.addMValue(0.0)
|
||||
geom = QgsGeometry(pnt)
|
||||
geom = QgsGeometry.fromPoint(p)
|
||||
if vector.checkMinDistance(p, index, minDistance, points):
|
||||
f = QgsFeature(nPoints)
|
||||
f.initAttributes(1)
|
||||
|
@ -36,7 +36,6 @@ from qgis.core import (QgsField,
|
||||
QgsFeature,
|
||||
QgsFields,
|
||||
QgsGeometry,
|
||||
QgsPoint,
|
||||
QgsPointXY,
|
||||
QgsWkbTypes,
|
||||
QgsSpatialIndex,
|
||||
@ -45,7 +44,6 @@ from qgis.core import (QgsField,
|
||||
QgsProcessingParameterExtent,
|
||||
QgsProcessingParameterNumber,
|
||||
QgsProcessingParameterCrs,
|
||||
QgsProcessingParameterBoolean,
|
||||
QgsProcessingParameterFeatureSink,
|
||||
QgsProcessingParameterDefinition)
|
||||
|
||||
@ -61,8 +59,6 @@ class RandomPointsExtent(QgisAlgorithm):
|
||||
POINTS_NUMBER = 'POINTS_NUMBER'
|
||||
MIN_DISTANCE = 'MIN_DISTANCE'
|
||||
TARGET_CRS = 'TARGET_CRS'
|
||||
ADD_Z = 'ADD_Z'
|
||||
ADD_M = 'ADD_M'
|
||||
OUTPUT = 'OUTPUT'
|
||||
|
||||
def icon(self):
|
||||
@ -87,18 +83,6 @@ class RandomPointsExtent(QgisAlgorithm):
|
||||
self.addParameter(QgsProcessingParameterCrs(self.TARGET_CRS,
|
||||
self.tr('Target CRS'),
|
||||
'ProjectCrs'))
|
||||
|
||||
params = []
|
||||
params.append(QgsProcessingParameterBoolean(self.ADD_Z,
|
||||
self.tr('Add Z coordinate'),
|
||||
False))
|
||||
params.append(QgsProcessingParameterBoolean(self.ADD_M,
|
||||
self.tr('Add M coordinate'),
|
||||
False))
|
||||
for p in params:
|
||||
p.setFlags(p.flags() | QgsProcessingParameterDefinition.FlagAdvanced)
|
||||
self.addParameter(p)
|
||||
|
||||
self.addParameter(QgsProcessingParameterFeatureSink(self.OUTPUT,
|
||||
self.tr('Random points'),
|
||||
type=QgsProcessing.TypeVectorPoint))
|
||||
@ -114,22 +98,14 @@ class RandomPointsExtent(QgisAlgorithm):
|
||||
pointCount = self.parameterAsDouble(parameters, self.POINTS_NUMBER, context)
|
||||
minDistance = self.parameterAsDouble(parameters, self.MIN_DISTANCE, context)
|
||||
crs = self.parameterAsCrs(parameters, self.TARGET_CRS, context)
|
||||
addZ = self.parameterAsBool(parameters, self.ADD_Z, context)
|
||||
addM = self.parameterAsBool(parameters, self.ADD_M, context)
|
||||
|
||||
extent = QgsGeometry().fromRect(bbox)
|
||||
|
||||
fields = QgsFields()
|
||||
fields.append(QgsField('id', QVariant.Int, '', 10, 0))
|
||||
|
||||
wkbType = QgsWkbTypes.Point
|
||||
if addZ:
|
||||
wkbType = QgsWkbTypes.addZ(wkbType)
|
||||
if addM:
|
||||
wkbType = QgsWkbTypes.addM(wkbType)
|
||||
|
||||
(sink, dest_id) = self.parameterAsSink(parameters, self.OUTPUT, context,
|
||||
fields, wkbType, crs)
|
||||
fields, QgsWkbTypes.Point, crs)
|
||||
|
||||
nPoints = 0
|
||||
nIterations = 0
|
||||
@ -148,13 +124,8 @@ class RandomPointsExtent(QgisAlgorithm):
|
||||
rx = bbox.xMinimum() + bbox.width() * random.random()
|
||||
ry = bbox.yMinimum() + bbox.height() * random.random()
|
||||
|
||||
pnt = QgsPoint(rx, ry)
|
||||
p = QgsPointXY(rx, ry)
|
||||
if addZ:
|
||||
pnt.addZValue(0.0)
|
||||
if addM:
|
||||
pnt.addMValue(0.0)
|
||||
geom = QgsGeometry(pnt)
|
||||
geom = QgsGeometry.fromPoint(p)
|
||||
if geom.within(extent) and \
|
||||
vector.checkMinDistance(p, index, minDistance, points):
|
||||
f = QgsFeature(nPoints)
|
||||
|
@ -35,7 +35,6 @@ from qgis.core import (QgsField,
|
||||
QgsFeature,
|
||||
QgsFields,
|
||||
QgsGeometry,
|
||||
QgsPoint,
|
||||
QgsPointXY,
|
||||
QgsWkbTypes,
|
||||
QgsSpatialIndex,
|
||||
@ -43,7 +42,6 @@ from qgis.core import (QgsField,
|
||||
QgsProcessing,
|
||||
QgsProcessingException,
|
||||
QgsProcessingParameterNumber,
|
||||
QgsProcessingParameterBoolean,
|
||||
QgsProcessingParameterFeatureSource,
|
||||
QgsProcessingParameterFeatureSink,
|
||||
QgsProcessingParameterDefinition)
|
||||
@ -59,8 +57,6 @@ class RandomPointsLayer(QgisAlgorithm):
|
||||
INPUT = 'INPUT'
|
||||
POINTS_NUMBER = 'POINTS_NUMBER'
|
||||
MIN_DISTANCE = 'MIN_DISTANCE'
|
||||
ADD_Z = 'ADD_Z'
|
||||
ADD_M = 'ADD_M'
|
||||
OUTPUT = 'OUTPUT'
|
||||
|
||||
def icon(self):
|
||||
@ -84,17 +80,6 @@ class RandomPointsLayer(QgisAlgorithm):
|
||||
self.tr('Minimum distance between points'),
|
||||
QgsProcessingParameterNumber.Double,
|
||||
0, False, 0, 1000000000))
|
||||
params = []
|
||||
params.append(QgsProcessingParameterBoolean(self.ADD_Z,
|
||||
self.tr('Add Z coordinate'),
|
||||
False))
|
||||
params.append(QgsProcessingParameterBoolean(self.ADD_M,
|
||||
self.tr('Add M coordinate'),
|
||||
False))
|
||||
for p in params:
|
||||
p.setFlags(p.flags() | QgsProcessingParameterDefinition.FlagAdvanced)
|
||||
self.addParameter(p)
|
||||
|
||||
self.addParameter(QgsProcessingParameterFeatureSink(self.OUTPUT,
|
||||
self.tr('Random points'),
|
||||
type=QgsProcessing.TypeVectorPoint))
|
||||
@ -109,8 +94,6 @@ class RandomPointsLayer(QgisAlgorithm):
|
||||
source = self.parameterAsSource(parameters, self.INPUT, context)
|
||||
pointCount = self.parameterAsDouble(parameters, self.POINTS_NUMBER, context)
|
||||
minDistance = self.parameterAsDouble(parameters, self.MIN_DISTANCE, context)
|
||||
addZ = self.parameterAsBool(parameters, self.ADD_Z, context)
|
||||
addM = self.parameterAsBool(parameters, self.ADD_M, context)
|
||||
|
||||
bbox = source.sourceExtent()
|
||||
sourceIndex = QgsSpatialIndex(source, feedback)
|
||||
@ -118,14 +101,8 @@ class RandomPointsLayer(QgisAlgorithm):
|
||||
fields = QgsFields()
|
||||
fields.append(QgsField('id', QVariant.Int, '', 10, 0))
|
||||
|
||||
wkbType = QgsWkbTypes.Point
|
||||
if addZ:
|
||||
wkbType = QgsWkbTypes.addZ(wkbType)
|
||||
if addM:
|
||||
wkbType = QgsWkbTypes.addM(wkbType)
|
||||
|
||||
(sink, dest_id) = self.parameterAsSink(parameters, self.OUTPUT, context,
|
||||
fields, wkbType, source.sourceCrs())
|
||||
fields, QgsWkbTypes.Point, source.sourceCrs())
|
||||
|
||||
nPoints = 0
|
||||
nIterations = 0
|
||||
@ -144,13 +121,8 @@ class RandomPointsLayer(QgisAlgorithm):
|
||||
rx = bbox.xMinimum() + bbox.width() * random.random()
|
||||
ry = bbox.yMinimum() + bbox.height() * random.random()
|
||||
|
||||
pnt = QgsPoint(rx, ry)
|
||||
p = QgsPointXY(rx, ry)
|
||||
if addZ:
|
||||
pnt.addZValue(0.0)
|
||||
if addM:
|
||||
pnt.addMValue(0.0)
|
||||
geom = QgsGeometry(pnt)
|
||||
geom = QgsGeometry.fromPoint(p)
|
||||
ids = sourceIndex.intersects(geom.buffer(5, 5).boundingBox())
|
||||
if len(ids) > 0 and \
|
||||
vector.checkMinDistance(p, index, minDistance, points):
|
||||
|
@ -35,7 +35,6 @@ from qgis.core import (QgsField,
|
||||
QgsFeature,
|
||||
QgsFields,
|
||||
QgsGeometry,
|
||||
QgsPoint,
|
||||
QgsPointXY,
|
||||
QgsWkbTypes,
|
||||
QgsSpatialIndex,
|
||||
@ -46,7 +45,6 @@ from qgis.core import (QgsField,
|
||||
QgsProcessing,
|
||||
QgsProcessingException,
|
||||
QgsProcessingParameterNumber,
|
||||
QgsProcessingParameterBoolean,
|
||||
QgsProcessingParameterFeatureSource,
|
||||
QgsProcessingParameterFeatureSink,
|
||||
QgsProcessingParameterExpression,
|
||||
@ -65,8 +63,6 @@ class RandomPointsPolygons(QgisAlgorithm):
|
||||
EXPRESSION = 'EXPRESSION'
|
||||
MIN_DISTANCE = 'MIN_DISTANCE'
|
||||
STRATEGY = 'STRATEGY'
|
||||
ADD_Z = 'ADD_Z'
|
||||
ADD_M = 'ADD_M'
|
||||
OUTPUT = 'OUTPUT'
|
||||
|
||||
def icon(self):
|
||||
@ -97,17 +93,6 @@ class RandomPointsPolygons(QgisAlgorithm):
|
||||
self.tr('Minimum distance between points'),
|
||||
QgsProcessingParameterNumber.Double,
|
||||
0, False, 0, 1000000000))
|
||||
params = []
|
||||
params.append(QgsProcessingParameterBoolean(self.ADD_Z,
|
||||
self.tr('Add Z coordinate'),
|
||||
False))
|
||||
params.append(QgsProcessingParameterBoolean(self.ADD_M,
|
||||
self.tr('Add M coordinate'),
|
||||
False))
|
||||
for p in params:
|
||||
p.setFlags(p.flags() | QgsProcessingParameterDefinition.FlagAdvanced)
|
||||
self.addParameter(p)
|
||||
|
||||
self.addParameter(QgsProcessingParameterFeatureSink(self.OUTPUT,
|
||||
self.tr('Random points'),
|
||||
type=QgsProcessing.TypeVectorPoint))
|
||||
@ -122,8 +107,6 @@ class RandomPointsPolygons(QgisAlgorithm):
|
||||
source = self.parameterAsSource(parameters, self.INPUT, context)
|
||||
strategy = self.parameterAsEnum(parameters, self.STRATEGY, context)
|
||||
minDistance = self.parameterAsDouble(parameters, self.MIN_DISTANCE, context)
|
||||
addZ = self.parameterAsBool(parameters, self.ADD_Z, context)
|
||||
addM = self.parameterAsBool(parameters, self.ADD_M, context)
|
||||
|
||||
expression = QgsExpression(self.parameterAsString(parameters, self.EXPRESSION, context))
|
||||
if expression.hasParserError():
|
||||
@ -137,14 +120,8 @@ class RandomPointsPolygons(QgisAlgorithm):
|
||||
fields = QgsFields()
|
||||
fields.append(QgsField('id', QVariant.Int, '', 10, 0))
|
||||
|
||||
wkbType = QgsWkbTypes.Point
|
||||
if addZ:
|
||||
wkbType = QgsWkbTypes.addZ(wkbType)
|
||||
if addM:
|
||||
wkbType = QgsWkbTypes.addM(wkbType)
|
||||
|
||||
(sink, dest_id) = self.parameterAsSink(parameters, self.OUTPUT, context,
|
||||
fields, wkbType, source.sourceCrs())
|
||||
fields, QgsWkbTypes.Point, source.sourceCrs())
|
||||
|
||||
da = QgsDistanceArea()
|
||||
da.setSourceCrs(source.sourceCrs())
|
||||
@ -190,13 +167,8 @@ class RandomPointsPolygons(QgisAlgorithm):
|
||||
rx = bbox.xMinimum() + bbox.width() * random.random()
|
||||
ry = bbox.yMinimum() + bbox.height() * random.random()
|
||||
|
||||
pnt = QgsPoint(rx, ry)
|
||||
p = QgsPointXY(rx, ry)
|
||||
if addZ:
|
||||
pnt.addZValue(0.0)
|
||||
if addM:
|
||||
pnt.addMValue(0.0)
|
||||
geom = QgsGeometry(pnt)
|
||||
geom = QgsGeometry.fromPoint(p)
|
||||
if geom.within(fGeom) and \
|
||||
vector.checkMinDistance(p, index, minDistance, points):
|
||||
f = QgsFeature(nPoints)
|
||||
|
Loading…
x
Reference in New Issue
Block a user