public string XYZoomToBBox(int x, int y, int zoom)
        {
            var tileSize = 256;

            NumberFormatInfo nfi = new NumberFormatInfo();

            nfi.NumberDecimalSeparator = ".";

            // From the grid position and zoom, work out the min and max Latitude / Longitude values of this tile
            double w = ((float)(x * tileSize) * 360 / (float)(tileSize * Math.Pow(2, zoom)) - 180);
            double n = ((float)Math.Asin((Math.Exp((0.5 - (y * tileSize) / (tileSize) / Math.Pow(2, zoom)) * 4 * Math.PI) - 1) / (Math.Exp((0.5 - (y * tileSize) / 256 / Math.Pow(2, zoom)) * 4 * Math.PI) + 1)) * 180 / (float)Math.PI);
            double e = ((float)((x + 1) * tileSize) * 360 / (float)(tileSize * Math.Pow(2, zoom)) - 180);
            double s = ((float)Math.Asin((Math.Exp((0.5 - ((y + 1) * tileSize) / (tileSize) / Math.Pow(2, zoom)) * 4 * Math.PI) - 1) / (Math.Exp((0.5 - ((y + 1) * tileSize) / 256 / Math.Pow(2, zoom)) * 4 * Math.PI) + 1)) * 180 / (float)Math.PI);

            if (UseSweref99)
            {
                WGS84Position wgstopLeft     = new WGS84Position(n, w);
                WGS84Position wgsBottomRight = new WGS84Position(s, e);

                SWEREF99Position swerefTopLeft     = new SWEREF99Position(wgstopLeft, SWEREF99Position.SWEREFProjection.sweref_99_tm);
                SWEREF99Position swerefBottomRight = new SWEREF99Position(wgsBottomRight, SWEREF99Position.SWEREFProjection.sweref_99_tm);

                string[] bounds = new string[] { swerefTopLeft.Longitude.ToString(nfi), swerefBottomRight.Latitude.ToString(nfi), swerefBottomRight.Longitude.ToString(nfi), swerefTopLeft.Latitude.ToString(nfi) };

                return(string.Join(",", bounds));
            }
            else
            {
                string[] bounds = new string[] { w.ToString(nfi), s.ToString(nfi), e.ToString(nfi), n.ToString(nfi) };

                return(string.Join(",", bounds));
            }
        }
Exemple #2
0
    public static double[] GetLatLon(float x, float y)
    {
        var sweRef = new SWEREF99Position(y, x);
        var wgs84  = sweRef.ToWGS84();

        return(new double[] { wgs84.Latitude, wgs84.Longitude });
    }
        public static WebMercatorPosition ToWebMercator(this SWEREF99Position pos)
        {
            var calc  = new WebMercatorCalculator();
            var wgs84 = pos.ToWGS84();

            return(new WebMercatorPosition(calc.LatitudeToY(wgs84.Latitude), calc.LongitudeToX(wgs84.Longitude)));
        }
Exemple #4
0
        public void ToWgs84_FromSweRef99(double lat, double lng, double expectedLat, double expectedLng, int decimals)
        {
            var pos       = new SWEREF99Position(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));
        }
Exemple #5
0
        public void LatitudeToStringTest2()
        {
            SWEREF99Position swePos = new SWEREF99Position(6652797.165, 658185.201);
            WGS84Position    wgsPos = swePos.ToWGS84();

            string latDegStringFromLM = "59.982008334868";
            string lonDegStringFromLM = "17.8350333249246";

            Assert.AreEqual(latDegStringFromLM, wgsPos.LatitudeToString(WGS84Position.WGS84Format.Degrees));
            Assert.AreEqual(lonDegStringFromLM, wgsPos.LongitudeToString(WGS84Position.WGS84Format.Degrees));
        }
Exemple #6
0
        public static Point GetPointFromWgs(Geometry geo)
        {
            if (!string.IsNullOrWhiteSpace(geo.Wgs84))
            {
                var point  = PointFromString(geo.Wgs84);
                var wgsPos = new WGS84Position(point.Latitude, point.Longitude);
                var rtPos  = new SWEREF99Position(wgsPos, SWEREF99Position.SWEREFProjection.sweref_99_tm);

                return(new Point(rtPos.Longitude, rtPos.Latitude));
            }

            return(null);
        }
Exemple #7
0
        public void SwerefToWGS84()
        {
            SWEREF99Position swePos = new SWEREF99Position(6652797.165, 658185.201);
            WGS84Position    wgsPos = swePos.ToWGS84();

            // String values from Lantmateriet.se, they convert DMS only.
            // Reference: http://www.lantmateriet.se/templates/LMV_Enkelkoordinattransformation.aspx?id=11500
            string latDmsStringFromLM = "N 59º 58' 55.23001\"";
            string lonDmsStringFromLM = "E 17º 50' 6.11997\"";

            Assert.AreEqual(latDmsStringFromLM, wgsPos.LatitudeToString(WGS84Position.WGS84Format.DegreesMinutesSeconds));
            Assert.AreEqual(lonDmsStringFromLM, wgsPos.LongitudeToString(WGS84Position.WGS84Format.DegreesMinutesSeconds));
        }
Exemple #8
0
        public void Load(string path)
        {
            var networkPath  = Path.Combine(path, "network-plain.xml");
            var schedulePath = Path.Combine(path, "transitSchedule.xml");
            var vehiclePath  = Path.Combine(path, "vehicles.xml");

            var matSimNetwork     = MatSimNetwork.Load(networkPath);
            var matSimSchedule    = MatSimSchedule.Load(schedulePath);
            var vehicleDefinition = VehicleDefinitions.Load(vehiclePath);

            var networkMinMax = matSimNetwork.GetMinMaxXY();

            SWEREF99Position minSwe = new SWEREF99Position(networkMinMax[1], networkMinMax[0]);
            SWEREF99Position maxSwe = new SWEREF99Position(networkMinMax[3], networkMinMax[2]);

            WGS84Position netMinWgs = minSwe.ToWGS84();
            WGS84Position netMaxWgs = maxSwe.ToWGS84();

            Console.WriteLine($"Min Lat: {netMinWgs.LatitudeToString(WGS84Position.WGS84Format.Degrees)}");
            Console.WriteLine($"Min Lon: {netMinWgs.LongitudeToString(WGS84Position.WGS84Format.Degrees)}");
            Console.WriteLine($"Max Lat: {netMaxWgs.LatitudeToString(WGS84Position.WGS84Format.Degrees)}");
            Console.WriteLine($"Max Lon: {netMaxWgs.LongitudeToString(WGS84Position.WGS84Format.Degrees)}");

            var scheduleMinMax = matSimSchedule.GetMinMaxXY();

            minSwe = new SWEREF99Position(scheduleMinMax[1], scheduleMinMax[0]);
            maxSwe = new SWEREF99Position(scheduleMinMax[3], scheduleMinMax[2]);

            WGS84Position schMinWgs = minSwe.ToWGS84();
            WGS84Position schMaxWgs = maxSwe.ToWGS84();

            Console.WriteLine($"Min Lat: {schMinWgs.LatitudeToString(WGS84Position.WGS84Format.Degrees)}, {scheduleMinMax[1]}");
            Console.WriteLine($"Min Lat: {schMinWgs.Latitude}");

            Console.WriteLine($"Min Lon: {schMinWgs.LongitudeToString(WGS84Position.WGS84Format.Degrees)}, {scheduleMinMax[0]}");
            Console.WriteLine($"Max Lat: {schMaxWgs.LatitudeToString(WGS84Position.WGS84Format.Degrees)}, {scheduleMinMax[3]}");
            Console.WriteLine($"Max Lon: {schMaxWgs.LongitudeToString(WGS84Position.WGS84Format.Degrees)}, {scheduleMinMax[2]}");


            //Console.WriteLine(matSimSchedule.GetStopString("99999"));
            //Console.WriteLine(matSimSchedule.GetLineString("line1_r"));
            //Console.WriteLine(matSimSchedule.GetLineString("line10_r"));

            //Console.WriteLine(matSimNetwork.GetLinkString("100004_AB"));
            //Console.WriteLine(matSimNetwork.GetNodeString("tr_65905"));

            //Console.WriteLine(vehicleDefinition.GetVehicleTypeString("BUS"));
            //Console.WriteLine(vehicleDefinition.GetVehicleString("Veh144931"));
            //Console.WriteLine($"vehicle list count: {vehicleDefinition.vehicles.Count}");
        }
Exemple #9
0
        public void WGS84ToSweref()
        {
            WGS84Position wgsPos = new WGS84Position();

            wgsPos.SetLatitudeFromString("N 59º 58' 55.23\"", WGS84Position.WGS84Format.DegreesMinutesSeconds);
            wgsPos.SetLongitudeFromString("E 017º 50' 06.12\"", WGS84Position.WGS84Format.DegreesMinutesSeconds);

            SWEREF99Position rtPos = new SWEREF99Position(wgsPos, SWEREF99Position.SWEREFProjection.sweref_99_tm);

            // Conversion values from Lantmateriet.se, they convert from DMS only.
            // Reference: http://www.lantmateriet.se/templates/LMV_Enkelkoordinattransformation.aspx?id=11500
            double xPosFromLM = 6652797.165;
            double yPosFromLM = 658185.201;

            Assert.AreEqual(Math.Round(rtPos.Latitude, 3), xPosFromLM);
            Assert.AreEqual(Math.Round(rtPos.Longitude, 3), yPosFromLM);
        }
 public static WGS84Position ToWgs84(this SWEREF99Position pos)
 {
     return(pos.ToWGS84());
 }
 public static RT90Position ToRt90(this SWEREF99Position pos)
 {
     return(new RT90Position(pos.ToWGS84(), RT90Position.RT90Projection.rt90_2_5_gon_v));
 }
Exemple #12
0
 public static WGS84Position WgsFromSweref(SWEREF99Position position)
 {
     return(position.ToWGS84());
 }