Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
eclipse
GitHub Repository: eclipse/sumo
Path: blob/main/tools/contributed/sumopy/plugins/mapmatching/wxgui.py
169580 views
1
# Eclipse SUMO, Simulation of Urban MObility; see https://eclipse.dev/sumo
2
# Copyright (C) 2016-2025 German Aerospace Center (DLR) and others.
3
# SUMOPy module
4
# Copyright (C) 2012-2021 University of Bologna - DICAM
5
# This program and the accompanying materials are made available under the
6
# terms of the Eclipse Public License 2.0 which is available at
7
# https://www.eclipse.org/legal/epl-2.0/
8
# This Source Code may also be made available under the following Secondary
9
# Licenses when the conditions for such availability set forth in the Eclipse
10
# Public License 2.0 are satisfied: GNU General Public License, version 2
11
# or later which is available at
12
# https://www.gnu.org/licenses/old-licenses/gpl-2.0-standalone.html
13
# SPDX-License-Identifier: EPL-2.0 OR GPL-2.0-or-later
14
15
# @file wxgui.py
16
# @author Joerg Schweizer
17
# @date 2012
18
19
import os
20
import wx
21
import numpy as np
22
23
from agilepy.lib_wx.modulegui import ModuleGui
24
from agilepy.lib_wx.ogleditor import *
25
from agilepy.lib_base.processes import Process
26
from agilepy.lib_wx.processdialog import ProcessDialog, ProcessDialogInteractive
27
28
from coremodules.network import routing
29
from coremodules.demand import demand
30
31
import mapmatching
32
33
34
#import results_mpl as results_mpl
35
try:
36
import results_mpl as results_mpl
37
is_mpl = True # we have matplotlib support
38
except:
39
print "WARNING: python matplotlib package not installed, no matplotlib plots."
40
is_mpl = False
41
42
43
class GpsPointsDrawings(Circles):
44
def __init__(self, ident, gpspoints, parent, **kwargs):
45
46
Circles.__init__(self, ident, parent, name='GPS points',
47
is_parentobj=False,
48
is_fill=True, # Fill objects,
49
is_outline=False, # show outlines
50
n_vert=11, # default number of vertex per circle
51
linewidth=3,
52
**kwargs)
53
54
self.delete('centers')
55
self.delete('radii')
56
57
self.add(cm.AttrConf('color_default', np.array([1.0, 0.8, 0.1, 0.5], np.float32),
58
groupnames=['options', 'colors'],
59
metatype='color',
60
perm='wr',
61
name='Default color',
62
info='Default point color.',
63
))
64
65
# self.set_netelement(gpspoints)
66
67
def get_netelement(self):
68
return self._gpspoints
69
70
def get_centers_array(self):
71
# return self._gpspoints.coords.value[self._inds_map]
72
return self._gpspoints.coords[self.get_ids()]
73
74
def get_radii_array(self):
75
return self._gpspoints.radii[self.get_ids()]
76
# return self._gpspoints.radii.value[self._inds_map]
77
78
def is_tool_allowed(self, tool, id_drawobj=-1):
79
"""
80
Returns True if this tool can be applied to this drawobj.
81
Optionally a particular drawobj can be specified with id_drawobj.
82
"""
83
# basic tools:
84
return tool.ident not in ['select_handles', 'delete', 'stretch'] # 'configure',
85
# return tool.ident not in ['delete','stretch']
86
87
def set_netelement(self, gpspoints):
88
# print 'set_nodes'
89
self._gpspoints = gpspoints
90
# if len(self)>0:
91
# self.del_rows(self.get_ids())
92
self.clear_rows()
93
94
ids = self._gpspoints.get_ids_selected()
95
n = len(ids)
96
97
#self._inds_map = self._gpspoints.get_inds(ids)
98
99
# print 'color_node_default',self.color_node_default.value
100
# print 'colors\n', np.ones((n,1),np.int32)*self.color_node_default.value
101
self.add_rows(ids=ids,
102
#colors = np.ones((n,1),np.int32)*self.color_default.value,
103
#colors_highl = self._get_colors_highl(np.ones((n,1),np.int32)*self.color_default.value),
104
colors_fill=np.ones((n, 1), np.int32)*self.color_default.value,
105
colors_highl_highl=self._get_colors_highl(np.ones((n, 1), np.int32)*self.color_default.value),
106
#centers = self._nodes.coords[ids],
107
#radii = self._nodes.radii[ids],
108
)
109
110
self.centers = self._gpspoints.coords
111
self.radii = self._gpspoints.radii
112
self.update()
113
114
def update(self, is_update=True):
115
116
if is_update:
117
self._update_vertexvbo()
118
self._update_colorvbo()
119
120
121
class GpsRoutesDrawings(Polylines):
122
def __init__(self, ident, edges, parent, **kwargs):
123
124
# joinstyle
125
# FLATHEAD = 0
126
# BEVELHEAD = 1
127
Polylines.__init__(self, ident, parent, name='GPS routes drawings',
128
is_lefthalf=True,
129
is_righthalf=True,
130
arrowstretch=1.5,
131
joinstyle=BEVELHEAD, # FLATHEAD,#BEVELHEAD is good for both halfs,
132
**kwargs)
133
134
# self.delete('vertices')
135
# self.delete('widths')
136
# self.delete('colors')
137
138
self.add(cm.AttrConf('width_default', 4.0,
139
groupnames=['options'],
140
perm='wr',
141
name='Default width',
142
info='Default route width of drawing.',
143
))
144
145
self.add(cm.AttrConf('color_default', np.array([1.0, 0.4, 0.0, 0.6], np.float32),
146
groupnames=['options'],
147
perm='wr',
148
metatype='color',
149
name='Default color',
150
info='Default route color.',
151
))
152
153
# self.set_netelement(edges)
154
155
def get_netelement(self):
156
return self._routes
157
158
# def get_vertices_array(self):
159
# return self._routes.shapes[self.get_ids()]#.value[self._inds_map]#[self.get_ids()]
160
161
# def get_widths_array(self):
162
# # double because only the right half is shown
163
# # add a little bit to the width to make it a little wider than the lanes contained
164
# #return 2.2*self._edges.widths.value[self._inds_map]
165
# return 1.1*self._edges.widths[self.get_ids()]#.value[self._inds_map]
166
167
# def get_vertices(self, ids):
168
# return self._edges.shapes[ids]
169
170
# def set_vertices(self, ids, vertices, is_update = True):
171
# self._edges.set_shapes(ids, vertices)
172
# if is_update:
173
# self._update_vertexvbo()
174
# self.parent.get_drawobj_by_ident('lanedraws').update()
175
# self.parent.get_drawobj_by_ident('crossingsdraws').update()
176
# self.parent.get_drawobj_by_ident('connectiondraws').update()
177
178
# def get_widths(self, ids):
179
# return 1.1*self._edges.widths[ids]
180
181
# def set_widths(self, ids, values):
182
# #self._edges.widths[ids] = values/1.1
183
# pass
184
185
def is_tool_allowed(self, tool, id_drawobj=-1):
186
"""
187
Returns True if this tool can be applied to this drawobj.
188
Optionally a particular drawobj can be specified with id_drawobj.
189
"""
190
# basic tools:
191
return tool.ident not in ['configure', 'select_handles', 'delete', 'move', 'stretch']
192
# return tool.ident not in ['delete',]
193
194
def set_netelement(self, routes):
195
196
self._routes = routes
197
#self._inds_edges = self._edges.get_inds()
198
self.clear_rows()
199
# if len(self)>0:
200
# self.del_rows(self.get_ids())
201
202
ids = self._routes.parent.get_ids_route_selected()
203
#self._inds_map = self._edges.get_inds(ids)
204
n = len(ids)
205
#self.vertices = self._edges.shapes
206
#self.widths = self._edges.widths
207
# print '\n\nGpsRoutesDrawings.set_netelement',n
208
# print ' ids.dtype',ids.dtype
209
# print ' self._ids.dtype',self._ids.dtype
210
# print ' self._inds.dtype',self._inds.dtype
211
# print ' ids',ids
212
self.add_rows(ids=ids,
213
beginstyles=np.ones(n, dtype=np.float32)*FLATHEAD,
214
endstyles=np.ones(n, dtype=np.float32)*TRIANGLEHEAD,
215
widths=np.ones(n, dtype=np.float32)*self.width_default.get_value()
216
)
217
self.vertices[ids] = self._routes.get_shapes(ids)
218
self.update()
219
220
def update(self, is_update=True):
221
"""
222
Update color, assume that there have not been structural changes of the arrays
223
"""
224
# assumes that edges have been set in set_edges
225
# print 'Edgedrawing.update'
226
#edgeinds = self._edges.get_inds()
227
n = len(self)
228
ids = self.get_ids()
229
230
self.colors_fill.value[:] = self._routes.colors[ids]
231
#self.colors_fill.value[:] = np.ones((n,1),np.float32)*self.color_default.value
232
self.colors_fill_highl.value[:] = self._get_colors_highl(self.colors_fill.value)
233
234
if is_update:
235
self._update_vertexvbo()
236
self._update_colorvbo()
237
238
239
class WxGui(ModuleGui):
240
"""Contains functions that communicate between the widgets of the main wx gui
241
and the functions of the plugin.
242
"""
243
244
def __init__(self, ident):
245
self._mapmatching = None
246
self._matchprocess = None
247
self._results = None
248
self._scenario = None
249
self._canvas = None
250
self._init_common(ident, priority=100001,
251
icondirpath=os.path.join(os.path.dirname(__file__), 'images'))
252
253
self._is_needs_refresh = False
254
255
def get_module(self):
256
return self._mapmatching
257
258
def get_scenario(self):
259
return self._mainframe.get_modulegui('coremodules.scenario').get_scenario()
260
261
def get_neteditor(self):
262
return self._mainframe.get_modulegui('coremodules.network').get_neteditor()
263
264
def get_canvas(self):
265
return self.get_neteditor().get_canvas()
266
267
def get_drawing(self):
268
return self.get_canvas().get_drawing()
269
270
def init_widgets(self, mainframe):
271
"""
272
Set mainframe and initialize widgets to various places.
273
"""
274
self._mainframe = mainframe
275
#self._neteditor = mainframe.add_view("Network", Neteditor)
276
277
# mainframe.browse_obj(self._module)
278
self.make_menu()
279
self.make_toolbar()
280
281
def refresh_widgets(self):
282
"""
283
Check through mainframe what the state of the application is
284
and reset widgets. For exampe enable/disable widgets
285
dependent on the availability of data.
286
"""
287
print 'MapmatchingWxGui.refresh_widgets'
288
scenario = self.get_scenario()
289
is_refresh = False
290
if self._scenario != scenario:
291
del self._scenario
292
del self._mapmatching
293
del self._results
294
self._scenario = scenario
295
self._mapmatching = scenario.demand.add_demandobject(
296
ident='mapmatching', DemandClass=mapmatching.Mapmatching)
297
#self._mapmatching = mapmatching.Mapmatching('mapmatching', scenario)
298
self._matchprocess = None
299
self._results = mapmatching.Matchresults('matchresults',
300
self._mapmatching,
301
)
302
is_refresh = True
303
304
if is_refresh | self._is_needs_refresh:
305
self._is_needs_refresh = False
306
print ' is_refresh', is_refresh, self._is_needs_refresh
307
neteditor = self.get_neteditor()
308
#canvas = self.get_canvas()
309
drawing = self.get_drawing() # canvas.get_drawing()
310
311
# add or refresh facility drawing
312
drawing.set_element('gpspointsdraws', GpsPointsDrawings,
313
self._mapmatching.points, layer=150)
314
315
drawing.set_element('gpsroutesdraws', GpsRoutesDrawings,
316
self._mapmatching.trips.get_routes(), layer=149)
317
318
# neteditor.get_toolbox().add_toolclass(AddZoneTool)# will check if tool is already there
319
# neteditor.get_toolbox().add_toolclass(AddFacilityTool)
320
neteditor.draw()
321
322
self._canvas = self.get_canvas()
323
324
def make_menu(self):
325
menubar = self._mainframe.menubar
326
menubar.append_menu('plugins/mapmatching',
327
bitmap=self.get_icon("icon_gps.png"),
328
)
329
menubar.append_item('plugins/mapmatching/browse',
330
self.on_browse, # common function in modulegui
331
info='View and browse mapmatching in object panel.',
332
bitmap=self.get_agileicon('icon_browse_24px.png'), # ,
333
)
334
335
# menubar.append_item( 'plugins/mapmatching/open...',
336
# self.on_open,
337
# bitmap = wx.ArtProvider.GetBitmap(wx.ART_FILE_OPEN,wx.ART_MENU),
338
# )
339
340
menubar.append_menu('plugins/mapmatching/import',
341
bitmap=self.get_agileicon("Document_Import_24px.png"),
342
)
343
344
menubar.append_item('plugins/mapmatching/import/European cycling challange...',
345
self.on_import_ecc,
346
# info=self.on_import_ecc.__doc__.strip(),
347
bitmap=self.get_agileicon("Document_Import_24px.png"),
348
)
349
350
menubar.append_item('plugins/mapmatching/import/Bella mossa...',
351
self.on_import_bellamossa,
352
# info=self.on_import_ecc.__doc__.strip(),
353
bitmap=self.get_agileicon("Document_Import_24px.png"),
354
)
355
356
menubar.append_item('plugins/mapmatching/import/Mobike...',
357
self.on_import_mobike,
358
# info=self.on_import_ecc.__doc__.strip(),
359
bitmap=self.get_agileicon("Document_Import_24px.png"),
360
)
361
menubar.append_item('plugins/mapmatching/import/Strava...',
362
self.on_import_strava,
363
# info=self.on_import_ecc.__doc__.strip(),
364
bitmap=self.get_agileicon("Document_Import_24px.png"),
365
)
366
367
menubar.append_item('plugins/mapmatching/import/GPX file...',
368
self.on_import_gpx,
369
# info=self.on_import_ecc.__doc__.strip(),
370
bitmap=self.get_agileicon("Document_Import_24px.png"),
371
)
372
373
# menubar.append_item( 'plugins/mapmatching/project points',
374
# self.on_project_points,
375
# #bitmap = wx.ArtProvider.GetBitmap(wx.ART_FILE_SAVE_AS,wx.ART_MENU),
376
# )
377
# -------------------------------------------------------------------------------
378
379
menubar.append_menu('plugins/mapmatching/mapmatching',
380
# bitmap = self.get_icon('icon_results_24px.png'),#,
381
info='Apply different mapmatching methods to identify the network edges that best represent a trace of GPS points.'
382
)
383
384
menubar.append_item('plugins/mapmatching/mapmatching/match points to road network...',
385
self.on_match_birgil,
386
#bitmap = wx.ArtProvider.GetBitmap(wx.ART_FILE_SAVE_AS,wx.ART_MENU),
387
)
388
389
menubar.append_item('plugins/mapmatching/mapmatching/match points to PT network...',
390
self.on_match_pt,
391
#bitmap = wx.ArtProvider.GetBitmap(wx.ART_FILE_SAVE_AS,wx.ART_MENU),
392
)
393
394
# -------------------------------------------------------------------------------
395
menubar.append_menu('plugins/mapmatching/routing',
396
# bitmap = self.get_icon('icon_results_24px.png'),#,
397
info='Apply different routing algorithms to create alternative routes to the mapmatched routes.'
398
)
399
menubar.append_item('plugins/mapmatching/routing/shortest path routing...',
400
self.on_route_shortest,
401
#bitmap = wx.ArtProvider.GetBitmap(wx.ART_FILE_SAVE_AS,wx.ART_MENU),
402
)
403
404
menubar.append_item('plugins/mapmatching/routing/fastest path routing...',
405
self.on_route_fastest,
406
#bitmap = wx.ArtProvider.GetBitmap(wx.ART_FILE_SAVE_AS,wx.ART_MENU),
407
)
408
409
410
# -------------------------------------------------------------------------------
411
412
menubar.append_menu('plugins/mapmatching/person analysis',
413
bitmap=self.get_icon('icon_results_24px.png'), # ,
414
info='Person analysis tools'
415
)
416
417
menubar.append_item('plugins/mapmatching/person analysis/analyze',
418
self.on_analyze_persons,
419
#bitmap = wx.ArtProvider.GetBitmap(wx.ART_FILE_SAVE_AS,wx.ART_MENU),
420
)
421
422
menubar.append_item('plugins/mapmatching/person analysis/save matched in csv...',
423
self.on_export_persons_csv,
424
info='Save persons with matched trips in a CSV file.',
425
bitmap=self.get_agileicon("Document_Export_24px.png"),
426
)
427
# -------------------------------------------------------------------------------
428
429
menubar.append_menu('plugins/mapmatching/point analysis',
430
bitmap=self.get_icon('icon_results_24px.png'), # ,
431
info='Point analysis tools'
432
)
433
434
if is_mpl:
435
menubar.append_item('plugins/mapmatching/point analysis/plot point results...',
436
self.on_plot_pointresults,
437
bitmap=results_mpl.get_mplicon(), # ,
438
)
439
440
# -------------------------------------------------------------------------------
441
442
menubar.append_menu('plugins/mapmatching/route analysis',
443
bitmap=self.get_icon('icon_results_24px.png'), # ,
444
info='Route analysis tools'
445
)
446
447
menubar.append_item('plugins/mapmatching/route analysis/browse',
448
self.on_browse_results, # common function in modulegui
449
bitmap=self.get_agileicon('icon_browse_24px.png'), # ,
450
)
451
452
menubar.append_item('plugins/mapmatching/route analysis/analyze...',
453
self.on_routeanalyze, # common function in modulegui
454
# bitmap = self.get_agileicon('icon_browse_24px.png'),#,
455
)
456
457
menubar.append_item('plugins/mapmatching/route analysis/create trips database...',
458
self.on_create_trips_database, # common function in modulegui
459
# bitmap = self.get_agileicon('icon_browse_24px.png'),#,
460
)
461
462
menubar.append_item('plugins/mapmatching/route analysis/create cyclists database...',
463
self.on_create_cyclists_database, # common function in modulegui
464
# bitmap = self.get_agileicon('icon_browse_24px.png'),#,
465
)
466
menubar.append_item('plugins/mapmatching/route analysis/analyze alternative routes...',
467
self.on_altrouteanalyze, # common function in modulegui
468
# bitmap = self.get_agileicon('icon_browse_24px.png'),#,
469
)
470
471
menubar.append_item('plugins/mapmatching/route analysis/analyze PT routes...',
472
self.on_ptanalyze, # common function in modulegui
473
# bitmap = self.get_agileicon('icon_browse_24px.png'),#,
474
)
475
476
if is_mpl:
477
menubar.append_item('plugins/mapmatching/route analysis/plot route results...',
478
self.on_plot_routeresults,
479
bitmap=results_mpl.get_mplicon(), # ,
480
)
481
482
menubar.append_item('plugins/mapmatching/route analysis/plot public transport flows...',
483
self.on_plot_ptflows,
484
bitmap=results_mpl.get_mplicon(), # ,
485
)
486
487
menubar.append_item('plugins/mapmatching/route analysis/plot edge results...',
488
self.on_plot_edgeresults,
489
bitmap=results_mpl.get_mplicon(), # ,
490
)
491
menubar.append_item('plugins/mapmatching/route analysis/plot connection results...',
492
self.on_plot_connectionresults,
493
bitmap=results_mpl.get_mplicon(), # ,
494
)
495
496
menubar.append_item('plugins/mapmatching/route analysis/plot speed profiles...',
497
self.on_plot_speedprofiles,
498
bitmap=results_mpl.get_mplicon(), # ,
499
)
500
menubar.append_item('plugins/mapmatching/route analysis/plot node results...',
501
self.on_plot_noderesults,
502
bitmap=results_mpl.get_mplicon(), # ,
503
)
504
505
menubar.append_item('plugins/mapmatching/route analysis/plot alternative routes...',
506
self.on_plot_alternative_routes,
507
bitmap=results_mpl.get_mplicon(), # ,
508
)
509
510
menubar.append_item('plugins/mapmatching/route analysis/safe as...',
511
self.on_save_results,
512
bitmap=wx.ArtProvider.GetBitmap(wx.ART_FILE_SAVE_AS, wx.ART_MENU),
513
)
514
515
menubar.append_item('plugins/mapmatching/route analysis/open...',
516
self.on_open_results,
517
bitmap=wx.ArtProvider.GetBitmap(wx.ART_FILE_OPEN, wx.ART_MENU),
518
)
519
520
521
# -------------------------------------------------------------------------------
522
menubar.append_menu('plugins/mapmatching/demand generation',
523
bitmap=self.get_icon('icon_sim.png'), # ,
524
info='Create vp from trips'
525
)
526
527
menubar.append_item('plugins/mapmatching/demand generation/zone-to-zone demand generation',
528
self.create_zonetozone_demand,
529
bitmap=self.get_icon('icon_od.png'), # ,
530
#bitmap = wx.ArtProvider.GetBitmap(wx.ART_FILE_SAVE_AS,wx.ART_MENU),
531
)
532
menubar.append_item('plugins/mapmatching/demand generation/routes generation...',
533
self.create_odroute_from_trips,
534
bitmap=self.get_icon('icon_sim.png'), # ,
535
#bitmap = wx.ArtProvider.GetBitmap(wx.ART_FILE_SAVE_AS,wx.ART_MENU),
536
)
537
menubar.append_item('plugins/mapmatching/demand generation/virtual pop generation',
538
self.create_vp_from_trips,
539
bitmap=self.get_icon('icon_vp.png'), # ,
540
#bitmap = wx.ArtProvider.GetBitmap(wx.ART_FILE_SAVE_AS,wx.ART_MENU),
541
)
542
543
# -------------------------------------------------------------------------------
544
545
menubar.append_menu('plugins/mapmatching/filter and select',
546
# bitmap = self.get_icon('icon_results_24px.png'),#,
547
info='Filter and select GPS trips.'
548
)
549
550
menubar.append_item('plugins/mapmatching/filter and select/select traces by geometry...',
551
self.on_geomfilter_trips,
552
#bitmap = wx.ArtProvider.GetBitmap(wx.ART_FILE_SAVE_AS,wx.ART_MENU),
553
)
554
555
menubar.append_item('plugins/mapmatching/filter and select/post-match filter trips...',
556
self.on_postmatchfilter_trips,
557
#bitmap = wx.ArtProvider.GetBitmap(wx.ART_FILE_SAVE_AS,wx.ART_MENU),
558
)
559
560
menubar.append_item('plugins/mapmatching/filter and select/select mode...',
561
self.on_select_mode,
562
#bitmap = wx.ArtProvider.GetBitmap(wx.ART_FILE_SAVE_AS,wx.ART_MENU),
563
)
564
565
menubar.append_item('plugins/mapmatching/filter and select/select all trips',
566
self.on_select_all_trips,
567
)
568
569
menubar.append_item('plugins/mapmatching/filter and select/unselect all trips',
570
self.on_unselect_all_trips,
571
)
572
573
menubar.append_item('plugins/mapmatching/filter and select/invert selected trips',
574
self.on_invert_selected_trips,
575
)
576
# -------------------------------------------------------------------------------
577
578
menubar.append_menu('plugins/mapmatching/delete',
579
bitmap=wx.ArtProvider.GetBitmap(wx.ART_DELETE, wx.ART_MENU),
580
info='Delete tools.'
581
)
582
583
menubar.append_item('plugins/mapmatching/delete/delete unselected trips',
584
self.on_delete_unselected,
585
bitmap=wx.ArtProvider.GetBitmap(wx.ART_DELETE, wx.ART_MENU),
586
)
587
588
menubar.append_item('plugins/mapmatching/delete/delete routes',
589
self.on_clear_routes,
590
bitmap=wx.ArtProvider.GetBitmap(wx.ART_DELETE, wx.ART_MENU),
591
)
592
593
menubar.append_item('plugins/mapmatching/delete/delete all',
594
self.on_clear_all,
595
bitmap=wx.ArtProvider.GetBitmap(wx.ART_DELETE, wx.ART_MENU),
596
)
597
598
# -------------------------------------------------------------------------------
599
menubar.append_menu('plugins/mapmatching/export',
600
bitmap=self.get_agileicon("Document_Export_24px.png"),
601
)
602
603
menubar.append_item('plugins/mapmatching/export/route results to shape...',
604
self.on_routes_to_shapefile,
605
bitmap=wx.ArtProvider.GetBitmap(wx.ART_FILE_SAVE_AS, wx.ART_MENU),
606
)
607
608
menubar.append_item('plugins/mapmatching/export/edge results to shape...',
609
self.on_edgesresults_to_shapefile,
610
bitmap=wx.ArtProvider.GetBitmap(wx.ART_FILE_SAVE_AS, wx.ART_MENU),
611
)
612
613
menubar.append_item('plugins/mapmatching/export/GPS points to shape...',
614
self.on_points_to_shapefile,
615
bitmap=wx.ArtProvider.GetBitmap(wx.ART_FILE_SAVE_AS, wx.ART_MENU),
616
)
617
618
# -------------------------------------------------------------------------------
619
menubar.append_menu('plugins/mapmatching/GTFS',
620
bitmap=self.get_icon('icon_g.png'), # ,
621
info="GTFS import, matching and public transport generation functionality, based on Goole Transit file formats."
622
)
623
624
menubar.append_item('plugins/mapmatching/GTFS/GTFS shapes...',
625
self.on_import_gtfs,
626
# info=self.on_import_ecc.__doc__.strip(),
627
bitmap=self.get_agileicon("Document_Import_24px.png"),
628
)
629
630
menubar.append_item('plugins/mapmatching/GTFS/generate Stops from GTFS...',
631
self.on_gtfsstopgenerate, # common function in modulegui
632
bitmap=self.get_icon('icon_g.png'), # ,
633
)
634
635
menubar.append_item('plugins/mapmatching/GTFS/generate services from GTFS...',
636
self.on_gtfsservicegenerate, # common function in modulegui
637
bitmap=self.get_icon('icon_g.png'), # ,
638
)
639
640
# -------------------------------------------------------------------------------
641
642
menubar.append_item('plugins/mapmatching/redraw GPS data',
643
self.on_redraw,
644
)
645
646
def on_plot_pointresults(self, event=None):
647
"""
648
Plot point results of route analysis in Matplotlib plotting envitonment.
649
"""
650
if is_mpl:
651
resultplotter = results_mpl.PointresultPlotter(self._results,
652
logger=self._mainframe.get_logger()
653
)
654
dlg = results_mpl.ResultDialog(self._mainframe, resultplotter)
655
656
dlg.CenterOnScreen()
657
658
# this does not return until the dialog is closed.
659
val = dlg.ShowModal()
660
# print ' val,val == wx.ID_OK',val,wx.ID_OK,wx.ID_CANCEL,val == wx.ID_CANCEL
661
# print ' status =',dlg.get_status()
662
if dlg.get_status() != 'success': # val == wx.ID_CANCEL:
663
# print ">>>>>>>>>Unsuccessful\n"
664
dlg.Destroy()
665
666
if dlg.get_status() == 'success':
667
# print ">>>>>>>>>successful\n"
668
# apply current widget values to scenario instance
669
dlg.apply()
670
dlg.Destroy()
671
672
def od_analysis(self, event=None):
673
"""
674
OD analysis.
675
"""
676
if is_mpl:
677
p = results_mpl.ODanalysis(self._results,
678
logger=self._mainframe.get_logger()
679
)
680
dlg = ProcessDialog(self._mainframe, p, immediate_apply=True)
681
682
dlg.CenterOnScreen()
683
684
# this does not return until the dialog is closed.
685
val = dlg.ShowModal()
686
# print ' val,val == wx.ID_OK',val,wx.ID_OK,wx.ID_CANCEL,val == wx.ID_CANCEL
687
# print ' status =',dlg.get_status()
688
if dlg.get_status() != 'success': # val == wx.ID_CANCEL:
689
# print ">>>>>>>>>Unsuccessful\n"
690
dlg.Destroy()
691
692
if dlg.get_status() == 'success':
693
# print ">>>>>>>>>successful\n"
694
# apply current widget values to scenario instance
695
dlg.apply()
696
dlg.Destroy()
697
698
def create_odroute_from_trips(self, event=None):
699
"""
700
Create vp from GPS trips.
701
"""
702
703
mapmatching.OdRouteCreator('create_odroute_from_trips',
704
self._mapmatching,
705
logger=self._mainframe.get_logger(),
706
).do()
707
708
def create_zonetozone_demand(self, event=None):
709
"""
710
Create zone-to-zone demand from GPS trips.
711
"""
712
713
p = mapmatching.OdCreator('Create_zonetozone_demand_from_trips',
714
self._mapmatching,
715
logger=self._mainframe.get_logger(),
716
)
717
dlg = ProcessDialog(self._mainframe,
718
p,
719
title='Create Virtual Population from GPS Trips')
720
721
dlg.CenterOnScreen()
722
723
# this does not return until the dialog is closed.
724
val = dlg.ShowModal()
725
# print ' val,val == wx.ID_OK',val,wx.ID_OK,wx.ID_CANCEL,val == wx.ID_CANCEL
726
# print ' status =',dlg.get_status()
727
if dlg.get_status() != 'success': # val == wx.ID_CANCEL:
728
# print ">>>>>>>>>Unsuccessful\n"
729
dlg.Destroy()
730
731
if dlg.get_status() == 'success':
732
# print ">>>>>>>>>successful\n"
733
# apply current widget values to scenario instance
734
dlg.apply()
735
dlg.Destroy()
736
737
def create_vp_from_trips(self, event=None):
738
"""
739
Create vp from GPS trips.
740
"""
741
742
p = mapmatching.VpCreator('Create_Vp_from_trips',
743
self._mapmatching,
744
logger=self._mainframe.get_logger(),
745
)
746
dlg = ProcessDialog(self._mainframe,
747
p,
748
title='Create Virtual Population from GPS Trips')
749
750
dlg.CenterOnScreen()
751
752
# this does not return until the dialog is closed.
753
val = dlg.ShowModal()
754
# print ' val,val == wx.ID_OK',val,wx.ID_OK,wx.ID_CANCEL,val == wx.ID_CANCEL
755
# print ' status =',dlg.get_status()
756
if dlg.get_status() != 'success': # val == wx.ID_CANCEL:
757
# print ">>>>>>>>>Unsuccessful\n"
758
dlg.Destroy()
759
760
if dlg.get_status() == 'success':
761
# print ">>>>>>>>>successful\n"
762
# apply current widget values to scenario instance
763
dlg.apply()
764
dlg.Destroy()
765
766
def on_plot_routeresults(self, event=None):
767
"""
768
Plot route results of route analysis in Matplotlib plotting envitonment.
769
"""
770
if is_mpl:
771
resultplotter = results_mpl.RouteresultPlotter(self._results,
772
logger=self._mainframe.get_logger()
773
)
774
dlg = results_mpl.ResultDialog(self._mainframe, resultplotter)
775
776
dlg.CenterOnScreen()
777
778
# this does not return until the dialog is closed.
779
val = dlg.ShowModal()
780
# print ' val,val == wx.ID_OK',val,wx.ID_OK,wx.ID_CANCEL,val == wx.ID_CANCEL
781
# print ' status =',dlg.get_status()
782
if dlg.get_status() != 'success': # val == wx.ID_CANCEL:
783
# print ">>>>>>>>>Unsuccessful\n"
784
dlg.Destroy()
785
786
if dlg.get_status() == 'success':
787
# print ">>>>>>>>>successful\n"
788
# apply current widget values to scenario instance
789
dlg.apply()
790
dlg.Destroy()
791
792
def on_plot_edgeresults(self, event=None):
793
"""
794
Plot edge results of route analysis in Matplotlib plotting envitonment.
795
"""
796
if is_mpl:
797
resultplotter = results_mpl.EdgeresultPlotter(self._results,
798
logger=self._mainframe.get_logger()
799
)
800
dlg = results_mpl.ResultDialog(self._mainframe, resultplotter)
801
802
dlg.CenterOnScreen()
803
804
# this does not return until the dialog is closed.
805
val = dlg.ShowModal()
806
# print ' val,val == wx.ID_OK',val,wx.ID_OK,wx.ID_CANCEL,val == wx.ID_CANCEL
807
# print ' status =',dlg.get_status()
808
if dlg.get_status() != 'success': # val == wx.ID_CANCEL:
809
# print ">>>>>>>>>Unsuccessful\n"
810
dlg.Destroy()
811
812
if dlg.get_status() == 'success':
813
# print ">>>>>>>>>successful\n"
814
# apply current widget values to scenario instance
815
dlg.apply()
816
dlg.Destroy()
817
818
def on_plot_connectionresults(self, event=None):
819
"""
820
Plot connection results of route analysis in Matplotlib plotting envitonment.
821
"""
822
if is_mpl:
823
resultplotter = results_mpl.ConnectionresultPlotter(self._results,
824
logger=self._mainframe.get_logger()
825
)
826
dlg = results_mpl.ResultDialog(self._mainframe, resultplotter)
827
828
dlg.CenterOnScreen()
829
830
# this does not return until the dialog is closed.
831
val = dlg.ShowModal()
832
# print ' val,val == wx.ID_OK',val,wx.ID_OK,wx.ID_CANCEL,val == wx.ID_CANCEL
833
# print ' status =',dlg.get_status()
834
if dlg.get_status() != 'success': # val == wx.ID_CANCEL:
835
# print ">>>>>>>>>Unsuccessful\n"
836
dlg.Destroy()
837
838
if dlg.get_status() == 'success':
839
# print ">>>>>>>>>successful\n"
840
# apply current widget values to scenario instance
841
dlg.apply()
842
dlg.Destroy()
843
844
def on_plot_alternative_routes(self, event=None):
845
"""
846
Plot alternative route results in Matplotlib plotting envitonment.
847
"""
848
if is_mpl:
849
resultplotter = results_mpl.AlternativeRoutesPlotter(self._results,
850
logger=self._mainframe.get_logger()
851
)
852
dlg = results_mpl.ResultDialog(self._mainframe, resultplotter)
853
854
dlg.CenterOnScreen()
855
856
# this does not return until the dialog is closed.
857
val = dlg.ShowModal()
858
# print ' val,val == wx.ID_OK',val,wx.ID_OK,wx.ID_CANCEL,val == wx.ID_CANCEL
859
# print ' status =',dlg.get_status()
860
if dlg.get_status() != 'success': # val == wx.ID_CANCEL:
861
# print ">>>>>>>>>Unsuccessful\n"
862
dlg.Destroy()
863
864
if dlg.get_status() == 'success':
865
# print ">>>>>>>>>successful\n"
866
# apply current widget values to scenario instance
867
dlg.apply()
868
dlg.Destroy()
869
870
def on_plot_noderesults(self, event=None):
871
"""
872
Plot node results of route analysis in Matplotlib plotting envitonment.
873
"""
874
if is_mpl:
875
resultplotter = results_mpl.NoderesultPlotter(self._results,
876
logger=self._mainframe.get_logger()
877
)
878
dlg = results_mpl.ResultDialog(self._mainframe, resultplotter)
879
880
dlg.CenterOnScreen()
881
882
# this does not return until the dialog is closed.
883
val = dlg.ShowModal()
884
# print ' val,val == wx.ID_OK',val,wx.ID_OK,wx.ID_CANCEL,val == wx.ID_CANCEL
885
# print ' status =',dlg.get_status()
886
if dlg.get_status() != 'success': # val == wx.ID_CANCEL:
887
# print ">>>>>>>>>Unsuccessful\n"
888
dlg.Destroy()
889
890
if dlg.get_status() == 'success':
891
# print ">>>>>>>>>successful\n"
892
# apply current widget values to scenario instance
893
dlg.apply()
894
dlg.Destroy()
895
896
def on_plot_speedprofiles(self, event=None):
897
"""
898
Plot speedprofiles of route analysis in Matplotlib plotting envitonment.
899
"""
900
if is_mpl:
901
resultplotter = results_mpl.SpeedprofilePlotter(self._results,
902
logger=self._mainframe.get_logger()
903
)
904
dlg = results_mpl.ResultDialog(self._mainframe, resultplotter)
905
906
dlg.CenterOnScreen()
907
908
# this does not return until the dialog is closed.
909
val = dlg.ShowModal()
910
# print ' val,val == wx.ID_OK',val,wx.ID_OK,wx.ID_CANCEL,val == wx.ID_CANCEL
911
# print ' status =',dlg.get_status()
912
if dlg.get_status() != 'success': # val == wx.ID_CANCEL:
913
# print ">>>>>>>>>Unsuccessful\n"
914
dlg.Destroy()
915
916
if dlg.get_status() == 'success':
917
# print ">>>>>>>>>successful\n"
918
# apply current widget values to scenario instance
919
dlg.apply()
920
dlg.Destroy()
921
922
def on_routes_to_shapefile(self, event=None):
923
"""
924
Export route results to shape file.
925
"""
926
# print 'on_routes_to_shapefile'
927
scenario = self._mapmatching.get_scenario()
928
dirpath = scenario.get_workdirpath()
929
defaultFile = scenario.get_rootfilename()+'.routeres.shp'
930
wildcards_all = 'All files (*.*)|*.*|SHP files (*.shp)|*.shp'
931
dlg = wx.FileDialog(None, message='Export route results to shapefile',
932
defaultDir=dirpath,
933
# defaultFile=defaultFile,
934
wildcard=wildcards_all, style=wx.SAVE | wx.CHANGE_DIR)
935
if dlg.ShowModal() == wx.ID_OK:
936
filepath = dlg.GetPath()
937
938
else:
939
return
940
941
mapmatching.routes_to_shapefile(self._mapmatching,
942
self._results,
943
filepath,
944
log=self._mainframe.get_logger())
945
946
def on_edgesresults_to_shapefile(self, event=None):
947
"""
948
Export edge results to shape file.
949
"""
950
print 'on_nodes_to_shapefile'
951
scenario = self._mapmatching.get_scenario()
952
dirpath = scenario.get_workdirpath()
953
#defaultFile = scenario.get_rootfilename()+'.edgeres.shp'
954
wildcards_all = 'All files (*.*)|*.*|SHP files (*.shp)|*.shp'
955
dlg = wx.FileDialog(None, message='Export edge results to shapefile',
956
defaultDir=dirpath,
957
# defaultFile=defaultFile,
958
wildcard=wildcards_all, style=wx.SAVE | wx.CHANGE_DIR)
959
if dlg.ShowModal() == wx.ID_OK:
960
filepath = dlg.GetPath()
961
962
else:
963
return
964
965
mapmatching.edgesresults_to_shapefile(self._mapmatching,
966
self._results,
967
filepath,
968
log=self._mainframe.get_logger())
969
970
def on_points_to_shapefile(self, event=None):
971
"""
972
Export GPS points to shapefile.
973
"""
974
print 'on_points_to_shapefile'
975
scenario = self._mapmatching.get_scenario()
976
dirpath = scenario.get_workdirpath()
977
defaultFile = scenario.get_rootfilename()+'.points.shp'
978
wildcards_all = 'All files (*.*)|*.*|SHP files (*.shp)|*.shp'
979
dlg = wx.FileDialog(None, message='Export GPS points to shapefile',
980
defaultDir=dirpath,
981
# defaultFile=defaultFile,
982
wildcard=wildcards_all, style=wx.SAVE | wx.CHANGE_DIR)
983
if dlg.ShowModal() == wx.ID_OK:
984
filepath = dlg.GetPath()
985
986
else:
987
return
988
989
mapmatching.points_to_shapefile(self._mapmatching,
990
filepath,
991
log=self._mainframe.get_logger())
992
993
def on_save_results(self, event=None):
994
"""
995
Save mapmatching analysis results to binary file.
996
"""
997
if self._results is None:
998
return
999
scenario = self.get_scenario()
1000
wildcards_all = "All files (*.*)|*.*"
1001
wildcards_obj = "Python binary files (*.obj)|*.obj"
1002
wildcards = wildcards_obj+"|"+wildcards_all
1003
1004
# Finally, if the directory is changed in the process of getting files, this
1005
# dialog is set up to change the current working directory to the path chosen.
1006
dlg = wx.FileDialog(
1007
self._mainframe, message="Save results to file",
1008
defaultDir=scenario.get_workdirpath(),
1009
#defaultFile = scenario.get_rootfilepath()+'.mmatch.obj',
1010
wildcard=wildcards,
1011
style=wx.SAVE | wx.CHANGE_DIR
1012
)
1013
val = dlg.ShowModal()
1014
# Show the dialog and retrieve the user response. If it is the OK response,
1015
# process the data.
1016
if val == wx.ID_OK:
1017
# This returns a Python list of files that were selected.
1018
filepath = dlg.GetPath()
1019
if len(filepath) > 0:
1020
# now set new filename and workdir
1021
self._results.save(filepath)
1022
1023
# Destroy the dialog. Don't do this until you are done with it!
1024
# BAD things can happen otherwise!
1025
dlg.Destroy()
1026
1027
def on_open_results(self, event=None):
1028
1029
wildcards_all = "All files (*.*)|*.*"
1030
wildcards_obj = "Python binary files (*.obj)|*.obj"
1031
wildcards = wildcards_obj+"|"+wildcards_all
1032
1033
# Finally, if the directory is changed in the process of getting files, this
1034
# dialog is set up to change the current working directory to the path chosen.
1035
dlg = wx.FileDialog(
1036
self._mainframe, message="Open results file",
1037
defaultDir=self.get_scenario().get_workdirpath(),
1038
#defaultFile = os.path.join(scenario.get_workdirpath(), scenario.format_ident()+'.obj'),
1039
wildcard=wildcards,
1040
style=wx.OPEN | wx.CHANGE_DIR
1041
)
1042
1043
# Show the dialog and retrieve the user response. If it is the OK response,
1044
# process the data.
1045
is_newresults = False
1046
if dlg.ShowModal() == wx.ID_OK:
1047
# This returns a Python list of files that were selected.
1048
filepath = dlg.GetPath()
1049
if len(filepath) > 0:
1050
if self._results is not None:
1051
# browse away from results
1052
# self._mainframe.browse_obj(self._results.get_scenario())
1053
del self._results
1054
1055
self._results = mapmatching.load_results(filepath,
1056
parent=self._mapmatching,
1057
logger=self._mainframe.get_logger()
1058
)
1059
is_newresults = True
1060
1061
# Destroy the dialog. Don't do this until you are done with it!
1062
# BAD things can happen otherwise!
1063
dlg.Destroy()
1064
1065
if is_newresults:
1066
# this should update all widgets for the new scenario!!
1067
# print 'call self._mainframe.refresh_moduleguis()'
1068
self._mainframe.browse_obj(self._results)
1069
# self._mainframe.select_view(name = "Result viewer") #!!!!!!!!tricky, crashes without
1070
self._is_needs_refresh = True
1071
self.refresh_widgets()
1072
# wx.CallAfter(self.refresh_widgets)
1073
# self._mainframe.refresh_moduleguis()
1074
#if event: event.Skip()
1075
1076
def on_select_all_trips(self, event=None):
1077
"""
1078
Select all GPS trips.
1079
"""
1080
self._mapmatching.trips.select_all()
1081
self._mainframe.browse_obj(self._mapmatching.trips)
1082
self._is_needs_refresh = True
1083
self.refresh_widgets()
1084
1085
def on_unselect_all_trips(self, event=None):
1086
"""
1087
Unselect all GPS trips.
1088
"""
1089
self._mapmatching.trips.unselect_all()
1090
self._mainframe.browse_obj(self._mapmatching.trips)
1091
self._is_needs_refresh = True
1092
self.refresh_widgets()
1093
1094
def on_invert_selected_trips(self, event=None):
1095
"""
1096
Invert selected GPS trips, all selected will be unselected and vice versa.
1097
"""
1098
self._mapmatching.trips.invert_selection()
1099
self._mainframe.browse_obj(self._mapmatching.trips)
1100
self._is_needs_refresh = True
1101
self.refresh_widgets()
1102
1103
def on_clear_all(self, event=None):
1104
"""
1105
Clear all GPS points, routes and persons.
1106
"""
1107
self._mapmatching.clear_all()
1108
self._mainframe.browse_obj(self._mapmatching)
1109
self._is_needs_refresh = True
1110
self.refresh_widgets()
1111
1112
def on_clear_routes(self, event=None):
1113
"""
1114
Clear matched routes and minimal distance routes.
1115
"""
1116
self._mapmatching.clear_routes()
1117
self._mainframe.browse_obj(self._mapmatching)
1118
self._is_needs_refresh = True
1119
self.refresh_widgets()
1120
1121
def on_delete_unselected(self, event=None):
1122
"""
1123
Delete unselected trips.
1124
"""
1125
self._mapmatching.delete_unselected_trips()
1126
self._mainframe.browse_obj(self._mapmatching.trips)
1127
self._is_needs_refresh = True
1128
self.refresh_widgets()
1129
1130
def is_matchprocess(self, ident):
1131
if self._matchprocess is None:
1132
return False
1133
else:
1134
return self._matchprocess.ident == ident
1135
1136
def on_match_birgil(self, event=None):
1137
"""
1138
Match selected traces with GPS points to the road network based on Birgillito's method.
1139
"""
1140
# self.prepare_results()
1141
if not self.is_matchprocess('birgilmatcher'):
1142
self._matchprocess = mapmatching.BirgilMatcher('birgilmatcher',
1143
self._mapmatching,
1144
logger=self._mainframe.get_logger(),
1145
)
1146
1147
dlg = ProcessDialogInteractive(self._mainframe,
1148
self._matchprocess,
1149
#title = 'Mapmatching with Birgillito method',
1150
func_close=self.close_match_birgil,
1151
)
1152
1153
dlg.CenterOnScreen()
1154
1155
# this does not return until the dialog is closed.
1156
#val = dlg.ShowModal()
1157
# print 'open_sumodialog_interactive'
1158
dlg.Show()
1159
dlg.MakeModal(True)
1160
# print ' val,val == wx.ID_OK',val,wx.ID_OK,wx.ID_CANCEL,val == wx.ID_CANCEL
1161
# print ' status =',dlg.get_status()
1162
# print 'returned to main window self.simulator.status',self.simulator.status
1163
1164
def close_match_birgil(self, dlg):
1165
# called before destroying the dialog
1166
if dlg.get_status() == 'success':
1167
#p = self._mapmatchprocess
1168
1169
self._mainframe.browse_obj(self._mapmatching.trips)
1170
self._is_needs_refresh = True
1171
self.refresh_widgets()
1172
1173
def on_match_pt(self, event=None):
1174
"""
1175
Match selected traces with GPS points to the public transport network. A public transport network must be previously built.
1176
"""
1177
# self.prepare_results()
1178
if not self.is_matchprocess('ptmatcher'):
1179
self._matchprocess = mapmatching.PTMatcher('ptmatcher',
1180
self._mapmatching,
1181
logger=self._mainframe.get_logger(),
1182
)
1183
1184
dlg = ProcessDialogInteractive(self._mainframe,
1185
self._matchprocess,
1186
#title = 'Mapmatching with Birgillito method',
1187
func_close=self.close_match_birgil,
1188
)
1189
1190
dlg.CenterOnScreen()
1191
1192
# this does not return until the dialog is closed.
1193
#val = dlg.ShowModal()
1194
# print 'open_sumodialog_interactive'
1195
dlg.Show()
1196
dlg.MakeModal(True)
1197
# print ' val,val == wx.ID_OK',val,wx.ID_OK,wx.ID_CANCEL,val == wx.ID_CANCEL
1198
# print ' status =',dlg.get_status()
1199
# print 'returned to main window self.simulator.status',self.simulator.status
1200
1201
def on_select_mode(self, event=None):
1202
"""
1203
Select GPS traces of a specific mode.
1204
The mode is selected only among the currently selected trips.
1205
"""
1206
p = mapmatching.ModeSelector(self._mapmatching, logger=self._mainframe.get_logger())
1207
dlg = ProcessDialog(self._mainframe, p, immediate_apply=True)
1208
1209
dlg.CenterOnScreen()
1210
1211
# this does not return until the dialog is closed.
1212
val = dlg.ShowModal()
1213
# print ' val,val == wx.ID_OK',val,wx.ID_OK,wx.ID_CANCEL,val == wx.ID_CANCEL
1214
# print ' status =',dlg.get_status()
1215
if dlg.get_status() != 'success': # val == wx.ID_CANCEL:
1216
# print ">>>>>>>>>Unsuccessful\n"
1217
dlg.Destroy()
1218
1219
if dlg.get_status() == 'success':
1220
# print ">>>>>>>>>successful\n"
1221
# apply current widget values to scenario instance
1222
dlg.apply()
1223
dlg.Destroy()
1224
self._mainframe.browse_obj(self._mapmatching.trips)
1225
self._is_needs_refresh = True
1226
self.refresh_widgets()
1227
1228
def on_geomfilter_trips(self, event=None):
1229
"""
1230
Select GPS traces to satisfy geometric requirements.
1231
This should be done before the mapmatching process.
1232
"""
1233
p = mapmatching.TripGeomfilter(self._mapmatching, logger=self._mainframe.get_logger())
1234
dlg = ProcessDialog(self._mainframe, p, immediate_apply=True)
1235
1236
dlg.CenterOnScreen()
1237
1238
# this does not return until the dialog is closed.
1239
val = dlg.ShowModal()
1240
# print ' val,val == wx.ID_OK',val,wx.ID_OK,wx.ID_CANCEL,val == wx.ID_CANCEL
1241
# print ' status =',dlg.get_status()
1242
if dlg.get_status() != 'success': # val == wx.ID_CANCEL:
1243
# print ">>>>>>>>>Unsuccessful\n"
1244
dlg.Destroy()
1245
1246
if dlg.get_status() == 'success':
1247
# print ">>>>>>>>>successful\n"
1248
# apply current widget values to scenario instance
1249
dlg.apply()
1250
dlg.Destroy()
1251
self._mainframe.browse_obj(self._mapmatching.trips)
1252
self._is_needs_refresh = True
1253
self.refresh_widgets()
1254
1255
def on_postmatchfilter_trips(self, event=None):
1256
"""
1257
Select trips by different parameters to ensure the quality of the mapmatching results.
1258
This should be done after the map-matching process.
1259
"""
1260
p = mapmatching.PostMatchfilter(self._mapmatching, logger=self._mainframe.get_logger())
1261
dlg = ProcessDialog(self._mainframe, p, immediate_apply=True)
1262
1263
dlg.CenterOnScreen()
1264
1265
# this does not return until the dialog is closed.
1266
val = dlg.ShowModal()
1267
# print ' val,val == wx.ID_OK',val,wx.ID_OK,wx.ID_CANCEL,val == wx.ID_CANCEL
1268
# print ' status =',dlg.get_status()
1269
if dlg.get_status() != 'success': # val == wx.ID_CANCEL:
1270
# print ">>>>>>>>>Unsuccessful\n"
1271
dlg.Destroy()
1272
1273
if dlg.get_status() == 'success':
1274
# print ">>>>>>>>>successful\n"
1275
# apply current widget values to scenario instance
1276
dlg.apply()
1277
dlg.Destroy()
1278
self._mainframe.browse_obj(self._mapmatching.trips)
1279
self._is_needs_refresh = True
1280
self.refresh_widgets()
1281
1282
def on_route_shortest(self, event=None):
1283
"""
1284
Shortest path routing of matched routes.
1285
"""
1286
p = mapmatching.Shortestrouter('shortestpathrouter', self._mapmatching, logger=self._mainframe.get_logger())
1287
dlg = ProcessDialog(self._mainframe, p, immediate_apply=True)
1288
1289
dlg.CenterOnScreen()
1290
1291
# this does not return until the dialog is closed.
1292
val = dlg.ShowModal()
1293
# print ' val,val == wx.ID_OK',val,wx.ID_OK,wx.ID_CANCEL,val == wx.ID_CANCEL
1294
# print ' status =',dlg.get_status()
1295
if dlg.get_status() != 'success': # val == wx.ID_CANCEL:
1296
# print ">>>>>>>>>Unsuccessful\n"
1297
dlg.Destroy()
1298
1299
if dlg.get_status() == 'success':
1300
# print ">>>>>>>>>successful\n"
1301
# apply current widget values to scenario instance
1302
dlg.apply()
1303
dlg.Destroy()
1304
self._mainframe.browse_obj(self._mapmatching.trips)
1305
self._is_needs_refresh = True
1306
self.refresh_widgets()
1307
1308
def on_route_fastest(self, event=None):
1309
"""
1310
Fastest path routing of matched routes.
1311
"""
1312
p = mapmatching.Fastestrouter('fastestpathrouter', self._mapmatching,
1313
matchresults=self._results,
1314
logger=self._mainframe.get_logger()
1315
)
1316
dlg = ProcessDialog(self._mainframe, p, immediate_apply=True)
1317
1318
dlg.CenterOnScreen()
1319
1320
# this does not return until the dialog is closed.
1321
val = dlg.ShowModal()
1322
# print ' val,val == wx.ID_OK',val,wx.ID_OK,wx.ID_CANCEL,val == wx.ID_CANCEL
1323
# print ' status =',dlg.get_status()
1324
if dlg.get_status() != 'success': # val == wx.ID_CANCEL:
1325
# print ">>>>>>>>>Unsuccessful\n"
1326
dlg.Destroy()
1327
1328
if dlg.get_status() == 'success':
1329
# print ">>>>>>>>>successful\n"
1330
# apply current widget values to scenario instance
1331
dlg.apply()
1332
dlg.Destroy()
1333
self._mainframe.browse_obj(self._mapmatching.trips)
1334
self._is_needs_refresh = True
1335
self.refresh_widgets()
1336
1337
def on_redraw(self, event=None):
1338
self._mainframe.browse_obj(self._mapmatching)
1339
self._is_needs_refresh = True
1340
self.refresh_widgets()
1341
1342
def on_import_ecc(self, event=None):
1343
"""
1344
Import and filter data from a European cycling challange.
1345
"""
1346
p = mapmatching.EccTracesImporter(self._mapmatching, logger=self._mainframe.get_logger())
1347
dlg = ProcessDialog(self._mainframe, p, immediate_apply=True)
1348
1349
dlg.CenterOnScreen()
1350
1351
# this does not return until the dialog is closed.
1352
val = dlg.ShowModal()
1353
# print ' val,val == wx.ID_OK',val,wx.ID_OK,wx.ID_CANCEL,val == wx.ID_CANCEL
1354
# print ' status =',dlg.get_status()
1355
if dlg.get_status() != 'success': # val == wx.ID_CANCEL:
1356
# print ">>>>>>>>>Unsuccessful\n"
1357
dlg.Destroy()
1358
1359
if dlg.get_status() == 'success':
1360
# print ">>>>>>>>>successful\n"
1361
# apply current widget values to scenario instance
1362
dlg.apply()
1363
dlg.Destroy()
1364
self._mainframe.browse_obj(self._mapmatching.trips)
1365
self._is_needs_refresh = True
1366
self.refresh_widgets()
1367
1368
def on_import_mobike(self, event=None):
1369
"""
1370
Import and filter data from a Mobike database file.
1371
"""
1372
p = mapmatching.MobikeImporter(self._mapmatching, logger=self._mainframe.get_logger())
1373
dlg = ProcessDialog(self._mainframe, p, immediate_apply=True)
1374
1375
dlg.CenterOnScreen()
1376
1377
# this does not return until the dialog is closed.
1378
val = dlg.ShowModal()
1379
# print ' val,val == wx.ID_OK',val,wx.ID_OK,wx.ID_CANCEL,val == wx.ID_CANCEL
1380
# print ' status =',dlg.get_status()
1381
if dlg.get_status() != 'success': # val == wx.ID_CANCEL:
1382
# print ">>>>>>>>>Unsuccessful\n"
1383
dlg.Destroy()
1384
1385
if dlg.get_status() == 'success':
1386
# print ">>>>>>>>>successful\n"
1387
# apply current widget values to scenario instance
1388
dlg.apply()
1389
dlg.Destroy()
1390
self._mainframe.browse_obj(self._mapmatching.trips)
1391
self._is_needs_refresh = True
1392
self.refresh_widgets()
1393
1394
def on_import_bellamossa(self, event=None):
1395
"""
1396
Import and filter data from a Bella Mossa data.
1397
"""
1398
p = mapmatching.BellamossaImporter(self._mapmatching, logger=self._mainframe.get_logger())
1399
dlg = ProcessDialog(self._mainframe, p, immediate_apply=True)
1400
1401
dlg.CenterOnScreen()
1402
1403
# this does not return until the dialog is closed.
1404
val = dlg.ShowModal()
1405
# print ' val,val == wx.ID_OK',val,wx.ID_OK,wx.ID_CANCEL,val == wx.ID_CANCEL
1406
# print ' status =',dlg.get_status()
1407
if dlg.get_status() != 'success': # val == wx.ID_CANCEL:
1408
# print ">>>>>>>>>Unsuccessful\n"
1409
dlg.Destroy()
1410
1411
if dlg.get_status() == 'success':
1412
# print ">>>>>>>>>successful\n"
1413
# apply current widget values to scenario instance
1414
dlg.apply()
1415
dlg.Destroy()
1416
self._mainframe.browse_obj(self._mapmatching.trips)
1417
self._is_needs_refresh = True
1418
self.refresh_widgets()
1419
1420
def on_import_strava(self, event=None):
1421
"""
1422
Import and filter data from a Bella Mossa data.
1423
"""
1424
p = mapmatching.StravaImporter(self._mapmatching, logger=self._mainframe.get_logger())
1425
dlg = ProcessDialog(self._mainframe, p, immediate_apply=True)
1426
1427
dlg.CenterOnScreen()
1428
1429
# this does not return until the dialog is closed.
1430
val = dlg.ShowModal()
1431
# print ' val,val == wx.ID_OK',val,wx.ID_OK,wx.ID_CANCEL,val == wx.ID_CANCEL
1432
# print ' status =',dlg.get_status()
1433
if dlg.get_status() != 'success': # val == wx.ID_CANCEL:
1434
# print ">>>>>>>>>Unsuccessful\n"
1435
dlg.Destroy()
1436
1437
if dlg.get_status() == 'success':
1438
# print ">>>>>>>>>successful\n"
1439
# apply current widget values to scenario instance
1440
dlg.apply()
1441
dlg.Destroy()
1442
self._mainframe.browse_obj(self._mapmatching.trips)
1443
self._is_needs_refresh = True
1444
self.refresh_widgets()
1445
1446
def on_import_gtfs(self, event=None):
1447
"""
1448
Import and filter data from GTFS shape database.
1449
"""
1450
p = mapmatching.GtfsShapeImporter(self._mapmatching, logger=self._mainframe.get_logger())
1451
dlg = ProcessDialog(self._mainframe, p, immediate_apply=True)
1452
1453
dlg.CenterOnScreen()
1454
1455
# this does not return until the dialog is closed.
1456
val = dlg.ShowModal()
1457
# print ' val,val == wx.ID_OK',val,wx.ID_OK,wx.ID_CANCEL,val == wx.ID_CANCEL
1458
# print ' status =',dlg.get_status()
1459
if dlg.get_status() != 'success': # val == wx.ID_CANCEL:
1460
# print ">>>>>>>>>Unsuccessful\n"
1461
dlg.Destroy()
1462
1463
if dlg.get_status() == 'success':
1464
# print ">>>>>>>>>successful\n"
1465
# apply current widget values to scenario instance
1466
dlg.apply()
1467
dlg.Destroy()
1468
self._mainframe.browse_obj(self._mapmatching.trips)
1469
self._is_needs_refresh = True
1470
self.refresh_widgets()
1471
1472
def on_import_gpx(self, event=None):
1473
"""
1474
Import and filter data from GPX file.
1475
"""
1476
p = mapmatching.GpxImporter(self._mapmatching, logger=self._mainframe.get_logger())
1477
dlg = ProcessDialog(self._mainframe, p, immediate_apply=True)
1478
1479
dlg.CenterOnScreen()
1480
1481
# this does not return until the dialog is closed.
1482
val = dlg.ShowModal()
1483
# print ' val,val == wx.ID_OK',val,wx.ID_OK,wx.ID_CANCEL,val == wx.ID_CANCEL
1484
# print ' status =',dlg.get_status()
1485
if dlg.get_status() != 'success': # val == wx.ID_CANCEL:
1486
# print ">>>>>>>>>Unsuccessful\n"
1487
dlg.Destroy()
1488
1489
if dlg.get_status() == 'success':
1490
# print ">>>>>>>>>successful\n"
1491
# apply current widget values to scenario instance
1492
dlg.apply()
1493
dlg.Destroy()
1494
self._mainframe.browse_obj(self._mapmatching.trips)
1495
self._is_needs_refresh = True
1496
self.refresh_widgets()
1497
1498
def on_project_points(self, event=None):
1499
self._mapmatching.points.project()
1500
self._mainframe.browse_obj(self._mapmatching.points)
1501
1502
if event:
1503
event.Skip()
1504
1505
def on_browse(self, event=None):
1506
1507
self._mainframe.browse_obj(self._mapmatching)
1508
if event:
1509
event.Skip()
1510
1511
def on_browse_results(self, event=None):
1512
"""
1513
Browse mapmatching analyses results
1514
"""
1515
self._mainframe.browse_obj(self._results)
1516
if event:
1517
event.Skip()
1518
1519
def on_analyze_persons(self, event=None):
1520
"""
1521
Analyze the trips of each person in the database.
1522
Ensure that mapmatching and shortest trip routing
1523
has been previously executed.
1524
"""
1525
1526
self._mapmatching.persons.analyze()
1527
self._mainframe.browse_obj(self._mapmatching.persons)
1528
1529
def on_export_persons_csv(self, event=None):
1530
if self._results is None:
1531
return
1532
scenario = self._results.get_scenario()
1533
wildcards_all = "All files (*.*)|*.*"
1534
wildcards_obj = "CSV files (*.csv)|*.csv|Text file (*.txt)|*.txt"
1535
wildcards = wildcards_obj+"|"+wildcards_all
1536
1537
# Finally, if the directory is changed in the process of getting files, this
1538
# dialog is set up to change the current working directory to the path chosen.
1539
dlg = wx.FileDialog(
1540
self._mainframe, message="Export persons to CSV file",
1541
defaultDir=scenario.get_workdirpath(),
1542
#defaultFile = scenario.get_rootfilepath()+'.gpspersons.csv',
1543
wildcard=wildcards,
1544
style=wx.SAVE | wx.CHANGE_DIR
1545
)
1546
val = dlg.ShowModal()
1547
# Show the dialog and retrieve the user response. If it is the OK response,
1548
# process the data.
1549
if val == wx.ID_OK:
1550
# This returns a Python list of files that were selected.
1551
filepath = dlg.GetPath()
1552
if len(filepath) > 0:
1553
# now set new filename and workdir
1554
persons = self._mapmatching.persons
1555
ids_pers = persons.select_ids(persons.lengths_tot_route_matched.get_value() > 0)
1556
self._mapmatching.persons.export_csv(filepath, ids=ids_pers)
1557
1558
# Destroy the dialog. Don't do this until you are done with it!
1559
# BAD things can happen otherwise!
1560
dlg.Destroy()
1561
1562
def on_routeanalyze(self, event=None):
1563
"""
1564
Analyze attributes of matched and alternative routes.
1565
"""
1566
p = mapmatching.Routesanalyzer('routeanalyzer',
1567
self._mapmatching,
1568
self._results,
1569
logger=self._mainframe.get_logger())
1570
1571
dlg = ProcessDialog(self._mainframe, p, immediate_apply=True)
1572
1573
dlg.CenterOnScreen()
1574
1575
# this does not return until the dialog is closed.
1576
val = dlg.ShowModal()
1577
# print ' val,val == wx.ID_OK',val,wx.ID_OK,wx.ID_CANCEL,val == wx.ID_CANCEL
1578
# print ' status =',dlg.get_status()
1579
if dlg.get_status() != 'success': # val == wx.ID_CANCEL:
1580
# print ">>>>>>>>>Unsuccessful\n"
1581
dlg.Destroy()
1582
1583
if dlg.get_status() == 'success':
1584
# print ">>>>>>>>>successful\n"
1585
# apply current widget values to scenario instance
1586
dlg.apply()
1587
dlg.Destroy()
1588
self._mainframe.browse_obj(self._results)
1589
self._is_needs_refresh = True
1590
self.refresh_widgets()
1591
1592
def on_altrouteanalyze(self, event=None):
1593
"""
1594
Analyze attributes of matched and alternative routes.
1595
"""
1596
p = mapmatching.AlternativeRoutesanalyzer('altrouteanalyzer',
1597
self._mapmatching,
1598
self._results,
1599
logger=self._mainframe.get_logger())
1600
1601
dlg = ProcessDialog(self._mainframe, p, immediate_apply=True)
1602
1603
dlg.CenterOnScreen()
1604
1605
# this does not return until the dialog is closed.
1606
val = dlg.ShowModal()
1607
# print ' val,val == wx.ID_OK',val,wx.ID_OK,wx.ID_CANCEL,val == wx.ID_CANCEL
1608
# print ' status =',dlg.get_status()
1609
if dlg.get_status() != 'success': # val == wx.ID_CANCEL:
1610
# print ">>>>>>>>>Unsuccessful\n"
1611
dlg.Destroy()
1612
1613
if dlg.get_status() == 'success':
1614
# print ">>>>>>>>>successful\n"
1615
# apply current widget values to scenario instance
1616
dlg.apply()
1617
dlg.Destroy()
1618
self._mainframe.browse_obj(self._results)
1619
self._is_needs_refresh = True
1620
self.refresh_widgets()
1621
1622
def on_ptanalyze(self, event=None):
1623
"""
1624
Analyze public tranport routes, calculating trips per line and trip distribution on public transport net.
1625
"""
1626
p = mapmatching.PtRoutesanalyzer('ptrouteanalyzer',
1627
self._mapmatching,
1628
self._results,
1629
logger=self._mainframe.get_logger())
1630
1631
dlg = ProcessDialog(self._mainframe, p, immediate_apply=True)
1632
1633
dlg.CenterOnScreen()
1634
1635
# this does not return until the dialog is closed.
1636
val = dlg.ShowModal()
1637
# print ' val,val == wx.ID_OK',val,wx.ID_OK,wx.ID_CANCEL,val == wx.ID_CANCEL
1638
# print ' status =',dlg.get_status()
1639
if dlg.get_status() != 'success': # val == wx.ID_CANCEL:
1640
# print ">>>>>>>>>Unsuccessful\n"
1641
dlg.Destroy()
1642
1643
if dlg.get_status() == 'success':
1644
# print ">>>>>>>>>successful\n"
1645
# apply current widget values to scenario instance
1646
dlg.apply()
1647
dlg.Destroy()
1648
self._mainframe.browse_obj(self._results)
1649
self._is_needs_refresh = True
1650
self.refresh_widgets()
1651
1652
def on_plot_ptflows(self, event=None):
1653
"""
1654
Plot matched flow graph of public transport lines with the Matplotlib plotting envitonment.
1655
"""
1656
if is_mpl:
1657
resultplotter = results_mpl.PtFlowdigramPlotter(self._results,
1658
logger=self._mainframe.get_logger()
1659
)
1660
dlg = results_mpl.ResultDialog(self._mainframe, resultplotter)
1661
1662
dlg.CenterOnScreen()
1663
1664
# this does not return until the dialog is closed.
1665
val = dlg.ShowModal()
1666
# print ' val,val == wx.ID_OK',val,wx.ID_OK,wx.ID_CANCEL,val == wx.ID_CANCEL
1667
# print ' status =',dlg.get_status()
1668
if dlg.get_status() != 'success': # val == wx.ID_CANCEL:
1669
# print ">>>>>>>>>Unsuccessful\n"
1670
dlg.Destroy()
1671
1672
if dlg.get_status() == 'success':
1673
# print ">>>>>>>>>successful\n"
1674
# apply current widget values to scenario instance
1675
dlg.apply()
1676
dlg.Destroy()
1677
1678
def on_gtfsstopgenerate(self, event=None):
1679
"""
1680
Generate public transport stops from google transit file system data
1681
and previously imported public transit routes.
1682
"""
1683
p = mapmatching.GtfsStopGenerator('gtfsstopgenerator',
1684
self._mapmatching,
1685
self._results,
1686
logger=self._mainframe.get_logger()
1687
)
1688
1689
dlg = ProcessDialog(self._mainframe, p, immediate_apply=True)
1690
1691
dlg.CenterOnScreen()
1692
1693
# this does not return until the dialog is closed.
1694
val = dlg.ShowModal()
1695
# print ' val,val == wx.ID_OK',val,wx.ID_OK,wx.ID_CANCEL,val == wx.ID_CANCEL
1696
# print ' status =',dlg.get_status()
1697
if dlg.get_status() != 'success': # val == wx.ID_CANCEL:
1698
# print ">>>>>>>>>Unsuccessful\n"
1699
dlg.Destroy()
1700
1701
else:
1702
# print ">>>>>>>>>successful\n"
1703
# apply current widget values to scenario instance
1704
dlg.apply()
1705
dlg.Destroy()
1706
1707
self._mainframe.refresh_moduleguis()
1708
self._is_needs_refresh = True
1709
self.refresh_widgets()
1710
print ' set browser to', self.get_scenario().net.ptstops
1711
self._mainframe.browse_obj(self.get_scenario().net.ptstops)
1712
1713
def on_gtfsservicegenerate(self, event=None):
1714
"""
1715
Generate public transport services from google transit file system data
1716
and previously generated public transit stops.
1717
"""
1718
p = mapmatching.GtfsServiceGenerator('gtfsservicegenerator',
1719
self._mapmatching,
1720
self._results,
1721
logger=self._mainframe.get_logger()
1722
)
1723
1724
dlg = ProcessDialog(self._mainframe, p, immediate_apply=True)
1725
1726
dlg.CenterOnScreen()
1727
1728
# this does not return until the dialog is closed.
1729
val = dlg.ShowModal()
1730
# print ' val,val == wx.ID_OK',val,wx.ID_OK,wx.ID_CANCEL,val == wx.ID_CANCEL
1731
# print ' status =',dlg.get_status()
1732
if dlg.get_status() != 'success': # val == wx.ID_CANCEL:
1733
# print ">>>>>>>>>Unsuccessful\n"
1734
dlg.Destroy()
1735
1736
if dlg.get_status() == 'success':
1737
# print ">>>>>>>>>successful\n"
1738
# apply current widget values to scenario instance
1739
dlg.apply()
1740
dlg.Destroy()
1741
print ' set browser to', self.get_scenario().demand.ptlines
1742
self._mainframe.browse_obj(self.get_scenario().demand.ptlines)
1743
# self._mainframe.refresh_moduleguis()
1744
#self._is_needs_refresh = True
1745
# self.refresh_widgets()
1746
1747
def on_create_trips_database(self, event=None):
1748
"""
1749
Analyze attributes of matched routes and create an elaborated trips database.
1750
"""
1751
1752
p = mapmatching.TripsDatabaseAnalyzer('tripsdatabase', self._mapmatching,
1753
results=self._results,
1754
logger=self._mainframe.get_logger())
1755
1756
dlg = ProcessDialog(self._mainframe, p, immediate_apply=True)
1757
1758
dlg.CenterOnScreen()
1759
1760
# this does not return until the dialog is closed.
1761
val = dlg.ShowModal()
1762
# print ' val,val == wx.ID_OK',val,wx.ID_OK,wx.ID_CANCEL,val == wx.ID_CANCEL
1763
# print ' status =',dlg.get_status()
1764
if dlg.get_status() != 'success': # val == wx.ID_CANCEL:
1765
# print ">>>>>>>>>Unsuccessful\n"
1766
dlg.Destroy()
1767
1768
if dlg.get_status() == 'success':
1769
# print ">>>>>>>>>successful\n"
1770
# apply current widget values to scenario instance
1771
dlg.apply()
1772
dlg.Destroy()
1773
self._mainframe.browse_obj(self._results.tripsdatabase)
1774
self._is_needs_refresh = True
1775
self.refresh_widgets()
1776
1777
def on_create_cyclists_database(self, event=None):
1778
"""
1779
Analyze attributes of persons and create an elaborated trips database.
1780
"""
1781
1782
p = mapmatching.CyclistsDatabaseAnalyzer('cyclistsdatabase', self._mapmatching,
1783
results=self._results,
1784
logger=self._mainframe.get_logger())
1785
1786
dlg = ProcessDialog(self._mainframe, p, immediate_apply=True)
1787
1788
dlg.CenterOnScreen()
1789
1790
# this does not return until the dialog is closed.
1791
val = dlg.ShowModal()
1792
# print ' val,val == wx.ID_OK',val,wx.ID_OK,wx.ID_CANCEL,val == wx.ID_CANCEL
1793
# print ' status =',dlg.get_status()
1794
if dlg.get_status() != 'success': # val == wx.ID_CANCEL:
1795
# print ">>>>>>>>>Unsuccessful\n"
1796
dlg.Destroy()
1797
1798
if dlg.get_status() == 'success':
1799
# print ">>>>>>>>>successful\n"
1800
# apply current widget values to scenario instance
1801
dlg.apply()
1802
dlg.Destroy()
1803
self._mainframe.browse_obj(self._results.cyclistsdatabase)
1804
self._is_needs_refresh = True
1805
self.refresh_widgets()
1806
1807