private PointD GetLonLat(Point pixelOffset, TileXY tilexy) { double lat, lon; BingProjection.PixelXYToLatLong(tilexy.x * 256 + pixelOffset.X, tilexy.y * 256 + pixelOffset.Y, (int)tilexy.level, out lat, out lon); return(new PointD(lon, lat)); }
private void ShowCenterTileInfo() { if (!tiles.ContainsKey(centerTilexy)) { tbTileInfo.Text = "center tile is blank!"; return; } TileMeta centerTile = tiles[centerTilexy]; string result = "X,Y,Z/" + centerTilexy + " TileCount/" + tiles.Count + " LevelRange/" + levelMin + "->" + levelMax; // show utm info int utmx, utmy; double res; centerTilexy.GetUtmXy(out utmx, out utmy, out res); result += "\r\nIf Utm: x,y,zone,res/" + utmx + "," + utmy + "," + centerTile.zone + "," + res + " x1,x2,y1,y2/" + utmx * 400 * res + "," + (utmx + 1) * 400 * res + "," + (utmy + 1) * 400 * res + "," + utmy * 400 * res; // show bing info result += "\r\nIf Bing: QKey/" + BingProjection.GetQuadKey(centerTilexy) + " LatLon/" + BingProjection.TileXYToLatLong(centerTilexy); // show NASA info double lat, lon; centerTilexy.GetNeighbor(0, 1).GetNASALatLon(out lat, out lon); result += "\r\nIf NASA: LeftBot/" + lat.ToString("F6") + "," + lon.ToString("F6"); centerTilexy.GetNeighbor(1, 0).GetNASALatLon(out lat, out lon); result += " RightTop/" + lat.ToString("F6") + "," + lon.ToString("F6"); tbTileInfo.Text = result + "\r\n\r\n"; }
/// <summary> /// check if this mask contains a tile /// </summary> /// <param name="tilexy"></param> /// <returns></returns> public bool ContainsTile(TileXY tilexy) { double lat, lon; BingProjection.PixelXYToLatLong((int)tilexy.x * 256, (int)tilexy.y * 256, (int)tilexy.level, out lat, out lon); if (!ContainsLatLon(lat, lon)) { return(false); } BingProjection.PixelXYToLatLong((int)tilexy.x * 256 + 256, (int)tilexy.y * 256, (int)tilexy.level, out lat, out lon); if (!ContainsLatLon(lat, lon)) { return(false); } BingProjection.PixelXYToLatLong((int)tilexy.x * 256, (int)tilexy.y * 256 + 256, (int)tilexy.level, out lat, out lon); if (!ContainsLatLon(lat, lon)) { return(false); } BingProjection.PixelXYToLatLong((int)tilexy.x * 256 + 256, (int)tilexy.y * 256 + 256, (int)tilexy.level, out lat, out lon); if (!ContainsLatLon(lat, lon)) { return(false); } return(true); }
public bool ContainsTilePixel(TileXY tilexy, Point pixelOffset) { double lat, lon; BingProjection.PixelXYToLatLong((int)tilexy.x * 256 + pixelOffset.X, (int)tilexy.y * 256 + pixelOffset.Y, (int)tilexy.level, out lat, out lon); return(ContainsLatLon(lat, lon) ? true : false); }
public Point[] GetUtmCorrectedRelativePolygon(TileXY tilexy, int zone) { double[] input = new double[4]; double[] result = new double[8]; input[0] = box.top; input[1] = box.right; input[2] = box.bottom; input[3] = box.left; for (int i = 0; i < 4; i++) { input[i] = input[i] * Math.PI / 180; } MUtilities.LatLonRectangleExpandByUtm(zone, input, result); for (int i = 0; i < 8; i++) { result[i] = result[i] * 180 / Math.PI; } Point[] points = new Point[4]; points[0] = BingProjection.LatLongToPixelXY(result[0], result[1], tilexy.level); points[1] = BingProjection.LatLongToPixelXY(result[2], result[3], tilexy.level); points[2] = BingProjection.LatLongToPixelXY(result[4], result[5], tilexy.level); points[3] = BingProjection.LatLongToPixelXY(result[6], result[7], tilexy.level); for (int i = 0; i < 4; i++) { points[i].X -= tilexy.x * 256; points[i].Y -= tilexy.y * 256; } return(points); }
public void VerifyCenterAsBing(PictureBox pbVerify) { string quadKey = BingProjection.GetQuadKey(centerTilexy); string url = "http://ecn.dynamic.t0.tiles.virtualearth.net/comp/ch/" + quadKey + "?mkt=en-us&it=A,G,L&shading=hill&og=4&n=z"; pbVerify.Load(url); Paint(false, true); }
public Point[] GetRelativePolygon(TileXY tilexy) { Point[] points = new Point[4]; points[0] = BingProjection.LatLongToPixelXY(box.top, box.left, tilexy.level); points[1] = BingProjection.LatLongToPixelXY(box.top, box.right, tilexy.level); points[2] = BingProjection.LatLongToPixelXY(box.bottom, box.right, tilexy.level); points[3] = BingProjection.LatLongToPixelXY(box.bottom, box.left, tilexy.level); for (int i = 0; i < 4; i++) { points[i].X -= tilexy.x * 256; points[i].Y -= tilexy.y * 256; } return(points); }
/// <summary> /// initialize map from a dir which contains *.tdata and *.tmeta files /// </summary> /// <param name="dataDir"></param> public TDataNavigator(string[] tmetaPaths, PictureBox pbox, TextBox tbTileInfo, ComboBox cbGuessedPixelValidRanges, TextBox tbUtmCorrectionZone) { this.pbox = pbox; this.tbTileInfo = tbTileInfo; this.cbGuessedPixelValidRanges = cbGuessedPixelValidRanges; this.tbUtmCorrectionZone = tbUtmCorrectionZone; // create dataPath array tdataPaths = new string[tmetaPaths.Length]; for (int i = 0; i < tmetaPaths.Length; i++) { tdataPaths[i] = tmetaPaths[i].ToLower().Replace(".tmeta", ".tdata"); } // load all meta info levelMin = Int32.MaxValue; levelMax = 0; for (int i = 0; i < tmetaPaths.Length; i++) { using (MMetaFile metaFile = new MMetaFile(tmetaPaths[i])) { int recordCnt = metaFile.GetRecordCnt(); for (int j = 0; j < recordCnt; j++) { MSTileMetaInfo meta = metaFile.Read(j); if ((int)meta.tilexy.level < levelMin) { levelMin = (int)meta.tilexy.level; centerTilexy = new TileXY(meta.tilexy); } levelMax = Math.Max(levelMax, (int)meta.tilexy.level); tiles.Add(new TileXY(meta.tilexy), new TileMeta(meta, i)); } } } // zoom in center tile to a reasonable level while (true) { int validSonCount = 0; TileXY validSonXY = centerTilexy; foreach (TileXY txy in centerTilexy.GetSon().GetSiblings()) { if (tiles.ContainsKey(txy)) { validSonCount++; validSonXY = txy; } } if (validSonCount == 1) { centerTilexy = validSonXY; } else { break; } } // guess an initial utm correction zone double lat, lon; BingProjection.PixelXYToLatLong(centerTilexy.x * 256 + 128, centerTilexy.y * 256 + 128, (int)centerTilexy.level, out lat, out lon); tbUtmCorrectionZone.Text = Helper.LongitudeToUtmZone(lon).ToString(); Paint(); }