Matthias Kuhn bb79d13e82 Remove deprecated Qgis::WKBType and API cleanup (#3325)
* Remove deprecated Qgis::WKBType and API cleanup

Renames QgsWKBTypes to QgsWkbTypes

Replaces usage of the enums:

* Qgis::WKBType with QgsWkbTypes::Type
* Qgis::GeometryType with QgsWkbTypes::GeometryType

Their values should be forward compatible (a fact that was already
explited up to now by casting between the types)

Renames some SSLxxx to SslXxx and URIxxx to UriXxx

* Fix build warnings and simplify type handling

* Add a fixer to rewrite imports

* The forgotten rebase conflictThe forgotten rebase conflicts

* QgsDataSourcURI > QgsDataSourceUri

* QgsWKBTypes > QgsWkbTypes

* Qgis.WKBGeom > QgsWkbTypes.Geom

* Further python fixes

* Guess what... Qgis::wkbDimensions != QgsWkbTypes::wkbDimensions

* Fix tests

* Python 3 updates

* [travis] pull request caching cannot be disabled

so at least use it in r/w mode

* Fix python3 print in plugins
2016-08-04 09:10:08 +02:00

104 lines
4.1 KiB
Python

# -*- coding: utf-8 -*-
"""
***************************************************************************
Gridify.py
---------------------
Date : May 2010
Copyright : (C) 2010 by Michael Minn
Email : pyqgis at michaelminn 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__ = 'Michael Minn'
__date__ = 'May 2010'
__copyright__ = '(C) 2010, Michael Minn'
# This will get replaced with a git SHA1 when you do a git archive
__revision__ = '$Format:%H$'
from qgis.core import Qgis, QgsFeature, QgsGeometry, QgsPoint, QgsWkbTypes
from processing.core.GeoAlgorithm import GeoAlgorithm
from processing.core.GeoAlgorithmExecutionException import GeoAlgorithmExecutionException
from processing.core.parameters import ParameterVector
from processing.core.parameters import ParameterTableField
from processing.core.outputs import OutputVector
from processing.tools import dataobjects, vector
class HubLines(GeoAlgorithm):
HUBS = 'HUBS'
HUB_FIELD = 'HUB_FIELD'
SPOKES = 'SPOKES'
SPOKE_FIELD = 'SPOKE_FIELD'
OUTPUT = 'OUTPUT'
def defineCharacteristics(self):
self.name, self.i18n_name = self.trAlgorithm('Hub lines')
self.group, self.i18n_group = self.trAlgorithm('Vector analysis tools')
self.addParameter(ParameterVector(self.HUBS,
self.tr('Hub point layer'), [ParameterVector.VECTOR_TYPE_ANY]))
self.addParameter(ParameterTableField(self.HUB_FIELD,
self.tr('Hub ID field'), self.HUBS))
self.addParameter(ParameterVector(self.SPOKES,
self.tr('Spoke point layer'), [ParameterVector.VECTOR_TYPE_ANY]))
self.addParameter(ParameterTableField(self.SPOKE_FIELD,
self.tr('Spoke ID field'), self.SPOKES))
self.addOutput(OutputVector(self.OUTPUT, self.tr('Hub lines')))
def processAlgorithm(self, progress):
layerHub = dataobjects.getObjectFromUri(
self.getParameterValue(self.HUBS))
layerSpoke = dataobjects.getObjectFromUri(
self.getParameterValue(self.SPOKES))
fieldHub = self.getParameterValue(self.HUB_FIELD)
fieldSpoke = self.getParameterValue(self.SPOKE_FIELD)
if layerHub.source() == layerSpoke.source():
raise GeoAlgorithmExecutionException(
self.tr('Same layer given for both hubs and spokes'))
writer = self.getOutputFromName(self.OUTPUT).getVectorWriter(
layerSpoke.pendingFields(), QgsWkbTypes.LineString, layerSpoke.crs())
spokes = vector.features(layerSpoke)
hubs = vector.features(layerHub)
total = 100.0 / len(spokes)
for current, spokepoint in enumerate(spokes):
p = spokepoint.geometry().boundingBox().center()
spokeX = p.x()
spokeY = p.y()
spokeId = unicode(spokepoint[fieldSpoke])
for hubpoint in hubs:
hubId = unicode(hubpoint[fieldHub])
if hubId == spokeId:
p = hubpoint.geometry().boundingBox().center()
hubX = p.x()
hubY = p.y()
f = QgsFeature()
f.setAttributes(spokepoint.attributes())
f.setGeometry(QgsGeometry.fromPolyline(
[QgsPoint(spokeX, spokeY), QgsPoint(hubX, hubY)]))
writer.addFeature(f)
break
progress.setPercentage(int(current * total))
del writer