forked from anitagraser/pgRoutingLayer
-
-
Notifications
You must be signed in to change notification settings - Fork 19
Expand file tree
/
Copy pathTest_FunctionBase.py
More file actions
executable file
·104 lines (92 loc) · 3.65 KB
/
Copy pathTest_FunctionBase.py
File metadata and controls
executable file
·104 lines (92 loc) · 3.65 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
# coding=utf-8
# -*- coding: utf-8 -*-
# /*PGR-GNU*****************************************************************
# File: qgis_models.py
#
# Copyright (c) 2011~2019 pgRouting developers
# Mail: project@pgrouting.org
#
# Developer's GitHub nickname:
# - cayetanobv
# - AasheeshT
# - cvvergara
# - anitagraser
# ------
#
# 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.
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
# ********************************************************************PGR-GNU*/
import unittest
import FunctionBase as FB
class TestFB(unittest.TestCase):
def test_getJoinResultWithEdgeTable(self):
args = {
'geometry': 'test_geom', 'source': 'test_source', 'startpoint': 10,
'id': 'test_id', 'edge_table': 'test_Table', 'target': 100, 'endpoint': 90
}
expected_sql = """
WITH
result AS ( )
SELECT
CASE
WHEN result._node = test_Table.test_source
THEN test_Table.test_geom
ELSE ST_Reverse(test_Table.test_geom)
END AS path_geom,
result.*, test_Table.*
FROM test_Table JOIN result
ON test_Table.test_id = result._edge ORDER BY result.seq
"""
self.maxDiff = None
self.assertEqual(FB.getJoinResultWithEdgeTable(args), expected_sql)
def test_getExportManySourceManyTargetMergeQuery(self):
args = {
'geometry': 'test_geom', 'source': 'test_source', 'startpoint': 10,
'id': 'test_id', 'edge_table': 'test_Table', 'target': 100, 'endpoint': 90
}
expected_sql = """WITH
result AS ( ),
with_geom AS (
SELECT
seq, result.path_name,
CASE
WHEN result._node = test_Table.test_source
THEN test_Table.test_geom
ELSE ST_Reverse(test_Table.test_geom)
END AS path_geom
FROM test_Table JOIN result
ON test_Table.test_id = result._edge
),
one_geom AS (
SELECT path_name, ST_LineMerge(ST_Union(path_geom)) AS path_geom
FROM with_geom
GROUP BY path_name
ORDER BY path_name
),
aggregates AS (
SELECT
path_name, _start_vid, _end_vid,
SUM(_cost) AS agg_cost,
array_agg(_node ORDER BY _path_seq) AS _nodes,
array_agg(_edge ORDER BY _path_seq) AS _edges
FROM result
GROUP BY path_name, _start_vid, _end_vid
ORDER BY _start_vid, _end_vid )
SELECT row_number() over() as seq,
path_name, _start_vid, _end_vid, agg_cost, _nodes, _edges,
path_geom AS path_geom FROM aggregates JOIN one_geom
USING (path_name)
"""
self.maxDiff = None
self.assertEqual(FB.getExportManySourceManyTargetMergeQuery(args), expected_sql)
if __name__ == '__main__':
unittest.main()