Skip to content

Commit dfc7788

Browse files
authored
Merge pull request #78 from cayetanobv/cayetanobv/python3_cleaning
Cayetanobv/python3 cleaning
2 parents 4e0d77d + 17b02fc commit dfc7788

File tree

7 files changed

+112
-270
lines changed

7 files changed

+112
-270
lines changed

Test_utils.py

Lines changed: 0 additions & 140 deletions
This file was deleted.

functions/alphashape.py

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,19 @@
11
from __future__ import absolute_import
22

33
from builtins import str
4-
from qgis.core import QgsCoordinateReferenceSystem, QgsCoordinateTransform, QgsPoint, QgsMessageLog, QgsProject
4+
from qgis.core import QgsCoordinateReferenceSystem, QgsCoordinateTransform, QgsPoint, Qgis, QgsProject
55
from qgis.gui import QgsRubberBand
66
import psycopg2
77
from pgRoutingLayer import pgRoutingLayer_utils as Utils
88
from .FunctionBase import FunctionBase
99

1010
class Function(FunctionBase):
11-
11+
1212
@classmethod
1313
def getName(self):
1414
''' returns Function name. '''
1515
return 'alphashape'
16-
16+
1717
@classmethod
1818
def getControlNames(self, version):
1919
''' returns control names for this function. '''
@@ -29,7 +29,7 @@ def getControlNames(self, version):
2929
'labelAlpha', 'lineEditAlpha',
3030
'checkBoxDirected', 'checkBoxHasReverseCost'
3131
]
32-
32+
3333
@classmethod
3434
def canExportMerged(self):
3535
return False
@@ -64,7 +64,7 @@ def getQuery(self, args):
6464
)
6565
SELECT * FROM node$$::text)
6666
""" % args
67-
67+
6868
# V21.+ has pgr_drivingDistance with big int
6969
# and pgr_alphaShape has an alpha value
7070
args['alpha'] = ', ' + str(args['alpha'])
@@ -90,7 +90,7 @@ def getQuery(self, args):
9090
)
9191
SELECT * FROM node$$::text%(alpha)s)
9292
""" % args
93-
93+
9494

9595

9696
def getExportQuery(self, args):
@@ -148,24 +148,24 @@ def draw(self, rows, con, args, geomType, canvasItemList, mapCanvas):
148148

149149
resultAreaRubberBand = canvasItemList['area']
150150
trans = None
151-
151+
152152
canvasCrs = Utils.getDestinationCrs(mapCanvas)
153153
layerCrs = QgsCoordinateReferenceSystem()
154154
Utils.createFromSrid(layerCrs, args['srid'])
155155
trans = QgsCoordinateTransform(layerCrs, canvasCrs,QgsProject.instance())
156-
156+
157157
# return columns are 'x', 'y'
158158
for row in rows:
159159
x = row[0]
160160
y = row[1]
161161
if args['version'] > 2.0 and ((x is None) or (y is None)):
162-
Utils.logMessage(u'Alpha shape result geometry is MultiPolygon or has holes.\nPlease click [Export] button to see complete result.', level=QgsMessageLog.WARNING)
162+
Utils.logMessage(u'Alpha shape result geometry is MultiPolygon or has holes.\nPlease click [Export] button to see complete result.', level=Qgis.Warning)
163163
return
164164
pt = QgsPoint(x, y)
165165
if trans:
166166
pt = trans.transform(pt.x(),pt.y())
167-
167+
168168
resultAreaRubberBand.addPoint(pt)
169-
169+
170170
def __init__(self, ui):
171171
FunctionBase.__init__(self, ui)

functions/ksp.py

Lines changed: 14 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -12,12 +12,12 @@ class Function(FunctionBase):
1212

1313
version = 2.0
1414

15-
15+
1616
@classmethod
1717
def getName(self):
1818
''' returns Function name. '''
1919
return 'ksp'
20-
20+
2121
@classmethod
2222
def getControlNames(self, version):
2323
''' returns control names. '''
@@ -26,30 +26,17 @@ def getControlNames(self, version):
2626
# only works for directed graph
2727
self.version = version
2828
if (self.version < 2.1):
29-
return [
30-
'labelId', 'lineEditId',
31-
'labelSource', 'lineEditSource',
32-
'labelTarget', 'lineEditTarget',
33-
'labelCost', 'lineEditCost',
34-
'labelReverseCost', 'lineEditReverseCost',
29+
return self.commonControls + self.commonBoxes + [
3530
'labelSourceId', 'lineEditSourceId', 'buttonSelectSourceId',
3631
'labelTargetId', 'lineEditTargetId', 'buttonSelectTargetId',
37-
'labelPaths', 'lineEditPaths',
38-
'checkBoxHasReverseCost'
32+
'labelPaths', 'lineEditPaths'
3933
]
4034
else:
4135
# function pgr_ksp(text,bigint,bigint,integer,boolean,boolean)
42-
return [
43-
'labelId', 'lineEditId',
44-
'labelSource', 'lineEditSource',
45-
'labelTarget', 'lineEditTarget',
46-
'labelCost', 'lineEditCost',
47-
'labelReverseCost', 'lineEditReverseCost',
36+
return self.commonControls + self.commonBoxes + [
4837
'labelSourceId', 'lineEditSourceId', 'buttonSelectSourceId',
4938
'labelTargetId', 'lineEditTargetId', 'buttonSelectTargetId',
5039
'labelPaths', 'lineEditPaths',
51-
'checkBoxDirected',
52-
'checkBoxHasReverseCost',
5340
'checkBoxHeapPaths'
5441
]
5542

@@ -61,6 +48,7 @@ def prepare(self, canvasItemList):
6148

6249
def getQuery(self, args):
6350
''' returns the sql query in required signature format of pgr_bdDijkstra '''
51+
args['where_clause'] = self.whereClause(args['edge_table'], args['geometry'], args['BBOX'])
6452
if (self.version < 2.1):
6553
return """
6654
SELECT
@@ -74,8 +62,8 @@ def getQuery(self, args):
7462
%(cost)s::float8 AS cost
7563
%(reverse_cost)s
7664
FROM %(edge_table)s
77-
WHERE %(edge_table)s.%(geometry)s && %(BBOX)s',
78-
%(source_id)s, %(target_id)s, %(paths)s, %(has_reverse_cost)s)""" % args
65+
%(where_clause)s',
66+
%(source_id)s, %(target_id)s, %(paths)s, %(has_reverse_cost)s)""" % args
7967
else:
8068
return """
8169
SELECT seq,
@@ -92,7 +80,7 @@ def getQuery(self, args):
9280
%(cost)s AS cost
9381
%(reverse_cost)s
9482
FROM %(edge_table)s
95-
WHERE %(edge_table)s.%(geometry)s && %(BBOX)s',
83+
%(where_clause)s',
9684
%(source_id)s, %(target_id)s, %(paths)s,
9785
%(directed)s, %(heap_paths)s)""" % args
9886

@@ -106,15 +94,15 @@ def getExportMergeQuery(self, args):
10694
args['result_query'] = self.getQuery(args)
10795

10896
args['with_geom_query'] = """
109-
SELECT
97+
SELECT
11098
seq, _route,
11199
CASE
112100
WHEN result._node = %(edge_table)s.%(source)s
113101
THEN %(edge_table)s.%(geometry)s
114102
ELSE ST_Reverse(%(edge_table)s.%(geometry)s)
115103
END AS path_geom
116104
FROM %(edge_table)s JOIN result
117-
ON %(edge_table)s.%(id)s = result._edge
105+
ON %(edge_table)s.%(id)s = result._edge
118106
""" % args
119107

120108
args['one_geom_query'] = """
@@ -149,15 +137,15 @@ def getExportMergeQuery(self, args):
149137
args['result_query'] = self.getQuery(args)
150138

151139
args['with_geom_query'] = """
152-
SELECT
140+
SELECT
153141
seq, result.path_name,
154142
CASE
155143
WHEN result._node = %(edge_table)s.%(source)s
156144
THEN %(edge_table)s.%(geometry)s
157145
ELSE ST_Reverse(%(edge_table)s.%(geometry)s)
158146
END AS path_geom
159147
FROM %(edge_table)s JOIN result
160-
ON %(edge_table)s.%(id)s = result._edge
148+
ON %(edge_table)s.%(id)s = result._edge
161149
""" % args
162150

163151
args['one_geom_query'] = """
@@ -183,7 +171,7 @@ def getExportMergeQuery(self, args):
183171
aggregates AS ( %(aggregates_query)s )
184172
SELECT row_number() over() as seq,
185173
_path_id, path_name, _nodes, _edges, agg_cost,
186-
path_geom FROM aggregates JOIN one_geom
174+
path_geom FROM aggregates JOIN one_geom
187175
USING (path_name)
188176
ORDER BY _path_id
189177
""" % args

0 commit comments

Comments
 (0)