public static double DMSToDouble(string dms) { string[] coordComponents = dms.Split(new char[] { '°', '\'', '.' }); double coordValue = GeoConvert.DMSToDouble(int.Parse(coordComponents[0]), int.Parse(coordComponents[1]), int.Parse(coordComponents[2])); if (coordComponents[3].Equals("S") || coordComponents[3].Equals("W")) { coordValue = -coordValue; } return(coordValue); }
// FromWGS84: from lon,lat gives the google tile index // From http://wiki.openstreetmap.org/wiki/Slippy_map_tilenames // lower and upper bounds are 85; public static Tile FromWGS84(int zoom, double lonDeg, double latDeg) { Tile tile = new Tile(); if (latDeg > 85) { latDeg = 85; } if (latDeg < -85) { latDeg = -85; } var latRad = GeoConvert.Radians(latDeg); var n = Math.Pow(2, zoom); tile.Zoom = zoom; tile.X = (int)Math.Floor(n * ((lonDeg + 180) / 360)); tile.Y = (int)Math.Floor(((1.0d - Math.Log(Math.Tan(latRad) + (1 / Math.Cos(latRad))) / Math.PI) / 2.0d * n)); return(tile); }