Example #1
0
        static void Get_TileBBox(double lat1, double lon1, double lat2, double lon2, int level)
        {
            int pixelX1, pixelY1, pixelX2, pixelY2;
            int tileX1, tileY1, tileX2, tileY2;

            TileSystem.LatLongToPixelXY(lat1, lon1, level, out pixelX1, out pixelY1);
            TileSystem.LatLongToPixelXY(lat2, lon2, level, out pixelX2, out pixelY2);
            TileSystem.PixelXYToTileXY(pixelX1, pixelY1, out tileX1, out tileY1);
            TileSystem.PixelXYToTileXY(pixelX2, pixelY2, out tileX2, out tileY2);


            TileSystem.TileXYToPixelXY(tileX1, tileY1, out pixelX1, out pixelY1);
            TileSystem.TileXYToPixelXY(tileX2 + 1, tileY2 + 1, out pixelX2, out pixelY2);


            double olat1, olon1, olat2, olon2;

            TileSystem.PixelXYToLatLong(pixelX1, pixelY1, level, out olat1, out olon1);
            TileSystem.PixelXYToLatLong(pixelX2, pixelY2, level, out olat2, out olon2);

            Console.WriteLine(olon1 + "," + olat1);
            Console.WriteLine(olon2 + "," + olat2);
        }
Example #2
0
        static void Download_sateimg(double lat1, double lon1, double lat2, double lon2, int level)
        {
            int pixelX1, pixelY1, pixelX2, pixelY2;

            Get_TileBBox(lat1, lon1, lat2, lon2, level);

            outputPath = outputPath + "_" + lat1 + "_" + lon1 + "_" + lat2 + "_" + lon2;
            if (!Directory.Exists(outputPath))
            {
                Directory.CreateDirectory(outputPath);
            }
            TileSystem.LatLongToPixelXY(lat1, lon1, level, out pixelX1, out pixelY1);
            TileSystem.LatLongToPixelXY(lat2, lon2, level, out pixelX2, out pixelY2);
            int tileX1, tileY1, tileX2, tileY2;

            TileSystem.PixelXYToTileXY(pixelX1, pixelY1, out tileX1, out tileY1);
            TileSystem.PixelXYToTileXY(pixelX2, pixelY2, out tileX2, out tileY2);

            for (int i = tileX1; i < tileX2; i++)
            {
                for (int j = tileY1; j < tileY2; j++)
                {
                    try
                    {
                        string quadKey = TileSystem.TileXYToQuadKey(i, j, level);
                        Download(quadKey);
                        int pixelX, pixelY;
                        TileSystem.TileXYToPixelXY(i, j, out pixelX, out pixelY);
                        Console.WriteLine(quadKey + " " + i + " " + j + " " + pixelX + " " + pixelY);
                    }
                    catch (Exception e)
                    {
                        Console.WriteLine(e.Message);
                    }
                }
            }
        }
Example #3
0
        static void Gen_meta(string regionname)
        {
            StreamWriter sw   = new StreamWriter(@"F:\data\" + regionname + ".txt");
            string       path = @"F:\data\" + regionname;

            string[] files = Directory.GetFiles(path, "*.jpeg");
            int      minpixelX = -1, maxpixelX = -1, minpixelY = -1, maxpixelY = -1;
            double   minlon = -1, maxlon = -1, minlat = -1, maxlat = -1;

            int level = 19;

            foreach (var file in files)
            {
                int    tileX, tileY;
                string quadKey = Path.GetFileNameWithoutExtension(file).Remove(0, 1);
                TileSystem.QuadKeyToTileXY(quadKey, out tileX, out tileY, out level);
                int    pixelX, pixelY;
                double lon, lat;
                TileSystem.TileXYToPixelXY(tileX, tileY, out pixelX, out pixelY);
                TileSystem.PixelXYToLatLong(pixelX, pixelY, level, out lat, out lon);

                if (pixelX < minpixelX || minpixelX == -1)
                {
                    minpixelX = pixelX;
                }

                if (pixelX > maxpixelX || maxpixelX == -1)
                {
                    maxpixelX = pixelX;
                }

                if (pixelY < minpixelY || minpixelY == -1)
                {
                    minpixelY = pixelY;
                }

                if (pixelY > maxpixelY || maxpixelY == -1)
                {
                    maxpixelY = pixelY;
                }

                if (lon < minlon || minlon == -1)
                {
                    minlon = lon;
                }

                if (lon > maxlon || maxlon == -1)
                {
                    maxlon = lon;
                }

                if (lat < minlat || minlat == -1)
                {
                    minlat = lat;
                }

                if (lat > maxlat || maxlat == -1)
                {
                    maxlat = lat;
                }


                sw.WriteLine(quadKey + "," + tileX + "," + tileY + "," + level + "," + pixelX + "," + pixelY + "," + lat + "," + lon);
            }
            sw.Close();

            sw = new StreamWriter(@"F:\data\" + regionname + "_meta.txt");
            sw.WriteLine(minpixelX + "," + minpixelY + "," + maxpixelX + "," + maxpixelY + "," + level);
            sw.WriteLine(minlat + "," + maxlat + "," + minlon + "," + maxlon + "," + level);
            sw.WriteLine((maxpixelX - minpixelX) + "," + (maxpixelY - minpixelY));
            sw.Close();
        }