Exemplo n.º 1
0
        // Generates the Travel Path from PoitnA to B - Under Working...
        private void button2_Click(object sender, EventArgs e)
        {
            try
            {
                button2.Text = "Working...";

                int c = 0;

                // Creates a coordinate array to store the Path points
                Coordinate[] Coord = new Coordinate[listView1.Items.Count];

                // Loads the stop list into the Coordinate array
                foreach (ListViewItem item in listView1.Items)
                {
                    Coord[c]           = new Coordinate();
                    Coord[c].Latitude  = (int)(Convert.ToDouble(item.SubItems[5].Text) / 0.000001); // Convert from Double to Int
                    Coord[c].Longitude = (int)(Convert.ToDouble(item.SubItems[6].Text) / 0.000001);
                    c++;
                }

                // Call the WebService
                TravelPathResult r = RNA.WebServices.TravelPath(Coord);

                // Loads the result into the Location Class
                c = 0;
                AUX.Services.Location[] Loc = new AUX.Services.Location[r.Path.Points.Count()];

                // Loads the returned points into the Location class required to build the KML file
                foreach (Coordinate p in r.Path.Points) // Load all points from the Path
                {
                    Loc[c]     = new AUX.Services.Location();
                    Loc[c].Lat = p.Latitude * 0.000001; // Convert from Int to Double
                    Loc[c].Lon = p.Longitude * 0.000001;
                    c++;
                }

                button2.Text = "Travel Path";

                // Displays a SaveFileDialog
                SaveFileDialog saveFileDialog1 = new SaveFileDialog();
                saveFileDialog1.InitialDirectory = Convert.ToString(Environment.SpecialFolder.MyDocuments);
                saveFileDialog1.FileName         = "Route " + Route_Name + ".kml";
                saveFileDialog1.DefaultExt       = "*.kml";
                saveFileDialog1.Filter           = "KML File|*.kml";
                saveFileDialog1.Title            = "Export Travel Path to a KML File";

                // If the file name returns OK
                if (saveFileDialog1.ShowDialog() == DialogResult.OK)
                {
                    // Creates the KML file
                    AUX.Services.CreateKML(saveFileDialog1.FileName, Loc);
                }
            }
            catch (Exception Ex)
            {
                MessageBox.Show(Ex.Message, "Error");
            }
        }
Exemplo n.º 2
0
        // Generates the Travel Path
        public static TravelPathResult TravelPath(Coordinate[] Coord)
        {
            try
            {
                // Call the Web Services
                TravelPathResult pathResult = MappingServiceClient.GenerateTravelPath(
                    SessionHeader,
                    RegionContext,
                    new GenerateTravelPathOptions
                {
                    MeasurementOptions = new MeasurementOptions
                    {
                        DistanceUnit_DistanceUnit         = DistanceUnit.Kilometers.ToString(),
                        FuelEconomyUnit_FuelEconomyUnit   = FuelEconomyUnit.LitersPerHundredKilometers.ToString(),
                        LengthUnit_LengthUnit             = LengthUnit.Centimeters.ToString(),
                        LiquidVolumeUnit_LiquidVolumeUnit = LiquidVolumeUnit.Liters.ToString(),
                        SpeedUnit_SpeedUnit   = SpeedUnit.KilometersPerHour.ToString(),
                        WeightUnit_WeightUnit = WeightUnit.Kilograms.ToString()
                    },
                    PropertyOptions = new TravelPathResultPropertyOptions
                    {
                        ArcIDs = false,
                        DestinationPathErrors   = false,
                        DestinationPointIndices = false,
                        Directions = false,
                        Path       = true
                    },
                    CalculatorOptions = new TravelPathCalculatorOptions
                    {
                        LoadEndpointsToNodes         = false,
                        LoadEndpointsToLoadableRoads = false
                    },
                    Coordinates = Coord
                });

                return(pathResult); // Returns the Travel Path result
            }
            catch (Exception Ex)
            {
                throw new Exception(Ex.Message);
            }
        }