public static LocationCollection ToLocationCollection(this IEnumerable <Location> locations) { var locationCollection = new LocationCollection(); foreach (var location in locations) { locationCollection.Add(location); } return(locationCollection); }
public static LocationCollection ToLocationCollection(this LineString lineString, bool assignIds = false) { var key = 0; var locationCollection = new LocationCollection(); foreach (var coordinate in lineString.Coordinates) { locationCollection.Add(new Location { Key = assignIds ? key++ + "" : null, Latitude = coordinate.Latitude, Longitude = coordinate.Longitude }); } return(locationCollection); }
/// <summary> /// Reads a LocationCollection from a CSV file. The file is expected to have 3 columns - Section ID, Lat, Lon. The file /// is assumed to have a header. /// </summary> /// <param name="path">Full path of the file to read.</param> /// <returns>Contents to the file as LocationCollection.</returns> public static LocationCollection ReadCsv(string path) { var locationCollection = new LocationCollection(); var lines = File.ReadAllLines(path); var headers = lines.First() .Trim() .Split(",".ToArray()); foreach (var line in lines.Skip(1)) { var parts = line.Trim().Split(",".ToCharArray()); if (parts.Length != headers.Count()) { continue; } var location = new Location(); for (var i = 0; i < headers.Length; i++) { if (headers[i].Trim().ToLower() == "latitude") { location.Latitude = Convert.ToDouble(parts[i]); } else if (headers[i].Trim().ToLower() == "longitude") { location.Longitude = Convert.ToDouble(parts[i]); } else if (headers[i].Trim().ToLower() == "section id") { location.Key = parts[i]; } else { location[headers[i]] = parts[i].Parse(); } } locationCollection.Add(location); } return(locationCollection); }