3 - Generating the Network

Instructors: Michael Zilske, Andreas Neumann

(If you cannot use the osm data (for example because you have network data in a different format), see here.)

  • Visit http://download.geofabrik.de/osm/europe/ and download the switzerland.osm.bz2 file. Unpack it using a bunzip2 utility for your platform.
  • Visit http://wiki.openstreetmap.org/wiki/Osmosis and download the latest stable build. Try running the command line program osmosis and have a look at the available options.
    If you use the matsim-0.1.1 release, make sure to use Osmosis 0.35. There seems to be an incompatibility with Osmosis 0.36 and matsim-0.1.1. With matsim-0.2.0, you can again use the newest version of Osmosis (tested with Osmosis 0.38).
  • Visit OpenStreetMap and, using the export tab, select a region of interest. In this tutorial, we will use the Zurich metropolitan area. Make note of the coordinates.
  • Create an OpenStreetMap excerpt containing only roads within the region of interest. Try this command line:
osmosis --rx file=switzerland.osm --bounding-box top=47.701 left=8.346 bottom=47.146 right=9.019 completeWays=true --used-node --wx zurich.osm

  • Create another excerpt containing only big roads, but this time without any geographic constraints:

osmosis --rx file=switzerland.osm --tf accept-ways highway=motorway,motorway_link,trunk,trunk_link,primary,primary_link --used-node --wx switzerland-bigroads.osm

  • Merge the two networks using the following command:
osmosis --rx file=switzerland-bigroads.osm --rx zurich.osm --merge --wx merged-network.osm


  • Of course, you can pick any other data file which contains the region in which you are interested. Keep in mind, however, that the time osmosis needs to filter the data depends on the size of the input file. My PC needs about 8 minutes to process Switzerland, but 270 minutes for all of Europe.
  • Use a bit of Java code to convert the merged OpenStreetMap network to the MATSim format like this:
import org.matsim.api.core.v01.Scenario;
import org.matsim.api.core.v01.network.Network;
import org.matsim.core.api.experimental.network.NetworkWriter;
import org.matsim.core.config.Config;
import org.matsim.core.network.algorithms.NetworkCleaner;
import org.matsim.core.scenario.ScenarioUtils;
import org.matsim.core.utils.geometry.CoordinateTransformation;
import org.matsim.core.utils.geometry.transformations.TransformationFactory;
import org.matsim.core.utils.io.OsmNetworkReader;
import org.matsim.core.utils.misc.ConfigUtils;


public class CreateNetwork {

   public static void main(String[] args) {
      String osm = "merged-network.osm";
      Config config = ConfigUtils.createConfig();
      Scenario sc = ScenarioUtils.createScenario(config);
      Network net = sc.getNetwork();
      CoordinateTransformation ct = 
       TransformationFactory.getCoordinateTransformation(
        TransformationFactory.WGS84, TransformationFactory.WGS84_UTM33N);
      OsmNetworkReader onr = new OsmNetworkReader(net,ct);
      onr.parse(osm); 
      new NetworkCleaner().run(net);
      new NetworkWriter(net).write("network.xml");
   }

}

  • Use OTFVis to view your network. Congratulations.

If you cannot use the osm data (for example because you have network data in a different format), see here.

SlidesSlides
2.92 MB

Warning: Table 'watchdog' is read only query: INSERT INTO watchdog (uid, type, message, severity, link, location, referer, hostname, timestamp) VALUES (0, 'php', '<em>Table &amp;#039;sessions&amp;#039; is read only\nquery: UPDATE sessions SET uid = 0, cache = 0, hostname = &amp;#039;38.107.179.233&amp;#039;, session = &amp;#039;&amp;#039;, timestamp = 1328356077 WHERE sid = &amp;#039;e972b2ab7dd755a2094beea8ac708f02&amp;#039;</em> in <em>/home01/vsp_access/matsimwww/includes/database.mysql.inc</em> on line <em>174</em>.', 2, '', 'http://matsim.org/node/463', '', '38.107.179.233', 1328356077) in /home01/vsp_access/matsimwww/includes/database.mysql.inc on line 174