Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8611437
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T04:22:34+00:00 2026-06-12T04:22:34+00:00

I have some data looking like this: <?xml version=1.0 encoding=utf-8?> <levels> <level nr=0 tileWidth=512

  • 0

I have some data looking like this:

<?xml version="1.0" encoding="utf-8"?>
<levels>
  <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" />
  <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" />
  <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" />
  <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" />
  <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" />
  <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" />
  <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" />
  <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" />
  <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" />
  <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" />
  <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" />
</levels>

I have to use this data to designate tiles’ extents (minX, maxX, minY, maxY). I wrote a method that gets a level and calculates its tiles. Then it gets the tiles and chooses these which belong to a viewport area.

I thought that everything works fine, but I noticed the differences between data (when I compare GdalInfo data from metadata of TIFF file and my counted values there are some differences…

e.g.
GDAL_INFO = 465000, 465554.871466667, 109445.128533333, 110000
MY_EXTENTS = (465000, 465499.9, 105001, 105500.9)

Here’s my method:

public static IEnumerable<Envelope> GetTiles(string xmlFileName, int level, Rect viewportData, bool debug = false)
{
    // viewport data
    double x = viewportData.X, y = viewportData.Y;
    double width = viewportData.Width, height = viewportData.Height;

    // load level data
    XDocument doc = XDocument.Load(xmlFileName);
    if (doc == null)
    {
        throw new FileNotFoundException("File '" + xmlFileName + "' not found.");
    }

    XElement levelData =
        doc.Element("levels")
            .Descendants()
            .First(element => int.Parse(element.Attribute("nr").Value) == level);

    double minX = double.Parse(levelData.Attribute("minX").Value);
    double maxX = double.Parse(levelData.Attribute("maxX").Value);
    double minY = double.Parse(levelData.Attribute("minY").Value);
    double maxY = double.Parse(levelData.Attribute("maxY").Value);

    int tilesCountX = int.Parse(levelData.Attribute("tilesCountX").Value);
    int tilesCountY = int.Parse(levelData.Attribute("tilesCountY").Value);

    Envelope[][] extents = new Envelope[tilesCountX][];

    Envelope bounds = new Envelope();
    bounds.MinX = 0;
    bounds.MaxX = 0;
    bounds.MinY = 0;
    bounds.MaxY = 0;
    for (int i = 0; i < extents.Length; i++)
    {
        extents[i] = new Envelope[tilesCountY];
        for (int j = 0; j < extents[i].Length; j++)
        {
            // count extents for pieces
            double tileGeoWidth = (maxX - minX)/(double) tilesCountX;
            double tileGeoHeight = (maxY - minY)/(double) tilesCountY;
            double offsetX = (double) j*tileGeoWidth;
            double offsetY = (double) i*tileGeoHeight;

            extents[i][j] = new Envelope();
            extents[i][j].MinX = minX + offsetX;
            extents[i][j].MaxX = minX + tileGeoWidth + offsetX; // poprawic dla ostatnich (niewymiarowych) tilesow
            extents[i][j].MinY = minY + offsetY;
            extents[i][j].MaxY = minY + tileGeoHeight + offsetY;

            // check if a piece matches to the viewport
            // 1. find geo-bounds
            if (offsetX <= x)
                bounds.MinX = offsetX;
            if (offsetX <= x + width)
                bounds.MaxX = offsetX;
            if (offsetY <= y)
                bounds.MinY = offsetY;
            if (offsetY <= y + height)
                bounds.MaxY = offsetY;
        }
    }

    // 2. increase "max" bounds (+ width/height)
    bounds.MaxX += width;
    bounds.MaxY += height;

    var intersectedTiles =
        extents
        .SelectMany(es => es)
        .Where(e => EnvIntersects(e, bounds))
        .ToList();

    if (debug)
    {
        Console.WriteLine("GLOBAL_EXTENT = {0}, {1}, {2}, {3}", minX, maxX, minY, maxY);
        Console.WriteLine("TILES_COUNT = {0}/{1}", tilesCountX, tilesCountY);
        for (int i = 0; i < extents.LongLength; i++)
        {
            for (int j = 0; j < extents.Length; j++)
            {
                Console.WriteLine("EXTENTS = ({0}, {1}, {2}, {3})", extents[i][j].MinX, extents[i][j].MaxX, extents[i][j].MinY, extents[i][j].MaxY);
            }
        }
        foreach (Envelope intersectedTile in intersectedTiles)
        {
            Console.WriteLine("INTERSECTION = ({0}, {1}, {2}, {3})", intersectedTile.MinX, intersectedTile.MaxX,
                              intersectedTile.MinY, intersectedTile.MaxY);
        }
    }

    return intersectedTiles;
}

And an example call:

Rect viewportData = new Rect(100000, 200000, 70000, 50000); 
GdalRetile.GetTiles(@"D:\#PYRAMID\su60ne.xml", 1, viewportData, true);

Could anyone help me to correct this code?
Thanks in advance!

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-12T04:22:36+00:00Added an answer on June 12, 2026 at 4:22 am

    Ok. I did it my myself… Again xDDD Maybe the code will be useful for some1 in the future:)

    public static IEnumerable<Envelope> GetTiles(string xmlFileName, int level, Rect viewportData, bool debug = false)
    {
        // viewport data
        double x = viewportData.X, y = viewportData.Y;
        double width = viewportData.Width, height = viewportData.Height;
    
        // load level data
        XDocument doc = XDocument.Load(xmlFileName);
        if (doc == null)
        {
            throw new FileNotFoundException("File '" + xmlFileName + "' not found.");
        }
    
        XElement levelData =
            doc.Element("levels")
                .Descendants()
                .First(element => int.Parse(element.Attribute("nr").Value) == level);
    
        double minX = double.Parse(levelData.Attribute("minX").Value);
        double maxX = double.Parse(levelData.Attribute("maxX").Value);
        double minY = double.Parse(levelData.Attribute("minY").Value);
        double maxY = double.Parse(levelData.Attribute("maxY").Value);
    
        int tilesCountX = int.Parse(levelData.Attribute("tilesCountX").Value);
        int tilesCountY = int.Parse(levelData.Attribute("tilesCountY").Value);
    
        double scaleFactor = double.Parse(levelData.Attribute("scaleFactor").Value);
        double rasterXSize = double.Parse(levelData.Attribute("rasterXSize").Value);
        double rasterYSize = double.Parse(levelData.Attribute("rasterYSize").Value);
        double lastTileXSize = double.Parse(levelData.Attribute("lastTileXSize").Value);
        double lastTileYSize = double.Parse(levelData.Attribute("lastTileYSize").Value);
    
        Envelope[][] extents = new Envelope[tilesCountX][];
    
        Envelope bounds = new Envelope();
        bounds.MinX = 0;
        bounds.MaxX = 0;
        bounds.MinY = 0;
        bounds.MaxY = 0;
    
        double tileGeoWidth = rasterXSize * scaleFactor;
        double tileGeoHeight = rasterYSize * scaleFactor;
        for (int i = 0; i < extents.Length; i++)
        {
            double offsetY = (double) i*tileGeoHeight;
            extents[i] = new Envelope[tilesCountY];
            for (int j = 0; j < extents[i].Length; j++)
            {
                // count extents for pieces
                double offsetX = (double) j*tileGeoWidth;
    
                extents[i][j] = new Envelope();
                extents[i][j].MinX = minX + offsetX;
                extents[i][j].MinY = minY + offsetY;
                extents[i][j].MaxX = minX + tileGeoWidth + offsetX;
                extents[i][j].MaxY = minY + tileGeoHeight + offsetY;
    
                // last tiles are cut
                if (j == extents[i].Length - 1)
                {
                    extents[i][j].MaxX -= (rasterXSize - lastTileXSize);
                    extents[i][j].MinY -= (rasterYSize - lastTileYSize);
                }
    
                // check if a piece matches to the viewport
                // 1. find geo-bounds
                if (offsetX <= x)
                    bounds.MinX = offsetX;
                if (offsetX <= x + width)
                    bounds.MaxX = offsetX;
                if (offsetY <= y)
                    bounds.MinY = offsetY;
                if (offsetY <= y + height)
                    bounds.MaxY = offsetY;
            }
        }
    
        // 2. increase "max" bounds (+ width/height)
        bounds.MaxX += width;
        bounds.MaxY += height;
    
        var intersectedTiles =
            extents
            .SelectMany(es => es)
            .Where(e => EnvIntersects(e, bounds))
            .ToList();
    
        if (debug)
        {
            Console.WriteLine("GLOBAL_EXTENT = {0}, {1}, {2}, {3}", minX, maxX, minY, maxY);
            Console.WriteLine("TILES_COUNT = {0}/{1}", tilesCountX, tilesCountY);
            for (int i = 0; i < extents.LongLength; i++)
            {
                for (int j = 0; j < extents.Length; j++)
                {
                    Console.WriteLine("EXTENTS = ({0}, {1}, {2}, {3})", extents[i][j].MinX, extents[i][j].MaxX, extents[i][j].MinY, extents[i][j].MaxY);
                }
            }
            foreach (Envelope intersectedTile in intersectedTiles)
            {
                Console.WriteLine("INTERSECTION = ({0}, {1}, {2}, {3})", intersectedTile.MinX, intersectedTile.MaxX,
                                  intersectedTile.MinY, intersectedTile.MaxY);
            }
        }
    
        return intersectedTiles;
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

So I have some xml file like this: <?xml version=1.0 encoding=ISO-8859-1?> <root result=0 >
I have some XML code that looks like this <SEARCHRESULTS> <FUNCTION name=BarGraph> <PARAMETER name=numList></PARAMETER>
I have some data from log files and would like to group entries by
I have some data and need to create a json file with this structure
I have some data that I would like to visualize. Each byte of the
I have some simple data in XML format which I need to convert to
Lets suppose we have some XML like so: <a> <b> <c>text</c> <d> <e>text</e> <f>
I am currently trying to parse some xml data into an NSDictionary . This
I have some data loaded as a np.ndarray and need to convert it to
I have some data files in the resources/ folder for my Rubymotion project. How

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.