Archive for the Google Earth Category
Update: this information is now out of date because of improvements to the KML format in version 2.2. You can read about this in a later post and in Google’s great tutorial on extended data.
Recently, Chris over at FortiusOne has written a couple articles, focusing largely on the Schema tag in KML. One thing in particular from this article got me thinking:
Google Earth will display your custom fields in the markers that get displayed in a Schema-based KML file, but it’s still up to you to make a pretty-looking description if you want, and if you want to include some of the data in your custom fields, you’ll have to duplicate the information which isn’t ideal.
This certainly seems like a bit of a roadblock for the good old Schema tag. It really breaks the whole separation of content from style idea, which surprised me because this separation had been accommodated in other KML tags. So I started hacking… and found that this isn’t really a limitation. One word: BalloonStyle.
Using this tag, you can easily use Schema to transport relatively pure attributes, while pointing to style information located elsewhere in the document or, if you’re in the mood, in a different document entirely.
Here’s some data in a relatively simple schema:
<Newt>
<name>Sammy G</name>
<styleUrl>http://www.jasonbirch.com/files/kml_schema_style.kml#newt_style</styleUrl>
<Point>
<coordinates>1.75,1.75,0</coordinates>
</Point>
<newt_id>36</newt_id>
<newt_breed>Common Orange Slitherer</newt_breed>
<newt_slime_factor>7.2</newt_slime_factor>
<newt_tail_length>6</newt_tail_length>
</Newt>
Which can be combined with the following BalloonStyle:
<Style id="newt_style">
<BalloonStyle>
<text><![CDATA[
<h1>$[name]</h1>
<table>
<tr>
<td>Breed:</td>
<td>$[newt_breed]</td>
</tr>
<tr>
<td>Tail Length:</td>
<td>$[newt_tail_length]</td>
</tr>
<tr>
<td>Slime Factor:</td>
<td>$[newt_slime_factor]</td>
</tr>
<tr>
<td colspan=”2″><img src=
”http://www.jasonbirch.com/files/jason_small.jpg?id=$[newt_id]”
/></td>
</tr>
</table>
]]></text>
</BalloonStyle>
</Style>
To give you the fully separated content/style shown below:
Now, I think that’s downright cool. I can have my cake and eat it too. If you want to see this example live in Google Earth ™, just click on the image above. You can also view the source of the content document, or of the style document. I’ll leave it as an exercise for the reader to determine whether this technique can be used with more complex tags than SimpleField, such as SimpleArrayField and ObjField
I am aware of one other application (Safe Software’s FME) that is using the Schema tag to pass around attributes, and have really liked the idea ever since I first saw it in Rebecca Moore’s anti-logging KML file. It’s easy to use, doesn’t require external documents, and combined with other KML goodness allows you to pack styling around with your fully attributed data.
There is a nasty rumour floating around that Schema has been deprecated. It isn’t listed as such in the KML docs yet, and I certainly hope that it isn’t too late to ensure continued support for this handy tag from Google.
-J
Related posts
Google Earth now shows the City of Nanaimo in beautiful 10cm colour.
With our last ortho project, the City ensured that we could provide the images to consumer-oriented providers like Google. We did this for two reasons. First, it would allow local residents, businesses, and educators to benefit from the higher resolution imagery in Google Earth and Maps (eventually). Second, now that our GIS applications support KML output, staff can use Google Earth Pro to visualise and communicate more effectively. In particular, they are able to easily create movies that tell a story in three dimensions.
I’m impressed by the fidelity of the images in Google Earth. If you compare them with our CityMap site (IE/Windows only. Sorry - I’m working on it…), they are actually somewhat cleaner, though there may be some smoothing. The compression format we are using introduces some artefacts.
Nanaimo City Hall in CityMap:

Nanaimo City Hall in Google Earth:

This update gives me a stronger platform (and incentive) for providing additional services to our residents, such as interactive KML layers and GeoRSS feeds.

Thanks to the other Michael Jones (data acquisition, not CTO) at Google for working with me to get these images loaded. I heard a funny story from a colleague about a business card mix-up that resulted in him waking up the CTO in India at 4am to talk about data provision. Apparently he was quite nice, despite the confusion
If anyone else sees the same value in providing their orthos to Google as I do, please get in touch with me and I’ll pass along the correct Michael’s contact info.
-J
Related posts
Earlier today, Rob over at Spatial Miscellany posted an article on how to add an EDN (ESRI Developer Network) search to Internet Explorer 7.
I don’t have a real use for EDN search, but just for fun I’ve created a page where anyone can add this OpenSearch to their modern (Firefox 2.0 or IE 7) browser without having to copy and paste URLs.
Adding an EDN search to your browser
Anybody feel like creating a resource page that stores a bunch of GIS searches in this easily-accessible format?
I’d love to see the earth browsers and online maps support this sort of feature as well. For instance, it would be great if I could build some plugins to allow Google Earth users to easily search my municipality’s geospatial data without relying on the Google KML Search to know what they are interested in.
-J
Related posts
With the final 1.1.0 release of MapGuide Open Source just around the corner, I thought I’d talk about the initial support for KML 2.1 (Google Earth 4.0 or newer only) in this release.
Key Features:
- Any Map Definition that you publish to the MapGuide server repository can be accessed as KML
- KML 2.1 Regions are used, so you only serve data when necessary
- Published scale ranges are honoured (to an approximate level with oblique views)
- MapTips are published as feature descriptions
As an example, I’m going to use the default MapDefinition that comes with the Sheboygan sample data set (available on the MapGuide Open Source website).
Here is a picture of the map as it appears in Autodesk MapGuide Studio:

This is the request I sent to the MapAgent to view this MapDefinition in Google Earth:
http://localhost:8008/mapguide/mapagent/mapagent.fcgi?
OPERATION=GetMapKml&
VERSION=1.0.0&
MAPDEFINITION=Library://Samples/Sheboygan/Maps/Sheboygan.MapDefinition
Which gave me the following KML:

Which in turn looks like this in Google Earth:

Although you could just push out any of your maps to Google Earth, in practice you will likely want to create a special Map Definition just for GE so that you can account for some of the display limitations in Google Earth.
So, how do you publish your maps to Google Earth? Using the ever-helpful MapGuide MapAgent. The MapAgent is a URL-based web service which interacts with the MapGuide Server based on the parameters you pass. In the case of KML, the primary parameter that is important to you is OPERATION=GetMapKml. Full documentation for this parameter can be found on the KML in MapGuide RFC page, but the basics follow…
Required parameters:
- OPERATION=GetMapKml - tells the MapAgent that you want a KML version of the Map Definition
- VERSION=1.0.0 - can currently only be 1.0.0
- MAPDEFINITION=<PathToYourMapDefinition> - path to your map definition in the repository. For example: Library://Samples/Sheboygan/Maps/Sheboygan.MapDefinition
Optional parameters:
- FORMAT=<KML|KMZ|XML> - allows you to publish in either KML, compressed KML (KMZ) or, for easy debugging, XML
- DPI=<default: 96> - is used to perform the viewer-to-map calculations required to honour the scale ranges defined in your map
- USERNAME=<Anonymous or whatever you want> - (unsupported) can be used to prevent an authentication prompt on first request. Generating this initial request from a server-side script that creates a session is the preferred method.
- PASSWORD=<no value for Anonymous, or whatever you want> - (unsupported) as above.
If you want to play around with these parameters some more to see what they do, the MapAgent test html pages that come with MapGuide 1.1.0 include test cases for the KML service. This can be found by default at http://localhost:8008/mapguide/mapagent/index.html .
If you have any questions about this functionality, or want to help expand the functionality offered by this tool, please join us in the MapGuide Open Source community.
-J
Related posts
Well, this has been sitting in my half-finished pile for a long time, so I figured I’d better polish it up and kick it out the door (I’m practicing for my kids). There are probably other sites that have documented this, but here’s my version.
Google’s KML format has some really strong styling elements built into it, similar to HTML/CSS. In a single <Style> tag, you can specify how points, lines, and polygons should display in the Google Earth browser. For instance:
<Style id="parcelNormal">
<IconStyle>
<scale>0.8</scale>
<Icon>
<href>http://maps.google.com/mapfiles/kml/pal4/icon56.png</href>
</Icon>
</IconStyle>
<LabelStyle>
<scale>0</scale>
</LabelStyle>
<LineStyle>
<color>ff4090ff</color>
<width>10</width>
</LineStyle>
<PolyStyle>
<color>00000000</color>
</PolyStyle>
</Style>
This allows you to define polygons, points, and lines, all referencing the same style definition. Definitely a space saver over having to define the style against each feature:
<Placemark>
<name>238 Franklyn St.</name>
<styleUrl>#parcelNormal</styleUrl>
<Point>
<coordinates>-123.938788334,49.1646409443,0</coordinates>
</Point>
</Placemark>
<Placemark>
<name>238 Franklyn St.</name>
<styleUrl>#parcelNormal</styleUrl>
<Polygon>
<outerBoundaryIs>
<LinearRing>
<coordinates>
-123.93904811,49.16434558280001,0
-123.939274779,49.16457225540001,0
-123.939105984,49.1646449658,0
-123.93924107,49.1647800536,0
-123.938876261,49.16493630590001,0
-123.938424057,49.1646143977,0
-123.93904811,49.16434558280001,0
</coordinates>
</LinearRing>
</outerBoundaryIs>
</Polygon>
</Placemark>
And this is what it looks like:

There is also a <StyleMap> entity that allows you to specify a style to apply when a feature is active and when a feature is inactive:
<StyleMap id="parcel">
<Pair>
<key>normal</key>
<styleUrl>#parcelNormal</styleUrl>
</Pair>
<Pair>
<key>highlight</key>
<styleUrl>#parcelHighlight</styleUrl>
</Pair>
</StyleMap>
Unfortunately, the only feature type that triggers this normal/highlight switch is the point:

The secret to working around this is to provide a point feature as part of every line or polygon Placemark that you want to be affected by a mouseover. Then, when the user hovers over the point, the line or polygon is affected by the stylemap that applies to that composite feature. The key to doing this is a “wrapper” called MultiGeometry. MultiGeometry allows you to have multiple geometries tied to a single feature. For example:
<Placemark>
<name>238 Franklyn St.</name>
<styleUrl>#parcel</styleUrl>
<MultiGeometry>
<Point>
<coordinates>-123.938788334,49.1646409443,0</coordinates>
</Point>
<Polygon>
<outerBoundaryIs>
<LinearRing>
<coordinates>
-123.93904811,49.16434558280001,0
-123.939274779,49.16457225540001,0
-123.939105984,49.1646449658,0
-123.93924107,49.1647800536,0
-123.938876261,49.16493630590001,0
-123.938424057,49.1646143977,0
-123.93904811,49.16434558280001,0
</coordinates>
</LinearRing>
</outerBoundaryIs>
</Polygon>
</MultiGeometry>
</Placemark>
As you can see, both the point and the polygon are affected:

This trick is useful for those hand-crafting their KML, but it is also possible to build this kind of construct in some of the KML generating tools out there. For instance, in Safe Software’s FME, you can generate a point at the centroid of a polygon with a CenterPointReplacer, and then merge the polygons and their centroids using an Aggregator before writing this out into KML format (pdf). You can even generate the StyleMap elements (see format docs for details). In MapGuide Open Source, I use the GetPointInRegion() method to determine the centroid of the polygon, and build my MultiGeometry from this and the polygon coordinates. Most other GIS software has similar functionality.
The final example shown here is available for download in KML, XML and TXT formats.
-J
