Skip to content

Commit 3e26c0f

Browse files
committed
Cleanup, changing requirements and small rewrites to adjust to previous changes
1 parent ba91a6d commit 3e26c0f

File tree

3 files changed

+22
-36
lines changed

3 files changed

+22
-36
lines changed

pgRoutingLayer.py

Lines changed: 20 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -954,8 +954,7 @@ def get_innerQueryArguments(self, controls):
954954
if not self.dock.checkBoxHasReverseCost.isChecked():
955955
args['reverse_cost'] = sql.SQL(" -1 ")
956956
else:
957-
args['reverse_cost'] = sql.SQL("{}").format(sql.Identifier(
958-
str(self.dock.lineEditReverseCost.text())))
957+
args['reverse_cost'] = sql.Identifier(str(self.dock.lineEditReverseCost.text()))
959958

960959
if 'lineEditX1' in controls:
961960
args['x1'] = sql.Identifier(self.dock.lineEditX1.text())
@@ -1031,33 +1030,17 @@ def _getArguments(self, controls, conn):
10311030
function = str(self.dock.comboBoxFunction.currentText()).lower()
10321031
args['function'] = sql.Identifier(str(function))
10331032

1034-
if function in ['pgr_astarcost', 'pgr_dijkstracost', 'pgr_bdastarcost', 'pgr_bddijkstracost']:
1035-
# TODO: capture vertices table, geometry of vertices table
1036-
args['vertex_schema'] = sql.Identifier(str(self.dock.lineEditSchema.text()))
1037-
args['vertex_table'] = sql.Identifier(str(self.dock.lineEditTable.text()) + '_vertices_pgr')
1038-
args['geometry_vt'] = sql.Identifier(str(self.dock.lineEditGeometry.text()))
1039-
# QMessageBox.information(self.dock, self.dock.windowTitle(),
1040-
# 'TODO: capture vertices table, geometry of vertices table, label the edges')
1041-
10421033
if 'lineEditX1' in controls:
10431034
args['astarHeuristic'] = sql.Literal(str(self.dock.selectAstarHeuristic.currentIndex()))
10441035
args['astarFactor'] = sql.Literal(str(self.dock.selectAstarFactor.text()))
10451036
args['astarEpsilon'] = sql.Literal(str(self.dock.selectAstarEpsilon.value()))
10461037

1047-
# args['rule'] = self.dock.lineEditRule.text() if 'lineEditRule' in controls
1048-
# args['to_cost'] = self.dock.lineEditToCost.text() if 'lineEditToCost' in controls:
1049-
10501038
if 'lineEditIds' in controls:
10511039
args['ids'] = self.dock.lineEditIds.text()
10521040

10531041
if 'lineEditPcts' in controls:
10541042
args['pcts'] = self.dock.lineEditPcts.text()
10551043

1056-
# Used in pgr_KSP
1057-
if 'lineEditSourceId' in controls:
1058-
args['source_id'] = sql.Literal(self.dock.lineEditSourceId.text())
1059-
args['target_id'] = sql.Literal(self.dock.lineEditTargetId.text())
1060-
10611044
# Used in pgr_KSP
10621045
if 'lineEditPaths' in controls:
10631046
args['Kpaths'] = sql.Literal(self.dock.lineEditPaths.text())
@@ -1085,13 +1068,6 @@ def _getArguments(self, controls, conn):
10851068
if 'checkBoxHeapPaths' in controls:
10861069
args['heap_paths'] = sql.SQL("heap_paths := {}::BOOLEAN").format(sql.Literal(str(self.dock.checkBoxHeapPaths.isChecked()).lower()))
10871070

1088-
# if 'labelDrivingSide' in controls:
1089-
# args['driving_side'] = str('b')
1090-
# if (self.dock.checkBoxLeft.isChecked() == True and self.dock.checkBoxRight.isChecked() == False):
1091-
# args['driving_side'] = str('l')
1092-
# elif (self.dock.checkBoxLeft.isChecked() == False and self.dock.checkBoxRight.isChecked() == True):
1093-
# args['driving_side'] = str('r')
1094-
10951071
return args
10961072

10971073
# emulate "matching.sql" - "find_nearest_node_within_distance"
@@ -1113,13 +1089,25 @@ def findNearestNode(self, args, pt):
11131089
args['SBBOX'] = self.getBBOX(args['srid'])[0]
11141090
args['geom_t'] = Utils.getTransformedGeom(args['srid'], args['dbcanvas_srid'], args['geometry'])
11151091

1116-
db, cur = self._exec_sql(PgrQ.get_closestVertexInfo(args))
1117-
if cur:
1118-
row = cur.fetchone()
1119-
db.con.close()
1120-
return True, row[0], row[2]
1121-
else:
1122-
return False, None, None
1092+
try:
1093+
dbname = str(self.dock.comboConnections.currentText())
1094+
db = self.actionsDb[dbname].connect()
1095+
connection = db.con
1096+
cursor = connection.cursor()
1097+
1098+
#Utils.logMessage(PgrQ.get_closestVertexInfo(args).as_string(connection))
1099+
cursor.execute(PgrQ.get_closestVertexInfo(args))
1100+
if cursor:
1101+
data = cursor.fetchone()
1102+
return True, data[0], data[2]
1103+
else:
1104+
return False, None, None
1105+
1106+
db.connection.close()
1107+
1108+
except psycopg2.DatabaseError as e:
1109+
QApplication.restoreOverrideCursor()
1110+
QMessageBox.critical(self.dock, self.dock.windowTitle(), '%s' % e)
11231111

11241112
# emulate "matching.sql" - "find_nearest_link_within_distance"
11251113
def findNearestLink(self, args, pt):
@@ -1182,9 +1170,6 @@ def loadSettings(self):
11821170
self.dock.selectAstarFactor.setText(Utils.getStringValue(settings, '/pgRoutingLayer/sql/factor', '1'))
11831171
self.dock.selectAstarEpsilon.setTickPosition(int(Utils.getStringValue(settings, '/pgRoutingLayer/sql/epsilon', '100')))
11841172

1185-
# self.dock.lineEditRule.setText(Utils.getStringValue(settings, '/pgRoutingLayer/sql/rule', 'rule'))
1186-
# self.dock.lineEditToCost.setText(Utils.getStringValue(settings, '/pgRoutingLayer/sql/to_cost', 'to_cost'))
1187-
11881173
self.dock.lineEditIds.setText(Utils.getStringValue(settings, '/pgRoutingLayer/ids', ''))
11891174
self.dock.lineEditPcts.setText(Utils.getStringValue(settings, '/pgRoutingLayer/pcts', ''))
11901175

pgRoutingLayer_utils.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ def getCanvasSrid(crs):
9494

9595
def createFromSrid(crs, srid):
9696
''' Creates Spatial reference system based of SRID. '''
97-
return crs.createFromSrid(srid)
97+
return crs.createFromProj(str(srid))
9898

9999

100100
def getRubberBandType(isPolygon):

requirements.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,3 @@
11
mkdocs
22
pb_tool
3+
setuptools

0 commit comments

Comments
 (0)