/// <summary> /// Reads all of the formations and returns a list of objects with data. /// </summary> /// <param name="excel">The excel application.</param> /// <returns>List<DBLocation>.</returns> private static List <FormationMatcher> ReadFormations(ExcelFile excel) { List <FormationMatcher> locations = new List <FormationMatcher>(); List <string> areas = excel.RangeValuesBelowHeader("AreaChild"); List <string> names = excel.RangeValuesBelowHeader("Formation"); int numberOfRows = names.Count; List <string> latitudes = excel.RangeValuesBelowHeader("Latitude", includeNull: true, numberOfRows: numberOfRows); List <string> longitudes = excel.RangeValuesBelowHeader("Longitude", includeNull: true, numberOfRows: numberOfRows); List <string> otherNames = excel.RangeValuesBelowHeader("SubFormation", includeNull: true, numberOfRows: numberOfRows); for (int i = 0, length = names.Count; i < length; i++) { double longitude; if (!double.TryParse(longitudes[i], out longitude)) { longitude = 0; } double latitude; if (!double.TryParse(latitudes[i], out latitude)) { latitude = 0; } if (!(NMath.Abs(longitude) < 1) || !(NMath.Abs(latitude) < 1)) { continue; } FormationMatcher location = new FormationMatcher(areas[i], names[i], otherNames[i]); locations.Add(location); } return(locations); }
/// <summary> /// Writes location to a KML file. /// </summary> /// <param name="filePath">The file path.</param> /// <param name="dbLocation">The database location.</param> public static void WriteToKml(string filePath, FormationMatcher dbLocation) { // This is the root element of the file Dom.Kml kml = AssembleToKml(dbLocation); WriteToKml(filePath, kml); }
public void CondensePotentialMatches_Cathedral_Peak_And_Eichorns_Pinnacle() { string regionName = "Cathedral Area"; string formationCathedralPk = "Cathedral Peak"; string formationEichornsPinnacle = "Eichorn''s Pinnacle"; List <FormationMatcher> formationMatchers = new List <FormationMatcher>(); FormationMatcher formationMatcher1 = new FormationMatcher(regionName, formationCathedralPk); formationMatchers.Add(formationMatcher1); FormationMatcher formationMatcher2 = new FormationMatcher(regionName, formationEichornsPinnacle); formationMatchers.Add(formationMatcher2); List <Formation> formations = new List <Formation>(); Formation formation1 = new Formation(formationCathedralPk, 1, 2); formations.Add(formation1); Formation formation2 = new Formation(formationCathedralPk, 3, 4, subformationName: formationEichornsPinnacle); formations.Add(formation2); Region region = new Region(regionName, StarRegion); region.AddFormationsByRegionName(formationMatchers); region.AddFormationsByCoordinates(formations); region.MergeFormations(); Assert.That(region.Formations.Count, Is.EqualTo(2)); Assert.That(region.Formations[0].MatchedFormation, Is.Null); Assert.That(region.Formations[0].PossibleFormations.Count, Is.EqualTo(2)); Assert.That(region.Formations[0].PossibleFormations[0].Name, Is.EqualTo(formationCathedralPk)); Assert.That(region.Formations[0].PossibleFormations[0].SubFormationName, Is.Empty); Assert.That(region.Formations[0].PossibleFormations[1].Name, Is.EqualTo(formationCathedralPk)); Assert.That(region.Formations[0].PossibleFormations[1].SubFormationName, Is.EqualTo(formationEichornsPinnacle)); Assert.That(region.Formations[1].MatchedFormation, Is.Null); Assert.That(region.Formations[1].PossibleFormations.Count, Is.EqualTo(1)); Assert.That(region.Formations[1].PossibleFormations[0].Name, Is.EqualTo(formationCathedralPk)); region.CondensePotentialMatches(); Assert.That(region.Formations[0].MatchedFormation, Is.Not.Null); int indexCathedral = formations.LastIndexOf(formation1); Assert.That(region.Formations[0].MatchedFormation.Name, Is.EqualTo(formations[indexCathedral].Name)); Assert.That(region.Formations[0].MatchedFormation.OtherName, Is.EqualTo(formations[indexCathedral].OtherName)); Assert.That(region.Formations[0].MatchedFormation.SubFormationName, Is.EqualTo(formations[indexCathedral].SubFormationName)); Assert.That(region.Formations[1].MatchedFormation, Is.Not.Null); int indexEichorn = formations.LastIndexOf(formation2); Assert.That(region.Formations[1].MatchedFormation.Name, Is.EqualTo(formations[indexEichorn].Name)); Assert.That(region.Formations[1].MatchedFormation.OtherName, Is.EqualTo(formations[indexEichorn].OtherName)); Assert.That(region.Formations[1].MatchedFormation.SubFormationName, Is.EqualTo(formations[indexEichorn].SubFormationName)); }
public void AddFormationByRegionName_Nonmatching_Region_Name_Does_Not_Add() { Region region = new Region(NAME_REGION, StarRegion); FormationMatcher nonMatchingFormationMatcher = new FormationMatcher(NAME_REGION + "NonMatching", NAME_FORMATION, NAME_SUBFORMATION); region.AddFormationByRegionName(nonMatchingFormationMatcher); Assert.That(region.Formations, Is.Empty); }
/// <summary> /// Assembles location to KML. /// </summary> /// <param name="dbLocation">The database location.</param> /// <returns>Dom.Kml.</returns> public static Dom.Kml AssembleToKml(FormationMatcher dbLocation) { // This is the root element of the file Dom.Kml kml = new Dom.Kml { Feature = AssembleToFolder(dbLocation) }; return(kml); }
public void AddFormationByRegionName_Matching_Region_Name_Adds() { Region region = new Region(NAME_REGION, StarRegion); FormationMatcher matchingFormationMatcher = new FormationMatcher(NAME_REGION, NAME_FORMATION); region.AddFormationByRegionName(matchingFormationMatcher); Assert.That(region.Formations.Count, Is.EqualTo(1)); Assert.That(region.Formations[0].FormationName, Is.EqualTo(NAME_FORMATION)); }
/// <summary> /// Assembles location to folder. /// </summary> /// <param name="dbLocation">The database location.</param> /// <returns>Dom.Folder.</returns> private static Dom.Folder AssembleToFolder(FormationMatcher dbLocation) { Dom.Folder locationGroup = new Dom.Folder { Name = dbLocation.FormationName }; if (!string.IsNullOrWhiteSpace(dbLocation.SubFormationName)) { locationGroup.Name += " (" + dbLocation.SubFormationName + ")"; } Location location = dbLocation.MatchedFormation; if (location == null) { return(locationGroup); } // This will be used for the placemark Dom.Point point = new Dom.Point { Coordinate = new Vector(location.Latitude, location.Longitude) }; Dom.Placemark placemark = new Dom.Placemark { Name = location.Name }; if (!string.IsNullOrWhiteSpace(location.OtherName)) { placemark.Name += " (" + location.OtherName + ")"; } placemark.Geometry = point; locationGroup.AddFeature(placemark); //foreach (PeakbaggerLocation location in dbLocation.PossibleLocations) //{ // // This will be used for the placemark // Dom.Point point = new Dom.Point {Coordinate = new Vector(location.Latitude, location.Longitude)}; // Dom.Placemark placemark = new Dom.Placemark {Name = location.Name}; // if (!string.IsNullOrWhiteSpace(location.OtherName)) // { // placemark.Name += " (" + location.OtherName + ")"; // } // placemark.Geometry = point; // locationGroup.AddFeature(placemark); //} return(locationGroup); // Add to the root //kml.Feature = locationGroup; //WriteToKml(filePath, kml); //Console.WriteLine(serializer.Xml); }
public void MergeFormations() { List <FormationMatcher> formationMatchers = new List <FormationMatcher>(); FormationMatcher nonMatchingFormationMatcher = new FormationMatcher(NAME_REGION + "NonMatching", NAME_FORMATION, NAME_SUBFORMATION); formationMatchers.Add(nonMatchingFormationMatcher); FormationMatcher matchingFormationMatcher = new FormationMatcher(NAME_REGION, NAME_FORMATION); formationMatchers.Add(matchingFormationMatcher); List <Formation> formations = new List <Formation>(); Coordinate coordinateOutside = new Coordinate(120, 5); Formation formationOutside = new Formation(NAME_FORMATION + "Outside", coordinateOutside); formations.Add(formationOutside); Coordinate coordinateInside = new Coordinate(23, 90); Formation formationInside = new Formation(NAME_FORMATION + "Inside", coordinateInside); formations.Add(formationInside); Coordinate coordinatePartiallyOutside = new Coordinate(25, 21); Formation formationPartiallyOutside = new Formation(NAME_FORMATION + "PartiallyOutside", coordinatePartiallyOutside); formations.Add(formationPartiallyOutside); Formation formationOnVertex = new Formation(NAME_FORMATION + "OnVertex", StarRegion[0]); formations.Add(formationOnVertex); Coordinate coordinateOnShapeSegment = new Coordinate(24, 45); Formation formationOnShapeSegment = new Formation(NAME_FORMATION + "OnSegment", coordinateOnShapeSegment); formations.Add(formationOnShapeSegment); Region region = new Region(NAME_REGION, StarRegion); region.AddFormationsByRegionName(formationMatchers); region.AddFormationsByCoordinates(formations); region.MergeFormations(); Assert.That(region.Formations.Count, Is.EqualTo(1)); Assert.That(region.Formations[0].MatchedFormation, Is.Null); Assert.That(region.Formations[0].PossibleFormations.Count, Is.EqualTo(3)); Assert.That(region.Formations[0].PossibleFormations[0].Name, Is.EqualTo(NAME_FORMATION + "Inside")); Assert.That(region.Formations[0].PossibleFormations[1].Name, Is.EqualTo(NAME_FORMATION + "OnVertex")); Assert.That(region.Formations[0].PossibleFormations[2].Name, Is.EqualTo(NAME_FORMATION + "OnSegment")); }
public void AddFormationsByRegionName() { List <FormationMatcher> formations = new List <FormationMatcher>(); FormationMatcher nonMatchingFormationMatcher = new FormationMatcher(NAME_REGION + "NonMatching", NAME_FORMATION, NAME_SUBFORMATION); formations.Add(nonMatchingFormationMatcher); FormationMatcher matchingFormationMatcher = new FormationMatcher(NAME_REGION, NAME_FORMATION); formations.Add(matchingFormationMatcher); Region region = new Region(NAME_REGION, StarRegion); region.AddFormationsByRegionName(formations); Assert.That(region.Formations.Count, Is.EqualTo(1)); Assert.That(region.Formations[0].FormationName, Is.EqualTo(NAME_FORMATION)); }
private static void testDummyPts() { string assemblyFolder = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location); if (assemblyFolder == null) { return; } string kmlPath = Path.Combine(assemblyFolder, "testDummyPts.kml"); FormationMatcher location = new FormationMatcher("Foo Region", "Bar Formation", "FooBar"); Location pbLocationInside = new Location("Foo", 42.544, -121.45); location.AddIfPotentialMatchByName(pbLocationInside); Kml.WriteToKml(kmlPath, location); //Merger.OpenInGoogleEarth(location, kmlPath, googleEarthPath); }
public void CondensePotentialMatches_Ericcson_Crags_And_Crag_And_Mountain() { string regionName = "Collegiate Area"; string baseName = "Ericsson"; string formationMtEricsson = $"Mount {baseName}"; string formationEricssonCrags = $"{baseName} Crags"; string formationEricssonCrag1 = $"{baseName} Crag 1"; string formationEricssonCrag2 = $"{baseName} Crag 2"; string formationEricssonCrag3 = $"{baseName} Crag #3"; string formationEricssonCrag4 = $"{baseName} Crag Number 4"; List <FormationMatcher> formationMatchers = new List <FormationMatcher>(); FormationMatcher formationMatcher1 = new FormationMatcher(regionName, formationEricssonCrags, formationEricssonCrag3); formationMatchers.Add(formationMatcher1); FormationMatcher formationMatcher2 = new FormationMatcher(regionName, formationMtEricsson); formationMatchers.Add(formationMatcher2); List <Formation> formations = new List <Formation>(); Formation formation1 = new Formation(formationEricssonCrags, 1, 2, subformationName: formationEricssonCrag1); formations.Add(formation1); Formation formation2 = new Formation(formationEricssonCrags, 3, 4, subformationName: formationEricssonCrag2); formations.Add(formation2); Formation formation3 = new Formation(formationEricssonCrags, 5, 6, subformationName: formationEricssonCrag3); formations.Add(formation3); Formation formation4 = new Formation(formationEricssonCrags, 7, 8, subformationName: formationEricssonCrag4); formations.Add(formation4); Formation formationCrags = new Formation(formationEricssonCrags, 9, 10); formations.Add(formationCrags); Formation formationMtn = new Formation(formationMtEricsson, 11, 12); formations.Add(formationMtn); Region region = new Region(regionName, StarRegion); region.AddFormationsByRegionName(formationMatchers); region.AddFormationsByCoordinates(formations); region.MergeFormations(); Assert.That(region.Formations.Count, Is.EqualTo(2)); Assert.That(region.Formations[0].MatchedFormation, Is.Null); Assert.That(region.Formations[0].PossibleFormations.Count, Is.EqualTo(5)); Assert.That(region.Formations[0].PossibleFormations[0].SubFormationName, Is.EqualTo(formationEricssonCrag1)); Assert.That(region.Formations[0].PossibleFormations[1].SubFormationName, Is.EqualTo(formationEricssonCrag2)); Assert.That(region.Formations[0].PossibleFormations[2].SubFormationName, Is.EqualTo(formationEricssonCrag3)); Assert.That(region.Formations[0].PossibleFormations[3].SubFormationName, Is.EqualTo(formationEricssonCrag4)); Assert.That(region.Formations[0].PossibleFormations[4].Name, Is.EqualTo(formationEricssonCrags)); Assert.That(region.Formations[1].MatchedFormation, Is.Null); Assert.That(region.Formations[1].PossibleFormations.Count, Is.EqualTo(1)); Assert.That(region.Formations[1].PossibleFormations[0].Name, Is.EqualTo(formationMtEricsson)); region.CondensePotentialMatches(); Assert.That(region.Formations[0].MatchedFormation, Is.Not.Null); int indexCrag = formations.IndexOf(formation3); Assert.That(region.Formations[0].MatchedFormation.Name, Is.EqualTo(formations[indexCrag].Name)); Assert.That(region.Formations[0].MatchedFormation.OtherName, Is.EqualTo(formations[indexCrag].OtherName)); Assert.That(region.Formations[0].MatchedFormation.SubFormationName, Is.EqualTo(formations[indexCrag].SubFormationName)); Assert.That(region.Formations[1].MatchedFormation, Is.Not.Null); int indexMtn = formations.IndexOf(formationMtn); Assert.That(region.Formations[1].MatchedFormation.Name, Is.EqualTo(formations[indexMtn].Name)); Assert.That(region.Formations[1].MatchedFormation.OtherName, Is.EqualTo(formations[indexMtn].OtherName)); Assert.That(region.Formations[1].MatchedFormation.SubFormationName, Is.EqualTo(formations[indexMtn].SubFormationName)); }