Rasters and world files and extents, oh my!

Ed McNierney ed at TOPOZONE.COM
Wed Feb 1 13:54:56 PST 2006


David -

The last two lines of the world file are the coordinates (x, y) of the
upper-left pixel.  The coordinate system for addressing pixels assumes
the normal Cartesian x-increases-to-the-right, y-increases-going-up
sense.  Since the world file specifies the coordinates of the UPPER left
corner rather than the LOWER left corner as one would expect in a
traditional Cartesian plane, the delta-y value is normally negative.
That means that the y sense is y-decreasing-going-down, which is, of
course, the same as saying y-increases-going-up.  You're just counting
top to bottom, so the numbers go down (negative increment) rather than
bottom to top (positive increment).

Imagine a Cartesian plane with an x axis and a y axis, crossing at (0,
0).  Your first world file places your image in the lower-right
quadrant, with the upper-left corner at the origin.  All x coordinates
on the image are positive, and all y coordinates on the image are
negative.

Your second world file creates a y-increases-going-down sense, which
will confuse you no end.  It takes the first scenario and reflects it
about the X axis.

It sounds like what you want to do is translate (i.e. slide) the image
from the lower-right quadrant to the upper-right quadrant, so both x and
y are positive.  You want to move the image "up" by its entire size, so
you want to add 6740 to its y coordinate.

Adding 6740 to the y coordinate of the upper left corner simply means
changing the last line of your original world file to be 6740 instead of
0.  You don't really need all those spurious 0.00000000 values in there
- just plain 0 works fine <g>.  If you do that all your y coordinates
will be 6740 greater than they were before, and they will all be
positive, with the LOWER left corner of the image at (0, 0).

	- 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 David Badke
Sent: Wednesday, February 01, 2006 3:03 PM
To: MAPSERVER-USERS at LISTS.UMN.EDU
Subject: [UMN_MAPSERVER-USERS] Rasters and world files and extents, oh
my!

I am confused...

I have a raster image, 10540 pixels wide by 6740 pixels high, non-Geo
TIFF. The specified units in the map file are meters. I created a world
file:

1
0.0000000000
0.0000000000
-1
0.00
0.00

meaning x co-ordinates increase moving right, y coordinates decrease 
moving down, from top-left pixel at x=0, y=0, with 1 pixel/meter (ie: 
the raster image is 10.54 km wide by 6.74 km high, in world
coordinates).

Through trial and error, with many blank output images, I found this 
extent setting (in the map file) produces a correct image, generated 
through a simple PHP MapScript:

EXTENT 0 -6739 10539 0

PHP is:

if (!extension_loaded('MapScript'))
    dl('php_mapscript_46.'.PHP_SHLIB_SUFFIX);
$oMap = ms_newMapObj( '/ms4w/apps/kamap/htdocs/map/vicbird1878.map' );
$oImg = $oMap->draw();
$szURL = $oImg->saveWebImage();
echo "<img src=$szURL>";

While this produces the image I expect, the y coordinate is always 
negative for any x, y point, which is a problem for me - and anyway, I 
don't understand why miny has to be -6739. So I tried a world file like:

1
0.0000000000
0.0000000000
1
0.00
0.00

and an extent like:

EXTENT 0 0 10539 6739

thinking that both x and y coordinates would be positive and increase 
from x=0, y=0 (upper left) to x=10539, y=6739 (bottom right), which is 
what I want. Doesn't work - the image is blank.

So can someone explain in simple terms for the 
cartographically-challenged just what the relationship is between the 
world file and the extent minx, miny, maxx, maxy? If minx, miny is the 
upper left pixel, and the world file says that the upper left pixel is 
x=0, y=0, why doesn't EXTENT 0 0 10539 6739 refer to the entire image? 
Why does a miny value of -6739 in the extent work if the top left is 0,0

and the y pixel size is -1? Sooooo confused...

David



More information about the MapServer-users mailing list