public static SWEREF99Position ToSweRef99(this WebMercatorPosition pos)
        {
            var calc     = new WebMercatorCalculator();
            var wgs84Pos = new WGS84Position(calc.YToLatitude(pos.Latitude), calc.XToLongitude(pos.Longitude));

            return(new SWEREF99Position(wgs84Pos, SWEREF99Position.SWEREFProjection.sweref_99_tm));
        }
        public static RT90Position ToRt90(this WebMercatorPosition pos)
        {
            var calc     = new WebMercatorCalculator();
            var wgs84Pos = new WGS84Position(calc.YToLatitude(pos.Latitude), calc.XToLongitude(pos.Longitude));

            return(new RT90Position(wgs84Pos, RT90Position.RT90Projection.rt90_2_5_gon_v));
        }
        private double GetDistanceKm(WebMercatorPosition pos1, WebMercatorPosition pos2)
        {
            var dLat = pos1.Latitude - pos2.Latitude;
            var dLng = pos1.Longitude - pos2.Longitude;

            return(Math.Sqrt(dLat * dLat + dLng * dLng) / 1000);
        }
示例#4
0
        public void ToWgs84_FromWebMercator(double lat, double lng, double expectedLat, double expectedLng, int decimals)
        {
            var pos       = new WebMercatorPosition(lat, lng);
            var converted = PositionConverter.ToWgs84(pos);

            Assert.AreEqual(Math.Round(expectedLat, decimals, MidpointRounding.AwayFromZero), Math.Round(converted.Latitude, decimals, MidpointRounding.AwayFromZero));
            Assert.AreEqual(Math.Round(expectedLng, decimals, MidpointRounding.AwayFromZero), Math.Round(converted.Longitude, decimals, MidpointRounding.AwayFromZero));
        }
        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();
        }
        public static WGS84Position ToWgs84(this WebMercatorPosition pos)
        {
            var calc = new WebMercatorCalculator();

            return(new WGS84Position(calc.YToLatitude(pos.Latitude), calc.XToLongitude(pos.Longitude)));
        }
        private double GetDistanceKm(WebMercatorPosition pos1, WebMercatorPosition pos2)
        {
            var dLat = pos1.Latitude - pos2.Latitude;
            var dLng = pos1.Longitude - pos2.Longitude;

            return Math.Sqrt(dLat * dLat + dLng * dLng) / 1000;
        }