예제 #1
0
        /// <summary>
        /// Populate the loop location information for each point in the train journey.
        /// </summary>
        /// <param name="train">A train object containing the journey details.</param>
        /// <param name="trackGeometry">The track geometry object indicating the location of the loops.</param>
        public void populateLoopLocations(Train train, List <trackGeometry> trackGeometry)
        {
            /* Create a track geometry object. */
            trackGeometry track      = new trackGeometry();
            int           index      = 0;
            double        trainPoint = 0;

            /* Cycle through the train journey. */
            foreach (TrainDetails journey in train.TrainJourney)
            {
                trainPoint = journey.geometryKm;
                /* Find the index of the closest point on the track to the train. */
                index = track.findClosestTrackGeometryPoint(trackGeometry, trainPoint);
                /* Populate the loop */
                journey.isLoopHere = trackGeometry[index].isLoopHere;
            }
        }
예제 #2
0
        /// <summary>
        /// Function reads in the track geometry data from file.
        /// </summary>
        /// <param name="filename">Full filename of teh geometry file.</param>
        /// <returns>A list of track Geometry objects describing the track geometry.</returns>
        public List <trackGeometry> readGeometryfile(string filename)
        {
            /* Create the list of track geometry objects. */
            List <trackGeometry> trackGeometry = new List <trackGeometry>();

            bool header = true;

            /* Read all the lines of the file. */
            string[] lines      = System.IO.File.ReadAllLines(filename);
            char[]   delimeters = { ',', '\'', '"', '\t', '\n' };   // not sure of the delimter ??

            /* Seperate the fields. */
            string[] fields = lines[0].Split(delimeters);

            bool firstPoint = true;

            /* Define the track geomerty parameters. */
            string geometryName        = null;
            double latitude            = 0.0;
            double longitude           = 0.0;
            double elevation           = 0.0;
            double kilometreage        = 0.0;
            double virtualKilometreage = 0.0;
            bool   isLoopHere          = false;

            /* Define some additional helper parameters. */
            double    distance     = 0;
            direction direction    = direction.notSpecified;
            double    previousLat  = 0;
            double    previousLong = 0;
            double    previouskm   = 0;
            string    loop;

            /* Add the trains to the list. */
            foreach (string line in lines)
            {
                if (header)
                {
                    /* Ignore the header line. */
                    header = false;
                }
                else
                {
                    /* Seperate each record into each field */
                    fields       = line.Split(delimeters);
                    geometryName = fields[0];
                    double.TryParse(fields[1], out latitude);
                    double.TryParse(fields[2], out longitude);
                    double.TryParse(fields[3], out elevation);
                    double.TryParse(fields[4], out kilometreage);
                    loop = fields[6];

                    if (loop.Equals("loop", StringComparison.OrdinalIgnoreCase) || loop.Equals("true", StringComparison.OrdinalIgnoreCase))
                    {
                        isLoopHere = true;
                    }
                    else
                    {
                        isLoopHere = false;
                    }

                    /* The virtual kilometreage starts at the first kilometreage of the track. */
                    if (firstPoint)
                    {
                        virtualKilometreage = kilometreage;
                        /* Set the 'pervious' parameters. */
                        previousLat  = latitude;
                        previousLong = longitude;
                        previouskm   = kilometreage;
                        firstPoint   = false;
                    }
                    else
                    {
                        /* Determine the direction the track kilometreage. */
                        if (direction == direction.notSpecified)
                        {
                            if (kilometreage - previouskm > 0)
                            {
                                direction = direction.increasing;
                            }
                            else
                            {
                                direction = direction.decreasing;
                            }
                        }

                        /* Calcualte the distance between succesive points and increment the virtual kilometreage. */
                        distance = processing.calculateDistance(previousLat, previousLong, latitude, longitude);
                        if (direction == direction.increasing)
                        {
                            virtualKilometreage = virtualKilometreage + distance / 1000;
                        }

                        else
                        {
                            virtualKilometreage = virtualKilometreage - distance / 1000;
                        }

                        /* Set the 'previous' parameters. */
                        previousLat  = latitude;
                        previousLong = longitude;
                    }

                    /* Add the geometry point to the list. */
                    trackGeometry geometry = new trackGeometry(0, geometryName, latitude, longitude, elevation, kilometreage, virtualKilometreage, isLoopHere);
                    trackGeometry.Add(geometry);
                }
            }


            return(trackGeometry);
        }