Path: blob/main/tools/contributed/sumopy/plugins/mapmatching/wxgui.py
169580 views
# Eclipse SUMO, Simulation of Urban MObility; see https://eclipse.dev/sumo1# Copyright (C) 2016-2025 German Aerospace Center (DLR) and others.2# SUMOPy module3# Copyright (C) 2012-2021 University of Bologna - DICAM4# This program and the accompanying materials are made available under the5# terms of the Eclipse Public License 2.0 which is available at6# https://www.eclipse.org/legal/epl-2.0/7# This Source Code may also be made available under the following Secondary8# Licenses when the conditions for such availability set forth in the Eclipse9# Public License 2.0 are satisfied: GNU General Public License, version 210# or later which is available at11# https://www.gnu.org/licenses/old-licenses/gpl-2.0-standalone.html12# SPDX-License-Identifier: EPL-2.0 OR GPL-2.0-or-later1314# @file wxgui.py15# @author Joerg Schweizer16# @date 20121718import os19import wx20import numpy as np2122from agilepy.lib_wx.modulegui import ModuleGui23from agilepy.lib_wx.ogleditor import *24from agilepy.lib_base.processes import Process25from agilepy.lib_wx.processdialog import ProcessDialog, ProcessDialogInteractive2627from coremodules.network import routing28from coremodules.demand import demand2930import mapmatching313233#import results_mpl as results_mpl34try:35import results_mpl as results_mpl36is_mpl = True # we have matplotlib support37except:38print "WARNING: python matplotlib package not installed, no matplotlib plots."39is_mpl = False404142class GpsPointsDrawings(Circles):43def __init__(self, ident, gpspoints, parent, **kwargs):4445Circles.__init__(self, ident, parent, name='GPS points',46is_parentobj=False,47is_fill=True, # Fill objects,48is_outline=False, # show outlines49n_vert=11, # default number of vertex per circle50linewidth=3,51**kwargs)5253self.delete('centers')54self.delete('radii')5556self.add(cm.AttrConf('color_default', np.array([1.0, 0.8, 0.1, 0.5], np.float32),57groupnames=['options', 'colors'],58metatype='color',59perm='wr',60name='Default color',61info='Default point color.',62))6364# self.set_netelement(gpspoints)6566def get_netelement(self):67return self._gpspoints6869def get_centers_array(self):70# return self._gpspoints.coords.value[self._inds_map]71return self._gpspoints.coords[self.get_ids()]7273def get_radii_array(self):74return self._gpspoints.radii[self.get_ids()]75# return self._gpspoints.radii.value[self._inds_map]7677def is_tool_allowed(self, tool, id_drawobj=-1):78"""79Returns True if this tool can be applied to this drawobj.80Optionally a particular drawobj can be specified with id_drawobj.81"""82# basic tools:83return tool.ident not in ['select_handles', 'delete', 'stretch'] # 'configure',84# return tool.ident not in ['delete','stretch']8586def set_netelement(self, gpspoints):87# print 'set_nodes'88self._gpspoints = gpspoints89# if len(self)>0:90# self.del_rows(self.get_ids())91self.clear_rows()9293ids = self._gpspoints.get_ids_selected()94n = len(ids)9596#self._inds_map = self._gpspoints.get_inds(ids)9798# print 'color_node_default',self.color_node_default.value99# print 'colors\n', np.ones((n,1),np.int32)*self.color_node_default.value100self.add_rows(ids=ids,101#colors = np.ones((n,1),np.int32)*self.color_default.value,102#colors_highl = self._get_colors_highl(np.ones((n,1),np.int32)*self.color_default.value),103colors_fill=np.ones((n, 1), np.int32)*self.color_default.value,104colors_highl_highl=self._get_colors_highl(np.ones((n, 1), np.int32)*self.color_default.value),105#centers = self._nodes.coords[ids],106#radii = self._nodes.radii[ids],107)108109self.centers = self._gpspoints.coords110self.radii = self._gpspoints.radii111self.update()112113def update(self, is_update=True):114115if is_update:116self._update_vertexvbo()117self._update_colorvbo()118119120class GpsRoutesDrawings(Polylines):121def __init__(self, ident, edges, parent, **kwargs):122123# joinstyle124# FLATHEAD = 0125# BEVELHEAD = 1126Polylines.__init__(self, ident, parent, name='GPS routes drawings',127is_lefthalf=True,128is_righthalf=True,129arrowstretch=1.5,130joinstyle=BEVELHEAD, # FLATHEAD,#BEVELHEAD is good for both halfs,131**kwargs)132133# self.delete('vertices')134# self.delete('widths')135# self.delete('colors')136137self.add(cm.AttrConf('width_default', 4.0,138groupnames=['options'],139perm='wr',140name='Default width',141info='Default route width of drawing.',142))143144self.add(cm.AttrConf('color_default', np.array([1.0, 0.4, 0.0, 0.6], np.float32),145groupnames=['options'],146perm='wr',147metatype='color',148name='Default color',149info='Default route color.',150))151152# self.set_netelement(edges)153154def get_netelement(self):155return self._routes156157# def get_vertices_array(self):158# return self._routes.shapes[self.get_ids()]#.value[self._inds_map]#[self.get_ids()]159160# def get_widths_array(self):161# # double because only the right half is shown162# # add a little bit to the width to make it a little wider than the lanes contained163# #return 2.2*self._edges.widths.value[self._inds_map]164# return 1.1*self._edges.widths[self.get_ids()]#.value[self._inds_map]165166# def get_vertices(self, ids):167# return self._edges.shapes[ids]168169# def set_vertices(self, ids, vertices, is_update = True):170# self._edges.set_shapes(ids, vertices)171# if is_update:172# self._update_vertexvbo()173# self.parent.get_drawobj_by_ident('lanedraws').update()174# self.parent.get_drawobj_by_ident('crossingsdraws').update()175# self.parent.get_drawobj_by_ident('connectiondraws').update()176177# def get_widths(self, ids):178# return 1.1*self._edges.widths[ids]179180# def set_widths(self, ids, values):181# #self._edges.widths[ids] = values/1.1182# pass183184def is_tool_allowed(self, tool, id_drawobj=-1):185"""186Returns True if this tool can be applied to this drawobj.187Optionally a particular drawobj can be specified with id_drawobj.188"""189# basic tools:190return tool.ident not in ['configure', 'select_handles', 'delete', 'move', 'stretch']191# return tool.ident not in ['delete',]192193def set_netelement(self, routes):194195self._routes = routes196#self._inds_edges = self._edges.get_inds()197self.clear_rows()198# if len(self)>0:199# self.del_rows(self.get_ids())200201ids = self._routes.parent.get_ids_route_selected()202#self._inds_map = self._edges.get_inds(ids)203n = len(ids)204#self.vertices = self._edges.shapes205#self.widths = self._edges.widths206# print '\n\nGpsRoutesDrawings.set_netelement',n207# print ' ids.dtype',ids.dtype208# print ' self._ids.dtype',self._ids.dtype209# print ' self._inds.dtype',self._inds.dtype210# print ' ids',ids211self.add_rows(ids=ids,212beginstyles=np.ones(n, dtype=np.float32)*FLATHEAD,213endstyles=np.ones(n, dtype=np.float32)*TRIANGLEHEAD,214widths=np.ones(n, dtype=np.float32)*self.width_default.get_value()215)216self.vertices[ids] = self._routes.get_shapes(ids)217self.update()218219def update(self, is_update=True):220"""221Update color, assume that there have not been structural changes of the arrays222"""223# assumes that edges have been set in set_edges224# print 'Edgedrawing.update'225#edgeinds = self._edges.get_inds()226n = len(self)227ids = self.get_ids()228229self.colors_fill.value[:] = self._routes.colors[ids]230#self.colors_fill.value[:] = np.ones((n,1),np.float32)*self.color_default.value231self.colors_fill_highl.value[:] = self._get_colors_highl(self.colors_fill.value)232233if is_update:234self._update_vertexvbo()235self._update_colorvbo()236237238class WxGui(ModuleGui):239"""Contains functions that communicate between the widgets of the main wx gui240and the functions of the plugin.241"""242243def __init__(self, ident):244self._mapmatching = None245self._matchprocess = None246self._results = None247self._scenario = None248self._canvas = None249self._init_common(ident, priority=100001,250icondirpath=os.path.join(os.path.dirname(__file__), 'images'))251252self._is_needs_refresh = False253254def get_module(self):255return self._mapmatching256257def get_scenario(self):258return self._mainframe.get_modulegui('coremodules.scenario').get_scenario()259260def get_neteditor(self):261return self._mainframe.get_modulegui('coremodules.network').get_neteditor()262263def get_canvas(self):264return self.get_neteditor().get_canvas()265266def get_drawing(self):267return self.get_canvas().get_drawing()268269def init_widgets(self, mainframe):270"""271Set mainframe and initialize widgets to various places.272"""273self._mainframe = mainframe274#self._neteditor = mainframe.add_view("Network", Neteditor)275276# mainframe.browse_obj(self._module)277self.make_menu()278self.make_toolbar()279280def refresh_widgets(self):281"""282Check through mainframe what the state of the application is283and reset widgets. For exampe enable/disable widgets284dependent on the availability of data.285"""286print 'MapmatchingWxGui.refresh_widgets'287scenario = self.get_scenario()288is_refresh = False289if self._scenario != scenario:290del self._scenario291del self._mapmatching292del self._results293self._scenario = scenario294self._mapmatching = scenario.demand.add_demandobject(295ident='mapmatching', DemandClass=mapmatching.Mapmatching)296#self._mapmatching = mapmatching.Mapmatching('mapmatching', scenario)297self._matchprocess = None298self._results = mapmatching.Matchresults('matchresults',299self._mapmatching,300)301is_refresh = True302303if is_refresh | self._is_needs_refresh:304self._is_needs_refresh = False305print ' is_refresh', is_refresh, self._is_needs_refresh306neteditor = self.get_neteditor()307#canvas = self.get_canvas()308drawing = self.get_drawing() # canvas.get_drawing()309310# add or refresh facility drawing311drawing.set_element('gpspointsdraws', GpsPointsDrawings,312self._mapmatching.points, layer=150)313314drawing.set_element('gpsroutesdraws', GpsRoutesDrawings,315self._mapmatching.trips.get_routes(), layer=149)316317# neteditor.get_toolbox().add_toolclass(AddZoneTool)# will check if tool is already there318# neteditor.get_toolbox().add_toolclass(AddFacilityTool)319neteditor.draw()320321self._canvas = self.get_canvas()322323def make_menu(self):324menubar = self._mainframe.menubar325menubar.append_menu('plugins/mapmatching',326bitmap=self.get_icon("icon_gps.png"),327)328menubar.append_item('plugins/mapmatching/browse',329self.on_browse, # common function in modulegui330info='View and browse mapmatching in object panel.',331bitmap=self.get_agileicon('icon_browse_24px.png'), # ,332)333334# menubar.append_item( 'plugins/mapmatching/open...',335# self.on_open,336# bitmap = wx.ArtProvider.GetBitmap(wx.ART_FILE_OPEN,wx.ART_MENU),337# )338339menubar.append_menu('plugins/mapmatching/import',340bitmap=self.get_agileicon("Document_Import_24px.png"),341)342343menubar.append_item('plugins/mapmatching/import/European cycling challange...',344self.on_import_ecc,345# info=self.on_import_ecc.__doc__.strip(),346bitmap=self.get_agileicon("Document_Import_24px.png"),347)348349menubar.append_item('plugins/mapmatching/import/Bella mossa...',350self.on_import_bellamossa,351# info=self.on_import_ecc.__doc__.strip(),352bitmap=self.get_agileicon("Document_Import_24px.png"),353)354355menubar.append_item('plugins/mapmatching/import/Mobike...',356self.on_import_mobike,357# info=self.on_import_ecc.__doc__.strip(),358bitmap=self.get_agileicon("Document_Import_24px.png"),359)360menubar.append_item('plugins/mapmatching/import/Strava...',361self.on_import_strava,362# info=self.on_import_ecc.__doc__.strip(),363bitmap=self.get_agileicon("Document_Import_24px.png"),364)365366menubar.append_item('plugins/mapmatching/import/GPX file...',367self.on_import_gpx,368# info=self.on_import_ecc.__doc__.strip(),369bitmap=self.get_agileicon("Document_Import_24px.png"),370)371372# menubar.append_item( 'plugins/mapmatching/project points',373# self.on_project_points,374# #bitmap = wx.ArtProvider.GetBitmap(wx.ART_FILE_SAVE_AS,wx.ART_MENU),375# )376# -------------------------------------------------------------------------------377378menubar.append_menu('plugins/mapmatching/mapmatching',379# bitmap = self.get_icon('icon_results_24px.png'),#,380info='Apply different mapmatching methods to identify the network edges that best represent a trace of GPS points.'381)382383menubar.append_item('plugins/mapmatching/mapmatching/match points to road network...',384self.on_match_birgil,385#bitmap = wx.ArtProvider.GetBitmap(wx.ART_FILE_SAVE_AS,wx.ART_MENU),386)387388menubar.append_item('plugins/mapmatching/mapmatching/match points to PT network...',389self.on_match_pt,390#bitmap = wx.ArtProvider.GetBitmap(wx.ART_FILE_SAVE_AS,wx.ART_MENU),391)392393# -------------------------------------------------------------------------------394menubar.append_menu('plugins/mapmatching/routing',395# bitmap = self.get_icon('icon_results_24px.png'),#,396info='Apply different routing algorithms to create alternative routes to the mapmatched routes.'397)398menubar.append_item('plugins/mapmatching/routing/shortest path routing...',399self.on_route_shortest,400#bitmap = wx.ArtProvider.GetBitmap(wx.ART_FILE_SAVE_AS,wx.ART_MENU),401)402403menubar.append_item('plugins/mapmatching/routing/fastest path routing...',404self.on_route_fastest,405#bitmap = wx.ArtProvider.GetBitmap(wx.ART_FILE_SAVE_AS,wx.ART_MENU),406)407408409# -------------------------------------------------------------------------------410411menubar.append_menu('plugins/mapmatching/person analysis',412bitmap=self.get_icon('icon_results_24px.png'), # ,413info='Person analysis tools'414)415416menubar.append_item('plugins/mapmatching/person analysis/analyze',417self.on_analyze_persons,418#bitmap = wx.ArtProvider.GetBitmap(wx.ART_FILE_SAVE_AS,wx.ART_MENU),419)420421menubar.append_item('plugins/mapmatching/person analysis/save matched in csv...',422self.on_export_persons_csv,423info='Save persons with matched trips in a CSV file.',424bitmap=self.get_agileicon("Document_Export_24px.png"),425)426# -------------------------------------------------------------------------------427428menubar.append_menu('plugins/mapmatching/point analysis',429bitmap=self.get_icon('icon_results_24px.png'), # ,430info='Point analysis tools'431)432433if is_mpl:434menubar.append_item('plugins/mapmatching/point analysis/plot point results...',435self.on_plot_pointresults,436bitmap=results_mpl.get_mplicon(), # ,437)438439# -------------------------------------------------------------------------------440441menubar.append_menu('plugins/mapmatching/route analysis',442bitmap=self.get_icon('icon_results_24px.png'), # ,443info='Route analysis tools'444)445446menubar.append_item('plugins/mapmatching/route analysis/browse',447self.on_browse_results, # common function in modulegui448bitmap=self.get_agileicon('icon_browse_24px.png'), # ,449)450451menubar.append_item('plugins/mapmatching/route analysis/analyze...',452self.on_routeanalyze, # common function in modulegui453# bitmap = self.get_agileicon('icon_browse_24px.png'),#,454)455456menubar.append_item('plugins/mapmatching/route analysis/create trips database...',457self.on_create_trips_database, # common function in modulegui458# bitmap = self.get_agileicon('icon_browse_24px.png'),#,459)460461menubar.append_item('plugins/mapmatching/route analysis/create cyclists database...',462self.on_create_cyclists_database, # common function in modulegui463# bitmap = self.get_agileicon('icon_browse_24px.png'),#,464)465menubar.append_item('plugins/mapmatching/route analysis/analyze alternative routes...',466self.on_altrouteanalyze, # common function in modulegui467# bitmap = self.get_agileicon('icon_browse_24px.png'),#,468)469470menubar.append_item('plugins/mapmatching/route analysis/analyze PT routes...',471self.on_ptanalyze, # common function in modulegui472# bitmap = self.get_agileicon('icon_browse_24px.png'),#,473)474475if is_mpl:476menubar.append_item('plugins/mapmatching/route analysis/plot route results...',477self.on_plot_routeresults,478bitmap=results_mpl.get_mplicon(), # ,479)480481menubar.append_item('plugins/mapmatching/route analysis/plot public transport flows...',482self.on_plot_ptflows,483bitmap=results_mpl.get_mplicon(), # ,484)485486menubar.append_item('plugins/mapmatching/route analysis/plot edge results...',487self.on_plot_edgeresults,488bitmap=results_mpl.get_mplicon(), # ,489)490menubar.append_item('plugins/mapmatching/route analysis/plot connection results...',491self.on_plot_connectionresults,492bitmap=results_mpl.get_mplicon(), # ,493)494495menubar.append_item('plugins/mapmatching/route analysis/plot speed profiles...',496self.on_plot_speedprofiles,497bitmap=results_mpl.get_mplicon(), # ,498)499menubar.append_item('plugins/mapmatching/route analysis/plot node results...',500self.on_plot_noderesults,501bitmap=results_mpl.get_mplicon(), # ,502)503504menubar.append_item('plugins/mapmatching/route analysis/plot alternative routes...',505self.on_plot_alternative_routes,506bitmap=results_mpl.get_mplicon(), # ,507)508509menubar.append_item('plugins/mapmatching/route analysis/safe as...',510self.on_save_results,511bitmap=wx.ArtProvider.GetBitmap(wx.ART_FILE_SAVE_AS, wx.ART_MENU),512)513514menubar.append_item('plugins/mapmatching/route analysis/open...',515self.on_open_results,516bitmap=wx.ArtProvider.GetBitmap(wx.ART_FILE_OPEN, wx.ART_MENU),517)518519520# -------------------------------------------------------------------------------521menubar.append_menu('plugins/mapmatching/demand generation',522bitmap=self.get_icon('icon_sim.png'), # ,523info='Create vp from trips'524)525526menubar.append_item('plugins/mapmatching/demand generation/zone-to-zone demand generation',527self.create_zonetozone_demand,528bitmap=self.get_icon('icon_od.png'), # ,529#bitmap = wx.ArtProvider.GetBitmap(wx.ART_FILE_SAVE_AS,wx.ART_MENU),530)531menubar.append_item('plugins/mapmatching/demand generation/routes generation...',532self.create_odroute_from_trips,533bitmap=self.get_icon('icon_sim.png'), # ,534#bitmap = wx.ArtProvider.GetBitmap(wx.ART_FILE_SAVE_AS,wx.ART_MENU),535)536menubar.append_item('plugins/mapmatching/demand generation/virtual pop generation',537self.create_vp_from_trips,538bitmap=self.get_icon('icon_vp.png'), # ,539#bitmap = wx.ArtProvider.GetBitmap(wx.ART_FILE_SAVE_AS,wx.ART_MENU),540)541542# -------------------------------------------------------------------------------543544menubar.append_menu('plugins/mapmatching/filter and select',545# bitmap = self.get_icon('icon_results_24px.png'),#,546info='Filter and select GPS trips.'547)548549menubar.append_item('plugins/mapmatching/filter and select/select traces by geometry...',550self.on_geomfilter_trips,551#bitmap = wx.ArtProvider.GetBitmap(wx.ART_FILE_SAVE_AS,wx.ART_MENU),552)553554menubar.append_item('plugins/mapmatching/filter and select/post-match filter trips...',555self.on_postmatchfilter_trips,556#bitmap = wx.ArtProvider.GetBitmap(wx.ART_FILE_SAVE_AS,wx.ART_MENU),557)558559menubar.append_item('plugins/mapmatching/filter and select/select mode...',560self.on_select_mode,561#bitmap = wx.ArtProvider.GetBitmap(wx.ART_FILE_SAVE_AS,wx.ART_MENU),562)563564menubar.append_item('plugins/mapmatching/filter and select/select all trips',565self.on_select_all_trips,566)567568menubar.append_item('plugins/mapmatching/filter and select/unselect all trips',569self.on_unselect_all_trips,570)571572menubar.append_item('plugins/mapmatching/filter and select/invert selected trips',573self.on_invert_selected_trips,574)575# -------------------------------------------------------------------------------576577menubar.append_menu('plugins/mapmatching/delete',578bitmap=wx.ArtProvider.GetBitmap(wx.ART_DELETE, wx.ART_MENU),579info='Delete tools.'580)581582menubar.append_item('plugins/mapmatching/delete/delete unselected trips',583self.on_delete_unselected,584bitmap=wx.ArtProvider.GetBitmap(wx.ART_DELETE, wx.ART_MENU),585)586587menubar.append_item('plugins/mapmatching/delete/delete routes',588self.on_clear_routes,589bitmap=wx.ArtProvider.GetBitmap(wx.ART_DELETE, wx.ART_MENU),590)591592menubar.append_item('plugins/mapmatching/delete/delete all',593self.on_clear_all,594bitmap=wx.ArtProvider.GetBitmap(wx.ART_DELETE, wx.ART_MENU),595)596597# -------------------------------------------------------------------------------598menubar.append_menu('plugins/mapmatching/export',599bitmap=self.get_agileicon("Document_Export_24px.png"),600)601602menubar.append_item('plugins/mapmatching/export/route results to shape...',603self.on_routes_to_shapefile,604bitmap=wx.ArtProvider.GetBitmap(wx.ART_FILE_SAVE_AS, wx.ART_MENU),605)606607menubar.append_item('plugins/mapmatching/export/edge results to shape...',608self.on_edgesresults_to_shapefile,609bitmap=wx.ArtProvider.GetBitmap(wx.ART_FILE_SAVE_AS, wx.ART_MENU),610)611612menubar.append_item('plugins/mapmatching/export/GPS points to shape...',613self.on_points_to_shapefile,614bitmap=wx.ArtProvider.GetBitmap(wx.ART_FILE_SAVE_AS, wx.ART_MENU),615)616617# -------------------------------------------------------------------------------618menubar.append_menu('plugins/mapmatching/GTFS',619bitmap=self.get_icon('icon_g.png'), # ,620info="GTFS import, matching and public transport generation functionality, based on Goole Transit file formats."621)622623menubar.append_item('plugins/mapmatching/GTFS/GTFS shapes...',624self.on_import_gtfs,625# info=self.on_import_ecc.__doc__.strip(),626bitmap=self.get_agileicon("Document_Import_24px.png"),627)628629menubar.append_item('plugins/mapmatching/GTFS/generate Stops from GTFS...',630self.on_gtfsstopgenerate, # common function in modulegui631bitmap=self.get_icon('icon_g.png'), # ,632)633634menubar.append_item('plugins/mapmatching/GTFS/generate services from GTFS...',635self.on_gtfsservicegenerate, # common function in modulegui636bitmap=self.get_icon('icon_g.png'), # ,637)638639# -------------------------------------------------------------------------------640641menubar.append_item('plugins/mapmatching/redraw GPS data',642self.on_redraw,643)644645def on_plot_pointresults(self, event=None):646"""647Plot point results of route analysis in Matplotlib plotting envitonment.648"""649if is_mpl:650resultplotter = results_mpl.PointresultPlotter(self._results,651logger=self._mainframe.get_logger()652)653dlg = results_mpl.ResultDialog(self._mainframe, resultplotter)654655dlg.CenterOnScreen()656657# this does not return until the dialog is closed.658val = dlg.ShowModal()659# print ' val,val == wx.ID_OK',val,wx.ID_OK,wx.ID_CANCEL,val == wx.ID_CANCEL660# print ' status =',dlg.get_status()661if dlg.get_status() != 'success': # val == wx.ID_CANCEL:662# print ">>>>>>>>>Unsuccessful\n"663dlg.Destroy()664665if dlg.get_status() == 'success':666# print ">>>>>>>>>successful\n"667# apply current widget values to scenario instance668dlg.apply()669dlg.Destroy()670671def od_analysis(self, event=None):672"""673OD analysis.674"""675if is_mpl:676p = results_mpl.ODanalysis(self._results,677logger=self._mainframe.get_logger()678)679dlg = ProcessDialog(self._mainframe, p, immediate_apply=True)680681dlg.CenterOnScreen()682683# this does not return until the dialog is closed.684val = dlg.ShowModal()685# print ' val,val == wx.ID_OK',val,wx.ID_OK,wx.ID_CANCEL,val == wx.ID_CANCEL686# print ' status =',dlg.get_status()687if dlg.get_status() != 'success': # val == wx.ID_CANCEL:688# print ">>>>>>>>>Unsuccessful\n"689dlg.Destroy()690691if dlg.get_status() == 'success':692# print ">>>>>>>>>successful\n"693# apply current widget values to scenario instance694dlg.apply()695dlg.Destroy()696697def create_odroute_from_trips(self, event=None):698"""699Create vp from GPS trips.700"""701702mapmatching.OdRouteCreator('create_odroute_from_trips',703self._mapmatching,704logger=self._mainframe.get_logger(),705).do()706707def create_zonetozone_demand(self, event=None):708"""709Create zone-to-zone demand from GPS trips.710"""711712p = mapmatching.OdCreator('Create_zonetozone_demand_from_trips',713self._mapmatching,714logger=self._mainframe.get_logger(),715)716dlg = ProcessDialog(self._mainframe,717p,718title='Create Virtual Population from GPS Trips')719720dlg.CenterOnScreen()721722# this does not return until the dialog is closed.723val = dlg.ShowModal()724# print ' val,val == wx.ID_OK',val,wx.ID_OK,wx.ID_CANCEL,val == wx.ID_CANCEL725# print ' status =',dlg.get_status()726if dlg.get_status() != 'success': # val == wx.ID_CANCEL:727# print ">>>>>>>>>Unsuccessful\n"728dlg.Destroy()729730if dlg.get_status() == 'success':731# print ">>>>>>>>>successful\n"732# apply current widget values to scenario instance733dlg.apply()734dlg.Destroy()735736def create_vp_from_trips(self, event=None):737"""738Create vp from GPS trips.739"""740741p = mapmatching.VpCreator('Create_Vp_from_trips',742self._mapmatching,743logger=self._mainframe.get_logger(),744)745dlg = ProcessDialog(self._mainframe,746p,747title='Create Virtual Population from GPS Trips')748749dlg.CenterOnScreen()750751# this does not return until the dialog is closed.752val = dlg.ShowModal()753# print ' val,val == wx.ID_OK',val,wx.ID_OK,wx.ID_CANCEL,val == wx.ID_CANCEL754# print ' status =',dlg.get_status()755if dlg.get_status() != 'success': # val == wx.ID_CANCEL:756# print ">>>>>>>>>Unsuccessful\n"757dlg.Destroy()758759if dlg.get_status() == 'success':760# print ">>>>>>>>>successful\n"761# apply current widget values to scenario instance762dlg.apply()763dlg.Destroy()764765def on_plot_routeresults(self, event=None):766"""767Plot route results of route analysis in Matplotlib plotting envitonment.768"""769if is_mpl:770resultplotter = results_mpl.RouteresultPlotter(self._results,771logger=self._mainframe.get_logger()772)773dlg = results_mpl.ResultDialog(self._mainframe, resultplotter)774775dlg.CenterOnScreen()776777# this does not return until the dialog is closed.778val = dlg.ShowModal()779# print ' val,val == wx.ID_OK',val,wx.ID_OK,wx.ID_CANCEL,val == wx.ID_CANCEL780# print ' status =',dlg.get_status()781if dlg.get_status() != 'success': # val == wx.ID_CANCEL:782# print ">>>>>>>>>Unsuccessful\n"783dlg.Destroy()784785if dlg.get_status() == 'success':786# print ">>>>>>>>>successful\n"787# apply current widget values to scenario instance788dlg.apply()789dlg.Destroy()790791def on_plot_edgeresults(self, event=None):792"""793Plot edge results of route analysis in Matplotlib plotting envitonment.794"""795if is_mpl:796resultplotter = results_mpl.EdgeresultPlotter(self._results,797logger=self._mainframe.get_logger()798)799dlg = results_mpl.ResultDialog(self._mainframe, resultplotter)800801dlg.CenterOnScreen()802803# this does not return until the dialog is closed.804val = dlg.ShowModal()805# print ' val,val == wx.ID_OK',val,wx.ID_OK,wx.ID_CANCEL,val == wx.ID_CANCEL806# print ' status =',dlg.get_status()807if dlg.get_status() != 'success': # val == wx.ID_CANCEL:808# print ">>>>>>>>>Unsuccessful\n"809dlg.Destroy()810811if dlg.get_status() == 'success':812# print ">>>>>>>>>successful\n"813# apply current widget values to scenario instance814dlg.apply()815dlg.Destroy()816817def on_plot_connectionresults(self, event=None):818"""819Plot connection results of route analysis in Matplotlib plotting envitonment.820"""821if is_mpl:822resultplotter = results_mpl.ConnectionresultPlotter(self._results,823logger=self._mainframe.get_logger()824)825dlg = results_mpl.ResultDialog(self._mainframe, resultplotter)826827dlg.CenterOnScreen()828829# this does not return until the dialog is closed.830val = dlg.ShowModal()831# print ' val,val == wx.ID_OK',val,wx.ID_OK,wx.ID_CANCEL,val == wx.ID_CANCEL832# print ' status =',dlg.get_status()833if dlg.get_status() != 'success': # val == wx.ID_CANCEL:834# print ">>>>>>>>>Unsuccessful\n"835dlg.Destroy()836837if dlg.get_status() == 'success':838# print ">>>>>>>>>successful\n"839# apply current widget values to scenario instance840dlg.apply()841dlg.Destroy()842843def on_plot_alternative_routes(self, event=None):844"""845Plot alternative route results in Matplotlib plotting envitonment.846"""847if is_mpl:848resultplotter = results_mpl.AlternativeRoutesPlotter(self._results,849logger=self._mainframe.get_logger()850)851dlg = results_mpl.ResultDialog(self._mainframe, resultplotter)852853dlg.CenterOnScreen()854855# this does not return until the dialog is closed.856val = dlg.ShowModal()857# print ' val,val == wx.ID_OK',val,wx.ID_OK,wx.ID_CANCEL,val == wx.ID_CANCEL858# print ' status =',dlg.get_status()859if dlg.get_status() != 'success': # val == wx.ID_CANCEL:860# print ">>>>>>>>>Unsuccessful\n"861dlg.Destroy()862863if dlg.get_status() == 'success':864# print ">>>>>>>>>successful\n"865# apply current widget values to scenario instance866dlg.apply()867dlg.Destroy()868869def on_plot_noderesults(self, event=None):870"""871Plot node results of route analysis in Matplotlib plotting envitonment.872"""873if is_mpl:874resultplotter = results_mpl.NoderesultPlotter(self._results,875logger=self._mainframe.get_logger()876)877dlg = results_mpl.ResultDialog(self._mainframe, resultplotter)878879dlg.CenterOnScreen()880881# this does not return until the dialog is closed.882val = dlg.ShowModal()883# print ' val,val == wx.ID_OK',val,wx.ID_OK,wx.ID_CANCEL,val == wx.ID_CANCEL884# print ' status =',dlg.get_status()885if dlg.get_status() != 'success': # val == wx.ID_CANCEL:886# print ">>>>>>>>>Unsuccessful\n"887dlg.Destroy()888889if dlg.get_status() == 'success':890# print ">>>>>>>>>successful\n"891# apply current widget values to scenario instance892dlg.apply()893dlg.Destroy()894895def on_plot_speedprofiles(self, event=None):896"""897Plot speedprofiles of route analysis in Matplotlib plotting envitonment.898"""899if is_mpl:900resultplotter = results_mpl.SpeedprofilePlotter(self._results,901logger=self._mainframe.get_logger()902)903dlg = results_mpl.ResultDialog(self._mainframe, resultplotter)904905dlg.CenterOnScreen()906907# this does not return until the dialog is closed.908val = dlg.ShowModal()909# print ' val,val == wx.ID_OK',val,wx.ID_OK,wx.ID_CANCEL,val == wx.ID_CANCEL910# print ' status =',dlg.get_status()911if dlg.get_status() != 'success': # val == wx.ID_CANCEL:912# print ">>>>>>>>>Unsuccessful\n"913dlg.Destroy()914915if dlg.get_status() == 'success':916# print ">>>>>>>>>successful\n"917# apply current widget values to scenario instance918dlg.apply()919dlg.Destroy()920921def on_routes_to_shapefile(self, event=None):922"""923Export route results to shape file.924"""925# print 'on_routes_to_shapefile'926scenario = self._mapmatching.get_scenario()927dirpath = scenario.get_workdirpath()928defaultFile = scenario.get_rootfilename()+'.routeres.shp'929wildcards_all = 'All files (*.*)|*.*|SHP files (*.shp)|*.shp'930dlg = wx.FileDialog(None, message='Export route results to shapefile',931defaultDir=dirpath,932# defaultFile=defaultFile,933wildcard=wildcards_all, style=wx.SAVE | wx.CHANGE_DIR)934if dlg.ShowModal() == wx.ID_OK:935filepath = dlg.GetPath()936937else:938return939940mapmatching.routes_to_shapefile(self._mapmatching,941self._results,942filepath,943log=self._mainframe.get_logger())944945def on_edgesresults_to_shapefile(self, event=None):946"""947Export edge results to shape file.948"""949print 'on_nodes_to_shapefile'950scenario = self._mapmatching.get_scenario()951dirpath = scenario.get_workdirpath()952#defaultFile = scenario.get_rootfilename()+'.edgeres.shp'953wildcards_all = 'All files (*.*)|*.*|SHP files (*.shp)|*.shp'954dlg = wx.FileDialog(None, message='Export edge results to shapefile',955defaultDir=dirpath,956# defaultFile=defaultFile,957wildcard=wildcards_all, style=wx.SAVE | wx.CHANGE_DIR)958if dlg.ShowModal() == wx.ID_OK:959filepath = dlg.GetPath()960961else:962return963964mapmatching.edgesresults_to_shapefile(self._mapmatching,965self._results,966filepath,967log=self._mainframe.get_logger())968969def on_points_to_shapefile(self, event=None):970"""971Export GPS points to shapefile.972"""973print 'on_points_to_shapefile'974scenario = self._mapmatching.get_scenario()975dirpath = scenario.get_workdirpath()976defaultFile = scenario.get_rootfilename()+'.points.shp'977wildcards_all = 'All files (*.*)|*.*|SHP files (*.shp)|*.shp'978dlg = wx.FileDialog(None, message='Export GPS points to shapefile',979defaultDir=dirpath,980# defaultFile=defaultFile,981wildcard=wildcards_all, style=wx.SAVE | wx.CHANGE_DIR)982if dlg.ShowModal() == wx.ID_OK:983filepath = dlg.GetPath()984985else:986return987988mapmatching.points_to_shapefile(self._mapmatching,989filepath,990log=self._mainframe.get_logger())991992def on_save_results(self, event=None):993"""994Save mapmatching analysis results to binary file.995"""996if self._results is None:997return998scenario = self.get_scenario()999wildcards_all = "All files (*.*)|*.*"1000wildcards_obj = "Python binary files (*.obj)|*.obj"1001wildcards = wildcards_obj+"|"+wildcards_all10021003# Finally, if the directory is changed in the process of getting files, this1004# dialog is set up to change the current working directory to the path chosen.1005dlg = wx.FileDialog(1006self._mainframe, message="Save results to file",1007defaultDir=scenario.get_workdirpath(),1008#defaultFile = scenario.get_rootfilepath()+'.mmatch.obj',1009wildcard=wildcards,1010style=wx.SAVE | wx.CHANGE_DIR1011)1012val = dlg.ShowModal()1013# Show the dialog and retrieve the user response. If it is the OK response,1014# process the data.1015if val == wx.ID_OK:1016# This returns a Python list of files that were selected.1017filepath = dlg.GetPath()1018if len(filepath) > 0:1019# now set new filename and workdir1020self._results.save(filepath)10211022# Destroy the dialog. Don't do this until you are done with it!1023# BAD things can happen otherwise!1024dlg.Destroy()10251026def on_open_results(self, event=None):10271028wildcards_all = "All files (*.*)|*.*"1029wildcards_obj = "Python binary files (*.obj)|*.obj"1030wildcards = wildcards_obj+"|"+wildcards_all10311032# Finally, if the directory is changed in the process of getting files, this1033# dialog is set up to change the current working directory to the path chosen.1034dlg = wx.FileDialog(1035self._mainframe, message="Open results file",1036defaultDir=self.get_scenario().get_workdirpath(),1037#defaultFile = os.path.join(scenario.get_workdirpath(), scenario.format_ident()+'.obj'),1038wildcard=wildcards,1039style=wx.OPEN | wx.CHANGE_DIR1040)10411042# Show the dialog and retrieve the user response. If it is the OK response,1043# process the data.1044is_newresults = False1045if dlg.ShowModal() == wx.ID_OK:1046# This returns a Python list of files that were selected.1047filepath = dlg.GetPath()1048if len(filepath) > 0:1049if self._results is not None:1050# browse away from results1051# self._mainframe.browse_obj(self._results.get_scenario())1052del self._results10531054self._results = mapmatching.load_results(filepath,1055parent=self._mapmatching,1056logger=self._mainframe.get_logger()1057)1058is_newresults = True10591060# Destroy the dialog. Don't do this until you are done with it!1061# BAD things can happen otherwise!1062dlg.Destroy()10631064if is_newresults:1065# this should update all widgets for the new scenario!!1066# print 'call self._mainframe.refresh_moduleguis()'1067self._mainframe.browse_obj(self._results)1068# self._mainframe.select_view(name = "Result viewer") #!!!!!!!!tricky, crashes without1069self._is_needs_refresh = True1070self.refresh_widgets()1071# wx.CallAfter(self.refresh_widgets)1072# self._mainframe.refresh_moduleguis()1073#if event: event.Skip()10741075def on_select_all_trips(self, event=None):1076"""1077Select all GPS trips.1078"""1079self._mapmatching.trips.select_all()1080self._mainframe.browse_obj(self._mapmatching.trips)1081self._is_needs_refresh = True1082self.refresh_widgets()10831084def on_unselect_all_trips(self, event=None):1085"""1086Unselect all GPS trips.1087"""1088self._mapmatching.trips.unselect_all()1089self._mainframe.browse_obj(self._mapmatching.trips)1090self._is_needs_refresh = True1091self.refresh_widgets()10921093def on_invert_selected_trips(self, event=None):1094"""1095Invert selected GPS trips, all selected will be unselected and vice versa.1096"""1097self._mapmatching.trips.invert_selection()1098self._mainframe.browse_obj(self._mapmatching.trips)1099self._is_needs_refresh = True1100self.refresh_widgets()11011102def on_clear_all(self, event=None):1103"""1104Clear all GPS points, routes and persons.1105"""1106self._mapmatching.clear_all()1107self._mainframe.browse_obj(self._mapmatching)1108self._is_needs_refresh = True1109self.refresh_widgets()11101111def on_clear_routes(self, event=None):1112"""1113Clear matched routes and minimal distance routes.1114"""1115self._mapmatching.clear_routes()1116self._mainframe.browse_obj(self._mapmatching)1117self._is_needs_refresh = True1118self.refresh_widgets()11191120def on_delete_unselected(self, event=None):1121"""1122Delete unselected trips.1123"""1124self._mapmatching.delete_unselected_trips()1125self._mainframe.browse_obj(self._mapmatching.trips)1126self._is_needs_refresh = True1127self.refresh_widgets()11281129def is_matchprocess(self, ident):1130if self._matchprocess is None:1131return False1132else:1133return self._matchprocess.ident == ident11341135def on_match_birgil(self, event=None):1136"""1137Match selected traces with GPS points to the road network based on Birgillito's method.1138"""1139# self.prepare_results()1140if not self.is_matchprocess('birgilmatcher'):1141self._matchprocess = mapmatching.BirgilMatcher('birgilmatcher',1142self._mapmatching,1143logger=self._mainframe.get_logger(),1144)11451146dlg = ProcessDialogInteractive(self._mainframe,1147self._matchprocess,1148#title = 'Mapmatching with Birgillito method',1149func_close=self.close_match_birgil,1150)11511152dlg.CenterOnScreen()11531154# this does not return until the dialog is closed.1155#val = dlg.ShowModal()1156# print 'open_sumodialog_interactive'1157dlg.Show()1158dlg.MakeModal(True)1159# print ' val,val == wx.ID_OK',val,wx.ID_OK,wx.ID_CANCEL,val == wx.ID_CANCEL1160# print ' status =',dlg.get_status()1161# print 'returned to main window self.simulator.status',self.simulator.status11621163def close_match_birgil(self, dlg):1164# called before destroying the dialog1165if dlg.get_status() == 'success':1166#p = self._mapmatchprocess11671168self._mainframe.browse_obj(self._mapmatching.trips)1169self._is_needs_refresh = True1170self.refresh_widgets()11711172def on_match_pt(self, event=None):1173"""1174Match selected traces with GPS points to the public transport network. A public transport network must be previously built.1175"""1176# self.prepare_results()1177if not self.is_matchprocess('ptmatcher'):1178self._matchprocess = mapmatching.PTMatcher('ptmatcher',1179self._mapmatching,1180logger=self._mainframe.get_logger(),1181)11821183dlg = ProcessDialogInteractive(self._mainframe,1184self._matchprocess,1185#title = 'Mapmatching with Birgillito method',1186func_close=self.close_match_birgil,1187)11881189dlg.CenterOnScreen()11901191# this does not return until the dialog is closed.1192#val = dlg.ShowModal()1193# print 'open_sumodialog_interactive'1194dlg.Show()1195dlg.MakeModal(True)1196# print ' val,val == wx.ID_OK',val,wx.ID_OK,wx.ID_CANCEL,val == wx.ID_CANCEL1197# print ' status =',dlg.get_status()1198# print 'returned to main window self.simulator.status',self.simulator.status11991200def on_select_mode(self, event=None):1201"""1202Select GPS traces of a specific mode.1203The mode is selected only among the currently selected trips.1204"""1205p = mapmatching.ModeSelector(self._mapmatching, logger=self._mainframe.get_logger())1206dlg = ProcessDialog(self._mainframe, p, immediate_apply=True)12071208dlg.CenterOnScreen()12091210# this does not return until the dialog is closed.1211val = dlg.ShowModal()1212# print ' val,val == wx.ID_OK',val,wx.ID_OK,wx.ID_CANCEL,val == wx.ID_CANCEL1213# print ' status =',dlg.get_status()1214if dlg.get_status() != 'success': # val == wx.ID_CANCEL:1215# print ">>>>>>>>>Unsuccessful\n"1216dlg.Destroy()12171218if dlg.get_status() == 'success':1219# print ">>>>>>>>>successful\n"1220# apply current widget values to scenario instance1221dlg.apply()1222dlg.Destroy()1223self._mainframe.browse_obj(self._mapmatching.trips)1224self._is_needs_refresh = True1225self.refresh_widgets()12261227def on_geomfilter_trips(self, event=None):1228"""1229Select GPS traces to satisfy geometric requirements.1230This should be done before the mapmatching process.1231"""1232p = mapmatching.TripGeomfilter(self._mapmatching, logger=self._mainframe.get_logger())1233dlg = ProcessDialog(self._mainframe, p, immediate_apply=True)12341235dlg.CenterOnScreen()12361237# this does not return until the dialog is closed.1238val = dlg.ShowModal()1239# print ' val,val == wx.ID_OK',val,wx.ID_OK,wx.ID_CANCEL,val == wx.ID_CANCEL1240# print ' status =',dlg.get_status()1241if dlg.get_status() != 'success': # val == wx.ID_CANCEL:1242# print ">>>>>>>>>Unsuccessful\n"1243dlg.Destroy()12441245if dlg.get_status() == 'success':1246# print ">>>>>>>>>successful\n"1247# apply current widget values to scenario instance1248dlg.apply()1249dlg.Destroy()1250self._mainframe.browse_obj(self._mapmatching.trips)1251self._is_needs_refresh = True1252self.refresh_widgets()12531254def on_postmatchfilter_trips(self, event=None):1255"""1256Select trips by different parameters to ensure the quality of the mapmatching results.1257This should be done after the map-matching process.1258"""1259p = mapmatching.PostMatchfilter(self._mapmatching, logger=self._mainframe.get_logger())1260dlg = ProcessDialog(self._mainframe, p, immediate_apply=True)12611262dlg.CenterOnScreen()12631264# this does not return until the dialog is closed.1265val = dlg.ShowModal()1266# print ' val,val == wx.ID_OK',val,wx.ID_OK,wx.ID_CANCEL,val == wx.ID_CANCEL1267# print ' status =',dlg.get_status()1268if dlg.get_status() != 'success': # val == wx.ID_CANCEL:1269# print ">>>>>>>>>Unsuccessful\n"1270dlg.Destroy()12711272if dlg.get_status() == 'success':1273# print ">>>>>>>>>successful\n"1274# apply current widget values to scenario instance1275dlg.apply()1276dlg.Destroy()1277self._mainframe.browse_obj(self._mapmatching.trips)1278self._is_needs_refresh = True1279self.refresh_widgets()12801281def on_route_shortest(self, event=None):1282"""1283Shortest path routing of matched routes.1284"""1285p = mapmatching.Shortestrouter('shortestpathrouter', self._mapmatching, logger=self._mainframe.get_logger())1286dlg = ProcessDialog(self._mainframe, p, immediate_apply=True)12871288dlg.CenterOnScreen()12891290# this does not return until the dialog is closed.1291val = dlg.ShowModal()1292# print ' val,val == wx.ID_OK',val,wx.ID_OK,wx.ID_CANCEL,val == wx.ID_CANCEL1293# print ' status =',dlg.get_status()1294if dlg.get_status() != 'success': # val == wx.ID_CANCEL:1295# print ">>>>>>>>>Unsuccessful\n"1296dlg.Destroy()12971298if dlg.get_status() == 'success':1299# print ">>>>>>>>>successful\n"1300# apply current widget values to scenario instance1301dlg.apply()1302dlg.Destroy()1303self._mainframe.browse_obj(self._mapmatching.trips)1304self._is_needs_refresh = True1305self.refresh_widgets()13061307def on_route_fastest(self, event=None):1308"""1309Fastest path routing of matched routes.1310"""1311p = mapmatching.Fastestrouter('fastestpathrouter', self._mapmatching,1312matchresults=self._results,1313logger=self._mainframe.get_logger()1314)1315dlg = ProcessDialog(self._mainframe, p, immediate_apply=True)13161317dlg.CenterOnScreen()13181319# this does not return until the dialog is closed.1320val = dlg.ShowModal()1321# print ' val,val == wx.ID_OK',val,wx.ID_OK,wx.ID_CANCEL,val == wx.ID_CANCEL1322# print ' status =',dlg.get_status()1323if dlg.get_status() != 'success': # val == wx.ID_CANCEL:1324# print ">>>>>>>>>Unsuccessful\n"1325dlg.Destroy()13261327if dlg.get_status() == 'success':1328# print ">>>>>>>>>successful\n"1329# apply current widget values to scenario instance1330dlg.apply()1331dlg.Destroy()1332self._mainframe.browse_obj(self._mapmatching.trips)1333self._is_needs_refresh = True1334self.refresh_widgets()13351336def on_redraw(self, event=None):1337self._mainframe.browse_obj(self._mapmatching)1338self._is_needs_refresh = True1339self.refresh_widgets()13401341def on_import_ecc(self, event=None):1342"""1343Import and filter data from a European cycling challange.1344"""1345p = mapmatching.EccTracesImporter(self._mapmatching, logger=self._mainframe.get_logger())1346dlg = ProcessDialog(self._mainframe, p, immediate_apply=True)13471348dlg.CenterOnScreen()13491350# this does not return until the dialog is closed.1351val = dlg.ShowModal()1352# print ' val,val == wx.ID_OK',val,wx.ID_OK,wx.ID_CANCEL,val == wx.ID_CANCEL1353# print ' status =',dlg.get_status()1354if dlg.get_status() != 'success': # val == wx.ID_CANCEL:1355# print ">>>>>>>>>Unsuccessful\n"1356dlg.Destroy()13571358if dlg.get_status() == 'success':1359# print ">>>>>>>>>successful\n"1360# apply current widget values to scenario instance1361dlg.apply()1362dlg.Destroy()1363self._mainframe.browse_obj(self._mapmatching.trips)1364self._is_needs_refresh = True1365self.refresh_widgets()13661367def on_import_mobike(self, event=None):1368"""1369Import and filter data from a Mobike database file.1370"""1371p = mapmatching.MobikeImporter(self._mapmatching, logger=self._mainframe.get_logger())1372dlg = ProcessDialog(self._mainframe, p, immediate_apply=True)13731374dlg.CenterOnScreen()13751376# this does not return until the dialog is closed.1377val = dlg.ShowModal()1378# print ' val,val == wx.ID_OK',val,wx.ID_OK,wx.ID_CANCEL,val == wx.ID_CANCEL1379# print ' status =',dlg.get_status()1380if dlg.get_status() != 'success': # val == wx.ID_CANCEL:1381# print ">>>>>>>>>Unsuccessful\n"1382dlg.Destroy()13831384if dlg.get_status() == 'success':1385# print ">>>>>>>>>successful\n"1386# apply current widget values to scenario instance1387dlg.apply()1388dlg.Destroy()1389self._mainframe.browse_obj(self._mapmatching.trips)1390self._is_needs_refresh = True1391self.refresh_widgets()13921393def on_import_bellamossa(self, event=None):1394"""1395Import and filter data from a Bella Mossa data.1396"""1397p = mapmatching.BellamossaImporter(self._mapmatching, logger=self._mainframe.get_logger())1398dlg = ProcessDialog(self._mainframe, p, immediate_apply=True)13991400dlg.CenterOnScreen()14011402# this does not return until the dialog is closed.1403val = dlg.ShowModal()1404# print ' val,val == wx.ID_OK',val,wx.ID_OK,wx.ID_CANCEL,val == wx.ID_CANCEL1405# print ' status =',dlg.get_status()1406if dlg.get_status() != 'success': # val == wx.ID_CANCEL:1407# print ">>>>>>>>>Unsuccessful\n"1408dlg.Destroy()14091410if dlg.get_status() == 'success':1411# print ">>>>>>>>>successful\n"1412# apply current widget values to scenario instance1413dlg.apply()1414dlg.Destroy()1415self._mainframe.browse_obj(self._mapmatching.trips)1416self._is_needs_refresh = True1417self.refresh_widgets()14181419def on_import_strava(self, event=None):1420"""1421Import and filter data from a Bella Mossa data.1422"""1423p = mapmatching.StravaImporter(self._mapmatching, logger=self._mainframe.get_logger())1424dlg = ProcessDialog(self._mainframe, p, immediate_apply=True)14251426dlg.CenterOnScreen()14271428# this does not return until the dialog is closed.1429val = dlg.ShowModal()1430# print ' val,val == wx.ID_OK',val,wx.ID_OK,wx.ID_CANCEL,val == wx.ID_CANCEL1431# print ' status =',dlg.get_status()1432if dlg.get_status() != 'success': # val == wx.ID_CANCEL:1433# print ">>>>>>>>>Unsuccessful\n"1434dlg.Destroy()14351436if dlg.get_status() == 'success':1437# print ">>>>>>>>>successful\n"1438# apply current widget values to scenario instance1439dlg.apply()1440dlg.Destroy()1441self._mainframe.browse_obj(self._mapmatching.trips)1442self._is_needs_refresh = True1443self.refresh_widgets()14441445def on_import_gtfs(self, event=None):1446"""1447Import and filter data from GTFS shape database.1448"""1449p = mapmatching.GtfsShapeImporter(self._mapmatching, logger=self._mainframe.get_logger())1450dlg = ProcessDialog(self._mainframe, p, immediate_apply=True)14511452dlg.CenterOnScreen()14531454# this does not return until the dialog is closed.1455val = dlg.ShowModal()1456# print ' val,val == wx.ID_OK',val,wx.ID_OK,wx.ID_CANCEL,val == wx.ID_CANCEL1457# print ' status =',dlg.get_status()1458if dlg.get_status() != 'success': # val == wx.ID_CANCEL:1459# print ">>>>>>>>>Unsuccessful\n"1460dlg.Destroy()14611462if dlg.get_status() == 'success':1463# print ">>>>>>>>>successful\n"1464# apply current widget values to scenario instance1465dlg.apply()1466dlg.Destroy()1467self._mainframe.browse_obj(self._mapmatching.trips)1468self._is_needs_refresh = True1469self.refresh_widgets()14701471def on_import_gpx(self, event=None):1472"""1473Import and filter data from GPX file.1474"""1475p = mapmatching.GpxImporter(self._mapmatching, logger=self._mainframe.get_logger())1476dlg = ProcessDialog(self._mainframe, p, immediate_apply=True)14771478dlg.CenterOnScreen()14791480# this does not return until the dialog is closed.1481val = dlg.ShowModal()1482# print ' val,val == wx.ID_OK',val,wx.ID_OK,wx.ID_CANCEL,val == wx.ID_CANCEL1483# print ' status =',dlg.get_status()1484if dlg.get_status() != 'success': # val == wx.ID_CANCEL:1485# print ">>>>>>>>>Unsuccessful\n"1486dlg.Destroy()14871488if dlg.get_status() == 'success':1489# print ">>>>>>>>>successful\n"1490# apply current widget values to scenario instance1491dlg.apply()1492dlg.Destroy()1493self._mainframe.browse_obj(self._mapmatching.trips)1494self._is_needs_refresh = True1495self.refresh_widgets()14961497def on_project_points(self, event=None):1498self._mapmatching.points.project()1499self._mainframe.browse_obj(self._mapmatching.points)15001501if event:1502event.Skip()15031504def on_browse(self, event=None):15051506self._mainframe.browse_obj(self._mapmatching)1507if event:1508event.Skip()15091510def on_browse_results(self, event=None):1511"""1512Browse mapmatching analyses results1513"""1514self._mainframe.browse_obj(self._results)1515if event:1516event.Skip()15171518def on_analyze_persons(self, event=None):1519"""1520Analyze the trips of each person in the database.1521Ensure that mapmatching and shortest trip routing1522has been previously executed.1523"""15241525self._mapmatching.persons.analyze()1526self._mainframe.browse_obj(self._mapmatching.persons)15271528def on_export_persons_csv(self, event=None):1529if self._results is None:1530return1531scenario = self._results.get_scenario()1532wildcards_all = "All files (*.*)|*.*"1533wildcards_obj = "CSV files (*.csv)|*.csv|Text file (*.txt)|*.txt"1534wildcards = wildcards_obj+"|"+wildcards_all15351536# Finally, if the directory is changed in the process of getting files, this1537# dialog is set up to change the current working directory to the path chosen.1538dlg = wx.FileDialog(1539self._mainframe, message="Export persons to CSV file",1540defaultDir=scenario.get_workdirpath(),1541#defaultFile = scenario.get_rootfilepath()+'.gpspersons.csv',1542wildcard=wildcards,1543style=wx.SAVE | wx.CHANGE_DIR1544)1545val = dlg.ShowModal()1546# Show the dialog and retrieve the user response. If it is the OK response,1547# process the data.1548if val == wx.ID_OK:1549# This returns a Python list of files that were selected.1550filepath = dlg.GetPath()1551if len(filepath) > 0:1552# now set new filename and workdir1553persons = self._mapmatching.persons1554ids_pers = persons.select_ids(persons.lengths_tot_route_matched.get_value() > 0)1555self._mapmatching.persons.export_csv(filepath, ids=ids_pers)15561557# Destroy the dialog. Don't do this until you are done with it!1558# BAD things can happen otherwise!1559dlg.Destroy()15601561def on_routeanalyze(self, event=None):1562"""1563Analyze attributes of matched and alternative routes.1564"""1565p = mapmatching.Routesanalyzer('routeanalyzer',1566self._mapmatching,1567self._results,1568logger=self._mainframe.get_logger())15691570dlg = ProcessDialog(self._mainframe, p, immediate_apply=True)15711572dlg.CenterOnScreen()15731574# this does not return until the dialog is closed.1575val = dlg.ShowModal()1576# print ' val,val == wx.ID_OK',val,wx.ID_OK,wx.ID_CANCEL,val == wx.ID_CANCEL1577# print ' status =',dlg.get_status()1578if dlg.get_status() != 'success': # val == wx.ID_CANCEL:1579# print ">>>>>>>>>Unsuccessful\n"1580dlg.Destroy()15811582if dlg.get_status() == 'success':1583# print ">>>>>>>>>successful\n"1584# apply current widget values to scenario instance1585dlg.apply()1586dlg.Destroy()1587self._mainframe.browse_obj(self._results)1588self._is_needs_refresh = True1589self.refresh_widgets()15901591def on_altrouteanalyze(self, event=None):1592"""1593Analyze attributes of matched and alternative routes.1594"""1595p = mapmatching.AlternativeRoutesanalyzer('altrouteanalyzer',1596self._mapmatching,1597self._results,1598logger=self._mainframe.get_logger())15991600dlg = ProcessDialog(self._mainframe, p, immediate_apply=True)16011602dlg.CenterOnScreen()16031604# this does not return until the dialog is closed.1605val = dlg.ShowModal()1606# print ' val,val == wx.ID_OK',val,wx.ID_OK,wx.ID_CANCEL,val == wx.ID_CANCEL1607# print ' status =',dlg.get_status()1608if dlg.get_status() != 'success': # val == wx.ID_CANCEL:1609# print ">>>>>>>>>Unsuccessful\n"1610dlg.Destroy()16111612if dlg.get_status() == 'success':1613# print ">>>>>>>>>successful\n"1614# apply current widget values to scenario instance1615dlg.apply()1616dlg.Destroy()1617self._mainframe.browse_obj(self._results)1618self._is_needs_refresh = True1619self.refresh_widgets()16201621def on_ptanalyze(self, event=None):1622"""1623Analyze public tranport routes, calculating trips per line and trip distribution on public transport net.1624"""1625p = mapmatching.PtRoutesanalyzer('ptrouteanalyzer',1626self._mapmatching,1627self._results,1628logger=self._mainframe.get_logger())16291630dlg = ProcessDialog(self._mainframe, p, immediate_apply=True)16311632dlg.CenterOnScreen()16331634# this does not return until the dialog is closed.1635val = dlg.ShowModal()1636# print ' val,val == wx.ID_OK',val,wx.ID_OK,wx.ID_CANCEL,val == wx.ID_CANCEL1637# print ' status =',dlg.get_status()1638if dlg.get_status() != 'success': # val == wx.ID_CANCEL:1639# print ">>>>>>>>>Unsuccessful\n"1640dlg.Destroy()16411642if dlg.get_status() == 'success':1643# print ">>>>>>>>>successful\n"1644# apply current widget values to scenario instance1645dlg.apply()1646dlg.Destroy()1647self._mainframe.browse_obj(self._results)1648self._is_needs_refresh = True1649self.refresh_widgets()16501651def on_plot_ptflows(self, event=None):1652"""1653Plot matched flow graph of public transport lines with the Matplotlib plotting envitonment.1654"""1655if is_mpl:1656resultplotter = results_mpl.PtFlowdigramPlotter(self._results,1657logger=self._mainframe.get_logger()1658)1659dlg = results_mpl.ResultDialog(self._mainframe, resultplotter)16601661dlg.CenterOnScreen()16621663# this does not return until the dialog is closed.1664val = dlg.ShowModal()1665# print ' val,val == wx.ID_OK',val,wx.ID_OK,wx.ID_CANCEL,val == wx.ID_CANCEL1666# print ' status =',dlg.get_status()1667if dlg.get_status() != 'success': # val == wx.ID_CANCEL:1668# print ">>>>>>>>>Unsuccessful\n"1669dlg.Destroy()16701671if dlg.get_status() == 'success':1672# print ">>>>>>>>>successful\n"1673# apply current widget values to scenario instance1674dlg.apply()1675dlg.Destroy()16761677def on_gtfsstopgenerate(self, event=None):1678"""1679Generate public transport stops from google transit file system data1680and previously imported public transit routes.1681"""1682p = mapmatching.GtfsStopGenerator('gtfsstopgenerator',1683self._mapmatching,1684self._results,1685logger=self._mainframe.get_logger()1686)16871688dlg = ProcessDialog(self._mainframe, p, immediate_apply=True)16891690dlg.CenterOnScreen()16911692# this does not return until the dialog is closed.1693val = dlg.ShowModal()1694# print ' val,val == wx.ID_OK',val,wx.ID_OK,wx.ID_CANCEL,val == wx.ID_CANCEL1695# print ' status =',dlg.get_status()1696if dlg.get_status() != 'success': # val == wx.ID_CANCEL:1697# print ">>>>>>>>>Unsuccessful\n"1698dlg.Destroy()16991700else:1701# print ">>>>>>>>>successful\n"1702# apply current widget values to scenario instance1703dlg.apply()1704dlg.Destroy()17051706self._mainframe.refresh_moduleguis()1707self._is_needs_refresh = True1708self.refresh_widgets()1709print ' set browser to', self.get_scenario().net.ptstops1710self._mainframe.browse_obj(self.get_scenario().net.ptstops)17111712def on_gtfsservicegenerate(self, event=None):1713"""1714Generate public transport services from google transit file system data1715and previously generated public transit stops.1716"""1717p = mapmatching.GtfsServiceGenerator('gtfsservicegenerator',1718self._mapmatching,1719self._results,1720logger=self._mainframe.get_logger()1721)17221723dlg = ProcessDialog(self._mainframe, p, immediate_apply=True)17241725dlg.CenterOnScreen()17261727# this does not return until the dialog is closed.1728val = dlg.ShowModal()1729# print ' val,val == wx.ID_OK',val,wx.ID_OK,wx.ID_CANCEL,val == wx.ID_CANCEL1730# print ' status =',dlg.get_status()1731if dlg.get_status() != 'success': # val == wx.ID_CANCEL:1732# print ">>>>>>>>>Unsuccessful\n"1733dlg.Destroy()17341735if dlg.get_status() == 'success':1736# print ">>>>>>>>>successful\n"1737# apply current widget values to scenario instance1738dlg.apply()1739dlg.Destroy()1740print ' set browser to', self.get_scenario().demand.ptlines1741self._mainframe.browse_obj(self.get_scenario().demand.ptlines)1742# self._mainframe.refresh_moduleguis()1743#self._is_needs_refresh = True1744# self.refresh_widgets()17451746def on_create_trips_database(self, event=None):1747"""1748Analyze attributes of matched routes and create an elaborated trips database.1749"""17501751p = mapmatching.TripsDatabaseAnalyzer('tripsdatabase', self._mapmatching,1752results=self._results,1753logger=self._mainframe.get_logger())17541755dlg = ProcessDialog(self._mainframe, p, immediate_apply=True)17561757dlg.CenterOnScreen()17581759# this does not return until the dialog is closed.1760val = dlg.ShowModal()1761# print ' val,val == wx.ID_OK',val,wx.ID_OK,wx.ID_CANCEL,val == wx.ID_CANCEL1762# print ' status =',dlg.get_status()1763if dlg.get_status() != 'success': # val == wx.ID_CANCEL:1764# print ">>>>>>>>>Unsuccessful\n"1765dlg.Destroy()17661767if dlg.get_status() == 'success':1768# print ">>>>>>>>>successful\n"1769# apply current widget values to scenario instance1770dlg.apply()1771dlg.Destroy()1772self._mainframe.browse_obj(self._results.tripsdatabase)1773self._is_needs_refresh = True1774self.refresh_widgets()17751776def on_create_cyclists_database(self, event=None):1777"""1778Analyze attributes of persons and create an elaborated trips database.1779"""17801781p = mapmatching.CyclistsDatabaseAnalyzer('cyclistsdatabase', self._mapmatching,1782results=self._results,1783logger=self._mainframe.get_logger())17841785dlg = ProcessDialog(self._mainframe, p, immediate_apply=True)17861787dlg.CenterOnScreen()17881789# this does not return until the dialog is closed.1790val = dlg.ShowModal()1791# print ' val,val == wx.ID_OK',val,wx.ID_OK,wx.ID_CANCEL,val == wx.ID_CANCEL1792# print ' status =',dlg.get_status()1793if dlg.get_status() != 'success': # val == wx.ID_CANCEL:1794# print ">>>>>>>>>Unsuccessful\n"1795dlg.Destroy()17961797if dlg.get_status() == 'success':1798# print ">>>>>>>>>successful\n"1799# apply current widget values to scenario instance1800dlg.apply()1801dlg.Destroy()1802self._mainframe.browse_obj(self._results.cyclistsdatabase)1803self._is_needs_refresh = True1804self.refresh_widgets()180518061807