0

I use gdal2tiles to create tiles from a referenced image (with profile parameter set to "raster"). Then I use Proj4Leaflet to display the results. In order to do that I need to specify parameters of CRS such as resoultions, bounds and origin. After processing i get tilemapresource.xml that seems to contain all the information needed:

<?xml version="1.0" encoding="utf-8"?>
<TileMap version="1.0.0" tilemapservice="http://tms.osgeo.org/1.0.0">
  <Title>OUTPUT.tif</Title>
  <Abstract></Abstract>
  <SRS>+proj=aeqd +lat_0=90 +lon_0=0 +x_0=0 +y_0=0 +datum=WGS84 +units=m +no_defs</SRS>
  <BoundingBox minx="4081867.72157528297976" miny="-2321600.04517470393330" maxx="6014219.16503371112049" maxy="477065.79241934354650"/>
  <Origin x="4081867.72157528297976" y="-2321600.04517470393330"/>
  <TileFormat width="256" height="256" mime-type="image/png" extension="png"/>
  <TileSets profile="raster">
    <TileSet href="0" units-per-pixel="14828.59620879369504" order="0"/>
    <TileSet href="1" units-per-pixel="7414.29810439684752" order="1"/>
    <TileSet href="2" units-per-pixel="3707.14905219842376" order="2"/>
    <TileSet href="3" units-per-pixel="1853.57452609921188" order="3"/>
    <TileSet href="4" units-per-pixel="926.78726304960594" order="4"/>
    <TileSet href="5" units-per-pixel="463.39363152480297" order="5"/>
    <TileSet href="6" units-per-pixel="231.69681576240149" order="6"/>
  </TileSets>
</TileMap>

Assuming

  • origin = XML.Origin
  • resolutions = XML.untis-per-pixel array
  • bounds = XML.BoundingBox

I get correct Leaflet map - image sits where it should, coordinates returned by events are correct as well.

But bounds parameter actually stands for "Bounds of the CRS, in projected coordinates" according to the documentation (https://kartena.github.io/Proj4Leaflet/api/#l-proj-crs). And BoundingBox attribute in the .xml shows bounds of the tile layer, but not the whole CRS.

Docs and many tutorials also set resolutions parameter as array [... 2^(n+3), 2^(n+2), 2^(n+1), 2^n].

resolutions: [8192, 4096, 2048] // from the docs

However resolutions in the .xml file are never 2^n. Again, using them is fine as the result is correct.

I would be really grateful for some explanation of such behaviour:

  1. Why resolutions of zoom levels are usually set to 2^n while in fact they are equal to some random numbers?
  2. Should I really use extent of the image as bounds (extent of the CRS)?

Thanks in advance for your answer!

  • Have you tried using bounding box coordinates for CRS bounds, origin for CRS origin and resolutions for CRS resolutions? What was the result? – TomazicM Mar 18 at 13:25
  • So if it work's (as it should), please reformulate the entire question so that it will be clear that it works as expected and since you think it shouldn't, ask for explanation. – TomazicM Mar 18 at 14:03
1

Question is in a way similar to my first ever GIS question 2 years ago (see Tile names & coordinates relationship) when I had 0.00 knowledge about GIS. I'll try to answer on the basis of what I have learned till then.

gdal2tiles creates so called pyramid tile scheme. At zoom 0 the whole projected map image (map extent) is converted to one tile image of usually 256 x 256 pixels size. Map extent can be the whole world, single country or whatever area. Since tile is square, map area is also square. Here we come to the concept of resolution. If map area (extent) has size of D x D of projected map meters, then resolution is number of map meters covered by one pixel. At zoom level 0 there is only one tile, so formula for resolution at zoom 0 is: R = D / 256. Since map area (extent) can be of any size, this means that resolution can be decimal value, there is no need for it to be power of 2.

At zoom level 1 there are 4 equal tiles (2x2) covering map extent, at zoom level 2 there are 16 equal tiles (4x4) and so on. Generally at zoom level z there are 2z rows and columns of tiles. Since number of tiles in a row/column doubles with each higher zoom, as a consequence resolution at each zoom level is resolution of previous level divided by 2.

When defining projection with Proj4Leaflet plugin, only two things area necessary:

  1. Map tile area (extent) origin, so tiles can be placed at the right coordinates.
  2. Resolutions for all zooms, so that relation between projected map meters and map pixels can be known, and as a consequence coordinates of each pixel on screen can be derived.

What about specifying extent when defining projection? It's not necessary, but it tells Leaflet not to request nonexisting tiles outside extent bounds, so it should be specified also. If it's not specified in projection definition, it can be specified later with tile layer bounds option.

|improve this answer|||||
  • Clear enough.Thanks) – D.Moiseev Mar 19 at 10:41

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.