예제 #1
0
        // TODO: Read subformation
        /// <summary>
        /// Reads the www.peakbagger.com locations from the CSV file.
        /// </summary>
        /// <param name="filePath">The file path.</param>
        /// <param name="maxLatitude">The maximum latitude from which locations are to be read.</param>
        /// <param name="minLatitude">The minimum latitude from which locations are to be read.</param>
        /// <param name="maxLongitude">The maximum longitude from which locations are to be read.</param>
        /// <param name="minLongitude">The minimum longitude from which locations are to be read.</param>
        /// <returns>List&lt;Location&gt;.</returns>
        public static List <Formation> ReadPeakbaggerLocationsFromCsv(
            string filePath,
            double maxLatitude  = 0,
            double minLatitude  = 0,
            double maxLongitude = 0,
            double minLongitude = 0)
        {
            List <Formation> locations = new List <Formation>();

            using (TextReader reader = File.OpenText(filePath))
            {
                var csv     = new CsvReader(reader);
                var results = csv.GetRecords <PeakbaggerLocation>().ToList();

                foreach (PeakbaggerLocation locationRaw in results)
                {
                    if (locationRaw.Longitude == null ||
                        locationRaw.Latitude == null)
                    {
                        continue;
                    }
                    double longitude = (double)locationRaw.Longitude;
                    double latitude  = (double)locationRaw.Latitude;
                    if ((!(minLongitude <= longitude) || !(longitude <= maxLongitude)) ||
                        (!(minLatitude <= latitude) || !(latitude <= maxLatitude)))
                    {
                        continue;
                    }
                    int elevation = 0;
                    if (locationRaw.Elevation != null)
                    {
                        elevation = (int)locationRaw.Elevation;
                    }
                    Formation location = new Formation(
                        locationRaw.Name,
                        latitude, longitude,
                        locationRaw.OtherName,
                        elevation);
                    locations.Add(location);
                }
            }
            return(locations);
        }
예제 #2
0
        // TODO: Hande sub-formations
        /// <summary>
        /// Reads the peakbagger locations that lie within the latitude/longitude bounds given and returns a list of objects with data.
        /// </summary>
        /// <param name="excel">The Excel application.</param>
        /// <param name="maxLatitude">The maximum latitude.</param>
        /// <param name="minLatitude">The minimum latitude.</param>
        /// <param name="maxLongitude">The maximum longitude.</param>
        /// <param name="minLongitude">The minimum longitude.</param>
        /// <returns>List&lt;PeakbaggerLocation&gt;.</returns>
        public static List <Formation> ReadPeakbaggerLocations(
            ExcelHelper excel,
            double maxLatitude  = 0,
            double minLatitude  = 0,
            double maxLongitude = 0,
            double minLongitude = 0)
        {
            List <Formation> locations  = new List <Formation>();
            List <string>    names      = excel.RangeValuesBelowHeader("peakName");
            List <string>    latitudes  = excel.RangeValuesBelowHeader("peakLatitude");
            List <string>    longitudes = excel.RangeValuesBelowHeader("peakLongitude");
            int           numberOfRows  = names.Count;
            List <string> elevations    = excel.RangeValuesBelowHeader("elevationFt", includeNull: true, numberOfRows: numberOfRows);
            List <string> otherNames    = excel.RangeValuesBelowHeader("peakNameAlt", includeNull: true, numberOfRows: numberOfRows);


            for (int i = 0, length = latitudes.Count; i < length; i++)
            {
                double longitude;
                if (!double.TryParse(longitudes[i], out longitude))
                {
                    continue;
                }
                double latitude;
                if (!double.TryParse(latitudes[i], out latitude))
                {
                    continue;
                }
                if ((minLongitude <= longitude && longitude <= maxLongitude) &&
                    (minLatitude <= latitude && latitude <= maxLatitude))
                {
                    int elevation;
                    int.TryParse(elevations[i], out elevation);
                    Formation location = new Formation(names[i], latitude, longitude, otherNames[i], elevation);
                    locations.Add(location);
                }
            }
            return(locations);
        }