C# code for import network sample

C# code for import network sample

public static Storage ImportNetwork(string fileNameCoordinates, string fileNameAttributes)
    // Set up what types of data should be imported, and the coordinate system the data is in.
    // The third argument is for importing individual road geometry, use false to save memory,
    // but for generating accurate route lines it should be set to true.
    ReaderOptions options = new ReaderOptions(true, true, true, Unit.LatLong, Unit.Kilometer);

    // Create a oneway mapping, replace "ONEWAY" with correct field name, and value "1" and "2"
    // with values for oneway in and against digitized direction.
    OneWayMapping oneWayMap = new OneWayMapping("ONEWAY", "1", "2");

    // Use speeds from road attribute, field "SPEED", and use 50 as default speed
    SpeedMapping speedMap = new SpeedMapping(50, SpeedUnit.KmPerHour, "SPEED");

    // Set up main importer options, using "ROADNAME" for field containing road names (can be null tosave memory)
    ImporterOptions opt = new ImporterOptions(new ShapeReader(), options, "ROADNAME", oneWayMap);

    Importer imp = new Importer(fileNameCoordinates, fileNameAttributes, opt);
    Storage st = imp.Import(0); // if lines don't snap to same coord, use a tolerance (always in meter)

    // Optional: perform some simple preprocessing, in this case remove unconnected islands
    // and merge roads if there are 2 connecting links and they match (same name, speed, etc),
    PreProcess pre = new PreProcess(st);
    pre.Process(PreProcess.PreProcessing.RemoveIslands | PreProcess.PreProcessing.RoadMerging);

    // Save the network (assumes that the directory "c:\\networks" exists).
    st.Save("c:\\networks", "road_network");

    // Now the network can be loaded whenever needed with
    // Storage st = new Storage("c:\\networks", "road_network");

    return st;
Select all code
Copyright © 2012 Xtreme Route - All Rights Reserved. Contact us: