[GIS] Mapserver, TMS, Scales zoom levels and how to deal with all of it

coordinate systemmapserverscaletilecache

I have a whole bunch of data in my db that I need to draw at different zoom levels using Mapserver. Everything uses a 4326 SRID. My (custom) client, will fetch the data using 20 TMS zoom levels and images of 256×256 pixels.

In fact, for every zoom level, these are the units-per-pixel that every zoom level uses:

<TileMap version="1.0.0" tilemapservice="http://myserver.com/cgi-bin/tilecache.cgi/1.0.0/">
<!-- Additional data: tms_type is default -->
<Title>myimagery</Title>
<Abstract/>
<SRS>EPSG:4326</SRS>
<BoundingBox minx="-180.000000" miny="-90.000000" maxx="180.000000" maxy="90.000000"/>
<Origin x="-180.000000" y="-90.000000"/>
<TileFormat width="256" height="256" mime-type="image/png" extension="png"/>
<TileSets>
  <TileSet href="http://myserver.com/1.0.0/myimagery/0" units-per-pixel="0.70312500000000000000" order="0"/>
  <TileSet href="http://myserver.com/1.0.0/myimagery/1" units-per-pixel="0.35156250000000000000" order="1"/>
  <TileSet href="http://myserver.com/cgi-bin/tilecache.cgi/1.0.0/myimagery/2" units-per-pixel="0.17578125000000000000" order="2"/>
  <TileSet href="http://myserver.com/cgi-bin/tilecache.cgi/1.0.0/myimagery/3" units-per-pixel="0.08789062500000000000" order="3"/>
  <TileSet href="http://myserver.com/cgi-bin/tilecache.cgi/1.0.0/myimagery/4" units-per-pixel="0.04394531250000000000" order="4"/>
  <TileSet href="http://myserver.com/cgi-bin/tilecache.cgi/1.0.0/myimagery/5" units-per-pixel="0.02197265625000000000" order="5"/>
  <TileSet href="http://myserver.com/cgi-bin/tilecache.cgi/1.0.0/myimagery/6" units-per-pixel="0.01098632812500000000" order="6"/>
  <TileSet href="http://myserver.com/cgi-bin/tilecache.cgi/1.0.0/myimagery/7" units-per-pixel="0.00549316406250000000" order="7"/>
  <TileSet href="http://myserver.com/cgi-bin/tilecache.cgi/1.0.0/myimagery/8" units-per-pixel="0.00274658203125000000" order="8"/>
  <TileSet href="http://myserver.com/cgi-bin/tilecache.cgi/1.0.0/myimagery/9" units-per-pixel="0.00137329101562500000" order="9"/>
  <TileSet href="http://myserver.com/cgi-bin/tilecache.cgi/1.0.0/myimagery/10" units-per-pixel="0.00068664550781250000" order="10"/>
  <TileSet href="http://myserver.com/cgi-bin/tilecache.cgi/1.0.0/myimagery/11" units-per-pixel="0.00034332275390625000" order="11"/>
  <TileSet href="http://myserver.com/cgi-bin/tilecache.cgi/1.0.0/myimagery/12" units-per-pixel="0.00017166137695312500" order="12"/>
  <TileSet href="http://myserver.com/cgi-bin/tilecache.cgi/1.0.0/myimagery/13" units-per-pixel="0.00008583068847656250" order="13"/>
  <TileSet href="http://myserver.com/cgi-bin/tilecache.cgi/1.0.0/myimagery/14" units-per-pixel="0.00004291534423828125" order="14"/>
  <TileSet href="http://myserver.com/cgi-bin/tilecache.cgi/1.0.0/myimagery/15" units-per-pixel="0.00002145767211914062" order="15"/>
  <TileSet href="http://myserver.com/cgi-bin/tilecache.cgi/1.0.0/myimagery/16" units-per-pixel="0.00001072883605957031" order="16"/>
  <TileSet href="http://myserver.com/cgi-bin/tilecache.cgi/1.0.0/myimagery/17" units-per-pixel="0.00000536441802978516" order="17"/>
  <TileSet href="http://myserver.com/cgi-bin/tilecache.cgi/1.0.0/myimagery/18" units-per-pixel="0.00000268220901489258" order="18"/>
  <TileSet href="http://myserver.com/cgi-bin/tilecache.cgi/1.0.0/myimagery/19" units-per-pixel="0.00000134110450744629" order="19"/>
 </TileSets>
</TileMap>

I am aware that, depending on the projection I use, true scale changes differently. Some people have even produced scale tables for WGS84 at different latitudes for 72DPI output, which is very helpful to answer this question… so the question is:

How are people dealing with this problem when they want to guarantee that some data is only drawn at a particular zoom level? This seems like such a basic question, but I am honestly curious. I guess I could arbitrarily pick MAXSCALEDENOM and MINSCALEDENOM scale values that are half way between the zoom levels.

So using the table above, to guarantee that something should draw on level 13, but not level 14, I could say 1:40500, or * MAXSCALEDENOM 40500*. Is this right? It seems hacky 🙁

Best Answer

While I can't speak for others, I use Geoserver and had much the same question when I started. Unfortunately, I didn't find a particularly nice feeling solution to it either.

I used the Sld file to put in max and min zoom scales. Same as what you have mentioned as seeming hacky, just choosing 1:40500 for a display betwen level 13 and 14. For all levels I just went off your link to the table and picked something round inbetween.

It would be nicer in this situation to have a MaxLevel and MinLevel that then only renders between those levels, but I guess the scale calculations suffice for most.