Clarification on adding WMS to Google Earth

Ive noticed a few other blogs mention the need for WMS server operators to run my PHP code i posted earlier. This is untrue, so to clarify … read on.

1. If you havent already done so, grab the code here

2. This code will require at least 2 small changes for it to work for you … first off, go to lines 26 to 35. This block contains 2 arrays, $WMS (the full getmap WMS request to the server) and $name (a pretty server/layer descriptor).

3. Each array entry corresponds to a new layer inside google earth. Obviously, depending on how you want to display your map, you may wish to only have 1 layer. I will assume this is what most will like to do, so remove all the other array entries so you are only left with a single layer. eg

[0] = "Cadastre";  $WMS[0] = "http://link.to/your/wms?ServiceName=earth&VERSION=1.1.0&REQUEST=GetMap&SRS=EPSG:4326&WIDTH=".$width."&HEIGHT=".$height."&LAYERS=Land Parcels&STYLES=&BGCOLOR=0xCEFFFF&FORMAT=image/gif&TRANSPARENT=FALSE&WRAPDATELINE=TRUE";  ?>

4. Now, i will assume you understand how to submit a WMS getmap request. Many of the public WMS servers already have documentation on how to do this. The syntax should be similar to the above, but REMEMBER to set the EPSG code to 4326 (WGS84) otherwise your data will not fit googles projection. If the WMS server has the option, its always a good idea to set the background to transparent also.

5. Now assuming you have added your first WMS entry into the PHP code, all you have to do is modify the IP range which you are allowing to access your WMS-KML reflector script. Go to line 46

if ($match[1] != '151.130' && $match[1] != '202.72' && $match[1] != '115.205') {  ?>

Edit the partial IP addresses to reflect that of your own organisation / home computer. I have only done the pregmatch on the first 2 numbers, but feel free to modify it on line 42 if you wish to do a full ip comparison.

6. Ok, time to try adding it to google earth ..

7. Load it up and click Add -> Network Link. Enter an appropriate title for the entry and in the ‘location’ textbox, enter the full URL path to your PHP code eg. ‘http://url/kml.php’. In the dropdown for image request, change it to ‘When camera stops’ and ensure the value is set to 4 seconds.

8. Zoom to an area of interest (one which is covered by your WMS) and stop the camera from rotating. Wait for 4 seconds and a red ‘Loading..’ image should be shown over your extents. This is the standard image google earth places when it is attempting to retrieve the network link (ie. your WMS image). If all goes well, you should have your image overlaid very nicely. Otherwise, if you recieve a nasty error popup check that your WMS server request was entered correctly.

Thats pretty much all there is to it. You dont need to run your own WMS server, you simply need to point to an available public server. Of course, running your own you get added benefits of being able to completely customise the look and feel … but if you’re feeling really lucky, try playing around with some SLD documents :)

As always, any Q’s flick me an email or post a comment. Hope i have cleared any confused.

One thought on “Clarification on adding WMS to Google Earth”

  1. hi,
    i really dont understand what you have written any way my request with you is my home town is Ramagundam,India on which image was not overlayed and i feel it very bad because it consists a population of 3 lakhs and has 2 power generation units with 15000 employees and the are a is full of Black Gold*coal* employing more than 50000 in its mines.Ramagundam has aspecial place in South India with the above mentioned .I request you develop the layer on the town .

    regards

Comments are closed.