public static BoundingBoxQuery FromTileQuery(TileQuery query) { int tileX = query.X; int tileY = query.Y; int zoom = query.Z; int nwX; int nwY; double nwLat; double nwLon; double seLat; double seLon; BingMapsTileSystem.TileXYToPixelXY(tileX, tileY, out nwX, out nwY); BingMapsTileSystem.PixelXYToLatLong(nwX, nwY, zoom, out nwLat, out nwLon); BingMapsTileSystem.PixelXYToLatLong(nwX + 256, nwY + 256, zoom, out seLat, out seLon); BoundingBox bbox = new BoundingBox(nwLon, seLat, seLon, nwLat); return (new BoundingBoxQuery() { BBox = bbox, _querytables = query._querytables, Width = 256, Height = 256, SRID = 4326, IsBench = query.IsBench }); }
public Bitmap GetImage(TileQuery query) { int tileX = query.X; int tileY = query.Y; int zoom = query.Z; int nwX; int nwY; double nwLat; double nwLon; double seLat; double seLon; BingMapsTileSystem.TileXYToPixelXY(tileX, tileY, out nwX, out nwY); BingMapsTileSystem.PixelXYToLatLong(nwX, nwY, zoom, out nwLat, out nwLon); BingMapsTileSystem.PixelXYToLatLong(nwX + 256, nwY + 256, zoom, out seLat, out seLon); double res = BingMapsTileSystem.GroundResolution(seLat + (nwLat - seLat) / 2d, zoom); int numDigits = BingMapsTileSystem.UsefulDigits(res); BoundingBox bbox = new BoundingBox(nwLon, seLat, seLon, nwLat); return(GetImage( new BoundingBoxQuery() { BBox = bbox, _querytables = query._querytables, Width = 256, Height = 256, SRID = 4326, IsBench = query.IsBench } )); }
public static BoundingBoxQuery FromBingTileQuery(BingTileQuery query) { int tileX, tileY, zoom, nwX, nwY; double nwLat, nwLon, seLat, seLon; BingMapsTileSystem.QuadKeyToTileXY(query.quadKey, out tileX, out tileY, out zoom); BingMapsTileSystem.TileXYToPixelXY(tileX, tileY, out nwX, out nwY); BingMapsTileSystem.PixelXYToLatLong(nwX, nwY, zoom, out nwLat, out nwLon); BingMapsTileSystem.PixelXYToLatLong(nwX + 256, nwY + 256, zoom, out seLat, out seLon); BoundingBox bbox = new BoundingBox(nwLon, seLat, seLon, nwLat); return(new BoundingBoxQuery() { BBox = bbox, _querytables = query._querytables, Width = 256, Height = 256, SRID = 4326, IsBench = query.IsBench, FillColor = query.FillColor, StrokeColor = query.StrokeColor, strokeThickness = query.strokeThickness }); }
public string GetTileFilePath(string quadKey) { int tileX, tileY, zoom; BingMapsTileSystem.QuadKeyToTileXY(quadKey, out tileX, out tileY, out zoom); return(GetTileFilePath(zoom, tileX, tileY)); }
private void GenerateTile(BackgroundWorker worker, int zoomLevel, int tileX, int tileY) { string quadKey = BingMapsTileSystem.TileXYToQuadKey(tileX, tileY, zoomLevel); if (this.IsParentTileEmpty(quadKey)) { Interlocked.Increment(ref _numTilesSkipped); } else { BingTileQuery query = this.CreateQuery(quadKey, _tableName, enDiskCacheMode.ReadWrite); Bitmap bmp = _svc.GetImage(query); bool isEmpty = bmp.Tag != null; if (isEmpty) { _emptyQuadKeys.Add(quadKey); Interlocked.Increment(ref _numTilesEmpty); } else { //_rasterFS.SaveTileBitmap(bmp, ImageFormat.Png, zoomLevel, tileX, tileY); //bmp.Dispose(); Interlocked.Increment(ref _numTiles); } } }
public static bool ZoomDirectoryExists(string quadKey, string databaseName, string tableName) { int tileX, tileY, zoom; BingMapsTileSystem.QuadKeyToTileXY(quadKey, out tileX, out tileY, out zoom); return(Directory.Exists(Path.Combine(RasterFileSystem.GetOutputDirFromAppSettings(), databaseName, tableName, tableName + "-" + zoom.ToString()))); }
public static string GetTileFilePath(string quadKey, string databaseName, string tableName) { int tileX, tileY, zoom; BingMapsTileSystem.QuadKeyToTileXY(quadKey, out tileX, out tileY, out zoom); return(Path.Combine(RasterFileSystem.GetOutputDirFromAppSettings(), databaseName, tableName, tableName + "-" + zoom.ToString(), tileX.ToString(), tileY.ToString() + ".png")); }
public PointF GeoToLogical(Matrix matrix, PointF pt) { double px, py = 0; BingMapsTileSystem.LatLongToDoubleXY(pt.Y, pt.X, out px, out py); pt.X = (float)px; pt.Y = (float)py; var points = new PointF[] { pt }; matrix.TransformPoints(points); return(points.First()); }
public static SqlGeometry ReprojectGeometryToMercator(SqlGeometry geom, int zoomLevel) { //SqlGeometry testDotSpatial = geom.ReprojectTo(DotSpatial.Projections.KnownCoordinateSystems.Projected.World.Mercatorworld); return(SqlGeometryProjectionSink.ReprojectGeometry(geom, geom.STSrid.Value, new Func <double, double, double[]>((x, y) => { double projX = 0; double projY = 0; BingMapsTileSystem.LatLongToDoubleXY(y, x, out projX, out projY); //System.Diagnostics.Trace.TraceInformation("X: {0} / Y: {1}", projX, projY); return new double[] { projX, projY }; }))); }
public string GetGeoJson(BingTileQuery query) { int tileX, tileY, zoom; Metrics metrics = new Metrics(this._metricsType); metrics.Start("Global"); BoundingBoxQuery bboxQuery = BoundingBoxQuery.FromBingTileQuery(query); // Get tile coordinates BingMapsTileSystem.QuadKeyToTileXY(query.quadKey, out tileX, out tileY, out zoom); Queue <string> geoJsonQueue = new Queue <string>(); foreach (string table in query.Tables()) { string geojson = null; //bool foundInCache = false; //if (query.CacheMode != enDiskCacheMode.None) //{ // // If cacheMode is Read, see if image exists on disk // bmp = this.LoadTileFromDisc(tileX, tileY, zoom, table); // foundInCache = bmp != null; //} if (geojson == null) { DateTime start = DateTime.Now; geojson = GetGeoJson_BBox(bboxQuery, metrics, table); } //// Save to disc if image not empty and cacheMode is ReadWrite //if (query.CacheMode == enDiskCacheMode.ReadWrite // && !foundInCache // && bmp != null // && bmp.Tag == null) // this.SaveTileToDisc(tileX, tileY, zoom, table, bmp); geoJsonQueue.Enqueue(geojson); } return(geoJsonQueue.Dequeue()); }
private void GenerateTileSet4Zoom(BackgroundWorker worker, int zoomLevel) { double numTiles = BingMapsTileSystem.MapSize(zoomLevel) / 256; for (int x = 0; x < numTiles; x++) { for (int y = 0; y < numTiles; y++) { GenerateTile(worker, zoomLevel, x, y); if (worker.CancellationPending) { return; } } worker.ReportProgress(0, new TileWorkerEventArgs(_numTiles, _numTilesEmpty, _numTilesSkipped)); } }
public GeoJsonResult GetGeoJsonData(BingTileQuery query) { int tileX; int tileY; int zoom; int nwX; int nwY; double nwLat; double nwLon; double seLat; double seLon; BingMapsTileSystem.QuadKeyToTileXY(query.quadKey, out tileX, out tileY, out zoom); BingMapsTileSystem.TileXYToPixelXY(tileX, tileY, out nwX, out nwY); BingMapsTileSystem.PixelXYToLatLong(nwX, nwY, zoom, out nwLat, out nwLon); BingMapsTileSystem.PixelXYToLatLong(nwX + 256, nwY + 256, zoom, out seLat, out seLon); double res = BingMapsTileSystem.GroundResolution(seLat + (nwLat - seLat) / 2d, zoom); int numDigits = BingMapsTileSystem.UsefulDigits(res); object bbox = null; if (useGeography) { bbox = SqlServerModel.GeograhyFromBoundingBoxNwSe(nwLat, nwLon, seLat, seLon, 4326); } else { bbox = SqlServerModel.GeometryFromBoundingBoxNwSe(nwLat, nwLon, seLat, seLon, 4326); } return(GetGeoJsonData( new BoundingBoxQuery() { useGeography = useGeography, Box = bbox, Resolution = res, NumDigits = numDigits, Tables = query.Tables } )); }
public Bitmap GetImage(BingTileQuery query) { int tileX, tileY, zoom; Metrics metrics = new Metrics(this._metricsType); metrics.Start("Global"); BoundingBoxQuery bboxQuery = BoundingBoxQuery.FromBingTileQuery(query); // Get tile coordinates BingMapsTileSystem.QuadKeyToTileXY(query.quadKey, out tileX, out tileY, out zoom); Queue <Bitmap> bmpQueue = new Queue <Bitmap>(); foreach (string table in query.Tables()) { Bitmap bmp = null; bool foundInCache = false; if (query.CacheMode != enDiskCacheMode.None) { // If cacheMode is Read, see if image exists on disk bmp = this.LoadTileFromDisc(tileX, tileY, zoom, table); foundInCache = bmp != null; } if (bmp == null) { DateTime start = DateTime.Now; if (bboxQuery.IsBench) { bmp = GetBenchImageGeneric(bboxQuery, metrics, table, UseInMemoryCache); } else { //string test = GetGeoJson_BBox(bboxQuery, metrics, table); bmp = GetImage_BBox(bboxQuery, metrics, table); } //else // bmp = GetImageGeneric_FromDB(bboxQuery, metrics, table, false); } // Save to disc if image not empty and cacheMode is ReadWrite if (query.CacheMode == enDiskCacheMode.ReadWrite && !foundInCache && bmp != null && bmp.Tag == null) { this.SaveTileToDisc(tileX, tileY, zoom, table, bmp); } bmpQueue.Enqueue(bmp); } metrics.Stop("Global"); if (bmpQueue.Count <= 1) { Bitmap bmpOut = bmpQueue.Dequeue(); #region Calculate metrics to return. // Calculate metrics to return. switch (_metricsType) { case enMetricsType.OnlyTime: string msg = string.Empty; foreach (var kv in metrics.GetTaskTimes()) { msg += string.Format("{0}: {1,6:###,###} ms{2}", kv.Key, kv.Value.TotalMilliseconds, Environment.NewLine); } this.DrawMsgInImage(ref bmpOut, msg); break; default: break; } #endregion return(bmpOut); } else { Bitmap outBmp = bmpQueue.Dequeue(); using (Graphics g = Graphics.FromImage(outBmp)) { do { Bitmap curBmp = bmpQueue.Dequeue(); if (curBmp.Tag != null) { outBmp.Tag = curBmp.Tag; } g.DrawImageUnscaled(curBmp, 0, 0); curBmp.Dispose(); }while (bmpQueue.Count > 0); } return(outBmp); } }
private List <GeoBitmap> GetImageTiles(Matrix matrix) { List <GeoBitmap> v_ret = new List <GeoBitmap>(); BoundingBox viewBounds = GetViewBounds(matrix); double[] hgLog = LogicalToGeoLatLon(viewBounds.XMin, viewBounds.YMax); double[] bdLog = LogicalToGeoLatLon(viewBounds.XMax, viewBounds.YMin); BoundingBox viewPortBbox = new BoundingBox(hgLog[0], bdLog[0] , bdLog[1], hgLog[1]); BoundingBox bbox = matrix.Transform(_geomBBox); // Get current zoom level double mapSizeAtCurrentZoom = 1d * bbox.Width / _geomBBox.Width; int zoom = 0; uint size = 0; while (size <= mapSizeAtCurrentZoom) { zoom++; if (zoom == 24) { break; } size = BingMapsTileSystem.MapSize(zoom); } // At viewport zoom, what tile size is it ? double tileSizeAtZoom = 256 * mapSizeAtCurrentZoom / size; Trace.TraceInformation("tileSizeAtZoom: " + tileSizeAtZoom.ToString()); if (tileSizeAtZoom < 256 && !_baseLayer.UseLowResTiles) { Trace.TraceWarning("Error in zoom calculation, tile size should be <256 but it is " + tileSizeAtZoom); } bool bTakeLowerDef = tileSizeAtZoom < 400;// _baseLayer.UseLowResTiles; if (bTakeLowerDef) { zoom--; size = BingMapsTileSystem.MapSize(zoom); } // Contruct image list int startX, startY, endX, endY = 0; int tileStartX, tileStartY, tileEndX, tileEndY = 0; BingMapsTileSystem.LatLongToPixelXY(viewPortBbox.YMax, viewPortBbox.XMin, zoom, out startX, out startY); BingMapsTileSystem.LatLongToPixelXY(viewPortBbox.YMin, viewPortBbox.XMax, zoom, out endX, out endY); BingMapsTileSystem.PixelXYToTileXY(startX, startY, out tileStartX, out tileStartY); BingMapsTileSystem.PixelXYToTileXY(endX, endY, out tileEndX, out tileEndY); bool stop = false; for (int x = tileStartX; x <= tileEndX; x++) { for (int y = tileStartY; y <= tileEndY; y++) { if (stop) { break; } //GeoBitmap geoBmp = await _tileDownloader.DownloadTileAsync(zoom, x, y, _baseLayer); GeoBitmap geoBmp = _tileDownloader.DownloadTile(zoom, x, y, _baseLayer); stop = geoBmp != null && geoBmp.Exception != null && _baseLayer.StopDownloadBatchIfException; if (!stop) { v_ret.Add(geoBmp); } } if (stop) { break; } } return(v_ret); }
public string GetTileFilePath(int zoomLevel, int tileX, int tileY) { string quadKey = BingMapsTileSystem.TileXYToQuadKey(tileX, tileY, zoomLevel); return(Path.Combine(_outputDir, _tableName + "-" + zoomLevel.ToString(), tileX.ToString(), tileY.ToString() + ".png")); }