-
Notifications
You must be signed in to change notification settings - Fork 6
Scenarios
In this tutorial you will see two different scenarios of application.
In the first case, you will see how to include municipal transports (San Francisco, CA, U.S.A.), and the second on how to include a public bike service know in many european cities (Rennes, Bretagne, France).
In both cases, we will import also street data from the free openstreetmap project.
But first of all, we will see some generals settings of mumoro before importing any data.
Open with you favorite text-editor the file “scenario_model.py”
You will have to choose which type of database you will use to store all the data.
db_type = ’’
Affect db_type to one of the following values:
‘sqlite’ for SQLiTE file database
‘mysql’ for MySQL
‘postgres’ for PostgreSQL
‘oracle’ for Oracle
‘mssql’ for MSSQL
‘firebird’ for Firebird
Then you will have to define the location of the database.
db_params = ’’
If you chose SQLiTE, the location is simply the path to the database file
Affect to db_params the absolute path.
For example:
db_params = ‘/data/mumoro/mumoro.db’
For the remaining database types, which are user-oriented connection databases,
you muste define the username ,password, the host location (remote ip, or locahost) and the name of the database to use.
Affect to db_params the connection parameters following this syntax: ‘username:password@host/database’
If the port is different from the default one for the specific database use this syntax: ‘username:password@host:port/database’
For example:
db_params = ‘odysseas:mypassword@locahost/mumoro’
or
db_params = ‘odysseas:mypassword@locahost:5317/mumoro’
Then you must enter a valid email address used for the geocoding and reverse geocoding API.
Affect to admin_email your email
For example:
admin_email = ‘[email protected]’
You must define a port on which cherrypy listens and accepts connections
Check that the chosen port is free and port-fordwarded if behind of a router/firewall
Affect to listening_port
For example:
listening_port = 3000
Before we finish the general configuration, you must define the url of your web interface.
The syntax to follow is: ‘http://your_url/’
Don’t forget to begin with http:// and to finish with a /
Affect you url to web_url
For example:
web_url = ‘http://my_super_mumoro.org/’
or
web_url = ‘http://82.133.241.11/’
or
web_url = ‘http://localhost/’
Warning
If there is no domain pointing to your address:listening_port, then you must include the listening_port to your url : ‘http://my_url:listening_port/’
For example:
web_url = ‘http://localhost:3000’
The general configuration is done
Lets see the data import part
In the same file, we will append the data import configuration for establishing mumoro for the city of San Francisco.
First of all we, need the street data of the city.
Many web sites offer street data powered by openstreetmap project.
Go to http://downloads.cloudmade.com/north_america/united_states/california#downloads_breadcrumbs and download the file ‘california.osm.bz2’ ( ~350 MB )
The following part is optional, but important if you download a file containing street data of a very large region (or even a country) and you want to use only a part of it.
This part will show you how to extract a smaller region contained in a street data file
Download the tool Osmosis from http://dev.openstreetmap.org/~bretth/osmosis-build/osmosis-bin-latest.zip and extract it.
Move the file ‘california.osm.bz2’ to the bin directory included in the extracted osmosis folder
Then all you have to do is to execute this command in the bin directory.
osmosis —read-xml enableDateParsing=no file =“california.osm.bz2” —bounding-box top=37.951489 left=-122.768097 bottom=37.510525 right=-121.929016 completeWays=yes —write-xml file=“san_francisco.osm”
The coordinates passed in arguments can easily be found from http://www.gorissen.info/Pierre/maps/googleMapLocation.php
Wait for completion then you will have the generated file ‘san_francisco.osm’ containing only the street data of San Francisco
Back on our configuration file.
You must import the street data from the given file
The function ‘import_street_data( file )’ imports the data from the file passed in argument (absolute path) and returns an id useful for after.
For our example:
streets_california = import_street_data( ‘/data/mumoro/california.osm.bz2’ )
or
streets_san_francisco = import_street_data( ‘/data/mumoro/san_francisco.osm’ )
Then we will have to import municipal data.
But before that, you must define the starting and end date for the municipal data.
starting and end data must be in this format: ‘YYYMMDD’ Y for year’s digits, M for month’s, and D for day’s
Affect to starting_date and end_date the corresponding dates
For example if we want municipal data from 1st January of 2010 to 31th December 2010:
starting_date = ‘20100101’
end_date = ‘20101231’
Once the range dates defined, we can proceed to municipal data import.
Mumoro supports the GTFS format for municipal data files.
San Francisco has two different municipal transport network.
Lets grab one by one their data !
For San Francisco BART Network, grab the file from http://www.bart.gov/dev/schedules/google_transit.zip and rename it to bart.zip
For San Francisco Muni Network, grab the file from http://www.sfmta.com/transitdata/google_transit.zip and rename it to muni.zip
Back to the configuration file.
We must import the municipal data contained in the two files.
To do so, you must call for each file the function import_gtfs_data( file, name ) with the absolute file path and the network name in argument. It returns an id useful for later.
For our two networks:
bart_sf = import_gtfs_data( ‘/data/bart.zip’, ‘San Francisco BART’ )
muni_sf = import_gtfs_data( ‘/data/muni.zip’, ‘San Francisco Municipal’ )
Now we must define the different layers.
A layer represents a transport mode using data imported previously.
We will now create two layers from streets data ( One for the car, and one for foot ) and one for each municipal network.
The creation of street layer is done by calling street_layer( data , name , color , mode )
Here is the description of each argument:
- data is the origin data of this layer: the id returned from import_street_data
- name is the name that you give to this layer. Use an understandable name, it will appear on the user interface
- color is the color representing this layer on the user interface. Use the html color code syntax. For reference go to http://www.computerhope.com/htmcolor.htm
- mode is the desired mode. Choose among Foot, Car and Bike
street_layer function returns an id for the layer which is useful for after
Lets create our street layers for San Francicso:
foot_layer = street_layer( data = streets_california, name = ‘Foot’, color = ‘#7E2217’, mode = Foot )
car_layer = street_layer( data = streets_california, name = ‘Car’, color = ‘#842DCE’, mode = Car )
Now lets create the municipal layers.
This is done by calling public_transport_layer( data, name, color )
It works like street_layer but it takes no mode argument.
Lets create our municipal transports layers
bart_layer = public_transport_layer( data = bart_sf_data, name = ‘BART’, color = ‘#4CC417’ )
muni_layer = public_transport_layer( data = muni_sf_data, name = ‘Municipal’, color = ‘#817339’ )
Now we can connect layers with each other at a certain cost.
You must first define the costs. To create a cost, you must call cost( duration, mode_change )
Duration in seconds, and mode_change if you change the mode or not ( True or False)
Lets create two different costs:
cost1 = cost( duration = 120, mode_change = True )
cost2 = cost( duration = 60, mode_change = False )
Now we can connect the layers with the costs that we just created:
We can connect the foot_layer with each public transport layer, and the two public transport layer with each other.
To do so, you have to call connect_layers_on_nearest_nodes( layer1, layer2, cost1 )
Lets connect our layers as we said
connect_layers_on_nearest_nodes( bart_layer, foot_layer, cost1 )
connect_layers_on_nearest_nodes( muni_layer, foot_layer, cost2 )
connect_layers_on_nearest_nodes( muni_layer, bart_layer, cost2 )
The last thing is to define the paths that mumoro must return.
To define a path you must call paths( starting_layer, destination_layer, objectives )
-starting_layer and destination_layers are as they say, where the path must starts and ends
-objectives is an array of objectives chosen to be calculated for this path
Possible objectives:
– dist for distance
– elevation for elevation difference
– co2 for co2 emission
– mode_change for number of mode_changes
– line_change for number of line changes in a mode
To create the array use this syntax: [ objective1, objective2, objective3 ]
Warning For performances issues, you can not enter more than 3 objectives otherwise mumoro will calculate for the first 3 in alphabetical order. The remaining objectives will be ignored.
You can also enter an empty array: []
Lets define our paths:
paths( foot_layer, foot_layer, [ mode_change, line_change ] )
paths( car_layer, car_layer, [ dist ] )
Everything is configured !
Save the file as ‘san_francicso.py’ in the ‘scenarios’ directory in mumoro
Now, all you have to do is launch the data import process and once its done, launch the server.
To import the data:
In the mumoro directory with a command prompt/terminal type:
python data_import.py scenarios/san_francisco.py
and hit Enter. The process can take several minutes
Then to launch the server type:
python server.py scenarios/san_francisco.py
and hit Enter. Like data import, the launch of server takes several minutes, once its done, go to your browser at your url and start routing !
In the same file, we will append the data import configuration for establishing mumoro for the city of Rennes.
First of all we, need the street data of the city.
Many web sites offer street data powered by openstreetmap project.
Go to http://download.geofabrik.de/osm/europe/france/ and download the file ‘bretagne.osm.bz2’ ( ~75 MB )
The following part is optional, but important if you download a file containing street data of a very large region (or even a country) and you want to use only a part of it.
This part will show you how to extract a smaller region contained in a street data file
Download the tool Osmosis from http://dev.openstreetmap.org/~bretth/osmosis-build/osmosis-bin-latest.zip and extract it.
Move the file ‘bretagne.osm.bz2’ to the bin directory included in the extracted osmosis folder
Then all you have to do is to execute this command in the bin directory.
osmosis —read-xml enableDateParsing=no file =“bretagne.osm.bz2” —bounding-box top=48.14532 left=-1.73113 bottom=48.07448 right=-1.56359 completeWays=yes —write-xml file=“rennes.osm”
The coordinates passed in arguments can easily be found from http://www.gorissen.info/Pierre/maps/googleMapLocation.php
Wait for completion then you will have the generated file ‘rennes.osm’ containing only the street data of Rennes
Back on our configuration file.
You must import the street data from the given file
The function ‘import_street_data( file )’ imports the data from the file passed in argument (absolute path) and returns an id useful for after.
For our example:
streets_bretagne = import_street_data( ‘/data/mumoro/bretagne.osm.bz2’ )
or
streets_rennes = import_street_data( ‘/data/mumoro/rennes.osm’ )
There are no public transport data to import yet, so leave strating_date and end_date as they are
starting_date = ‘20100101’
end_date = ‘20101231’
Now we must define the different layers.
A layer represents a transport mode using data imported previously.
We will now create two layers from streets data ( One for the car, and one for foot ) and one for each municipal network.
The creation of street layer is done by calling street_layer( data , name , color , mode )
Here is the description of each argument:
- data is the origin data of this layer: the id returned from import_street_data
- name is the name that you give to this layer. Use an understandable name, it will appear on the user interface
- color is the color representing this layer on the user interface. Use the html color code syntax. For reference go to http://www.computerhope.com/htmcolor.htm
- mode is the desired mode. Choose among Foot, Car and Bike
street_layer function returns an id for the layer which is useful for after
Lets create our street layers for Rennes:
foot_layer = street_layer( data = streets_bretagne, name = ‘Foot’, color = ‘#7E2217’, mode = Foot )
car_layer = street_layer( data = streets_bretagne, name = ‘Car’, color = ‘#842DCE’, mode = Car )
bike_layer = street_layer( data = streets_bretagne, name = ‘Bike’, color = ‘#652AF7’, mode = Bike )
Now we must import the bike service. Contrary to street data, it is not a file but a service from a url.
You have to go to http://data.keolis-rennes.com/ create an account and then obtain an API Key.
Once you got the API Key, the url used for importing bike service is the following one:
‘http://data.keolis-rennes.com/xml/?version=1.0&key=%KEY%&cmd=getstation¶m[request]=all’
where KEY is your API Key.
To import the bike service you have to call the function import_bike_service(url,name)
Where url is the url above and name the name of the public bike network.
This function returnes an id used after.
Now we can connect layers with each other at a certain cost.
You must first define the costs. To create a cost, you must call cost( duration, mode_change )
Duration in seconds, and mode_change if you change the mode or not ( True or False)
Lets create two different costs:
cost1 = cost( duration = 120, mode_change = True )
cost2 = cost( duration = 60, mode_change = False )
Now we can connect the layers with the costs that we just created:
We can connect the foot_layer with the bike_layer on the public bike stations with the function connect_layers_from_node_list( layer1, layer2, data, cost1, cost2 )
data is the origin : returned id from the import_bike_service function
Two costs are present, one for layer1 to layer2 and the other one for the opposite side
Lets connect our layers as we said
connect_layers_from_node_list( foot_layer, bike_layer, bike_rennes, cost1, cost2 )
The last thing is to define the paths that mumoro must return.
To define a path you must call paths( starting_layer, destination_layer, objectives )
-starting_layer and destination_layers are as they say, where the path must starts and ends
-objectives is an array of objectives chosen to be calculated for this path
Possible objectives:
– dist for distance
– elevation for elevation difference
– co2 for co2 emission
– mode_change for number of mode_changes
– line_change for number of line changes in a mode
To create the array use this syntax: [ objective1, objective2, objective3 ]
Warning For performances issues, you can not enter more than 3 objectives otherwise mumoro will calculate for the first 3 in alphabetical order. The remaining objectives will be ignored.
You can also enter an empty array: []
Lets define our paths:
paths( foot_layer, foot_layer, [ mode_change, line_change ] )
paths( car_layer, car_layer, [ dist ] )
Everything is configured !
Save the file as ‘rennes.py’ in the ‘scenarios’ directory in mumoro
Now, all you have to do is launch the data import process and once its done, launch the server.
To import the data:
In the mumoro directory with a command prompt/terminal type:
python data_import.py scenarios/rennes.py
and hit Enter. The process can take several minutes
Then to launch the server type:
python server.py scenarios/rennes.py
and hit Enter. Like data import, the launch of server takes several minutes, once its done, go to your browser at your url and start routing !