Setting zoomlevels with gdalwarp?

Ed McNierney ed at TOPOZONE.COM
Tue Oct 24 12:07:18 PDT 2006


Jeff -

You need to know that by default MapServer uses a RESOLUTION setting of
72 DPI.  You say you want a zoom of 1:2,000 - what exactly does that
mean?  It means one inch on the screen equals 2,000 inches on the
ground.  But how do you know how much of your image will appear in one
inch on the screen?  You need to know the physical resolution of the
screen in pixels per inch or DPI.  This is always just a guess - the
user can adjust the horizontal size of the image and you'll never know
it - but it's a common guess.  MapServer uses a guess of 72 DPI unless
you put a RESOLUTION statement in your map file saying otherwise.  And
don't think that a different RESOLUTION statement makes a "better image"
- it doesn't improve the resolution of the image, it just tells
MapServer what it should use as the output device resolution in DPI so
it can calculate scale ratios.

You have a complicating factor of using images with a completely bogus
"projection" of "decimal degrees".  If you'd like an extended rant on
why this is a bad thing to do to your images, just let me know <g>.  But
it makes things like scalebars and scale ratios meaningless and even
more confusing than otherwise.  What's one "degree" supposed to be in
physical units you can measure on your screen?  At a scale of 1:2,000
you're saying that one inch on the screen equals 2,000 inches on your
image.  But the scale of your image in units like inches is dependent
both upon the latitude of that particular image AND on the angle of the
line you're measuring, since one degree of latitude is a different
number of inches than one degree of longitude.

I honestly do not know how to answer your question accurately in such a
situation.  I'm going to answer a similar question in the hope of
getting you on track.

At middle latitudes "one degree" is somewhere in the area of 100
kilometers.  If your image's X resolution is 0.00001279 "degrees" per
pixel, then that's 1.279 meters per pixel.  I will use that as the size
of your pixel and work through the math.

If one pixel is 1.279 meters, if you view that image at 72 DPI then one
inch on the screen = 72 * 1.279 meters = 92 meters.  92 meters is 92 *
39.37 inches = 3,625 inches.  If you view that image at full resolution
(1:1 pixel size) on a 72 DPI device you'll get a scale ratio of 1:3,625.
Your actual monitor is probably higher resolution than that (usually
around 100 DPI).  At 100 DPI you'll be viewing 100 * 1.279 * 39.37 =
5,035 inches for a ratio of 1:5,035.

Now that's all MapServer-speak, not GDAL-speak.  But you need to figure
out what image resolution you want to have at your "deepest zoom level".
Then you can calculate the scale ratio MapServer uses that would
correspond to that image at full resolution.  Your gdaladdo overviews
will then need to correspond to the list of zoom levels (multiples of
that base scale ratio) that you choose to allow the user to view in your
application.

	- Ed

Ed McNierney
President and Chief Mapmaker
TopoZone.com / Maps a la carte, Inc.
73 Princeton Street, Suite 305
North Chelmsford, MA  01863
ed at topozone.com
(978) 251-4242 

-----Original Message-----
From: UMN MapServer Users List [mailto:MAPSERVER-USERS at LISTS.UMN.EDU] On
Behalf Of Jeff Dege
Sent: Tuesday, October 24, 2006 12:34 PM
To: MAPSERVER-USERS at LISTS.UMN.EDU
Subject: [UMN_MAPSERVER-USERS] Setting zoomlevels with gdalwarp?

As I understand it, I will get the best performance with raster layers
if the raster image files match the map display image pixel-for-pixel.
So I want to use gdalwarp to convert the raster image files so that the
will match the display image at the deepest zoom level.  (After which, I
will add overviews with gdaladdo).

The question is, how?

I either need to set the resolution of the raster image files with
dgalwarp so that it matches my zoom level, or I need to set my zoom
level so that it matches the resolution of the raster image files.

The question is - what's the math for the conversion from zoom to
resolution?

Suppose, for example, I want might deepest zoom to be around 1:2000.
And I have a couple of hundred jpeg raster image files, with coordinates
in decimal degrees, and pixel sizes of (0.00001279,-0.00000900).

Gdalwarp seems to have two arguments that I'd use to specify a
particular resolution in the output file, -tr and -ts.

How do I calculate the values I use for one, or the other, to get the
appropriate resolution for the zoom level I've chosen?



More information about the MapServer-users mailing list