Example #1
0
        [TestCase(7670775, 1878314, ExpectedResult = CoordinateSystemType.Undefined)] // Inconclusive with RT90 position
        public CoordinateSystemType GetCoordinateSystemType(double lat, double lng)
        {
            var calc = new WebMercatorCalculator();
            var str  = calc.LatitudeToY(lat) + "," + calc.LongitudeToX(lng);

            return(new CoordinateSystemTypeCalculator().GetCoordinateSystemType(lat, lng));
        }
Example #2
0
        public void LatitudeToY(double lat, double expectedY)
        {
            var y = new WebMercatorCalculator().LatitudeToY(lat, 0);

            //Assert.Less(Math.Abs(y - expectedY), 0.4);
            Assert.AreEqual(expectedY, y);
        }
Example #3
0
        public void YToLatitude(double y, double expectedLat)
        {
            var lat = new WebMercatorCalculator().YToLatitude(y);

            Assert.Less(Math.Abs(lat - expectedLat), 0.000005);
            //Assert.AreEqual(expectedLat, lat);
        }
Example #4
0
        public void LongitudeToX(double lng, double expectedX)
        {
            var x = new WebMercatorCalculator().LongitudeToX(lng);

            Assert.Less(Math.Abs(x - expectedX), 0.5);
            //Assert.AreEqual(expectedX, x);
        }
Example #5
0
        public void XToLongitude(double x, double expectedLng)
        {
            var lng = new WebMercatorCalculator().XToLongitude(x);

            Assert.Less(Math.Abs(lng - expectedLng), 0.000005);
            //Assert.AreEqual(expectedLng, lng);
        }
        public async Task <IList <Site> > GetNearbySites(double latitude, double longitude, double distanceRadians)
        {
            var distance = distanceRadians * 7500000;

            if (distance == 0)
            {
                distance = 5000;
            }
            var pos = new WGS84Position(latitude, longitude).ToWebMercator();
            var sw  = new WebMercatorPosition(pos.Latitude - distance, pos.Longitude - distance);
            var ne  = new WebMercatorPosition(pos.Latitude + distance, pos.Longitude + distance);

            var sites = await _ap2WebClient.GetSitesWithinBoundsAsync(sw, ne);

            _artportalenAccountStorage.SaveCookies();

            // Run this in background for non blocking of UI
            Task.Run(async() =>
            {
                await UpdateSites(sites).ContinueWith(t =>
                {
                    if (t.IsFaulted)
                    {
                        t.Exception.Handle(ex => true);
                    }

                    return(t.Result);
                });
            });

            var webMercCalc = new WebMercatorCalculator();

            return(sites.Select(s =>
                                new Site
            {
                SiteId = s.SiteId,
                SiteName = s.SiteName,
                SiteYCoord = s.SiteYCoord,
                SiteXCoord = s.SiteXCoord,
                Latitude = webMercCalc.YToLatitude(s.SiteYCoord),
                Longitude = webMercCalc.XToLongitude(s.SiteXCoord),
                Kommun = s.Kommun,
                DistanceKm = GetDistanceKm(pos, new WebMercatorPosition(s.SiteYCoord, s.SiteXCoord)),
            }
                                ).OrderBy(x => x.DistanceKm).ToList());
        }
        public async Task<IList<Site>> GetNearbySites(double latitude, double longitude, double distanceRadians)
        {
            var distance = distanceRadians*7500000;
            if (distance == 0) distance = 5000;
            var pos = new WGS84Position(latitude, longitude).ToWebMercator();
            var sw = new WebMercatorPosition(pos.Latitude - distance, pos.Longitude - distance);
            var ne = new WebMercatorPosition(pos.Latitude + distance, pos.Longitude + distance);

            var sites = await _ap2WebClient.GetSitesWithinBoundsAsync(sw, ne);
            _artportalenAccountStorage.SaveCookies();

            // Run this in background for non blocking of UI
            Task.Run(async () =>
            {
                await UpdateSites(sites).ContinueWith(t =>
                {
                    if (t.IsFaulted)
                    {
                        t.Exception.Handle(ex => true);
                    }

                    return t.Result;
                });
            });

            var webMercCalc = new WebMercatorCalculator();

            return sites.Select(s =>
                new Site
                {
                    SiteId = s.SiteId,
                    SiteName = s.SiteName,
                    SiteYCoord = s.SiteYCoord,
                    SiteXCoord = s.SiteXCoord,
                    Latitude = webMercCalc.YToLatitude(s.SiteYCoord),
                    Longitude = webMercCalc.XToLongitude(s.SiteXCoord),
                    Kommun = s.Kommun,
                    DistanceKm = GetDistanceKm(pos, new WebMercatorPosition(s.SiteYCoord, s.SiteXCoord)),
                }
            ).OrderBy(x => x.DistanceKm).ToList();
        }