public static void near(double price, int min, int max, double lat, double lng, int zoom, Bitmap bitmap)
        {
            int r = (int)map(price, min, max, 0, 255);
            int g = 255 - Math.Abs((int)map(price, min, max, -255, 255));
            int b = (int)map(price, min, max, 255, 0);

            r = Math.Max(Math.Min(r, 255), 0);
            g = Math.Max(Math.Min(g, 255), 0);
            b = Math.Max(Math.Min(b, 255), 0);
            Color color = Color.FromArgb(255, r, g, b);

            GlobalMercator proj = new GlobalMercator();

            int[] pixel = proj.latLngToTile(lat, lng, zoom);

            if (zoom <= 8)
            {
                bitmap.SetPixel(pixel[0], pixel[1], color);
            }
            else
            {
                double   size0 = zoom - 5.0;
                int      size  = (int)Math.Max(size0, 1);
                int      px    = (pixel[0] - (int)(size * 0.5));
                int      py    = (pixel[1] - (int)(size * 0.5));
                Graphics grf   = Graphics.FromImage(bitmap);
                Brush    brsh  = new SolidBrush(color);
                grf.FillEllipse(brsh, px, py, size, size);
                grf.Dispose();
            }
        }
        /// <summary>
        /// Tests for previous bitmap.  none == -1, blank == 0, full == 1
        /// </summary>
        /// <param name="quadTree"></param>
        /// <returns></returns>
        int previousBitmap(string quadTree)
        {
            string         dir        = @"C:\data\" + dirType + @"\images\";
            GlobalMercator projection = new GlobalMercator();

            int[] tileXYZ = projection.quadKeyToTileXY(quadTree);

            // bitmap.Save(@"C:\data\HousePricesDownload\web\images\"+tileXYZ[2]+"/"+tileXYZ[0]+"/"+tileXYZ[1]+".png");

            string pathString = dir + tileXYZ[2] + "/" + tileXYZ[0] + "/" + tileXYZ[1] + ".png";
            bool   previous   = System.IO.File.Exists(pathString);

            if (!previous)
            {
                return(-1);
            }

            bool blank = isBlank(pathString);

            if (blank)
            {
                return(0);
            }
            else
            {
                return(1);
            }
        }
        static async Task <long> queryLand(string quadTree, IMongoCollection <BsonDocument> collection)
        {
            //filters for square footage
            string         dirType = "land";
            GlobalMercator proj    = new GlobalMercator();

            int[] tileXYZ = proj.quadKeyToTileXY(quadTree);
            System.Drawing.Bitmap bitmap = new System.Drawing.Bitmap(256, 256);
            long count = 0;
            int  zoom  = quadTree.Length;

            var builder = Builders <BsonDocument> .Filter;
            var regex   = new BsonRegularExpression(string.Format("^{0}", quadTree));
            var filter  = Builders <BsonDocument> .Filter.Regex("quad", regex);

            var filterGt = Builders <BsonDocument> .Filter.Gt("sf", 0);

            filter = filter & builder.Not(filterGt);


            using (var cursor = await collection.FindAsync(filter)) {
                while (await cursor.MoveNextAsync())
                {
                    var batch = cursor.Current;
                    foreach (var doc in batch)
                    {
                        if (doc["price"].BsonType != BsonType.Int32)
                        {
                            continue;
                        }

                        double p = (double)doc["price"].AsInt32;
                        // double sf = (double) doc["sf"].AsInt32;
                        double latitude  = (double)doc["lat"].AsDouble;
                        double longitude = (double)doc["lng"].AsDouble;
                        // double ppsf = p/sf;

                        Draw.near(p, 5000, 800000, latitude, longitude, zoom, bitmap);
                        //Draw.price(ppsf, latitude, longitude, zoom, bitmap);
                        //Draw.near(ppsf, 50, 250, latitude,longitude,zoom, bitmap);
                        //Draw.near(doc["price"].AsInt32, doc["nearMin"].AsInt32, doc["nearMax"].AsInt32, doc["lat"].AsDouble, doc["lng"].AsDouble, zoom, bitmap);
                    }
                }
            }


            ////save bitmap
            string pathString = @"C:\data\" + dirType + @"\images\" + tileXYZ[2] + "/" + tileXYZ[0] + "/";

            System.IO.Directory.CreateDirectory(pathString);
            bitmap.Save(@"C:\data\" + dirType + @"\images\" + tileXYZ[2] + "/" + tileXYZ[0] + "/" + tileXYZ[1] + ".png");

            return(count);
        }
        static async Task <long> queryToBitmap3(string quadTree, IMongoCollection <BsonDocument> collection, string dirType)
        {
            GlobalMercator proj = new GlobalMercator();

            int[] tileXYZ = proj.quadKeyToTileXY(quadTree);
            System.Drawing.Bitmap bitmap = new System.Drawing.Bitmap(256, 256);
            long count = 0;
            int  zoom  = quadTree.Length;

            var builder = Builders <BsonDocument> .Filter;
            var regex   = new BsonRegularExpression(string.Format("^{0}", quadTree));
            var filter  = Builders <BsonDocument> .Filter.Regex("quad", regex);

            //filter = filter & builder.Lt("lng", bounds[3]);
            //filter = filter & builder.Exists("nearMin",true);

            filter = filter & builder.Gt("sf", 0);


            //var result = await collection.Find(filter).ToListAsync();
            using (var cursor = await collection.FindAsync(filter)) {
                while (await cursor.MoveNextAsync())
                {
                    var batch = cursor.Current;
                    foreach (var doc in batch)
                    {
                        if (doc["price"].BsonType != BsonType.Int32)
                        {
                            continue;
                        }

                        int    p         = (int)doc["price"].AsInt32;
                        double latitude  = (double)doc["lat"].AsDouble;
                        double longitude = (double)doc["lng"].AsDouble;

                        Draw.price(p, latitude, longitude, zoom, bitmap);
                        //Draw.near(doc["price"].AsInt32, doc["nearMin"].AsInt32, doc["nearMax"].AsInt32, doc["lat"].AsDouble, doc["lng"].AsDouble, zoom, bitmap);
                    }
                }
            }


            ////save bitmap
            string pathString = @"C:\data\HousePricesDownload\web\images\" + tileXYZ[2] + "/" + tileXYZ[0] + "/";

            System.IO.Directory.CreateDirectory(pathString);
            bitmap.Save(@"C:\data\HousePricesDownload\web\images\" + tileXYZ[2] + "/" + tileXYZ[0] + "/" + tileXYZ[1] + ".png");

            return(count);
        }
        void cities(IMongoCollection <BsonDocument> collection, int minZoom, int maxZoom)
        {
            GlobalMercator proj = new GlobalMercator();



            string quadDallas       = proj.latlngToQuadKey(32.7805664, -96.8081442, minZoom);
            string quadFtWorth      = proj.latlngToQuadKey(32.7586487, -97.3324023, minZoom);
            string quadHouston      = proj.latlngToQuadKey(29.758169, -95.3684179, minZoom);
            string quadLosAngeles   = proj.latlngToQuadKey(34.0507041, -118.243092, minZoom);
            string quadSanFrancisco = proj.latlngToQuadKey(37.7608648, -122.4153602, minZoom);
            string quadSeattle      = proj.latlngToQuadKey(47.6059903, -122.3292994, minZoom);
            string quadChicago      = proj.latlngToQuadKey(41.8814234, -87.6292672, minZoom);
            string quadAtlanta      = proj.latlngToQuadKey(33.7515908, -84.3858375, minZoom);
            string quadNewYork      = proj.latlngToQuadKey(40.7322625, -73.9924373, minZoom);
            string quadBoston       = proj.latlngToQuadKey(42.3742784, -71.1165778, minZoom);
            string quadDetroit      = proj.latlngToQuadKey(42.3314207, -83.0458919, minZoom);
            string quadAustin       = proj.latlngToQuadKey(30.2682476, -97.7417557, minZoom);
            string quadDC           = proj.latlngToQuadKey(38.9073708, -77.0363579, minZoom);

            List <string> quads = new List <string>();

            quads.Add(quadDallas);
            quads.Add(quadFtWorth);
            quads.Add(quadNewYork);
            quads.Add(quadHouston);
            quads.Add(quadSanFrancisco);
            quads.Add(quadLosAngeles);
            quads.Add(quadBoston);
            quads.Add(quadAustin);
            quads.Add(quadAtlanta);
            quads.Add(quadChicago);
            quads.Add(quadDC);
            quads.Add(quadSeattle);
            quads.Add(quadDetroit);



            foreach (string quad in quads)
            {
                process(quad, collection, maxZoom);
            }
        }
        void dfw(IMongoCollection <BsonDocument> collection, int minZoom, int maxZoom)
        {
            GlobalMercator proj = new GlobalMercator();



            string quadDallas  = proj.latlngToQuadKey(32.7805664, -96.8081442, minZoom);
            string quadFtWorth = proj.latlngToQuadKey(32.7586487, -97.3324023, minZoom);

            List <string> quads = new List <string>();

            quads.Add(quadDallas);
            quads.Add(quadFtWorth);


            foreach (string quad in quads)
            {
                process(quad, collection, maxZoom);
            }
        }