mirror of
https://github.com/qgis/QGIS.git
synced 2025-11-22 00:14:55 -05:00
Remove deprecated algorithms
Removed: - Basic Stats for Numbers/String algs (replaced by generic Basic Stats alg) - Split Lines with Lines (replaced by generic Split with lines) - Vector Grid Lines/Polygons (replaced by other create grid algs)
This commit is contained in:
parent
2d3d9b4ce7
commit
432dd9dd90
@ -1,197 +0,0 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
|
||||
"""
|
||||
***************************************************************************
|
||||
BasicStatisticsNumbers.py
|
||||
---------------------
|
||||
Date : September 2012
|
||||
Copyright : (C) 2012 by Victor Olaya
|
||||
Email : volayaf at gmail dot com
|
||||
***************************************************************************
|
||||
* *
|
||||
* This program is free software; you can redistribute it and/or modify *
|
||||
* it under the terms of the GNU General Public License as published by *
|
||||
* the Free Software Foundation; either version 2 of the License, or *
|
||||
* (at your option) any later version. *
|
||||
* *
|
||||
***************************************************************************
|
||||
"""
|
||||
from builtins import str
|
||||
|
||||
__author__ = 'Victor Olaya'
|
||||
__date__ = 'September 2012'
|
||||
__copyright__ = '(C) 2012, Victor Olaya'
|
||||
|
||||
# This will get replaced with a git SHA1 when you do a git archive
|
||||
|
||||
__revision__ = '$Format:%H$'
|
||||
|
||||
import os
|
||||
import codecs
|
||||
|
||||
from qgis.PyQt.QtGui import QIcon
|
||||
|
||||
from qgis.core import (QgsStatisticalSummary,
|
||||
QgsFeatureRequest,
|
||||
QgsProcessingAlgorithm,
|
||||
QgsProcessingUtils)
|
||||
|
||||
from processing.algs.qgis.QgisAlgorithm import QgisAlgorithm
|
||||
from processing.core.parameters import ParameterTable
|
||||
from processing.core.parameters import ParameterTableField
|
||||
from processing.core.outputs import OutputHTML
|
||||
from processing.core.outputs import OutputNumber
|
||||
|
||||
pluginPath = os.path.split(os.path.split(os.path.dirname(__file__))[0])[0]
|
||||
|
||||
|
||||
class BasicStatisticsNumbers(QgisAlgorithm):
|
||||
|
||||
INPUT_LAYER = 'INPUT_LAYER'
|
||||
FIELD_NAME = 'FIELD_NAME'
|
||||
OUTPUT_HTML_FILE = 'OUTPUT_HTML_FILE'
|
||||
|
||||
CV = 'CV'
|
||||
MIN = 'MIN'
|
||||
MAX = 'MAX'
|
||||
SUM = 'SUM'
|
||||
MEAN = 'MEAN'
|
||||
COUNT = 'COUNT'
|
||||
STD_DEV = 'STD_DEV'
|
||||
RANGE = 'RANGE'
|
||||
MEDIAN = 'MEDIAN'
|
||||
UNIQUE = 'UNIQUE'
|
||||
MINORITY = 'MINORITY'
|
||||
MAJORITY = 'MAJORITY'
|
||||
FIRSTQUARTILE = 'FIRSTQUARTILE'
|
||||
THIRDQUARTILE = 'THIRDQUARTILE'
|
||||
NULLVALUES = 'NULLVALUES'
|
||||
IQR = 'IQR'
|
||||
|
||||
def flags(self):
|
||||
# this algorithm is deprecated - use BasicStatistics instead
|
||||
return QgsProcessingAlgorithm.FlagDeprecated
|
||||
|
||||
def icon(self):
|
||||
return QIcon(os.path.join(pluginPath, 'images', 'ftools', 'basic_statistics.png'))
|
||||
|
||||
def tags(self):
|
||||
return self.tr('stats,statistics,number,table,layer').split(',')
|
||||
|
||||
def group(self):
|
||||
return self.tr('Vector table tools')
|
||||
|
||||
def __init__(self):
|
||||
super().__init__()
|
||||
self.addParameter(ParameterTable(self.INPUT_LAYER,
|
||||
self.tr('Input vector layer')))
|
||||
self.addParameter(ParameterTableField(self.FIELD_NAME,
|
||||
self.tr('Field to calculate statistics on'),
|
||||
self.INPUT_LAYER, ParameterTableField.DATA_TYPE_NUMBER))
|
||||
|
||||
self.addOutput(OutputHTML(self.OUTPUT_HTML_FILE,
|
||||
self.tr('Statistics')))
|
||||
|
||||
self.addOutput(OutputNumber(self.CV, self.tr('Coefficient of Variation')))
|
||||
self.addOutput(OutputNumber(self.MIN, self.tr('Minimum value')))
|
||||
self.addOutput(OutputNumber(self.MAX, self.tr('Maximum value')))
|
||||
self.addOutput(OutputNumber(self.SUM, self.tr('Sum')))
|
||||
self.addOutput(OutputNumber(self.MEAN, self.tr('Mean value')))
|
||||
self.addOutput(OutputNumber(self.STD_DEV, self.tr('Standard deviation')))
|
||||
self.addOutput(OutputNumber(self.COUNT, self.tr('Count')))
|
||||
self.addOutput(OutputNumber(self.RANGE, self.tr('Range')))
|
||||
self.addOutput(OutputNumber(self.MEDIAN, self.tr('Median')))
|
||||
self.addOutput(OutputNumber(self.UNIQUE, self.tr('Number of unique values')))
|
||||
self.addOutput(OutputNumber(self.MINORITY, self.tr('Minority (rarest occurring value)')))
|
||||
self.addOutput(OutputNumber(self.MAJORITY, self.tr('Majority (most frequently occurring value)')))
|
||||
self.addOutput(OutputNumber(self.FIRSTQUARTILE, self.tr('First quartile')))
|
||||
self.addOutput(OutputNumber(self.THIRDQUARTILE, self.tr('Third quartile')))
|
||||
self.addOutput(OutputNumber(self.NULLVALUES, self.tr('NULL (missed) values')))
|
||||
self.addOutput(OutputNumber(self.IQR, self.tr('Interquartile Range (IQR)')))
|
||||
|
||||
def name(self):
|
||||
return 'basicstatisticsfornumericfields'
|
||||
|
||||
def displayName(self):
|
||||
return self.tr('Basic statistics for numeric fields')
|
||||
|
||||
def processAlgorithm(self, parameters, context, feedback):
|
||||
layer = QgsProcessingUtils.mapLayerFromString(self.getParameterValue(self.INPUT_LAYER), context)
|
||||
fieldName = self.getParameterValue(self.FIELD_NAME)
|
||||
|
||||
outputFile = self.getOutputValue(self.OUTPUT_HTML_FILE)
|
||||
|
||||
request = QgsFeatureRequest().setFlags(QgsFeatureRequest.NoGeometry).setSubsetOfAttributes([fieldName], layer.fields())
|
||||
stat = QgsStatisticalSummary()
|
||||
features = QgsProcessingUtils.getFeatures(layer, context, request)
|
||||
count = QgsProcessingUtils.featureCount(layer, context)
|
||||
total = 100.0 / float(count)
|
||||
for current, ft in enumerate(features):
|
||||
stat.addVariant(ft[fieldName])
|
||||
feedback.setProgress(int(current * total))
|
||||
|
||||
stat.finalize()
|
||||
|
||||
count = stat.count()
|
||||
uniqueValue = stat.variety()
|
||||
minValue = stat.min()
|
||||
maxValue = stat.max()
|
||||
rValue = stat.range()
|
||||
sumValue = stat.sum()
|
||||
meanValue = stat.mean()
|
||||
medianValue = stat.median()
|
||||
stdDevValue = stat.stDev()
|
||||
cvValue = stdDevValue / meanValue if meanValue != 0 else 0
|
||||
minority = stat.minority()
|
||||
majority = stat.majority()
|
||||
firstQuartile = stat.firstQuartile()
|
||||
thirdQuartile = stat.thirdQuartile()
|
||||
iqr = stat.interQuartileRange()
|
||||
nullValues = stat.countMissing()
|
||||
|
||||
data = []
|
||||
data.append(self.tr('Analyzed layer: {}').format(layer.name()))
|
||||
data.append(self.tr('Analyzed field: {}').format(fieldName))
|
||||
data.append(self.tr('Count: {}').format(count))
|
||||
data.append(self.tr('Unique values: {}').format(uniqueValue))
|
||||
data.append(self.tr('Minimum value: {}').format(minValue))
|
||||
data.append(self.tr('Maximum value: {}').format(maxValue))
|
||||
data.append(self.tr('Range: {}').format(rValue))
|
||||
data.append(self.tr('Sum: {}').format(sumValue))
|
||||
data.append(self.tr('Mean value: {}').format(meanValue))
|
||||
data.append(self.tr('Median value: {}').format(medianValue))
|
||||
data.append(self.tr('Standard deviation: {}').format(stdDevValue))
|
||||
data.append(self.tr('Coefficient of Variation: {}').format(cvValue))
|
||||
data.append(self.tr('Minority (rarest occurring value): {}').format(minority))
|
||||
data.append(self.tr('Majority (most frequently occurring value): {}').format(majority))
|
||||
data.append(self.tr('First quartile: {}').format(firstQuartile))
|
||||
data.append(self.tr('Third quartile: {}').format(thirdQuartile))
|
||||
data.append(self.tr('NULL (missing) values: {}').format(nullValues))
|
||||
data.append(self.tr('Interquartile Range (IQR): {}').format(iqr))
|
||||
|
||||
self.createHTML(outputFile, data)
|
||||
|
||||
self.setOutputValue(self.COUNT, count)
|
||||
self.setOutputValue(self.UNIQUE, uniqueValue)
|
||||
self.setOutputValue(self.MIN, minValue)
|
||||
self.setOutputValue(self.MAX, maxValue)
|
||||
self.setOutputValue(self.RANGE, rValue)
|
||||
self.setOutputValue(self.SUM, sumValue)
|
||||
self.setOutputValue(self.MEAN, meanValue)
|
||||
self.setOutputValue(self.MEDIAN, medianValue)
|
||||
self.setOutputValue(self.STD_DEV, stdDevValue)
|
||||
self.setOutputValue(self.MINORITY, minority)
|
||||
self.setOutputValue(self.MAJORITY, majority)
|
||||
self.setOutputValue(self.FIRSTQUARTILE, firstQuartile)
|
||||
self.setOutputValue(self.THIRDQUARTILE, thirdQuartile)
|
||||
self.setOutputValue(self.NULLVALUES, nullValues)
|
||||
self.setOutputValue(self.IQR, iqr)
|
||||
|
||||
def createHTML(self, outputFile, algData):
|
||||
with codecs.open(outputFile, 'w', encoding='utf-8') as f:
|
||||
f.write('<html><head>\n')
|
||||
f.write('<meta http-equiv="Content-Type" content="text/html; \
|
||||
charset=utf-8" /></head><body>\n')
|
||||
for s in algData:
|
||||
f.write('<p>' + str(s) + '</p>\n')
|
||||
f.write('</body></html>\n')
|
||||
@ -1,153 +0,0 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
|
||||
"""
|
||||
***************************************************************************
|
||||
BasicStatisticsStrings.py
|
||||
---------------------
|
||||
Date : September 2012
|
||||
Copyright : (C) 2012 by Victor Olaya
|
||||
Email : volayaf at gmail dot com
|
||||
***************************************************************************
|
||||
* *
|
||||
* This program is free software; you can redistribute it and/or modify *
|
||||
* it under the terms of the GNU General Public License as published by *
|
||||
* the Free Software Foundation; either version 2 of the License, or *
|
||||
* (at your option) any later version. *
|
||||
* *
|
||||
***************************************************************************
|
||||
"""
|
||||
from builtins import str
|
||||
|
||||
__author__ = 'Victor Olaya'
|
||||
__date__ = 'September 2012'
|
||||
__copyright__ = '(C) 2012, Victor Olaya'
|
||||
|
||||
# This will get replaced with a git SHA1 when you do a git archive
|
||||
|
||||
__revision__ = '$Format:%H$'
|
||||
|
||||
import os
|
||||
import codecs
|
||||
|
||||
from qgis.PyQt.QtGui import QIcon
|
||||
|
||||
from qgis.core import (QgsProcessingAlgorithm,
|
||||
QgsStringStatisticalSummary,
|
||||
QgsFeatureRequest,
|
||||
QgsProcessingUtils)
|
||||
|
||||
from processing.algs.qgis.QgisAlgorithm import QgisAlgorithm
|
||||
from processing.core.parameters import ParameterTable
|
||||
from processing.core.parameters import ParameterTableField
|
||||
from processing.core.outputs import OutputHTML
|
||||
from processing.core.outputs import OutputNumber
|
||||
|
||||
pluginPath = os.path.split(os.path.split(os.path.dirname(__file__))[0])[0]
|
||||
|
||||
|
||||
class BasicStatisticsStrings(QgisAlgorithm):
|
||||
|
||||
INPUT_LAYER = 'INPUT_LAYER'
|
||||
FIELD_NAME = 'FIELD_NAME'
|
||||
OUTPUT_HTML_FILE = 'OUTPUT_HTML_FILE'
|
||||
|
||||
MIN_LEN = 'MIN_LEN'
|
||||
MAX_LEN = 'MAX_LEN'
|
||||
MEAN_LEN = 'MEAN_LEN'
|
||||
COUNT = 'COUNT'
|
||||
EMPTY = 'EMPTY'
|
||||
FILLED = 'FILLED'
|
||||
UNIQUE = 'UNIQUE'
|
||||
MIN_VALUE = 'MIN_VALUE'
|
||||
MAX_VALUE = 'MAX_VALUE'
|
||||
|
||||
def flags(self):
|
||||
# this algorithm is deprecated - use BasicStatistics instead
|
||||
return QgsProcessingAlgorithm.FlagDeprecated
|
||||
|
||||
def icon(self):
|
||||
return QIcon(os.path.join(pluginPath, 'images', 'ftools', 'basic_statistics.png'))
|
||||
|
||||
def tags(self):
|
||||
return self.tr('stats,statistics,string,table,layer').split(',')
|
||||
|
||||
def group(self):
|
||||
return self.tr('Vector table tools')
|
||||
|
||||
def __init__(self):
|
||||
super().__init__()
|
||||
self.addParameter(ParameterTable(self.INPUT_LAYER,
|
||||
self.tr('Input vector layer')))
|
||||
self.addParameter(ParameterTableField(self.FIELD_NAME,
|
||||
self.tr('Field to calculate statistics on'),
|
||||
self.INPUT_LAYER, ParameterTableField.DATA_TYPE_STRING))
|
||||
|
||||
self.addOutput(OutputHTML(self.OUTPUT_HTML_FILE,
|
||||
self.tr('Statistics for text')))
|
||||
|
||||
self.addOutput(OutputNumber(self.MIN_LEN, self.tr('Minimum length')))
|
||||
self.addOutput(OutputNumber(self.MAX_LEN, self.tr('Maximum length')))
|
||||
self.addOutput(OutputNumber(self.MEAN_LEN, self.tr('Mean length')))
|
||||
self.addOutput(OutputNumber(self.COUNT, self.tr('Count')))
|
||||
self.addOutput(OutputNumber(self.EMPTY, self.tr('Number of empty values')))
|
||||
self.addOutput(OutputNumber(self.FILLED, self.tr('Number of non-empty values')))
|
||||
self.addOutput(OutputNumber(self.UNIQUE, self.tr('Number of unique values')))
|
||||
self.addOutput(OutputNumber(self.MIN_VALUE, self.tr('Minimum string value')))
|
||||
self.addOutput(OutputNumber(self.MAX_VALUE, self.tr('Maximum string value')))
|
||||
|
||||
def name(self):
|
||||
return 'basicstatisticsfortextfields'
|
||||
|
||||
def displayName(self):
|
||||
return self.tr('Basic statistics for text fields')
|
||||
|
||||
def processAlgorithm(self, parameters, context, feedback):
|
||||
layer = QgsProcessingUtils.mapLayerFromString(self.getParameterValue(self.INPUT_LAYER), context)
|
||||
fieldName = self.getParameterValue(self.FIELD_NAME)
|
||||
|
||||
outputFile = self.getOutputValue(self.OUTPUT_HTML_FILE)
|
||||
|
||||
request = QgsFeatureRequest().setFlags(QgsFeatureRequest.NoGeometry).setSubsetOfAttributes([fieldName],
|
||||
layer.fields())
|
||||
stat = QgsStringStatisticalSummary()
|
||||
features = QgsProcessingUtils.getFeatures(layer, context, request)
|
||||
count = QgsProcessingUtils.featureCount(layer, context)
|
||||
total = 100.0 / float(count)
|
||||
for current, ft in enumerate(features):
|
||||
stat.addValue(ft[fieldName])
|
||||
feedback.setProgress(int(current * total))
|
||||
|
||||
stat.finalize()
|
||||
|
||||
data = []
|
||||
data.append(self.tr('Analyzed layer: {}').format(layer.name()))
|
||||
data.append(self.tr('Analyzed field: {}').format(fieldName))
|
||||
data.append(self.tr('Minimum length: {}').format(stat.minLength()))
|
||||
data.append(self.tr('Maximum length: {}').format(stat.maxLength()))
|
||||
data.append(self.tr('Mean length: {}').format(stat.meanLength()))
|
||||
data.append(self.tr('Filled values: {}').format(stat.count() - stat.countMissing()))
|
||||
data.append(self.tr('NULL (missing) values: {}').format(stat.countMissing()))
|
||||
data.append(self.tr('Count: {}').format(stat.count()))
|
||||
data.append(self.tr('Unique: {}').format(stat.countDistinct()))
|
||||
data.append(self.tr('Minimum string value: {}').format(stat.min()))
|
||||
data.append(self.tr('Maximum string value: {}').format(stat.max()))
|
||||
|
||||
self.createHTML(outputFile, data)
|
||||
|
||||
self.setOutputValue(self.MIN_LEN, stat.minLength())
|
||||
self.setOutputValue(self.MAX_LEN, stat.maxLength())
|
||||
self.setOutputValue(self.MEAN_LEN, stat.meanLength())
|
||||
self.setOutputValue(self.FILLED, stat.count() - stat.countMissing())
|
||||
self.setOutputValue(self.EMPTY, stat.countMissing())
|
||||
self.setOutputValue(self.COUNT, stat.count())
|
||||
self.setOutputValue(self.UNIQUE, stat.countDistinct())
|
||||
self.setOutputValue(self.MIN_VALUE, stat.min())
|
||||
self.setOutputValue(self.MAX_VALUE, stat.max())
|
||||
|
||||
def createHTML(self, outputFile, algData):
|
||||
with codecs.open(outputFile, 'w', encoding='utf-8') as f:
|
||||
f.write('<html><head>\n')
|
||||
f.write('<meta http-equiv="Content-Type" content="text/html; charset=utf-8" /></head><body>\n')
|
||||
for s in algData:
|
||||
f.write('<p>' + str(s) + '</p>\n')
|
||||
f.write('</body></html>\n')
|
||||
@ -43,8 +43,6 @@ from .QgisAlgorithm import QgisAlgorithm
|
||||
# from .RegularPoints import RegularPoints
|
||||
# from .SymmetricalDifference import SymmetricalDifference
|
||||
# from .VectorSplit import VectorSplit
|
||||
# from .VectorGridLines import VectorGridLines
|
||||
# from .VectorGridPolygons import VectorGridPolygons
|
||||
# from .RandomExtract import RandomExtract
|
||||
# from .RandomExtractWithinSubsets import RandomExtractWithinSubsets
|
||||
# from .ExtractByLocation import ExtractByLocation
|
||||
@ -52,8 +50,6 @@ from .QgisAlgorithm import QgisAlgorithm
|
||||
# from .PointsInPolygonUnique import PointsInPolygonUnique
|
||||
# from .PointsInPolygonWeighted import PointsInPolygonWeighted
|
||||
# from .SumLines import SumLines
|
||||
# from .BasicStatisticsNumbers import BasicStatisticsNumbers
|
||||
# from .BasicStatisticsStrings import BasicStatisticsStrings
|
||||
# from .NearestNeighbourAnalysis import NearestNeighbourAnalysis
|
||||
# from .LinesIntersection import LinesIntersection
|
||||
# from .MeanCoords import MeanCoords
|
||||
@ -126,7 +122,6 @@ from .AutoincrementalField import AutoincrementalField
|
||||
# from .SelectByAttributeSum import SelectByAttributeSum
|
||||
# from .HypsometricCurves import HypsometricCurves
|
||||
# from .SplitWithLines import SplitWithLines
|
||||
# from .SplitLinesWithLines import SplitLinesWithLines
|
||||
# from .FieldsMapper import FieldsMapper
|
||||
# from .Datasources2Vrt import Datasources2Vrt
|
||||
from .CheckValidity import CheckValidity
|
||||
@ -192,7 +187,6 @@ class QGISAlgorithmProvider(QgsProcessingProvider):
|
||||
def getAlgs(self):
|
||||
# algs = [SumLines(), PointsInPolygon(),
|
||||
# PointsInPolygonWeighted(), PointsInPolygonUnique(),
|
||||
# BasicStatisticsStrings(), BasicStatisticsNumbers(),
|
||||
# NearestNeighbourAnalysis(), MeanCoords(),
|
||||
# LinesIntersection(), UniqueValues(), PointDistance(),
|
||||
# ExportGeometryInfo(),
|
||||
@ -206,7 +200,7 @@ class QGISAlgorithmProvider(QgsProcessingProvider):
|
||||
# SelectByLocation(), RandomExtract(),
|
||||
# RandomExtractWithinSubsets(), ExtractByLocation(),
|
||||
# SpatialJoin(), RegularPoints(), SymmetricalDifference(),
|
||||
# VectorSplit(), VectorGridLines(), VectorGridPolygons(),
|
||||
# VectorSplit(),
|
||||
# DeleteDuplicateGeometries(), TextToFloat(),
|
||||
# SelectByAttribute(),
|
||||
# GridLine(), Gridify(), HubDistancePoints(),
|
||||
@ -226,7 +220,7 @@ class QGISAlgorithmProvider(QgsProcessingProvider):
|
||||
# PostGISExecuteSQL(), ImportIntoPostGIS(),
|
||||
# SetVectorStyle(), SetRasterStyle(),
|
||||
# SelectByExpression(), HypsometricCurves(),
|
||||
# SplitWithLines(), SplitLinesWithLines(), CreateConstantRaster(),
|
||||
# SplitWithLines(), CreateConstantRaster(),
|
||||
# FieldsMapper(), SelectByAttributeSum(), Datasources2Vrt(),
|
||||
# OrientedMinimumBoundingBox(), Smooth(),
|
||||
# ReverseLineDirection(), SpatialIndex(), DefineProjection(),
|
||||
|
||||
@ -1,173 +0,0 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
|
||||
"""
|
||||
***************************************************************************
|
||||
SplitLinesWithLines.py
|
||||
DEPRECATED, replaced by SplitWithLines.py
|
||||
---------------------
|
||||
Date : November 2014
|
||||
Revised : November 2016
|
||||
Copyright : (C) 2014 by Bernhard Ströbl
|
||||
Email : bernhard dot stroebl at jena dot de
|
||||
***************************************************************************
|
||||
* *
|
||||
* This program is free software; you can redistribute it and/or modify *
|
||||
* it under the terms of the GNU General Public License as published by *
|
||||
* the Free Software Foundation; either version 2 of the License, or *
|
||||
* (at your option) any later version. *
|
||||
* *
|
||||
***************************************************************************
|
||||
"""
|
||||
|
||||
__author__ = 'Bernhard Ströbl'
|
||||
__date__ = 'November 2014'
|
||||
__copyright__ = '(C) 2014, Bernhard Ströbl'
|
||||
|
||||
# This will get replaced with a git SHA1 when you do a git archive
|
||||
|
||||
__revision__ = '$Format:%H$'
|
||||
|
||||
from qgis.core import (QgsProcessingAlgorithm,
|
||||
QgsApplication,
|
||||
QgsFeatureRequest,
|
||||
QgsFeature,
|
||||
QgsGeometry,
|
||||
QgsWkbTypes,
|
||||
QgsMessageLog,
|
||||
QgsProcessingUtils)
|
||||
from processing.algs.qgis.QgisAlgorithm import QgisAlgorithm
|
||||
from processing.core.parameters import ParameterVector
|
||||
from processing.core.outputs import OutputVector
|
||||
from processing.tools import dataobjects
|
||||
from processing.tools import vector
|
||||
|
||||
|
||||
class SplitLinesWithLines(QgisAlgorithm):
|
||||
|
||||
INPUT_A = 'INPUT_A'
|
||||
INPUT_B = 'INPUT_B'
|
||||
|
||||
OUTPUT = 'OUTPUT'
|
||||
|
||||
def flags(self):
|
||||
# this algorithm is deprecated - use SplitWithLines instead
|
||||
return QgsProcessingAlgorithm.FlagDeprecated
|
||||
|
||||
def icon(self):
|
||||
return QgsApplication.getThemeIcon("/providerQgis.svg")
|
||||
|
||||
def svgIconPath(self):
|
||||
return QgsApplication.iconPath("providerQgis.svg")
|
||||
|
||||
def group(self):
|
||||
return self.tr('Vector overlay tools')
|
||||
|
||||
def __init__(self):
|
||||
super().__init__()
|
||||
self.addParameter(ParameterVector(self.INPUT_A,
|
||||
self.tr('Input layer'), [dataobjects.TYPE_VECTOR_LINE]))
|
||||
self.addParameter(ParameterVector(self.INPUT_B,
|
||||
self.tr('Split layer'), [dataobjects.TYPE_VECTOR_LINE]))
|
||||
self.addOutput(OutputVector(self.OUTPUT, self.tr('Split'), datatype=[dataobjects.TYPE_VECTOR_LINE]))
|
||||
|
||||
def name(self):
|
||||
return 'splitlineswithlines'
|
||||
|
||||
def displayName(self):
|
||||
return self.tr('Split lines with lines')
|
||||
|
||||
def processAlgorithm(self, parameters, context, feedback):
|
||||
layerA = QgsProcessingUtils.mapLayerFromString(self.getParameterValue(self.INPUT_A), context)
|
||||
layerB = QgsProcessingUtils.mapLayerFromString(self.getParameterValue(self.INPUT_B), context)
|
||||
|
||||
sameLayer = self.getParameterValue(self.INPUT_A) == self.getParameterValue(self.INPUT_B)
|
||||
fieldList = layerA.fields()
|
||||
|
||||
writer = self.getOutputFromName(self.OUTPUT).getVectorWriter(fieldList, QgsWkbTypes.LineString, layerA.crs(),
|
||||
context)
|
||||
|
||||
spatialIndex = QgsProcessingUtils.createSpatialIndex(layerB, context)
|
||||
|
||||
outFeat = QgsFeature()
|
||||
features = QgsProcessingUtils.getFeatures(layerA, context)
|
||||
total = 100.0 / QgsProcessingUtils.featureCount(layerA, context)
|
||||
|
||||
for current, inFeatA in enumerate(features):
|
||||
inGeom = inFeatA.geometry()
|
||||
attrsA = inFeatA.attributes()
|
||||
outFeat.setAttributes(attrsA)
|
||||
inLines = [inGeom]
|
||||
lines = spatialIndex.intersects(inGeom.boundingBox())
|
||||
|
||||
engine = None
|
||||
if len(lines) > 0:
|
||||
# use prepared geometries for faster intersection tests
|
||||
engine = QgsGeometry.createGeometryEngine(inGeom.geometry())
|
||||
engine.prepareGeometry()
|
||||
|
||||
if len(lines) > 0: # hasIntersections
|
||||
splittingLines = []
|
||||
|
||||
request = QgsFeatureRequest().setFilterFids(lines).setSubsetOfAttributes([])
|
||||
for inFeatB in layerB.getFeatures(request):
|
||||
# check if trying to self-intersect
|
||||
if sameLayer:
|
||||
if inFeatA.id() == inFeatB.id():
|
||||
continue
|
||||
|
||||
splitGeom = inFeatB.geometry()
|
||||
|
||||
if engine.intersects(splitGeom.geometry()):
|
||||
splittingLines.append(splitGeom)
|
||||
|
||||
if len(splittingLines) > 0:
|
||||
for splitGeom in splittingLines:
|
||||
splitterPList = vector.extractPoints(splitGeom)
|
||||
outLines = []
|
||||
|
||||
split_geom_engine = QgsGeometry.createGeometryEngine(splitGeom.geometry())
|
||||
split_geom_engine.prepareGeometry()
|
||||
|
||||
while len(inLines) > 0:
|
||||
inGeom = inLines.pop()
|
||||
inPoints = vector.extractPoints(inGeom)
|
||||
|
||||
if split_geom_engine.intersects(inGeom.geometry()):
|
||||
try:
|
||||
result, newGeometries, topoTestPoints = inGeom.splitGeometry(splitterPList, False)
|
||||
except:
|
||||
QgsMessageLog.logMessage(self.tr('Geometry exception while splitting'),
|
||||
self.tr('Processing'), QgsMessageLog.WARNING)
|
||||
result = 1
|
||||
|
||||
# splitGeometry: If there are several intersections
|
||||
# between geometry and splitLine, only the first one is considered.
|
||||
if result == 0: # split occurred
|
||||
|
||||
if inPoints == vector.extractPoints(inGeom):
|
||||
# bug in splitGeometry: sometimes it returns 0 but
|
||||
# the geometry is unchanged
|
||||
outLines.append(inGeom)
|
||||
else:
|
||||
inLines.append(inGeom)
|
||||
|
||||
for aNewGeom in newGeometries:
|
||||
inLines.append(aNewGeom)
|
||||
else:
|
||||
outLines.append(inGeom)
|
||||
else:
|
||||
outLines.append(inGeom)
|
||||
|
||||
inLines = outLines
|
||||
|
||||
for aLine in inLines:
|
||||
if len(aLine.asPolyline()) > 2 or \
|
||||
(len(aLine.asPolyline()) == 2 and
|
||||
aLine.asPolyline()[0] != aLine.asPolyline()[1]):
|
||||
# sometimes splitting results in lines of zero length
|
||||
outFeat.setGeometry(aLine)
|
||||
writer.addFeature(outFeat)
|
||||
|
||||
feedback.setProgress(int(current * total))
|
||||
|
||||
del writer
|
||||
@ -1,148 +0,0 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
|
||||
"""
|
||||
***************************************************************************
|
||||
VectorGridLines.py
|
||||
---------------------
|
||||
Date : September 2014
|
||||
Copyright : (C) 2014 by Alexander Bruy
|
||||
Email : alexander dot bruy at gmail dot com
|
||||
***************************************************************************
|
||||
* *
|
||||
* This program is free software; you can redistribute it and/or modify *
|
||||
* it under the terms of the GNU General Public License as published by *
|
||||
* the Free Software Foundation; either version 2 of the License, or *
|
||||
* (at your option) any later version. *
|
||||
* *
|
||||
***************************************************************************
|
||||
"""
|
||||
|
||||
__author__ = 'Alexander Bruy'
|
||||
__date__ = 'September 2014'
|
||||
__copyright__ = '(C) 2014, Alexander Bruy'
|
||||
|
||||
# This will get replaced with a git SHA1 when you do a git archive
|
||||
|
||||
__revision__ = '$Format:%H$'
|
||||
|
||||
import os
|
||||
import math
|
||||
|
||||
from qgis.PyQt.QtGui import QIcon
|
||||
from qgis.PyQt.QtCore import QVariant
|
||||
|
||||
from qgis.core import (QgsProcessingAlgorithm,
|
||||
QgsRectangle,
|
||||
QgsFields,
|
||||
QgsField,
|
||||
QgsFeature,
|
||||
QgsGeometry,
|
||||
QgsPointXY,
|
||||
QgsWkbTypes)
|
||||
from qgis.utils import iface
|
||||
|
||||
from processing.algs.qgis.QgisAlgorithm import QgisAlgorithm
|
||||
from processing.core.parameters import ParameterExtent
|
||||
from processing.core.parameters import ParameterNumber
|
||||
from processing.core.outputs import OutputVector
|
||||
from processing.tools import dataobjects
|
||||
|
||||
pluginPath = os.path.split(os.path.split(os.path.dirname(__file__))[0])[0]
|
||||
|
||||
|
||||
class VectorGridLines(QgisAlgorithm):
|
||||
|
||||
EXTENT = 'EXTENT'
|
||||
STEP_X = 'STEP_X'
|
||||
STEP_Y = 'STEP_Y'
|
||||
OUTPUT = 'OUTPUT'
|
||||
|
||||
def flags(self):
|
||||
# this algorithm is deprecated - use GridLine instead
|
||||
return QgsProcessingAlgorithm.FlagDeprecated
|
||||
|
||||
def icon(self):
|
||||
return QIcon(os.path.join(pluginPath, 'images', 'ftools', 'vector_grid.png'))
|
||||
|
||||
def group(self):
|
||||
return self.tr('Vector creation tools')
|
||||
|
||||
def __init__(self):
|
||||
super().__init__()
|
||||
self.addParameter(ParameterExtent(self.EXTENT,
|
||||
self.tr('Grid extent'), optional=False))
|
||||
self.addParameter(ParameterNumber(self.STEP_X,
|
||||
self.tr('X spacing'), 0.0, 1000000000.0, 0.0001))
|
||||
self.addParameter(ParameterNumber(self.STEP_Y,
|
||||
self.tr('Y spacing'), 0.0, 1000000000.0, 0.0001))
|
||||
|
||||
self.addOutput(OutputVector(self.OUTPUT, self.tr('Grid'), datatype=[dataobjects.TYPE_VECTOR_LINE]))
|
||||
|
||||
def name(self):
|
||||
return 'vectorgridlines'
|
||||
|
||||
def displayName(self):
|
||||
return self.tr('Vector grid (lines)')
|
||||
|
||||
def processAlgorithm(self, parameters, context, feedback):
|
||||
extent = self.getParameterValue(self.EXTENT).split(',')
|
||||
xSpace = self.getParameterValue(self.STEP_X)
|
||||
ySpace = self.getParameterValue(self.STEP_Y)
|
||||
|
||||
bbox = QgsRectangle(float(extent[0]), float(extent[2]),
|
||||
float(extent[1]), float(extent[3]))
|
||||
|
||||
mapCRS = iface.mapCanvas().mapSettings().destinationCrs()
|
||||
|
||||
fields = QgsFields()
|
||||
fields.append(QgsField('id', QVariant.Int, '', 10, 0))
|
||||
|
||||
fields.append(QgsField('coord', QVariant.Double, '', 24, 15))
|
||||
fieldCount = 2
|
||||
writer = self.getOutputFromName(self.OUTPUT).getVectorWriter(fields, QgsWkbTypes.LineString, mapCRS, context)
|
||||
|
||||
feat = QgsFeature()
|
||||
feat.initAttributes(fieldCount)
|
||||
feat.setFields(fields)
|
||||
geom = QgsGeometry()
|
||||
idVar = 0
|
||||
|
||||
count = 0
|
||||
count_max = (bbox.yMaximum() - bbox.yMinimum()) / ySpace
|
||||
count_update = count_max * 0.10
|
||||
y = bbox.yMaximum()
|
||||
while y >= bbox.yMinimum():
|
||||
pt1 = QgsPointXY(bbox.xMinimum(), y)
|
||||
pt2 = QgsPointXY(bbox.xMaximum(), y)
|
||||
line = [pt1, pt2]
|
||||
feat.setGeometry(geom.fromPolyline(line))
|
||||
feat.setAttribute(0, idVar)
|
||||
feat.setAttribute(1, y)
|
||||
writer.addFeature(feat)
|
||||
y = y - ySpace
|
||||
idVar += 1
|
||||
count += 1
|
||||
if int(math.fmod(count, count_update)) == 0:
|
||||
feedback.setProgress(int(count / count_max * 50))
|
||||
|
||||
feedback.setProgress(50)
|
||||
# counters for progressbar - update every 5%
|
||||
count = 0
|
||||
count_max = (bbox.xMaximum() - bbox.xMinimum()) / xSpace
|
||||
count_update = count_max * 0.10
|
||||
x = bbox.xMinimum()
|
||||
while x <= bbox.xMaximum():
|
||||
pt1 = QgsPointXY(x, bbox.yMaximum())
|
||||
pt2 = QgsPointXY(x, bbox.yMinimum())
|
||||
line = [pt1, pt2]
|
||||
feat.setGeometry(geom.fromPolyline(line))
|
||||
feat.setAttribute(0, idVar)
|
||||
feat.setAttribute(1, x)
|
||||
writer.addFeature(feat)
|
||||
x = x + xSpace
|
||||
idVar += 1
|
||||
count += 1
|
||||
if int(math.fmod(count, count_update)) == 0:
|
||||
feedback.setProgress(50 + int(count / count_max * 50))
|
||||
|
||||
del writer
|
||||
@ -1,141 +0,0 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
|
||||
"""
|
||||
***************************************************************************
|
||||
VectorGridPolygons.py
|
||||
---------------------
|
||||
Date : September 2014
|
||||
Copyright : (C) 2014 by Alexander Bruy
|
||||
Email : alexander dot bruy at gmail dot com
|
||||
***************************************************************************
|
||||
* *
|
||||
* This program is free software; you can redistribute it and/or modify *
|
||||
* it under the terms of the GNU General Public License as published by *
|
||||
* the Free Software Foundation; either version 2 of the License, or *
|
||||
* (at your option) any later version. *
|
||||
* *
|
||||
***************************************************************************
|
||||
"""
|
||||
|
||||
__author__ = 'Alexander Bruy'
|
||||
__date__ = 'September 2014'
|
||||
__copyright__ = '(C) 2014, Alexander Bruy'
|
||||
|
||||
# This will get replaced with a git SHA1 when you do a git archive
|
||||
|
||||
__revision__ = '$Format:%H$'
|
||||
|
||||
import os
|
||||
import math
|
||||
|
||||
from qgis.PyQt.QtGui import QIcon
|
||||
from qgis.PyQt.QtCore import QVariant
|
||||
|
||||
from qgis.core import (QgsProcessingAlgorithm,
|
||||
QgsRectangle,
|
||||
QgsFields,
|
||||
QgsField,
|
||||
QgsFeature,
|
||||
QgsGeometry,
|
||||
QgsPointXY,
|
||||
QgsWkbTypes)
|
||||
from qgis.utils import iface
|
||||
|
||||
from processing.algs.qgis.QgisAlgorithm import QgisAlgorithm
|
||||
from processing.core.parameters import ParameterExtent
|
||||
from processing.core.parameters import ParameterNumber
|
||||
from processing.core.outputs import OutputVector
|
||||
from processing.tools import dataobjects
|
||||
|
||||
pluginPath = os.path.split(os.path.split(os.path.dirname(__file__))[0])[0]
|
||||
|
||||
|
||||
class VectorGridPolygons(QgisAlgorithm):
|
||||
|
||||
EXTENT = 'EXTENT'
|
||||
STEP_X = 'STEP_X'
|
||||
STEP_Y = 'STEP_Y'
|
||||
OUTPUT = 'OUTPUT'
|
||||
|
||||
def flags(self):
|
||||
# this algorithm is deprecated - use GridPolygon instead
|
||||
return QgsProcessingAlgorithm.FlagDeprecated
|
||||
|
||||
def icon(self):
|
||||
return QIcon(os.path.join(pluginPath, 'images', 'ftools', 'vector_grid.png'))
|
||||
|
||||
def group(self):
|
||||
return self.tr('Vector creation tools')
|
||||
|
||||
def __init__(self):
|
||||
super().__init__()
|
||||
self.addParameter(ParameterExtent(self.EXTENT,
|
||||
self.tr('Grid extent'), optional=False))
|
||||
self.addParameter(ParameterNumber(self.STEP_X,
|
||||
self.tr('X spacing'), 0.0, 1000000000.0, 0.0001))
|
||||
self.addParameter(ParameterNumber(self.STEP_Y,
|
||||
self.tr('Y spacing'), 0.0, 1000000000.0, 0.0001))
|
||||
|
||||
self.addOutput(OutputVector(self.OUTPUT, self.tr('Grid'), datatype=[dataobjects.TYPE_VECTOR_POLYGON]))
|
||||
|
||||
def name(self):
|
||||
return 'vectorgridpolygons'
|
||||
|
||||
def displayName(self):
|
||||
return self.tr('Vector grid (polygons)')
|
||||
|
||||
def processAlgorithm(self, parameters, context, feedback):
|
||||
extent = self.getParameterValue(self.EXTENT).split(',')
|
||||
xSpace = self.getParameterValue(self.STEP_X)
|
||||
ySpace = self.getParameterValue(self.STEP_Y)
|
||||
|
||||
bbox = QgsRectangle(float(extent[0]), float(extent[2]),
|
||||
float(extent[1]), float(extent[3]))
|
||||
|
||||
mapCRS = iface.mapCanvas().mapSettings().destinationCrs()
|
||||
|
||||
fields = QgsFields()
|
||||
fields.append(QgsField('id', QVariant.Int, '', 10, 0))
|
||||
|
||||
fields.append(QgsField('xmin', QVariant.Double, '', 24, 15))
|
||||
fields.append(QgsField('xmax', QVariant.Double, '', 24, 15))
|
||||
fields.append(QgsField('ymin', QVariant.Double, '', 24, 15))
|
||||
fields.append(QgsField('ymax', QVariant.Double, '', 24, 15))
|
||||
fieldCount = 5
|
||||
writer = self.getOutputFromName(self.OUTPUT).getVectorWriter(fields, QgsWkbTypes.Polygon, mapCRS, context)
|
||||
|
||||
feat = QgsFeature()
|
||||
feat.initAttributes(fieldCount)
|
||||
feat.setFields(fields)
|
||||
geom = QgsGeometry()
|
||||
idVar = 0
|
||||
|
||||
# counters for progressbar - update every 5%
|
||||
count = 0
|
||||
count_max = (bbox.yMaximum() - bbox.yMinimum()) / ySpace
|
||||
count_update = count_max * 0.05
|
||||
y = bbox.yMaximum()
|
||||
while y >= bbox.yMinimum():
|
||||
x = bbox.xMinimum()
|
||||
while x <= bbox.xMaximum():
|
||||
pt1 = QgsPointXY(x, y)
|
||||
pt2 = QgsPointXY(x + xSpace, y)
|
||||
pt3 = QgsPointXY(x + xSpace, y - ySpace)
|
||||
pt4 = QgsPointXY(x, y - ySpace)
|
||||
pt5 = QgsPointXY(x, y)
|
||||
polygon = [[pt1, pt2, pt3, pt4, pt5]]
|
||||
feat.setGeometry(geom.fromPolygon(polygon))
|
||||
feat.setAttribute(0, idVar)
|
||||
feat.setAttribute(1, x)
|
||||
feat.setAttribute(2, x + xSpace)
|
||||
feat.setAttribute(3, y - ySpace)
|
||||
feat.setAttribute(4, y)
|
||||
writer.addFeature(feat)
|
||||
idVar += 1
|
||||
x = x + xSpace
|
||||
y = y - ySpace
|
||||
count += 1
|
||||
if int(math.fmod(count, count_update)) == 0:
|
||||
feedback.setProgress(int(count / count_max * 100))
|
||||
|
||||
del writer
|
||||
Loading…
x
Reference in New Issue
Block a user