mirror of
https://github.com/qgis/QGIS.git
synced 2025-04-13 00:03:09 -04:00
move ftools utils to tools utils module
This commit is contained in:
parent
c02c28bbcd
commit
6d506d6a33
@ -26,19 +26,14 @@ __revision__ = '$Format:%H$'
|
||||
import math
|
||||
|
||||
from PyQt4.QtCore import *
|
||||
|
||||
from qgis.core import *
|
||||
|
||||
from processing.core.GeoAlgorithm import GeoAlgorithm
|
||||
from processing.core.QGisLayers import QGisLayers
|
||||
|
||||
from processing.parameters.ParameterVector import ParameterVector
|
||||
from processing.parameters.ParameterTableField import ParameterTableField
|
||||
|
||||
from processing.outputs.OutputHTML import OutputHTML
|
||||
from processing.outputs.OutputNumber import OutputNumber
|
||||
|
||||
from processing.algs.ftools import FToolsUtils as utils
|
||||
from processing.tools import vector as utils
|
||||
|
||||
class BasicStatisticsNumbers(GeoAlgorithm):
|
||||
|
||||
@ -57,7 +52,6 @@ class BasicStatisticsNumbers(GeoAlgorithm):
|
||||
MEDIAN = "MEDIAN"
|
||||
UNIQUE = "UNIQUE"
|
||||
|
||||
|
||||
#===========================================================================
|
||||
# def getIcon(self):
|
||||
# return QtGui.QIcon(os.path.dirname(__file__) + "/icons/basic_statistics.png")
|
||||
|
@ -26,20 +26,14 @@ __revision__ = '$Format:%H$'
|
||||
import codecs
|
||||
|
||||
from PyQt4.QtCore import *
|
||||
|
||||
from qgis.core import *
|
||||
|
||||
from processing.core.GeoAlgorithm import GeoAlgorithm
|
||||
from processing.core.QGisLayers import QGisLayers
|
||||
|
||||
from processing.parameters.ParameterVector import ParameterVector
|
||||
from processing.parameters.ParameterTableField import ParameterTableField
|
||||
from processing.parameters.ParameterBoolean import ParameterBoolean
|
||||
|
||||
from processing.outputs.OutputHTML import OutputHTML
|
||||
from processing.outputs.OutputNumber import OutputNumber
|
||||
|
||||
from processing.algs.ftools import FToolsUtils as utils
|
||||
from processing.tools import vector as utils
|
||||
|
||||
class BasicStatisticsStrings(GeoAlgorithm):
|
||||
|
||||
|
@ -24,18 +24,13 @@ __copyright__ = '(C) 2012, Victor Olaya'
|
||||
__revision__ = '$Format:%H$'
|
||||
|
||||
from PyQt4.QtCore import *
|
||||
|
||||
from qgis.core import *
|
||||
|
||||
from processing.core.GeoAlgorithm import GeoAlgorithm
|
||||
from processing.core.QGisLayers import QGisLayers
|
||||
from processing.core.ProcessingLog import ProcessingLog
|
||||
|
||||
from processing.parameters.ParameterVector import ParameterVector
|
||||
|
||||
from processing.outputs.OutputVector import OutputVector
|
||||
|
||||
from processing.algs.ftools import FToolsUtils as utils
|
||||
from processing.tools import vector as utils
|
||||
|
||||
class Clip(GeoAlgorithm):
|
||||
|
||||
@ -69,7 +64,7 @@ class Clip(GeoAlgorithm):
|
||||
inFeatB = QgsFeature()
|
||||
outFeat = QgsFeature()
|
||||
|
||||
index = utils.createSpatialIndex(layerB)
|
||||
index = utils.spatialindex(layerB)
|
||||
|
||||
selectionA = QGisLayers.features(layerA)
|
||||
|
||||
@ -113,7 +108,7 @@ class Clip(GeoAlgorithm):
|
||||
outFeat.setAttributes(attrs)
|
||||
writer.addFeature(outFeat)
|
||||
except:
|
||||
FEAT_EXCEPT = False
|
||||
FEATURE_EXCEPT = False
|
||||
continue
|
||||
except:
|
||||
GEOS_EXCEPT = False
|
||||
|
@ -26,20 +26,14 @@ __revision__ = '$Format:%H$'
|
||||
|
||||
from PyQt4.QtCore import *
|
||||
from PyQt4.QtGui import *
|
||||
|
||||
from qgis.core import *
|
||||
|
||||
from processing.core.GeoAlgorithm import GeoAlgorithm
|
||||
from processing.core.QGisLayers import QGisLayers
|
||||
from processing.core.ProcessingLog import ProcessingLog
|
||||
|
||||
from processing.parameters.ParameterVector import ParameterVector
|
||||
from processing.parameters.ParameterTableField import ParameterTableField
|
||||
from processing.parameters.ParameterSelection import ParameterSelection
|
||||
|
||||
from processing.outputs.OutputVector import OutputVector
|
||||
|
||||
from processing.algs.ftools import FToolsUtils as utils
|
||||
from processing.tools import vector as utils
|
||||
|
||||
class ConvexHull(GeoAlgorithm):
|
||||
|
||||
|
@ -23,18 +23,13 @@ __copyright__ = '(C) 2012, Victor Olaya'
|
||||
__revision__ = '$Format:%H$'
|
||||
|
||||
from PyQt4.QtCore import *
|
||||
|
||||
from qgis.core import *
|
||||
|
||||
from processing.core.QGisLayers import QGisLayers
|
||||
from processing.core.ProcessingLog import ProcessingLog
|
||||
from processing.core.GeoAlgorithm import GeoAlgorithm
|
||||
|
||||
from processing.parameters.ParameterVector import ParameterVector
|
||||
|
||||
from processing.outputs.OutputVector import OutputVector
|
||||
|
||||
from processing.algs.ftools import FToolsUtils as utils
|
||||
from processing.tools import vector as utils
|
||||
|
||||
class Difference(GeoAlgorithm):
|
||||
|
||||
@ -69,7 +64,7 @@ class Difference(GeoAlgorithm):
|
||||
inFeatB = QgsFeature()
|
||||
outFeat = QgsFeature()
|
||||
|
||||
index = utils.createSpatialIndex(layerB)
|
||||
index = utils.spatialindex(layerB)
|
||||
|
||||
selectionA = QGisLayers.features(layerA)
|
||||
|
||||
|
@ -28,13 +28,12 @@ from processing.core.GeoAlgorithm import GeoAlgorithm
|
||||
from PyQt4.QtCore import *
|
||||
from PyQt4.QtGui import *
|
||||
from qgis.core import *
|
||||
from processing.algs.ftools import FToolsUtils as utils
|
||||
from processing.tools import vector as utils
|
||||
from processing.parameters.ParameterVector import ParameterVector
|
||||
from processing.core.QGisLayers import QGisLayers
|
||||
from processing.outputs.OutputVector import OutputVector
|
||||
from processing.parameters.ParameterBoolean import ParameterBoolean
|
||||
from processing.parameters.ParameterTableField import ParameterTableField
|
||||
from processing.core.ProcessingLog import ProcessingLog
|
||||
|
||||
class Dissolve(GeoAlgorithm):
|
||||
|
||||
|
@ -24,18 +24,13 @@ __copyright__ = '(C) 2012, Victor Olaya'
|
||||
__revision__ = '$Format:%H$'
|
||||
|
||||
from PyQt4.QtCore import *
|
||||
|
||||
from qgis.core import *
|
||||
|
||||
from processing.core.GeoAlgorithm import GeoAlgorithm
|
||||
from processing.core.QGisLayers import QGisLayers
|
||||
|
||||
from processing.parameters.ParameterVector import ParameterVector
|
||||
from processing.parameters.ParameterSelection import ParameterSelection
|
||||
|
||||
from processing.outputs.OutputVector import OutputVector
|
||||
|
||||
from processing.algs.ftools import FToolsUtils as utils
|
||||
from processing.tools import vector as utils
|
||||
|
||||
class ExportGeometryInfo(GeoAlgorithm):
|
||||
|
||||
|
@ -25,13 +25,11 @@ __revision__ = '$Format:%H$'
|
||||
|
||||
from PyQt4.QtCore import *
|
||||
from qgis.core import *
|
||||
|
||||
from processing.core.GeoAlgorithm import GeoAlgorithm
|
||||
from processing.core.QGisLayers import QGisLayers
|
||||
from processing.parameters.ParameterVector import ParameterVector
|
||||
from processing.outputs.OutputVector import OutputVector
|
||||
|
||||
from processing.algs.ftools import FToolsUtils as utils
|
||||
from processing.tools import vector as utils
|
||||
|
||||
class ExtractNodes(GeoAlgorithm):
|
||||
|
||||
|
@ -1,160 +0,0 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
|
||||
"""
|
||||
***************************************************************************
|
||||
FToolsUtils.py
|
||||
---------------------
|
||||
Date : September 2012
|
||||
Copyright : (C) 2012 by Carson Farmer, 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. *
|
||||
* *
|
||||
***************************************************************************
|
||||
"""
|
||||
__author__ = 'Carson, Farmer, Victor Olaya'
|
||||
__date__ = 'September 2012'
|
||||
__copyright__ = '(C) 2012, Carson Farmer, Victor Olaya'
|
||||
# This will get replaced with a git SHA1 when you do a git archive
|
||||
__revision__ = '$Format:%H$'
|
||||
|
||||
from PyQt4.QtCore import *
|
||||
from processing.core.QGisLayers import QGisLayers
|
||||
from qgis.core import *
|
||||
|
||||
def createSpatialIndex(layer):
|
||||
idx = QgsSpatialIndex()
|
||||
features = QGisLayers.features(layer)
|
||||
for ft in features:
|
||||
idx.insertFeature(ft)
|
||||
return idx
|
||||
|
||||
def createUniqueFieldName(fieldName, fieldList):
|
||||
shortName = fieldName[:10]
|
||||
|
||||
if len(fieldList) == 0:
|
||||
return shortName
|
||||
|
||||
fieldNames = [f.name() for f in fieldList]
|
||||
|
||||
if shortName not in fieldNames:
|
||||
return shortName
|
||||
|
||||
shortName = fieldName[:8] + "_1"
|
||||
changed = True
|
||||
while changed:
|
||||
changed = False
|
||||
for n in fieldList:
|
||||
if n == shortName:
|
||||
# create unique field name
|
||||
num = int(shortName[-1:])
|
||||
if num < 9:
|
||||
shortName = shortName[:8] + "_" + str(num + 1)
|
||||
else:
|
||||
shortName = shortName[:7] + "_" + str(num + 1)
|
||||
|
||||
changed = True
|
||||
|
||||
return shortName
|
||||
|
||||
def findOrCreateField(layer, fieldList, fieldName, fieldLen=24, fieldPrec=15):
|
||||
idx = layer.fieldNameIndex(fieldName)
|
||||
if idx == -1:
|
||||
fn = createUniqueFieldName(fieldName, fieldList)
|
||||
field = QgsField(fn, QVariant.Double, "", fieldLen, fieldPrec)
|
||||
idx = len(fieldList)
|
||||
fieldList.append(field)
|
||||
|
||||
return idx, fieldList
|
||||
|
||||
def extractPoints(geom):
|
||||
points = []
|
||||
if geom.type() == QGis.Point:
|
||||
if geom.isMultipart():
|
||||
points = geom.asMultiPoint()
|
||||
else:
|
||||
points.append(geom.asPoint())
|
||||
elif geom.type() == QGis.Line:
|
||||
if geom.isMultipart():
|
||||
lines = geom.asMultiPolyline()
|
||||
for line in lines:
|
||||
points.extend(line)
|
||||
else:
|
||||
points = geom.asPolyline()
|
||||
elif geom.type() == QGis.Polygon:
|
||||
if geom.isMultipart():
|
||||
polygons = geom.asMultiPolygon()
|
||||
for poly in polygons:
|
||||
for line in poly:
|
||||
points.extend(line)
|
||||
else:
|
||||
polygon = geom.asPolygon()
|
||||
for line in polygon:
|
||||
points.extend(line)
|
||||
|
||||
return points
|
||||
|
||||
def simpleMeasure(geom, method=0, ellips=None, crs=None):
|
||||
# method defines calculation type:
|
||||
# 0 - layer CRS
|
||||
# 1 - project CRS
|
||||
# 2 - ellipsoidal
|
||||
if geom.wkbType() in [QGis.WKBPoint, QGis.WKBPoint25D]:
|
||||
pt = geom.asPoint()
|
||||
attr1 = pt.x()
|
||||
attr2 = pt.y()
|
||||
elif geom.wkbType() in [QGis.WKBMultiPoint, QGis.WKBMultiPoint25D]:
|
||||
pt = inGeom.asMultiPoint()
|
||||
attr1 = pt[0].x()
|
||||
attr2 = pt[0].y()
|
||||
else:
|
||||
measure = QgsDistanceArea()
|
||||
|
||||
if method == 2:
|
||||
measure.setSourceCrs(crs)
|
||||
measure.setEllipsoid(ellips)
|
||||
measure.setEllipsoidalMode(True)
|
||||
|
||||
attr1 = measure.measure(geom)
|
||||
if geom.type() == QGis.Polygon:
|
||||
attr2 = measure.measurePerimeter(geom)
|
||||
else:
|
||||
attr2 = None
|
||||
|
||||
return (attr1, attr2)
|
||||
|
||||
def getUniqueValues(layer, fieldIndex):
|
||||
values = []
|
||||
features = QGisLayers.features(layer)
|
||||
for feat in features:
|
||||
if feat.attributes()[fieldIndex] not in values:
|
||||
values.append(feat.attributes()[fieldIndex])
|
||||
return values
|
||||
|
||||
def getUniqueValuesCount(layer, fieldIndex):
|
||||
return len(getUniqueValues(layer, fieldIndex))
|
||||
|
||||
# From two input field maps, create single field map
|
||||
def combineVectorFields(layerA, layerB):
|
||||
fields = []
|
||||
fieldsA = layerA.dataProvider().fields()
|
||||
fields.extend(fieldsA)
|
||||
namesA = [unicode(f.name()).lower() for f in fieldsA]
|
||||
fieldsB = layerB.dataProvider().fields()
|
||||
for field in fieldsB:
|
||||
name = unicode(field.name()).lower()
|
||||
if name in namesA:
|
||||
idx=2
|
||||
newName = name + "_" + unicode(idx)
|
||||
while newName in namesA:
|
||||
idx += 1
|
||||
newName = name + "_" + unicode(idx)
|
||||
field = QgsField(newName, field.type(), field.typeName())
|
||||
fields.append(field)
|
||||
|
||||
return fields
|
||||
|
@ -16,7 +16,7 @@
|
||||
* *
|
||||
***************************************************************************
|
||||
"""
|
||||
from processing.core.GeoAlgorithmExecutionException import GeoAlgorithmExecutionException
|
||||
|
||||
__author__ = 'Victor Olaya'
|
||||
__date__ = 'August 2012'
|
||||
__copyright__ = '(C) 2012, Victor Olaya'
|
||||
@ -30,8 +30,7 @@ from qgis.core import *
|
||||
from processing.parameters.ParameterVector import ParameterVector
|
||||
from processing.core.QGisLayers import QGisLayers
|
||||
from processing.outputs.OutputVector import OutputVector
|
||||
from processing.algs.ftools import FToolsUtils as utils
|
||||
from processing.core.ProcessingLog import ProcessingLog
|
||||
from processing.tools import vector as utils
|
||||
|
||||
class Intersection(GeoAlgorithm):
|
||||
|
||||
@ -54,7 +53,7 @@ class Intersection(GeoAlgorithm):
|
||||
inFeatA = QgsFeature()
|
||||
inFeatB = QgsFeature()
|
||||
outFeat = QgsFeature()
|
||||
index = utils.createSpatialIndex(vlayerB)
|
||||
index = utils.spatialindex(vlayerB)
|
||||
nElement = 0
|
||||
selectionA = QGisLayers.features(vlayerA)
|
||||
nFeat = len(selectionA)
|
||||
|
@ -30,7 +30,7 @@ from processing.core.QGisLayers import QGisLayers
|
||||
from processing.parameters.ParameterVector import ParameterVector
|
||||
from processing.parameters.ParameterTableField import ParameterTableField
|
||||
from processing.outputs.OutputVector import OutputVector
|
||||
from processing.algs.ftools import FToolsUtils as utils
|
||||
from processing.tools import vector as utils
|
||||
|
||||
class LinesIntersection(GeoAlgorithm):
|
||||
|
||||
@ -73,7 +73,7 @@ class LinesIntersection(GeoAlgorithm):
|
||||
writer = self.getOutputFromName(self.OUTPUT).getVectorWriter(fieldList,
|
||||
QGis.WKBPoint, layerA.dataProvider().crs())
|
||||
|
||||
spatialIndex = utils.createSpatialIndex(layerB)
|
||||
spatialIndex = utils.spatialindex(layerB)
|
||||
|
||||
inFeatA = QgsFeature()
|
||||
inFeatB = QgsFeature()
|
||||
|
@ -30,7 +30,7 @@ from processing.core.QGisLayers import QGisLayers
|
||||
from processing.parameters.ParameterTableField import ParameterTableField
|
||||
from processing.parameters.ParameterVector import ParameterVector
|
||||
from processing.outputs.OutputVector import OutputVector
|
||||
from processing.algs.ftools import FToolsUtils as utils
|
||||
from processing.tools import vector as utils
|
||||
|
||||
class MeanCoords(GeoAlgorithm):
|
||||
|
||||
|
@ -30,7 +30,7 @@ from processing.core.QGisLayers import QGisLayers
|
||||
from processing.parameters.ParameterVector import ParameterVector
|
||||
from processing.outputs.OutputHTML import OutputHTML
|
||||
from processing.outputs.OutputNumber import OutputNumber
|
||||
from processing.algs.ftools import FToolsUtils as utils
|
||||
from processing.tools import vector as utils
|
||||
|
||||
class NearestNeighbourAnalysis(GeoAlgorithm):
|
||||
|
||||
@ -67,7 +67,7 @@ class NearestNeighbourAnalysis(GeoAlgorithm):
|
||||
layer = QGisLayers.getObjectFromUri(self.getParameterValue(self.POINTS))
|
||||
output = self.getOutputValue(self.OUTPUT)
|
||||
|
||||
spatialIndex = utils.createSpatialIndex(layer)
|
||||
spatialIndex = utils.spatialindex(layer)
|
||||
|
||||
neighbour = QgsFeature()
|
||||
distance = QgsDistanceArea()
|
||||
|
@ -16,7 +16,6 @@
|
||||
* *
|
||||
***************************************************************************
|
||||
"""
|
||||
|
||||
__author__ = 'Victor Olaya'
|
||||
__date__ = 'August 2012'
|
||||
__copyright__ = '(C) 2012, Victor Olaya'
|
||||
@ -24,20 +23,15 @@ __copyright__ = '(C) 2012, Victor Olaya'
|
||||
__revision__ = '$Format:%H$'
|
||||
|
||||
import math
|
||||
|
||||
from qgis.core import *
|
||||
|
||||
from processing.tools import dataobjects, vector
|
||||
from processing.core.GeoAlgorithm import GeoAlgorithm
|
||||
from processing.core.QGisLayers import QGisLayers
|
||||
|
||||
from processing.parameters.ParameterNumber import ParameterNumber
|
||||
from processing.parameters.ParameterVector import ParameterVector
|
||||
from processing.parameters.ParameterSelection import ParameterSelection
|
||||
from processing.parameters.ParameterTableField import ParameterTableField
|
||||
|
||||
from processing.outputs.OutputTable import OutputTable
|
||||
|
||||
from processing.algs.ftools import FToolsUtils as utils
|
||||
|
||||
class PointDistance(GeoAlgorithm):
|
||||
|
||||
@ -54,11 +48,6 @@ class PointDistance(GeoAlgorithm):
|
||||
"Summary distance matrix (mean, std. dev., min, max)"
|
||||
]
|
||||
|
||||
#===========================================================================
|
||||
# def getIcon(self):
|
||||
# return QtGui.QIcon(os.path.dirname(__file__) + "/icons/matrix.png")
|
||||
#===========================================================================
|
||||
|
||||
def defineCharacteristics(self):
|
||||
self.name = "Distance matrix"
|
||||
self.group = "Vector analysis tools"
|
||||
@ -73,9 +62,9 @@ class PointDistance(GeoAlgorithm):
|
||||
self.addOutput(OutputTable(self.DISTANCE_MATRIX, "Distance matrix"))
|
||||
|
||||
def processAlgorithm(self, progress):
|
||||
inLayer = QGisLayers.getObjectFromUri(self.getParameterValue(self.INPUT_LAYER))
|
||||
inLayer = dataobjects.getObjectFromUri(self.getParameterValue(self.INPUT_LAYER))
|
||||
inField = self.getParameterValue(self.INPUT_FIELD)
|
||||
targetLayer = QGisLayers.getObjectFromUri(self.getParameterValue(self.TARGET_LAYER))
|
||||
targetLayer = dataobjects.getObjectFromUri(self.getParameterValue(self.TARGET_LAYER))
|
||||
targetField = self.getParameterValue(self.TARGET_FIELD)
|
||||
matType = self.getParameterValue(self.MATRIX_TYPE)
|
||||
nPoints = self.getParameterValue(self.NEAREST_POINTS)
|
||||
@ -83,7 +72,7 @@ class PointDistance(GeoAlgorithm):
|
||||
outputFile = self.getOutputFromName(self.DISTANCE_MATRIX)
|
||||
|
||||
if nPoints < 1:
|
||||
nPoints = len(QGisLayers.features(targetLayer))
|
||||
nPoints = len(vector.features(targetLayer))
|
||||
|
||||
self.writer = outputFile.getTableWriter([])
|
||||
|
||||
@ -100,7 +89,7 @@ class PointDistance(GeoAlgorithm):
|
||||
else:
|
||||
self.writer.addRecord(["InputID", "MEAN", "STDDEV", "MIN", "MAX"])
|
||||
|
||||
index = utils.createSpatialIndex(targetLayer);
|
||||
index = vector.spatialindex(targetLayer);
|
||||
|
||||
inIdx = inLayer.fieldNameIndex(inField)
|
||||
inLayer.select([inIdx])
|
||||
@ -111,7 +100,7 @@ class PointDistance(GeoAlgorithm):
|
||||
outGeom = QgsGeometry()
|
||||
distArea = QgsDistanceArea()
|
||||
|
||||
features = QGisLayers.features(inLayer)
|
||||
features = vector.features(inLayer)
|
||||
current = 0
|
||||
total = 100.0 / float(len(features))
|
||||
for inFeat in features:
|
||||
@ -142,7 +131,7 @@ class PointDistance(GeoAlgorithm):
|
||||
progress.setPercentage(int(current * total))
|
||||
|
||||
def regularMatrix(self, inLayer, inField, targetLayer, targetField, nPoints, progress):
|
||||
index = utils.createSpatialIndex(targetLayer)
|
||||
index = vector.spatialindex(targetLayer)
|
||||
|
||||
inIdx = inLayer.fieldNameIndex(inField)
|
||||
outIdx = targetLayer.fieldNameIndex(inField)
|
||||
|
@ -24,19 +24,13 @@ __copyright__ = '(C) 2012, Victor Olaya'
|
||||
__revision__ = '$Format:%H$'
|
||||
|
||||
from PyQt4.QtCore import *
|
||||
|
||||
from qgis.core import *
|
||||
|
||||
from processing.core.GeoAlgorithm import GeoAlgorithm
|
||||
from processing.core.QGisLayers import QGisLayers
|
||||
from processing.core.ProcessingLog import ProcessingLog
|
||||
|
||||
from processing.parameters.ParameterVector import ParameterVector
|
||||
from processing.parameters.ParameterString import ParameterString
|
||||
|
||||
from processing.outputs.OutputVector import OutputVector
|
||||
|
||||
from processing.algs.ftools import FToolsUtils as utils
|
||||
from processing.tools import vector as utils
|
||||
|
||||
class PointsInPolygon(GeoAlgorithm):
|
||||
|
||||
@ -71,7 +65,7 @@ class PointsInPolygon(GeoAlgorithm):
|
||||
writer = self.getOutputFromName(self.OUTPUT).getVectorWriter(fieldList.toList(),
|
||||
polyProvider.geometryType(), polyProvider.crs())
|
||||
|
||||
spatialIndex = utils.createSpatialIndex(pointLayer)
|
||||
spatialIndex = utils.spatialindex(pointLayer)
|
||||
|
||||
ftPoly = QgsFeature()
|
||||
ftPoint = QgsFeature()
|
||||
|
@ -24,20 +24,14 @@ __copyright__ = '(C) 2012, Victor Olaya'
|
||||
# This will get replaced with a git SHA1 when you do a git archive
|
||||
__revision__ = '$Format:%H$'
|
||||
|
||||
from PyQt4 import QtGui
|
||||
from PyQt4.QtCore import *
|
||||
|
||||
from qgis.core import *
|
||||
|
||||
from processing.core.GeoAlgorithm import GeoAlgorithm
|
||||
from processing.core.QGisLayers import QGisLayers
|
||||
|
||||
from processing.parameters.ParameterVector import ParameterVector
|
||||
from processing.parameters.ParameterString import ParameterString
|
||||
|
||||
from processing.outputs.OutputVector import OutputVector
|
||||
|
||||
from processing.algs.ftools import FToolsUtils as utils
|
||||
from processing.tools import vector as utils
|
||||
|
||||
class PointsInPolygonUnique(GeoAlgorithm):
|
||||
|
||||
@ -75,7 +69,7 @@ class PointsInPolygonUnique(GeoAlgorithm):
|
||||
writer = self.getOutputFromName(self.OUTPUT).getVectorWriter(fieldList.toList(),
|
||||
polyProvider.geometryType(), polyProvider.crs())
|
||||
|
||||
spatialIndex = utils.createSpatialIndex(pointLayer)
|
||||
spatialIndex = utils.spatialindex(pointLayer)
|
||||
|
||||
ftPoint = QgsFeature()
|
||||
outFeat = QgsFeature()
|
||||
|
@ -24,20 +24,14 @@ __copyright__ = '(C) 2012, Victor Olaya'
|
||||
# This will get replaced with a git SHA1 when you do a git archive
|
||||
__revision__ = '$Format:%H$'
|
||||
|
||||
from PyQt4 import QtGui
|
||||
from PyQt4.QtCore import *
|
||||
|
||||
from qgis.core import *
|
||||
|
||||
from processing.core.GeoAlgorithm import GeoAlgorithm
|
||||
from processing.core.QGisLayers import QGisLayers
|
||||
|
||||
from processing.parameters.ParameterVector import ParameterVector
|
||||
from processing.parameters.ParameterString import ParameterString
|
||||
|
||||
from processing.outputs.OutputVector import OutputVector
|
||||
|
||||
from processing.algs.ftools import FToolsUtils as utils
|
||||
from processing.tools import vector as utils
|
||||
|
||||
class PointsInPolygonWeighted(GeoAlgorithm):
|
||||
|
||||
@ -76,7 +70,7 @@ class PointsInPolygonWeighted(GeoAlgorithm):
|
||||
writer = self.getOutputFromName(self.OUTPUT).getVectorWriter(fieldList.toList(),
|
||||
polyProvider.geometryType(), polyProvider.crs())
|
||||
|
||||
spatialIndex = utils.createSpatialIndex(pointLayer)
|
||||
spatialIndex = utils.spatialindex(pointLayer)
|
||||
|
||||
ftPoint = QgsFeature()
|
||||
outFeat = QgsFeature()
|
||||
|
@ -29,7 +29,7 @@ from qgis.core import *
|
||||
from processing.core.GeoAlgorithm import GeoAlgorithm
|
||||
from processing.core.GeoAlgorithmExecutionException import GeoAlgorithmExecutionException
|
||||
from processing.core.QGisLayers import QGisLayers
|
||||
from processing.algs.ftools import FToolsUtils as utils
|
||||
from processing.tools import vector as utils
|
||||
from processing.parameters.ParameterSelection import ParameterSelection
|
||||
from processing.parameters.ParameterVector import ParameterVector
|
||||
from processing.parameters.ParameterNumber import ParameterNumber
|
||||
|
@ -29,10 +29,8 @@ from processing.core.GeoAlgorithm import GeoAlgorithm
|
||||
from processing.core.QGisLayers import QGisLayers
|
||||
from processing.parameters.ParameterSelection import ParameterSelection
|
||||
from processing.parameters.ParameterVector import ParameterVector
|
||||
|
||||
from processing.outputs.OutputVector import OutputVector
|
||||
|
||||
from processing.algs.ftools import FToolsUtils as utils
|
||||
from processing.tools import vector as utils
|
||||
|
||||
class SelectByLocation(GeoAlgorithm):
|
||||
|
||||
@ -67,7 +65,7 @@ class SelectByLocation(GeoAlgorithm):
|
||||
selectLayer = QGisLayers.getObjectFromUri(filename)
|
||||
|
||||
oldSelection = set(inputLayer.selectedFeaturesIds())
|
||||
index = spatialIndex = utils.createSpatialIndex(inputLayer)
|
||||
index = spatialIndex = utils.spatialindex(inputLayer)
|
||||
|
||||
feat = QgsFeature()
|
||||
geom = QgsGeometry()
|
||||
|
@ -28,10 +28,9 @@ from qgis.core import *
|
||||
from processing.core.GeoAlgorithm import GeoAlgorithm
|
||||
from processing.core.GeoAlgorithmExecutionException import GeoAlgorithmExecutionException
|
||||
from processing.core.QGisLayers import QGisLayers
|
||||
from processing.algs.ftools import FToolsUtils as utils
|
||||
from processing.tools import vector as utils
|
||||
from processing.parameters.ParameterVector import ParameterVector
|
||||
from processing.parameters.ParameterTableField import ParameterTableField
|
||||
|
||||
from processing.outputs.OutputVector import OutputVector
|
||||
|
||||
class SinglePartsToMultiparts(GeoAlgorithm):
|
||||
|
@ -23,22 +23,15 @@ __copyright__ = '(C) 2012, Victor Olaya'
|
||||
# This will get replaced with a git SHA1 when you do a git archive
|
||||
__revision__ = '$Format:%H$'
|
||||
|
||||
import os.path
|
||||
|
||||
from PyQt4 import QtGui
|
||||
from PyQt4.QtCore import *
|
||||
|
||||
from qgis.core import *
|
||||
|
||||
from processing.core.GeoAlgorithm import GeoAlgorithm
|
||||
from processing.core.QGisLayers import QGisLayers
|
||||
from processing.core.ProcessingLog import ProcessingLog
|
||||
|
||||
from processing.parameters.ParameterVector import ParameterVector
|
||||
from processing.parameters.ParameterString import ParameterString
|
||||
from processing.outputs.OutputVector import OutputVector
|
||||
|
||||
from processing.algs.ftools import FToolsUtils as utils
|
||||
from processing.tools import vector as utils
|
||||
|
||||
class SumLines(GeoAlgorithm):
|
||||
|
||||
@ -78,7 +71,7 @@ class SumLines(GeoAlgorithm):
|
||||
writer = self.getOutputFromName(self.OUTPUT).getVectorWriter(fieldList.toList(),
|
||||
polyProvider.geometryType(), polyProvider.crs())
|
||||
|
||||
spatialIndex = utils.createSpatialIndex(lineLayer)
|
||||
spatialIndex = utils.spatialindex(lineLayer)
|
||||
|
||||
ftLine = QgsFeature()
|
||||
ftPoly = QgsFeature()
|
||||
|
@ -30,7 +30,7 @@ from qgis.core import *
|
||||
from processing.parameters.ParameterVector import ParameterVector
|
||||
from processing.core.QGisLayers import QGisLayers
|
||||
from processing.outputs.OutputVector import OutputVector
|
||||
from processing.algs.ftools import FToolsUtils as utils
|
||||
from processing.tools import vector as utils
|
||||
from processing.core.ProcessingLog import ProcessingLog
|
||||
from processing.core.GeoAlgorithm import GeoAlgorithm
|
||||
|
||||
@ -59,8 +59,8 @@ class Union(GeoAlgorithm):
|
||||
inFeatA = QgsFeature()
|
||||
inFeatB = QgsFeature()
|
||||
outFeat = QgsFeature()
|
||||
indexA = utils.createSpatialIndex(vlayerB)
|
||||
indexB = utils.createSpatialIndex(vlayerA)
|
||||
indexA = utils.spatialindex(vlayerB)
|
||||
indexB = utils.spatialindex(vlayerA)
|
||||
|
||||
count = 0
|
||||
nElement = 0
|
||||
|
@ -25,17 +25,13 @@ __copyright__ = '(C) 2012, Victor Olaya'
|
||||
__revision__ = '$Format:%H$'
|
||||
|
||||
import codecs
|
||||
|
||||
from processing.core.GeoAlgorithm import GeoAlgorithm
|
||||
from processing.core.QGisLayers import QGisLayers
|
||||
|
||||
from processing.parameters.ParameterVector import ParameterVector
|
||||
from processing.parameters.ParameterTableField import ParameterTableField
|
||||
|
||||
from processing.outputs.OutputHTML import OutputHTML
|
||||
from processing.outputs.OutputNumber import OutputNumber
|
||||
|
||||
from processing.algs.ftools import FToolsUtils as utils
|
||||
from processing.tools import vector as utils
|
||||
|
||||
class UniqueValues(GeoAlgorithm):
|
||||
|
||||
|
@ -119,7 +119,7 @@ class LayerExporter():
|
||||
isASCII=False
|
||||
isDbf = unicode(table.source()).endswith("dbf") or unicode(table.source()).endswith("shp")
|
||||
if (not isDbf or not isASCII):
|
||||
writer = QgsVectorFileWriter( output, systemEncoding, provider.fields(), QGis.WKBNoGeometry, layer.crs() )
|
||||
writer = QgsVectorFileWriter( output, systemEncoding, provider.fields(), QGis.WKBNoGeometry, QgsCoordinateReferenceSystem('4326') )
|
||||
for feat in table.getFeatures():
|
||||
writer.addFeature(feat)
|
||||
del writer
|
||||
|
@ -31,7 +31,6 @@ nElement = 0
|
||||
classes = {}
|
||||
|
||||
#Iterate over input layer to count unique values in each class
|
||||
|
||||
feats = processing.getfeatures(layer)
|
||||
nFeat = len(feats)
|
||||
for inFeat in feats:
|
||||
|
@ -25,6 +25,7 @@ __revision__ = '$Format:%H$'
|
||||
|
||||
from processing.core.QGisLayers import QGisLayers
|
||||
from qgis.core import *
|
||||
from PyQt4.QtCore import *
|
||||
|
||||
def uniquevalues(layer, attribute):
|
||||
'''Returns a list of unique values for a given attribute.
|
||||
@ -84,4 +85,131 @@ def spatialindex(layer):
|
||||
|
||||
def getfeatures(layer):
|
||||
'''returns an iterator over the features of a vector layer, considering the existing selection'''
|
||||
return QGisLayers.features(layer)
|
||||
return QGisLayers.features(layer)
|
||||
|
||||
|
||||
def createUniqueFieldName(fieldName, fieldList):
|
||||
shortName = fieldName[:10]
|
||||
|
||||
if len(fieldList) == 0:
|
||||
return shortName
|
||||
|
||||
fieldNames = [f.name() for f in fieldList]
|
||||
|
||||
if shortName not in fieldNames:
|
||||
return shortName
|
||||
|
||||
shortName = fieldName[:8] + "_1"
|
||||
changed = True
|
||||
while changed:
|
||||
changed = False
|
||||
for n in fieldList:
|
||||
if n == shortName:
|
||||
# create unique field name
|
||||
num = int(shortName[-1:])
|
||||
if num < 9:
|
||||
shortName = shortName[:8] + "_" + str(num + 1)
|
||||
else:
|
||||
shortName = shortName[:7] + "_" + str(num + 1)
|
||||
|
||||
changed = True
|
||||
|
||||
return shortName
|
||||
|
||||
def findOrCreateField(layer, fieldList, fieldName, fieldLen=24, fieldPrec=15):
|
||||
idx = layer.fieldNameIndex(fieldName)
|
||||
if idx == -1:
|
||||
fn = createUniqueFieldName(fieldName, fieldList)
|
||||
field = QgsField(fn, QVariant.Double, "", fieldLen, fieldPrec)
|
||||
idx = len(fieldList)
|
||||
fieldList.append(field)
|
||||
|
||||
return idx, fieldList
|
||||
|
||||
def extractPoints(geom):
|
||||
points = []
|
||||
if geom.type() == QGis.Point:
|
||||
if geom.isMultipart():
|
||||
points = geom.asMultiPoint()
|
||||
else:
|
||||
points.append(geom.asPoint())
|
||||
elif geom.type() == QGis.Line:
|
||||
if geom.isMultipart():
|
||||
lines = geom.asMultiPolyline()
|
||||
for line in lines:
|
||||
points.extend(line)
|
||||
else:
|
||||
points = geom.asPolyline()
|
||||
elif geom.type() == QGis.Polygon:
|
||||
if geom.isMultipart():
|
||||
polygons = geom.asMultiPolygon()
|
||||
for poly in polygons:
|
||||
for line in poly:
|
||||
points.extend(line)
|
||||
else:
|
||||
polygon = geom.asPolygon()
|
||||
for line in polygon:
|
||||
points.extend(line)
|
||||
|
||||
return points
|
||||
|
||||
def simpleMeasure(geom, method=0, ellips=None, crs=None):
|
||||
# method defines calculation type:
|
||||
# 0 - layer CRS
|
||||
# 1 - project CRS
|
||||
# 2 - ellipsoidal
|
||||
if geom.wkbType() in [QGis.WKBPoint, QGis.WKBPoint25D]:
|
||||
pt = geom.asPoint()
|
||||
attr1 = pt.x()
|
||||
attr2 = pt.y()
|
||||
elif geom.wkbType() in [QGis.WKBMultiPoint, QGis.WKBMultiPoint25D]:
|
||||
pt = inGeom.asMultiPoint()
|
||||
attr1 = pt[0].x()
|
||||
attr2 = pt[0].y()
|
||||
else:
|
||||
measure = QgsDistanceArea()
|
||||
|
||||
if method == 2:
|
||||
measure.setSourceCrs(crs)
|
||||
measure.setEllipsoid(ellips)
|
||||
measure.setEllipsoidalMode(True)
|
||||
|
||||
attr1 = measure.measure(geom)
|
||||
if geom.type() == QGis.Polygon:
|
||||
attr2 = measure.measurePerimeter(geom)
|
||||
else:
|
||||
attr2 = None
|
||||
|
||||
return (attr1, attr2)
|
||||
|
||||
def getUniqueValues(layer, fieldIndex):
|
||||
values = []
|
||||
features = QGisLayers.features(layer)
|
||||
for feat in features:
|
||||
if feat.attributes()[fieldIndex] not in values:
|
||||
values.append(feat.attributes()[fieldIndex])
|
||||
return values
|
||||
|
||||
def getUniqueValuesCount(layer, fieldIndex):
|
||||
return len(getUniqueValues(layer, fieldIndex))
|
||||
|
||||
# From two input field maps, create single field map
|
||||
def combineVectorFields(layerA, layerB):
|
||||
fields = []
|
||||
fieldsA = layerA.dataProvider().fields()
|
||||
fields.extend(fieldsA)
|
||||
namesA = [unicode(f.name()).lower() for f in fieldsA]
|
||||
fieldsB = layerB.dataProvider().fields()
|
||||
for field in fieldsB:
|
||||
name = unicode(field.name()).lower()
|
||||
if name in namesA:
|
||||
idx=2
|
||||
newName = name + "_" + unicode(idx)
|
||||
while newName in namesA:
|
||||
idx += 1
|
||||
newName = name + "_" + unicode(idx)
|
||||
field = QgsField(newName, field.type(), field.typeName())
|
||||
fields.append(field)
|
||||
|
||||
return fields
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user