This is a simple JavaScript calculator for figuring out world files.

Enter the coordinates of opposing corners of the image. Geographic coordinates should be positive with N/S and E/W chosen for direction from the equator and the prime meridian. For UTM enter either positive or negative numbers for northing and easting, and leave the selectors on N and W. The results can be copied and pasted into your world file.  Rotations are not handled in this implementation, so the second and third values will always be zero.


Calculate Worldfile

Use “N” and “W” if entering northing and easting
instead of latitude and longitude.

First corner:

Second corner:

Image size:
width:

px  height:

px
worldfile:
To use, worldfile name should
match image basename with
proper one of these for the suffix:

.gfwgif
.tfwtif
.jgwjpg
.pgwpng

11 Responses to “World file calculator”

  1. John Reed says:

    WONDERFUL Post.thanks for share..more wait ..

  2. RMFRunyan says:

    I’ve figured out what I am doing wrong. The lats should be 1/4th the polar circ, not half.

    Thanks for a very nice reference. Bookmarked.

    rmfr

  3. RMFRunyan says:

    OK. You’re right. I’m just always used to listing South and West as negatives even if listed South and West.

    However, line 4 still seems to be twice what it should.
    7143.334479058464
    0.00000
    0.00000
    -14272.22052182727
    -25716004.124610472
    25689996.939289085

    Shouldn’t it be: -7136.110260913635?

    BTW: the 7201pxW by 3601pxH is Equirectangular Projection. Thus, the height covers only 180 degrees, but the width will cover 360 degrees. Does the JS script assume height also covers 360 degrees?

    Thanks for the prompt reply.

    rmfr

  4. egb13 says:

    Well, I see for one thing that the negatives are confounding it; “West” means negative East, so you should enter the absolute value instead of a negative, unless you make the direction East as well. Likewise for N/S. If I remove the negative signs the results are closer to what you expect:

    7143.334479058464
    0.00000
    0.00000
    -14272.22052182727
    -25716004.124610472
    25689996.939289086

    The fourth value, delta-y, still doesn’t agree. Are you sure of your input and expected output? E.g., is the image height correct?

    It’s a simple-minded bit of code that works for what I needed. The code can be viewed at http://egb13.net/jscripts/worldfile.js. Any suggestions for improvements are appreciated. One thing that would come in handy sometimes would be to let you enter the pixel size, and have it give you the resulting image dimensions, for when I want to crop a map image to a specific extent, e.g.

  5. RMFRunyan says:

    This program does not truly work. When I enter the below data:
    N: 25697133.04955
    W: -25719575.79185
    S: -25697133.04955
    E: 25719575.79185
    width: 7201
    height: 3601

    I get these results:
    0
    0.00000
    0.00000
    0
    25719575.79185
    25697133.04955

    However, should the results actually have been:
    7143.334479
    0.00000
    0.00000
    -7136.110261
    -25716004.12461
    25693564.99442

    Just wondering…

    rmfr

  6. egb13 says:

    Is this program available for download? The JavaScript code for it can be found at http://egb13.net/jscripts/worldfile.js. It’s just a couple lines of arithmetic.

  7. Donald says:

    Is this program available for download?

  8. egb13 says:

    Replying to myself… my response to NickMcW is for Google Maps, but he asked about Google Earth. It’s a more interesting question, but not one I have an answer to. Yet.

  9. egb13 says:

    If in Google Maps you click on “Link” you get a choice two strings to copy and paste. The first one, for email or IM, is the bare URL of the displayed map; if you past it in the browser’s address box, you’ll get the map you see displayed. That Maps URL looks like this:

    http://maps.google.com/?ie=UTF8&ll=36.779042,-103.971863&spn=0.370679,0.801315&z=11

    The “ll=” parameter is the latitude and longitude of the center of the map. The “spn=” parameter must stand for “span”, because it appears to be the height and width of the displayed map in degrees. Test this by trying to find the coordinates of the upper-left corner: add half the vertical span to the latitude and subtract half the horizontal span from the longitude. (Moving northwest increases latitude and decreases longitude.) Applying that formula to the URL above gives this new URL:

    http://maps.google.com/?ie=UTF8&ll=36.964381,-104.372520&spn=0.370679,0.801315&z=11

    That indeed looks like the upper-left corner of the original map, and what was at the center (an extinct cinder-cone volcano that you can drive to the top of and hike through the crater) is now at the lower-right corner.

    Since you’re already given the degree span, you don’t really need this calculator; divide the vertical and horizontal span values given in the link URL by the pixel dimensions of the image and you have the 1st and 4th parameters for the worldfile.

    But I don’t know what projection Google uses to display their maps. Is it simple latitude x longitude (EPSG:4326)? Or is it a UTM projection? Or does it vary by the size of the area covered? UTM is not good for maps that cover more than a certain distance horizontally. EPSG:4326 is not good for lots of things. That’s what is used in the video in my Road Trip! posting, and even though that doesn’t cover a terribly large area (a little over 100 mi horizontally) and the counties shown are noticeably flatter than they should be. And a worldfile (at least with the 2nd & 3rd parameters zero) is not good for “curved” projections.

    Might this be the wrong approach, though? If you haven’t already investigated Google’s Maps API you might want to. I see lots of places around the internet making pretty good use of it. It’s been a very long time since I dabbled in it and am unable to offer any help with that, not to mention that I don’t know what exactly your after anyway.

  10. NickMcW says:

    Hi – nice utility, thanks for making it available. It prompts a related question: does anyone know a way to programmatically obtain the corner coordinates of the current view extent in Google Earth? The reason for asking is in order automate the creation of world files – as done with this calculator – for google earth screen-saved images. (The image size, in pixels, will depend on the resolution option chosen in GE; the options available depend on whether the free or pro version is used.)

  11. egb13 says:

    I’ve made a minor modification to the code to correctly calculate the location of the center of the corner pixel. It’s really trivial — just adjust by 1/2 of the pixel size in geo coordinates.

Leave a Reply