Check out the latest version of Routino: svn co http://routino.org/svn/trunk routino
Contents of /branches/destination-access/python/database.py
Parent Directory
|
Revision Log
Revision 1971 -
(show annotations)
(download)
(as text)
Sat Mar 16 14:22:37 2019 UTC (6 years ago) by amb
File MIME type: text/x-python
File size: 8525 byte(s)
Sat Mar 16 14:22:37 2019 UTC (6 years ago) by amb
File MIME type: text/x-python
File size: 8525 byte(s)
Update the Python interfaces for the 'destination-access' branch.
1 | #!/usr/bin/python3 |
2 | ########################################## |
3 | # Routino database access from Python. |
4 | # |
5 | # Part of the Routino routing software. |
6 | ########################################## |
7 | # This file Copyright 2018, 2019 Andrew M. Bishop |
8 | # |
9 | # This program is free software: you can redistribute it and/or modify |
10 | # it under the terms of the GNU Affero General Public License as published by |
11 | # the Free Software Foundation, either version 3 of the License, or |
12 | # (at your option) any later version. |
13 | # |
14 | # This program is distributed in the hope that it will be useful, |
15 | # but WITHOUT ANY WARRANTY; without even the implied warranty of |
16 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
17 | # GNU Affero General Public License for more details. |
18 | # |
19 | # You should have received a copy of the GNU Affero General Public License |
20 | # along with this program. If not, see <http://www.gnu.org/licenses/>. |
21 | ########################################## |
22 | |
23 | import routino.database |
24 | |
25 | |
26 | # Database, access all attributes |
27 | |
28 | database = routino.database.LoadDatabase("../../src/test/fat", "turns") |
29 | |
30 | if database is None: |
31 | database = routino.database.LoadDatabase("../src/test/fat", "turns") |
32 | |
33 | if database is None: |
34 | print("Failed to load database") |
35 | exit(1) |
36 | |
37 | print(database) |
38 | |
39 | database_attrs = ['nnodes', 'nsegments', 'nways', 'nrelations'] |
40 | |
41 | for attr in database_attrs: |
42 | print(" Attribute: " + attr + " =", getattr(database, attr)) |
43 | |
44 | print("") |
45 | |
46 | |
47 | # A single node, access all attributes and all functions |
48 | |
49 | node=database.GetNode(0) |
50 | |
51 | print("1st node =", node) |
52 | |
53 | node_attrs = ['id', 'firstsegment', 'latitude', 'longitude', 'allow', 'flags'] |
54 | node_infos = ['', '', 'degrees', 'degrees', '[note 1]', '[note 2]'] |
55 | |
56 | for attr,info in zip(node_attrs,node_infos): |
57 | print(" Attribute: " + attr + " =", getattr(node, attr), info) |
58 | |
59 | segments = node.Segments() |
60 | print(" Function: " + "Segments()" + " = [" + ", ".join([str(segments[x]) for x in range(len(segments))]) + "]") |
61 | |
62 | print("") |
63 | |
64 | |
65 | # A single segment, access all attributes and all functions |
66 | |
67 | segment=database.GetSegment(0) |
68 | |
69 | print("1st segment =", segment) |
70 | |
71 | segment_attrs = ['id', 'node1', 'node2', 'next2', 'way', 'distance', 'flags'] |
72 | segment_infos = ['', '', '', '', '', 'km', '[note 3]'] |
73 | |
74 | for attr,info in zip(segment_attrs,segment_infos): |
75 | print(" Attribute: " + attr + " =", getattr(segment, attr), info) |
76 | |
77 | print(" Function: " + "Node1()" + " = " + str(segment.Node1())) |
78 | print(" Function: " + "Node2()" + " = " + str(segment.Node2())) |
79 | print(" Function: " + "Way()" + " = " + str(segment.Way())) |
80 | |
81 | print("") |
82 | |
83 | |
84 | # A single way, access all attributes and all functions |
85 | |
86 | way=database.GetWay(0) |
87 | |
88 | print("1st way =", way) |
89 | |
90 | way_attrs = ['id', 'name', 'allow', 'destination', 'type', 'props', 'speed', 'weight', 'height', 'width', 'length'] |
91 | way_infos = ['', '', '[note 1]', '[note 1]', '[note 4]', '[note 5]', 'km/hr [note 6]', 'tonnes [note 6]', 'metres [note 6]', 'metres [note 6]', 'metres [note 6]'] |
92 | |
93 | for attr,info in zip(way_attrs,way_infos): |
94 | print(" Attribute: " + attr + " =", getattr(way, attr), info) |
95 | |
96 | print("") |
97 | |
98 | |
99 | # A single relation, access all attributes and all functions |
100 | |
101 | relation=database.GetRelation(0) |
102 | |
103 | print("1st relation =", relation) |
104 | |
105 | relation_attrs = ['id', 'from_seg', 'via_node', 'to_seg', 'from_way', 'to_way', 'from_node', 'to_node', 'except_transport'] |
106 | relation_infos = ['', '', '', '', '', '', '', '', '[note 7]'] |
107 | |
108 | for attr,info in zip(relation_attrs,relation_infos): |
109 | print(" Attribute: " + attr + " =", getattr(relation, attr), info) |
110 | |
111 | print(" Function: " + "FromSegment()" + " = " + str(relation.FromSegment())) |
112 | print(" Function: " + "ViaNode()" + " = " + str(relation.ViaNode())) |
113 | print(" Function: " + "ToSegment()" + " = " + str(relation.ToSegment())) |
114 | |
115 | print(" Function: " + "FromWay()" + " = " + str(relation.FromWay())) |
116 | print(" Function: " + "ToWay()" + " = " + str(relation.ToWay())) |
117 | |
118 | print(" Function: " + "FromNode()" + " = " + str(relation.FromNode())) |
119 | print(" Function: " + "ToNode()" + " = " + str(relation.ToNode())) |
120 | |
121 | print("") |
122 | |
123 | |
124 | # The list of nodes as a list and an iterable (just the first 4) |
125 | |
126 | nodes=database.Nodes() |
127 | |
128 | print("len(database.Nodes()) = " + str(len(nodes))) |
129 | |
130 | print("database.Nodes() = [" + ", ".join([str(nodes[x]) for x in range(4)]) + ", ...]") |
131 | |
132 | for node in nodes: |
133 | if node.id == 4: |
134 | break |
135 | print(node) |
136 | |
137 | print("") |
138 | |
139 | |
140 | # The list of segments as a list and an iterable (just the first 4) |
141 | |
142 | segments=database.Segments() |
143 | |
144 | print("len(database.Segments()) = " + str(len(segments))) |
145 | |
146 | print("database.Segments() = [" + ", ".join([str(segments[x]) for x in range(4)]) + ", ...]") |
147 | |
148 | for segment in segments: |
149 | if segment.id == 4: |
150 | break |
151 | print(segment) |
152 | |
153 | print("") |
154 | |
155 | |
156 | # The list of ways as a list and an iterable (just the first 4) |
157 | |
158 | ways=database.Ways() |
159 | |
160 | print("len(database.Ways()) = " + str(len(ways))) |
161 | |
162 | print("database.Ways() = [" + ", ".join([str(ways[x]) for x in range(4)]) + ", ...]") |
163 | |
164 | for way in ways: |
165 | if way.id == 4: |
166 | break |
167 | print(way) |
168 | |
169 | print("") |
170 | |
171 | |
172 | # The list of relations as a list and an iterable (just the first 4) |
173 | |
174 | relations=database.Relations() |
175 | |
176 | print("len(database.Relations()) = " + str(len(relations))) |
177 | |
178 | print("database.Relations() = [" + ", ".join([str(relations[x]) for x in range(4)]) + ", ...]") |
179 | |
180 | for relation in relations: |
181 | if relation.id == 4: |
182 | break |
183 | print(relation) |
184 | |
185 | print("") |
186 | |
187 | |
188 | # Enumerated lists |
189 | |
190 | transports_enum = ["Transports_None", |
191 | "Transports_Foot", |
192 | "Transports_Horse", |
193 | "Transports_Wheelchair", |
194 | "Transports_Bicycle", |
195 | "Transports_Moped", |
196 | "Transports_Motorcycle", |
197 | "Transports_Motorcar", |
198 | "Transports_Goods", |
199 | "Transports_HGV", |
200 | "Transports_PSV", |
201 | "Transports_ALL"] |
202 | |
203 | nodeflags_enum = ["Nodeflag_Super", |
204 | "Nodeflag_U_Turn", |
205 | "Nodeflag_Mini_Roundabout", |
206 | "Nodeflag_Turn_Restrict", |
207 | "Nodeflag_Turn_Restrict2"] |
208 | |
209 | segmentflags_enum = ["Segmentflag_Area", |
210 | "Segmentflag_Oneway_1to2", |
211 | "Segmentflag_Oneway_2to1", |
212 | "Segmentflag_Super", |
213 | "Segmentflag_Normal"] |
214 | |
215 | properties_enum = ["Properties_None", |
216 | "Properties_Paved", |
217 | "Properties_Multilane", |
218 | "Properties_Bridge", |
219 | "Properties_Tunnel", |
220 | "Properties_FootRoute", |
221 | "Properties_BicycleRoute", |
222 | "Properties_ALL"] |
223 | |
224 | highway_enum = ["Highway_Motorway", |
225 | "Highway_Trunk", |
226 | "Highway_Primary", |
227 | "Highway_Secondary", |
228 | "Highway_Tertiary", |
229 | "Highway_Unclassified", |
230 | "Highway_Residential", |
231 | "Highway_Service", |
232 | "Highway_Track", |
233 | "Highway_Cycleway", |
234 | "Highway_Path", |
235 | "Highway_Steps", |
236 | "Highway_Ferry", |
237 | "Highway_Count", |
238 | "Highway_CycleBothWays", |
239 | "Highway_OneWay", |
240 | "Highway_Roundabout", |
241 | "Highway_Area"] |
242 | |
243 | def print_enum(list): |
244 | for item in list: |
245 | print(" routino.database."+item) |
246 | |
247 | |
248 | print("Note 1: The Node's and Way's 'allow' parameter and the Way's 'destination' parameter can be the combination of these enumerated values:") |
249 | print_enum(transports_enum) |
250 | print("") |
251 | print("Note 2: The Node's 'flags' parameter can be the combination of these enumerated values:") |
252 | print_enum(nodeflags_enum) |
253 | print("") |
254 | print("Note 3: The Segment's 'flags' parameter can be the combination of these enumerated values:") |
255 | print_enum(segmentflags_enum) |
256 | print("") |
257 | print("Note 4: The Way's 'type' parameter can be one the combination of these enumerated values:") |
258 | print_enum(highway_enum) |
259 | print("") |
260 | print("Note 5: The Way's 'props' parameter can be the combination of these enumerated values:") |
261 | print_enum(properties_enum) |
262 | print("") |
263 | print("Note 6: A value of zero for a Way's speed, weight, height, width or length means that there is no limit.") |
264 | print("") |
265 | print("Note 7: The Relation's 'except_transport' parameter can be the combination of these enumerated values:") |
266 | print_enum(transports_enum) |
267 | print("") |
268 | |
269 | |
270 | import gc |
271 | |
272 | gc.collect() |
Properties
Name | Value |
---|---|
svn:executable | * |