Esempio n. 1
0
        private void ExtractGroupsFromFolderIntoSection(KmlFolder folder, MooiSection section, List <DiscoveredPlace> discoveredPlaces, string reportTempPath)
        {
            var groups = _mooiClusterFactory.CreateList(folder, discoveredPlaces, reportTempPath);

            groups.ForEach(x => x.Section = section);
            section.Clusters.AddRange(groups);
        }
Esempio n. 2
0
        public static void saveTracksWaypoints(string filename, string name, ArrayList tracks, bool saveTracks,
                                               ArrayList wpts, bool saveWaypoints,
                                               out int waypointCount, out int trkpointCount)
        {
            waypointCount = 0;
            trkpointCount = 0;

            KmlDocument kmlDoc = new KmlDocument(name, 1);

            if (saveWaypoints)
            {
                KmlFolder waypointsFolder = kmlDoc.CreateFolder("Waypoints");

                foreach (Waypoint wpt in wpts)
                {
                    waypointCount++;
                    KmlWaypoint kWaypoint = new KmlWaypoint(waypointsFolder, wpt);
                }
            }

            if (saveTracks)
            {
                KmlFolder tracksFolder = kmlDoc.CreateFolder("Tracks");

                foreach (Track trk in tracks)
                {
                    trkpointCount += trk.Trackpoints.Count;
                    KmlTrack kTrack = new KmlTrack(tracksFolder, trk);
                }
            }

            kmlDoc.CreateAbout();

            kmlDoc.SaveToKmz(filename, false);
        }
        public virtual GeoJsonFeatureCollection ConvertFolder(KmlFolder folder, IStyleProvider provider)
        {
            GeoJsonFeatureCollection collection = new GeoJsonFeatureCollection();

            foreach (KmlFeature feature in folder.Features)
            {
                ConvertFolder(folder, collection, feature, provider);
            }

            return(collection);
        }
Esempio n. 4
0
        public static KmlDocument createKmlTrack(Track trk)
        {
            KmlDocument kmlDoc = new KmlDocument(trk.Name, 1);

            KmlFolder waypointsFolder = kmlDoc.CreateFolder("Waypoints");

            KmlFolder tracksFolder = kmlDoc.CreateFolder("Tracks");

            KmlTrack kTrack = new KmlTrack(tracksFolder, trk);

            kmlDoc.CreateAbout();

            return(kmlDoc);
        }
Esempio n. 5
0
        public static KmlDocument createKmlEarthquakes(ArrayList eqs)
        {
            KmlDocument kmlDoc = new KmlDocument("Selected Earthquake" + (eqs.Count > 1 ? "s" : (": " + ((Earthquake)eqs[0]).NameDisplayed)), 1);

            KmlFolder earthquakesFolder = kmlDoc.CreateFolder("Earthquakes");

            foreach (Earthquake eq in eqs)
            {
                KmlEarthquake kEq = new KmlEarthquake(earthquakesFolder, eq);
            }

            kmlDoc.CreateAbout();

            return(kmlDoc);
        }
Esempio n. 6
0
        public static KmlDocument createKmlWaypoints(ArrayList wpts)
        {
            KmlDocument kmlDoc = new KmlDocument("Selected Waypoint" + (wpts.Count > 1 ? "s" : (": " + ((Waypoint)wpts[0]).NameDisplayed)), 1);

            KmlFolder waypointsFolder = kmlDoc.CreateFolder("Waypoints");

            foreach (Waypoint wpt in wpts)
            {
                KmlWaypoint kWpt = new KmlWaypoint(waypointsFolder, wpt);
            }

            kmlDoc.CreateAbout();

            return(kmlDoc);
        }
Esempio n. 7
0
        public void Folder_with_simple_placemarks_is_not_recognized_as_complete_route()
        {
            // Arrange
            var folder = new KmlFolder(new [] {
                new KmlPlacemark {
                    Coordinates = new [] { new GeoCoordinate() }
                }
            });

            // Act
            var result = _calculator.CompleteFolderIsRoute(folder);

            // Verify
            Assert.IsFalse(result);
        }
        public void When_creating_group_list_for_a_few_placemarks_a_single_group_is_created()
        {
            // Arrange
            var folder = new KmlFolder(new List <KmlPlacemark> {
                new KmlPlacemark(),
                new KmlPlacemark(),
                new KmlPlacemark()
            });

            // Act
            var result = _factory.Object.CreateList(folder, null, string.Empty);

            // Verify
            Assert.AreEqual(1, result.Count);
            Assert.AreEqual(folder.Placemarks.Count, result[0].Placemarks.Count);
        }
Esempio n. 9
0
        private void AssertKmlFolderNodeViewModel(KmlFolder kmlFolder, KmlObjectTreeNodeViewModel viewModel, bool isPartOfRoute)
        {
            Assert.AreEqual(kmlFolder, viewModel.Element);
            Assert.AreEqual(kmlFolder.Name, viewModel.Name);
            Assert.AreEqual(isPartOfRoute, viewModel.IsPartOfRoute);
            Assert.AreEqual(kmlFolder.Placemarks.Count, viewModel.Children.Count);
            for (var i = 0; i < viewModel.Children.Count; i++)
            {
                Assert.AreEqual(kmlFolder.Placemarks[i], viewModel.Children[i].Element);
                Assert.AreEqual(kmlFolder.Placemarks[i].Name, viewModel.Children[i].Name);
                Assert.AreEqual(isPartOfRoute, viewModel.Children[i].IsPartOfRoute);
                Assert.IsTrue(viewModel.Children[i].Enabled);
            }

            Assert.IsTrue(viewModel.Enabled);
        }
Esempio n. 10
0
        public static KmlDocument createKmlTracks(ArrayList trks)
        {
            KmlDocument kmlDoc = new KmlDocument("Selected Track" + (trks.Count > 1 ? "s" : (": " + ((Track)trks[0]).Name)), 1);

            KmlFolder waypointsFolder = kmlDoc.CreateFolder("Waypoints");

            KmlFolder tracksFolder = kmlDoc.CreateFolder("Tracks");

            foreach (Track trk in trks)
            {
                KmlTrack kTrack = new KmlTrack(tracksFolder, trk);
            }

            kmlDoc.CreateAbout();

            return(kmlDoc);
        }
        protected virtual void ConvertFolder(KmlFolder folder, GeoJsonFeatureCollection collection, KmlFeature feature, IStyleProvider provider)
        {
            switch (feature)
            {
            case KmlPlacemark placemark:

                collection.Add(ConvertPlacemark(placemark, provider));

                break;

            case KmlDocument document:
            // Why would you have a document in a folder? (although it seems legal according to the specification)

            case KmlFolder childFolder:
            // Why would you have folder in another folder? (although it seems legal according to the specification)

            default:
                throw new KmlException("Unsupported feature " + feature.GetType());
            }
        }
Esempio n. 12
0
        public bool CompleteFolderIsRoute(KmlFolder folder)
        {
            var routes = folder.Placemarks.Where(x => x.Coordinates.Length > 1).ToList();

            if (routes.Count != 1)
            {
                return(false);
            }

            Func <double, int> rounder = (d) => (int)Math.Round(d * 1000);

            var points = folder.Placemarks.Where(x => x.Coordinates.Length == 1)
                         .Select(x => new[] { rounder(x.Coordinates[0].Latitude), rounder(x.Coordinates[0].Longitude) })
                         .ToList();
            var routeCoords = routes[0].Coordinates.Select(x => new[] { rounder(x.Latitude), rounder(x.Longitude) }).ToList();

            var pointsOutsideRoute = points.Any(x => !routeCoords.Any(y => y[0] == x[0] && y[1] == x[1]));

            return(pointsOutsideRoute != true);
        }
Esempio n. 13
0
        public void Folder_with_route_as_first_placemark_and_not_associated_placemarks_is_not_recognized_as_complete_route()
        {
            // Arrange
            var folder = new KmlFolder(new[] {
                new KmlPlacemark {
                    Coordinates = new [] { new GeoCoordinate(1, 1), new GeoCoordinate(3, 3) }
                },
                new KmlPlacemark {
                    Coordinates = new [] { new GeoCoordinate(1, 1) }
                },
                new KmlPlacemark {
                    Coordinates = new [] { new GeoCoordinate(2, 2) }
                }
            });

            // Act
            var result = _calculator.CompleteFolderIsRoute(folder);

            // Verify
            Assert.IsFalse(result);
        }
Esempio n. 14
0
        public void ThenThesePlacemarksWillBeAssignedToTheFollowingClusters(Table table)
        {
            var folder = new KmlFolder(_placemarkTableRows.Select(x => new KmlPlacemark {
                Coordinates = new[] { new GeoCoordinate(x.Latitude, x.Longitude) },
                Name        = x.Name
            }));

            var kmlCalculator = new KmlCalculator();
            var resourceName  = new ResourceNameProvider();
            var factory       = new MooiClusterFactory(kmlCalculator, resourceName, new MooiPlacemarkFactory(kmlCalculator, resourceName));
            var clusters      = factory.CreateList(folder, null, string.Empty);
            var result        = clusters
                                .SelectMany((cluster, clusterIndex)
                                            => cluster.Placemarks.Select(placemark
                                                                         => new { p = placemark, i = clusterIndex }))
                                .Select(x => new PlacemarkInClusterTableRow {
                Name         = x.p.Name,
                ClusterIndex = x.i
            });

            table.CompareToSet(result);
        }
Esempio n. 15
0
        public static KmlDocument createKmlAreaWithObjects(ArrayList wpts, ArrayList eqs, ArrayList trks)
        {
            KmlDocument kmlDoc = new KmlDocument("Selected Area", 1);

            if (wpts.Count > 0)
            {
                KmlFolder waypointsFolder = kmlDoc.CreateFolder("Waypoints");

                foreach (Waypoint wpt in wpts)
                {
                    KmlWaypoint kWpt = new KmlWaypoint(waypointsFolder, wpt);
                }
            }

            if (eqs.Count > 0)
            {
                KmlFolder earthquakesFolder = kmlDoc.CreateFolder("Earthquakes");

                foreach (Earthquake eq in eqs)
                {
                    KmlEarthquake kEq = new KmlEarthquake(earthquakesFolder, eq);
                }
            }

            if (trks.Count > 0)
            {
                KmlFolder tracksFolder = kmlDoc.CreateFolder("Tracks");

                foreach (Track trk in trks)
                {
                    KmlTrack kTrack = new KmlTrack(tracksFolder, trk);
                }
            }

            kmlDoc.CreateAbout();

            return(kmlDoc);
        }
Esempio n. 16
0
        public void When_creating_group_list_for_route_a_single_group_is_created()
        {
            // Arrange
            var placemarks = Enumerable.Range(0, 10)
                             .Select(x => new KmlPlacemark {
                Coordinates = new[] { new GeoCoordinate(1, x) }
            })
                             .Concat(new[] {
                new KmlPlacemark {
                    Coordinates = Enumerable.Range(0, 10).Select(x => new GeoCoordinate(1, x)).ToArray()
                }
            });
            var folder = new KmlFolder(placemarks);

            _kmlCalculatorMock.Setup(x => x.CompleteFolderIsRoute(folder)).Returns(true);

            // Act
            var result = _factory.Object.CreateList(folder, null, string.Empty);

            // Verify
            Assert.AreEqual(1, result.Count);
            Assert.AreEqual(folder.Placemarks.Count, result[0].Placemarks.Count);
        }
Esempio n. 17
0
        private void AppendExploredPlaces(IEnumerable <DiscoveredPlace> discoveredPlaces, ICollection <KmlFolder> folders)
        {
            var exploredPlaces = discoveredPlaces?.Where(x => !x.IsForPlacemark).ToList();

            if (exploredPlaces == null || exploredPlaces.Count == 0)
            {
                return;
            }

            var folder = new KmlFolder(Resources.Kml_Folder_Explored);

            foreach (var place in exploredPlaces)
            {
                var placemark = new KmlPlacemark
                {
                    Name        = place.Venue.Title,
                    Coordinates = new[] { place.Venue.Coordinate },
                    IconPath    = place.Venue.IconUrl?.ToString()
                };
                place.AttachedToPlacemark = placemark;
                folder.Placemarks.Add(placemark);
            }
            folders.Add(folder);
        }
Esempio n. 18
0
        public List <MooiCluster> CreateList(KmlFolder folder, List <DiscoveredPlace> discoveredPlaces, string reportTempPath)
        {
            var clusters = new List <MooiCluster>();

            var placemarksConverted = folder.Placemarks
                                      .Select(x => _mooiPlacemarkFactory.Create(x,
                                                                                discoveredPlaces?.Where(dp => dp.AttachedToPlacemark == x).Select(dp => dp.Venue),
                                                                                reportTempPath))
                                      .ToList();

            if (placemarksConverted.Count <= MIN_COUNT_PER_CLUSTER)
            {
                return(CreateSingleCluster(placemarksConverted, reportTempPath));
            }

            if (folder.ContainsRoute && _kmlCalculator.CompleteFolderIsRoute(folder))
            {
                return(CreateSingleCluster(placemarksConverted, reportTempPath));
            }

            // TODO: Add support of lines within a folder which are not 'routes'
            placemarksConverted = placemarksConverted.Where(x => x.Coordinates.Length == 1).ToList();
            // ^^^

            var placemarksWithNeighbors       = GetPlacemarksWithNeighbors(placemarksConverted).ToList();
            var placemarksWithNeighborsLookup = placemarksWithNeighbors.ToDictionary(x => x.Placemark);

            var currentCluster = new MooiCluster();

            clusters.Add(currentCluster);

            var placemarksToProcess = placemarksWithNeighbors.ToList();

            while (placemarksToProcess.Any())
            {
                var startingPoint = placemarksToProcess[0];
                placemarksToProcess.RemoveAt(0);

                // Skip if the placemark has been added to any cluster before
                if (clusters.Any(g => g.Placemarks.Any(p => p == startingPoint.Placemark)))
                {
                    continue;
                }

                AppendPlacemarkToCluster(startingPoint.Placemark, currentCluster);

                // Add its closest neighbor to current cluster
                if (!clusters.Any(g => g.Placemarks.Any(p => p == startingPoint.NeighborWithMinDistance.Placemark)))
                {
                    AppendPlacemarkToCluster(startingPoint.NeighborWithMinDistance.Placemark, currentCluster);
                }

                foreach (var pm in placemarksToProcess.Skip(1).ToList())
                {
                    if (currentCluster.Placemarks.Any(x => x == pm.Placemark ||
                                                      x == pm.NeighborWithMinDistance.Placemark ||
                                                      pm.Neighbors.Any(n => n.Placemark == x && pm.NeighborWithMinDistance.AllowedDistance > n.Distance)
                                                      ))
                    {
                        if (currentCluster.Placemarks.Count >= MIN_COUNT_PER_CLUSTER)
                        {
                            var maxDistanceAmongAddedPlacemarks = placemarksWithNeighborsLookup[currentCluster.Placemarks[0]]
                                                                  .Neighbors.Where(x => currentCluster.Placemarks.Any(y => y == x.Placemark))
                                                                  .Select(x => x.AllowedDistance)
                                                                  .Max();

                            if (pm.NeighborWithMinDistance.Distance > maxDistanceAmongAddedPlacemarks)
                            {
                                continue;
                            }
                        }

                        AppendPlacemarkToCluster(pm.Placemark, currentCluster);
                        placemarksToProcess.Remove(pm);
                    }

                    if (currentCluster.Placemarks.Count == MAX_COUNT_PER_CLUSTER)
                    {
                        break;
                    }
                }

                currentCluster.OverviewMapFilePath = Path.Combine(reportTempPath, _resourceName.CreateFileNameForOverviewMap(currentCluster));
                currentCluster = new MooiCluster();
                clusters.Add(currentCluster);
            }

            // Trim out the last cluster which is always empty
            clusters = clusters.Where(x => x.Placemarks.Count > 0).ToList();

            MergeClusters(clusters);

            return(clusters);
        }
        public void LoadDetails(XmlNode node)
        {
            foreach (XmlNode child in node.ChildNodes)
            {
                KmlFeature newChild = null;
                switch (child.Name)
                {
                    case "NetworkLink":
                        newChild = new KmlNetworkLink();
                        break;
                    case "Placemark":
                        newChild = new KmlPlacemark();
                        break;
                    case "PhotoOverlay":
                        newChild = new KmlPhotoOverlay();
                        break;
                    case "ScreenOverlay":
                        newChild = new KmlScreenOverlay();
                        break;
                    case "GroundOverlay":
                        newChild = new KmlGroundOverlay();
                        break;
                    case "Folder":
                        newChild = new KmlFolder();
                        break;
                    case "Document":
                        newChild = Document = new KmlDocument();
                        break;
                }

                if (newChild != null)
                {
                    newChild.sky = this.sky;
                    newChild.LoadDetails(child, this);

                    children.Add(newChild);
                }
            }

            lastUpdate = DateTime.Now;
        }
        public override void LoadDetails(XmlNode node, KmlRoot owner)
        {
            base.LoadDetails(node, owner);

            foreach (XmlNode child in node.ChildNodes)
            {
                KmlFeature newChild = null;
                switch (child.Name)
                {
                    case "NetworkLink":
                        newChild = new KmlNetworkLink();
                        break;
                    case "Placemark":
                        newChild = new KmlPlacemark();
                        break;
                    case "PhotoOverlay":
                        newChild = new KmlPhotoOverlay();
                        break;
                    case "ScreenOverlay":
                        newChild = new KmlScreenOverlay();
                        break;
                    case "GroundOverlay":
                        newChild = new KmlGroundOverlay();
                        break;
                    case "Folder":
                        newChild = new KmlFolder();
                        break;
                    case "Document":
                        newChild = new KmlDocument();
                        break;
                }

                if (newChild != null)
                {
                    newChild.sky = this.sky;
                    newChild.LoadDetails(child, owner);
                    if (children == null)
                    {
                        children = new List<KmlFeature>();
                    }
                    children.Add(newChild);
                }
            }
        }
Esempio n. 21
0
 public KmlFolderNodeViewModel(KmlFolder folder)
 {
     _folder = folder;
 }