Google Earth with WMS Overlays continued ..

Apologies for the third thread on this topic, but again i need to clear the air and post a fix for the overlay accuracy issue. Paul raised the concern of overlay accuracy in his own script and so it was obvious i should post the solution.

It is a small fix and all that is required is to calculate a ratio of the min/max bounding box coordinates in order to caclulate the height, in pixels, of the image.

For everyone who has their own alternative script working, simply add the following calculation to your variables,

= 800; $ratio1 = ($coords[2] - $coords[0]);  $ratio2 = abs($coords[1] - $coords[3]); $ratio = $ratio1 / $ratio2;  $height = (int)($width / $ratio); ?>

Then all is needed is to reference these $height and $width vars when calling your WMS request, such as …

[1] = "Cadastre";  $WMS[1] = "http://your.server.com/servlet/wms?"; ?>

The problem with hardcoding these variables is that on occasion, the proportion of the returned WMS image does not match the proportions of the bounding box coordinates. In this situation google attempts to stretch the image to fit the given coordinates, and of course, distortion occurs … resulting in overlays which will not fit the base data. This will fix the problem.

Alternatively you can grab the entire example PHP source right here.

Any further questions id be glad to help.

Related posts:

  1. Adding WMS overlays to Google Earth
  2. Google earth WMS view scales
  3. Google Earth WMS still undercooked
  4. Google half bakes WMS support
  5. Clarification on adding WMS to Google Earth

2 Responses to “Google Earth with WMS Overlays continued ..”


  1. Gravatar Icon 1 MalaWolf

    http://chris.narx.net/wp-content/new.txt file is missing :(
    please repost (!)

  1. 1 Adding WMS overlays to Google Earth at Chris’ GISmo’s
Comments are currently closed.