daily pastebin goal
64%
SHARE
TWEET

Untitled

a guest Jan 18th, 2019 66 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. <?xml version="1.0" encoding="utf-8"?>
  2. <levels>
  3.   <level nr="0" tileWidth="512" tileHeight="512" envSizeX="5000" envSizeY="5000" minX="465000" maxX="470000" minY="105000" maxY="110000" scaleFactor="1" tilesCountX="10" tilesCountY="10" />
  4.   <level nr="1" tileWidth="512" tileHeight="512" envSizeX="4613" envSizeY="4613" minX="465000" maxX="469999" minY="105001" maxY="110000" scaleFactor="1.0837333333333332" tilesCountX="10" tilesCountY="10" />
  5.   <level nr="2" tileWidth="512" tileHeight="512" envSizeX="2286" envSizeY="2286" minX="465000" maxX="469955" minY="105045" maxY="110000" scaleFactor="2.1674666666666664" tilesCountX="5" tilesCountY="5" />
  6.   <level nr="3" tileWidth="512" tileHeight="512" envSizeX="1134" envSizeY="1134" minX="465000" maxX="469915" minY="105085" maxY="110000" scaleFactor="4.3349333333333329" tilesCountX="3" tilesCountY="3" />
  7.   <level nr="4" tileWidth="512" tileHeight="512" envSizeX="563" envSizeY="563" minX="465000" maxX="469879" minY="105121" maxY="110000" scaleFactor="8.6698666666666657" tilesCountX="2" tilesCountY="2" />
  8.   <level nr="5" tileWidth="512" tileHeight="512" envSizeX="275" envSizeY="275" minX="465000" maxX="469777" minY="105223" maxY="110000" scaleFactor="17.339733333333331" tilesCountX="1" tilesCountY="1" />
  9.   <level nr="6" tileWidth="512" tileHeight="512" envSizeX="134" envSizeY="134" minX="465000" maxX="469658" minY="105342" maxY="110000" scaleFactor="34.679466666666663" tilesCountX="1" tilesCountY="1" />
  10.   <level nr="7" tileWidth="512" tileHeight="512" envSizeX="67" envSizeY="67" minX="465000" maxX="469623" minY="105377" maxY="110000" scaleFactor="69.358933333333326" tilesCountX="1" tilesCountY="1" />
  11.   <level nr="8" tileWidth="512" tileHeight="512" envSizeX="33" envSizeY="33" minX="465000" maxX="469554" minY="105446" maxY="110000" scaleFactor="138.71786666666665" tilesCountX="1" tilesCountY="1" />
  12.   <level nr="9" tileWidth="512" tileHeight="512" envSizeX="16" envSizeY="16" minX="465000" maxX="469432" minY="105568" maxY="110000" scaleFactor="277.4357333333333" tilesCountX="1" tilesCountY="1" />
  13.   <level nr="10" tileWidth="512" tileHeight="512" envSizeX="8" envSizeY="8" minX="465000" maxX="469432" minY="105568" maxY="110000" scaleFactor="554.87146666666661" tilesCountX="1" tilesCountY="1" />
  14. </levels>
  15.    
  16. public static IEnumerable<Envelope> GetTiles(string xmlFileName, int level, Rect viewportData, bool debug = false)
  17. {
  18.     // viewport data
  19.     double x = viewportData.X, y = viewportData.Y;
  20.     double width = viewportData.Width, height = viewportData.Height;
  21.  
  22.     // load level data
  23.     XDocument doc = XDocument.Load(xmlFileName);
  24.     if (doc == null)
  25.     {
  26.         throw new FileNotFoundException("File '" + xmlFileName + "' not found.");
  27.     }
  28.  
  29.     XElement levelData =
  30.         doc.Element("levels")
  31.             .Descendants()
  32.             .First(element => int.Parse(element.Attribute("nr").Value) == level);
  33.  
  34.     double minX = double.Parse(levelData.Attribute("minX").Value);
  35.     double maxX = double.Parse(levelData.Attribute("maxX").Value);
  36.     double minY = double.Parse(levelData.Attribute("minY").Value);
  37.     double maxY = double.Parse(levelData.Attribute("maxY").Value);
  38.  
  39.     int tilesCountX = int.Parse(levelData.Attribute("tilesCountX").Value);
  40.     int tilesCountY = int.Parse(levelData.Attribute("tilesCountY").Value);
  41.  
  42.     Envelope[][] extents = new Envelope[tilesCountX][];
  43.  
  44.     Envelope bounds = new Envelope();
  45.     bounds.MinX = 0;
  46.     bounds.MaxX = 0;
  47.     bounds.MinY = 0;
  48.     bounds.MaxY = 0;
  49.     for (int i = 0; i < extents.Length; i++)
  50.     {
  51.         extents[i] = new Envelope[tilesCountY];
  52.         for (int j = 0; j < extents[i].Length; j++)
  53.         {
  54.             // count extents for pieces
  55.             double tileGeoWidth = (maxX - minX)/(double) tilesCountX;
  56.             double tileGeoHeight = (maxY - minY)/(double) tilesCountY;
  57.             double offsetX = (double) j*tileGeoWidth;
  58.             double offsetY = (double) i*tileGeoHeight;
  59.  
  60.             extents[i][j] = new Envelope();
  61.             extents[i][j].MinX = minX + offsetX;
  62.             extents[i][j].MaxX = minX + tileGeoWidth + offsetX; // poprawic dla ostatnich (niewymiarowych) tilesow
  63.             extents[i][j].MinY = minY + offsetY;
  64.             extents[i][j].MaxY = minY + tileGeoHeight + offsetY;
  65.  
  66.             // check if a piece matches to the viewport
  67.             // 1. find geo-bounds
  68.             if (offsetX <= x)
  69.                 bounds.MinX = offsetX;
  70.             if (offsetX <= x + width)
  71.                 bounds.MaxX = offsetX;
  72.             if (offsetY <= y)
  73.                 bounds.MinY = offsetY;
  74.             if (offsetY <= y + height)
  75.                 bounds.MaxY = offsetY;
  76.         }
  77.     }
  78.  
  79.     // 2. increase "max" bounds (+ width/height)
  80.     bounds.MaxX += width;
  81.     bounds.MaxY += height;
  82.  
  83.     var intersectedTiles =
  84.         extents
  85.         .SelectMany(es => es)
  86.         .Where(e => EnvIntersects(e, bounds))
  87.         .ToList();
  88.  
  89.     if (debug)
  90.     {
  91.         Console.WriteLine("GLOBAL_EXTENT = {0}, {1}, {2}, {3}", minX, maxX, minY, maxY);
  92.         Console.WriteLine("TILES_COUNT = {0}/{1}", tilesCountX, tilesCountY);
  93.         for (int i = 0; i < extents.LongLength; i++)
  94.         {
  95.             for (int j = 0; j < extents.Length; j++)
  96.             {
  97.                 Console.WriteLine("EXTENTS = ({0}, {1}, {2}, {3})", extents[i][j].MinX, extents[i][j].MaxX, extents[i][j].MinY, extents[i][j].MaxY);
  98.             }
  99.         }
  100.         foreach (Envelope intersectedTile in intersectedTiles)
  101.         {
  102.             Console.WriteLine("INTERSECTION = ({0}, {1}, {2}, {3})", intersectedTile.MinX, intersectedTile.MaxX,
  103.                               intersectedTile.MinY, intersectedTile.MaxY);
  104.         }
  105.     }
  106.  
  107.     return intersectedTiles;
  108. }
  109.    
  110. Rect viewportData = new Rect(100000, 200000, 70000, 50000);
  111. GdalRetile.GetTiles(@"D:#PYRAMIDsu60ne.xml", 1, viewportData, true);
  112.    
  113. public static IEnumerable<Envelope> GetTiles(string xmlFileName, int level, Rect viewportData, bool debug = false)
  114. {
  115.     // viewport data
  116.     double x = viewportData.X, y = viewportData.Y;
  117.     double width = viewportData.Width, height = viewportData.Height;
  118.  
  119.     // load level data
  120.     XDocument doc = XDocument.Load(xmlFileName);
  121.     if (doc == null)
  122.     {
  123.         throw new FileNotFoundException("File '" + xmlFileName + "' not found.");
  124.     }
  125.  
  126.     XElement levelData =
  127.         doc.Element("levels")
  128.             .Descendants()
  129.             .First(element => int.Parse(element.Attribute("nr").Value) == level);
  130.  
  131.     double minX = double.Parse(levelData.Attribute("minX").Value);
  132.     double maxX = double.Parse(levelData.Attribute("maxX").Value);
  133.     double minY = double.Parse(levelData.Attribute("minY").Value);
  134.     double maxY = double.Parse(levelData.Attribute("maxY").Value);
  135.  
  136.     int tilesCountX = int.Parse(levelData.Attribute("tilesCountX").Value);
  137.     int tilesCountY = int.Parse(levelData.Attribute("tilesCountY").Value);
  138.  
  139.     double scaleFactor = double.Parse(levelData.Attribute("scaleFactor").Value);
  140.     double rasterXSize = double.Parse(levelData.Attribute("rasterXSize").Value);
  141.     double rasterYSize = double.Parse(levelData.Attribute("rasterYSize").Value);
  142.     double lastTileXSize = double.Parse(levelData.Attribute("lastTileXSize").Value);
  143.     double lastTileYSize = double.Parse(levelData.Attribute("lastTileYSize").Value);
  144.  
  145.     Envelope[][] extents = new Envelope[tilesCountX][];
  146.  
  147.     Envelope bounds = new Envelope();
  148.     bounds.MinX = 0;
  149.     bounds.MaxX = 0;
  150.     bounds.MinY = 0;
  151.     bounds.MaxY = 0;
  152.  
  153.     double tileGeoWidth = rasterXSize * scaleFactor;
  154.     double tileGeoHeight = rasterYSize * scaleFactor;
  155.     for (int i = 0; i < extents.Length; i++)
  156.     {
  157.         double offsetY = (double) i*tileGeoHeight;
  158.         extents[i] = new Envelope[tilesCountY];
  159.         for (int j = 0; j < extents[i].Length; j++)
  160.         {
  161.             // count extents for pieces
  162.             double offsetX = (double) j*tileGeoWidth;
  163.  
  164.             extents[i][j] = new Envelope();
  165.             extents[i][j].MinX = minX + offsetX;
  166.             extents[i][j].MinY = minY + offsetY;
  167.             extents[i][j].MaxX = minX + tileGeoWidth + offsetX;
  168.             extents[i][j].MaxY = minY + tileGeoHeight + offsetY;
  169.  
  170.             // last tiles are cut
  171.             if (j == extents[i].Length - 1)
  172.             {
  173.                 extents[i][j].MaxX -= (rasterXSize - lastTileXSize);
  174.                 extents[i][j].MinY -= (rasterYSize - lastTileYSize);
  175.             }
  176.  
  177.             // check if a piece matches to the viewport
  178.             // 1. find geo-bounds
  179.             if (offsetX <= x)
  180.                 bounds.MinX = offsetX;
  181.             if (offsetX <= x + width)
  182.                 bounds.MaxX = offsetX;
  183.             if (offsetY <= y)
  184.                 bounds.MinY = offsetY;
  185.             if (offsetY <= y + height)
  186.                 bounds.MaxY = offsetY;
  187.         }
  188.     }
  189.  
  190.     // 2. increase "max" bounds (+ width/height)
  191.     bounds.MaxX += width;
  192.     bounds.MaxY += height;
  193.  
  194.     var intersectedTiles =
  195.         extents
  196.         .SelectMany(es => es)
  197.         .Where(e => EnvIntersects(e, bounds))
  198.         .ToList();
  199.  
  200.     if (debug)
  201.     {
  202.         Console.WriteLine("GLOBAL_EXTENT = {0}, {1}, {2}, {3}", minX, maxX, minY, maxY);
  203.         Console.WriteLine("TILES_COUNT = {0}/{1}", tilesCountX, tilesCountY);
  204.         for (int i = 0; i < extents.LongLength; i++)
  205.         {
  206.             for (int j = 0; j < extents.Length; j++)
  207.             {
  208.                 Console.WriteLine("EXTENTS = ({0}, {1}, {2}, {3})", extents[i][j].MinX, extents[i][j].MaxX, extents[i][j].MinY, extents[i][j].MaxY);
  209.             }
  210.         }
  211.         foreach (Envelope intersectedTile in intersectedTiles)
  212.         {
  213.             Console.WriteLine("INTERSECTION = ({0}, {1}, {2}, {3})", intersectedTile.MinX, intersectedTile.MaxX,
  214.                               intersectedTile.MinY, intersectedTile.MaxY);
  215.         }
  216.     }
  217.  
  218.     return intersectedTiles;
  219. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top