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] = "".$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.

DMSolutions done it again

Paul Spencer at DMSolutions has posted their latest demonstration of KA-Map which uses AJAX-esque technology to transform mapserver output into a tiled format similar to maps@google but with a lot more features.

Check out the demo site here. It is without a doubt the best demo i have seen showcasing Ka-Map and mapserver’s new WMS support for a time attribute. Excellent stuff … just make sure you press play !

ps. In a somewhat related line, anyone know of any projects working on an opensource routing solution? Let me know

10 Easy steps for converting mxd to map & sld

Pre-reqs: arcmap, mapserver (with PHP mapscript), webserver (with PHP support)

1. Load the layers and set the colourings and any filters you want into the mxd.
2. Download Amein! from sourceforge. Follow the instructions to add into arcmap
4. Once loaded, run amein! and fill out the dialog boxes (some are required)
5. Save and open the folder containing the generated map file
6. Open a text editor and create SLD.php. Paste the following ,

< ?php
// Load mapscript
// Create map object
$oMap = ms_newMapObj("C:\file\");
// Call the SLD output
$SLD = $oMap->generateSLD();
// Output
echo $SLD;

7. Save SLD.php to a web accessible directory. Browse to that URL in your browser. (eg. http://localhost/sld.php)
8. Some text should be written to the screen in an unformatted manner. Right click inside the browser window and click ‘View Source’
9. Tada, the SLD. Select all and save contents to file, SLD.xml will do.
10. Open SLD.xml and check contents. While generateSLD does work quite well, on occasion it can struggle with things like Literal filter attributes. Have a quick glean over it to make sure all the tags are closed and it validates.
11. Add &SLD= to your Mapserver query string and check the results.

Who said things always had to be done the hard way? :) These steps are particularly useful for further splitting the SLD into separate layers for use in Geoserver (dont get me started on WMS-SLD for gs :| ).

Hope this helps some people out there. Amein! is particularly good for converting a layer with a stack of class definitions. Ive done one with 45 class’es for one layer and it outputted the map file correctly, with the classification still in tact. Very nifty util, enjoy.

Latest ESRI goodies

Dave Macguire has released some new information on ESRI’s upcoming Image Server ..

On Monday during the Plenary we will introduce a new type of Image Server. It takes a different approach to serving up large (TB) quantities of Images. The data is held in the raw file format (no need to pre-process, or load into a DBMS). The Server builds an index so that the files can be treated as a continuous image map. Services can be authored to process the images on the fly as they are served up to desktop or web clients. For example, you could create a service that radiometrically corrects the images, georeferences them, orthorectifies them, resamples them and then serves them up in a browser or in ArcMap. The neat thing is that this can be done using Landsat 15m data for the entire globe, on the fly, with sub-second response. The same approach works for aerial photography and other image data sets.

Interesting and good news, but hardly surprising. Unfortunately i cannot invisage their IS serving out anything other than SID’s or TIFF’s which still serves as their bottle neck. The lack of any mention of “streaming” these on the fly, stiched up image maps has me worried. Still, seems a lot better than the solution of just storing a stack of SID’s in SDE. Of course, feel free to prove me wrong :)

It oozes keyhole technology, but even that isnt new. Speaking of which, tomorrow i will add an article outlining how to add dynamic, live WMS output to your google earth. It performs extremely well, minus some niggling issues.

ps. The 9.2 release definately seems to be raising the bar across all ESRI apps. Good work


I wont bother giving my background guys, as you can read up on that on the contact page. I have one aim setting this bugger up, and that is for venting, code snippets and assistance wherever I can. My experience at DLI gives me a broad overview of a lot of new GIS technology across the board .. I’m not an ESRI / Intergraph shop, I’m not a MS / GS shop and im certainly not going to preach how OGC standardisation is going to cure world hunger. No, its time to get back to basics.

The lack of any independant source of GIS info or help, free from “external” influences infuriates me. While seeking support at the product’s site obviously makes sense, seeing posts such as “What application should i go for? Arcims or Mapserver?” posted on the respective sites more often than not attracts incredibly biased information and sometimes outright wrong. It’s one thing I’ve noticed about GIS applications, word of mouth is key.

I guarantee that if you ask 8/10 people who run existing web GIS applications why they chose that product over any other, they’ll either

  • have no idea any other products exist
  • have been told how much “better” X product is from Y or
  • have contact with some other organisation that has said product installed and equally has no idea what other products are available

Its pretty much a given that there is a almost drought of information comparing web GIS products. Almost everything is subjective to opinion, then those facts just turn into chinese whispers. Well, hopefully in the coming months i will have some results benchmarking all web GIS applications i could get my little hands on. The preliminary results are very interesting to say the least ;) So stay tuned.