Skip to content

World File Calculator

Originally published 2009-03-31.

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.

First corner:

Second corner:

Image size:  width: px     height: px



2 thoughts on “World File Calculator

  1. bone

    what is the formula you are using to calculate the jgw entries.
    thank you for any information.
    Trying to calculate or to find formulas for a long time

    1. egb13

      It's very simple. The numbers in the world file are the map coordinates of the upper-left pixel and the x- and y-size of the pixels.

      Given two opposite corners of the image in map coordinates you get the upper-left corner by taking the lesser easting (longitude) and the greater northing (latitude) of the pair.

      Subtract the coordinates of opposite sides and you get the x and y dimension of the image in map coordinates. Divide those by the x and y size, respectively, of the image pixel size, and you have the size of each pixel in map coordinates. Then, because the specification says that the coordinates in the world file are of the center of the upper-left pixel, you need to add 1/2 the pixel size to that coordinate (I'm assuming that the coordinates entered are the absolute edge of the image, but a 1/2 pixel difference probably will make no difference.)

      If you look at the source code on this page (Ctrl-U in a desktop browser), you'll see the javascript code around line 220. The main bit after reading the values from the input form is:

      var ppx = (lon1 - lon2) / xsize ;
      if (lat1 > lat2) {
      var t = +lat1 ;
      lat1 = lat2 ;
      lat2 = t ;
      var ppy = (lat1 - lat2) / ysize ;
      lon2 += (ppx / 2) ; // x center of pixel
      lat2 += (ppy / 2) ; // y center of pixel
      var wf = ppx.toString() + "\n" +
      "0.00000\n0.00000\n" +
      ppy.toString() + "\n" +
      lon2.toString() + "\n" +
      lat2.toString() ;

      ppx and ppy are the pixel sizes, x and y, in map coordinates. xsize and ysize are the size of the image in pixels in the two dimensions.

      It makes no difference whether you're working in latitude and longitude or projected units like UTM; the math work out the same because the input and output are in the same coordinate system.


Leave a Reply

Your email address will not be published. Required fields are marked *