Geographic Locations of Tiles

Hello everybody, i
copied the code from the wiki to convert a tile code (x,y,zoom) into a geographic location.
Does this geographic location mark the left upper point of the tile or is it the intersection of both mid-meridians?
It is not mentioned on the wiki page :-/
Thanks in advance

upper left corner.

http://wiki.openstreetmap.org/wiki/Slippy_map_tilenames

Chris

Thanks, i must have overlooked this sentence where it says Top left… :-S
To describe the larger problem about all this:

I need to have the geographic bounding box of a set of tiles i have downloaded.
Therefor i have modified the conversion from tile code to coordinates so i can get the right upper, left lower and right lower coordinate

This is my adaption of the method displayed on the wiki page


public override Coordinate GetCoordinate(TileCode code, Tile.Corner corner)
        {
            TileCode modcode = new TileCode(code.X, code.Y, code.Z);
            switch (corner)
            {
                case Tile.Corner.BottomLeft:
                    // shift y value +1 to get the x-same but next lower tile beginning
                    modcode.Y++;
                    break;
                case Tile.Corner.BottomRight:
                    // shift x and y value +1 to get the beginning of the x-next and lower tile
                    modcode.X++;
                    modcode.Y++;
                    break;
                case Tile.Corner.TopLeft:
                    // do nothing formula fits
                    break;
                case Tile.Corner.TopRight:
                    // shift x value +1 to get the end of the tile
                    modcode.X++;
                    break;
            }
            Coordinate c = new Coordinate();
            double n = Math.PI - ((2.0 * Math.PI * modcode.Y) / Math.Pow(2.0, modcode.Z));
            c.Longitude = (modcode.X / Math.Pow(2.0, modcode.Z) * 360.0) - 180.0;
            c.Latitude = 180.0 / Math.PI * Math.Atan(Math.Sinh(n));
            return c;
        }

Now i can generate a bounding box with geographic coordinates from a list of tiles with a code


public GeographicBounds GetGeographicBounds(List<Tile> tiles)
        {
            GeographicBounds bounds = new GeographicBounds();
            foreach (Tile t in tiles)
            {
                Coordinate leftUpper = GetCoordinate(t.Code, Tile.Corner.TopLeft);
                Coordinate rightLower = GetCoordinate(t.Code, Tile.Corner.BottomRight);
                if (leftUpper.Latitude >= bounds.TopLatitude) bounds.TopLatitude = leftUpper.Latitude;
                if (rightLower.Latitude <= bounds.BottomLatitude) bounds.BottomLatitude = rightLower.Latitude;
                if (rightLower.Longitude >= bounds.RightLongitude) bounds.RightLongitude = rightLower.Longitude;
                if (leftUpper.Longitude <= bounds.LeftLongitude) bounds.LeftLongitude = leftUpper.Longitude;
            }
            return bounds;
        }

After that i continue with calculating the UTM positions of these geographics bounds.
With the utm positions i can measure the size of the large map (consists of the submitted tiles) in meters and compare it with the size in pixels to get the resolution…
But somehow the resolution does not fit when drawing a gps tracking on the map…
The region of the large map is not too large so the distortion of the tiles may not be so big that the resolution value depends on the tile size…
Do you have any idea what the mistake could be… i mean not programmatically but logically?

The Area described by the following bounds 9° <----> 10° (Longitude) and 47° <-----> 48° (Latitude) measures an area of

  • 118744m height on the left edge
  • 118742m height on the right edge
  • 78600m width on the top edge
  • 80212m width on the bottom edge

I would call this a windy rectangle, which does not match the rectangular bitmap image

Therefor it is not possible to calculate a unified resolution of meterPerPixel for the map image since it would either distort the coordinate system on the top/bottom or on the left/right side… In my opinion the problem is that every tile got its own Mercator projection and the accumulated error of lets say 20 x 20 tiles for the large image is the difference between those metric values mentioned above…

If i am wrong can someone tell me the truth, and if i am right, can someone tell me how to solve this problem? :smiley:

Thanks in advance

We did not know that UTM was involved. Please explain.

If you have a bounding box (minlat,minlon maxlat,maxlon than you know already the dimensions in m or km. You know widt and heigth in pixels of the map. Ready. So why UTM?

Is the gps tracking in utm? Which devices diliver such format? Moreover if you do not tell hou you draw we cannot help.

The resolution value depends on the lattitude.

Equal: ok.

The norther line of the square represents less distance than the southern one. Than is correct as resolution depends on lattitude. The more north the closer the lines.

Calculate 78600/cos(48) and 80212/cos(47) and see that they are about equal.

Thanks for your replies.
In the meanwhile i figured out some of the points you have mentioned. It is because the tile images are not distorted for a cartesian coordinate. They are projected using mercator so that every pixel corresponds to a longitude/latitude. I was stupid to think i could just calculate the UTM coordinates of a non UTM projected image :slight_smile:

My solution for now is, that i either use a stretching function to recalculate the difference of the UTM corner coordinates when drawing on the map image or just use longitude Latitude in the whole application without UTM coordiante systems. When measuring distances of coordinates with a strong neighbourhood one can easily use a simple formula for the distance calculation. And then i can use the tiles from OSM directly for drawing.

Conversion to UTM only seemed useful because my earlier map material was also projected graphically using an UTM system, so the distortion was also in the image information!

Thanks for your help i really got an epiphany! :slight_smile: