Changing map styles in google earth - kml

I'm adding a chloropleth US county map in Google Earth. I've made the map in qgis and exported as a KML, but the county borders become extremely thick when I open it in Google Earth. When I try to change it, it makes all of the borders and the county values uniform, and takes away the chloropleth. How can I change individual styles such as borders in Google Earth?
Here is a representative KML:
<?xml version="1.0" encoding="UTF-8"?>
<kml xmlns="http://www.opengis.net/kml/2.2">
<Document>
<name>geo_county_ma</name>
<Style id="style3">
<LineStyle>
<color>40000000</color>
<width>3</width>
</LineStyle>
<PolyStyle>
<color>ffe7d1af</color>
</PolyStyle>
</Style>
<Style id="style2">
<LineStyle>
<color>40000000</color>
<width>3</width>
</LineStyle>
<PolyStyle>
<color>fff4e6d7</color>
</PolyStyle>
</Style>
<Placemark>
<styleUrl>#style3</styleUrl>
<Polygon>
<outerBoundaryIs>
<LinearRing>
<coordinates>
-122.4361217223626,37.80089762963801 -122.431353047545,37.80152776851571 -122.4317440301943,37.80336276723568 -122.436466590289,37.80271696430888 -122.4361217223626,37.80089762963801
</coordinates>
</LinearRing>
</outerBoundaryIs>
</Polygon>
</Placemark>
<Placemark>
<styleUrl>#style2</styleUrl>
<Polygon>
<outerBoundaryIs>
<LinearRing>
<coordinates>
-122.436124895585,37.80088925120538 -122.4313590833908,37.80150407165125 -122.4310083235047,37.79963224033016 -122.435667004224,37.79900507682146 -122.436124895585,37.80088925120538
</coordinates>
</LinearRing>
</outerBoundaryIs>
</Polygon>
</Placemark>
</Document>
</kml>

If the lines/borders of polygons are too thick try changing the width value for LineStyle to 1 (or 2) whichever works best visually:
<LineStyle>
<color>40000000</color>
<width>1</width>
</LineStyle>
You can right-mouse click on each Placemark and manually change the style line width in Google Earth but suggest you change the KML in a text editor and globally replace <width>3</width> with <width>1</width>.

Related

KML file not formatting a drawn line

I am using the following code to generate a line in Google Earth, however the formatting of the line is not changing.
<Placemark>
<LineString>
<Style id="bendigo_line">
<LineStyle>
<width>3</width>
<color>64F0FF14</color>
</LineStyle>
</Style>
<coordinates>
-15,52,0
-20,53,0
-30,53,0
-40,53,0
-50,52,0
-53.233333,51.166667
</coordinates>
</LineString>
</Placemark>
I'm unsure of what I am doing wrong as this method has worked in the past and now doesn't change the line from the default thickness and colour.
Thanks
The <Style> element must appear outside the <LineString> element. KML requires elements in a particular order.
For the syntax of the Placemark refer to the KML Reference.
Try changing your KML to this order of elements:
<Placemark>
<Style>
<LineStyle>
<width>3</width>
<color>64F0FF14</color>
</LineStyle>
</Style>
<LineString>
<coordinates>
...
</coordinates>
</LineString>
</Placemark>
When there are problems with KML try first to validate it using the KML Validator.

Getting lines to work on Google Earth

So I've been sifting through GE's documentation, and found how to do LineStyle and LineString to style and display a line, but in practice I cannot actually make it work. Here's my KML:
<?xml version="1.0" encoding="UTF-8"?>
<kml xmlns="http://www.opengis.net/kml/2.2"><Document><Style id="thisStyle">
<LineStyle>
<color>500078F0</color>
<colorMode>Normal</colorMode>
<width>5</width>
</LineStyle>
</Style>
<Placemark>
<name>502-2012-11-19 05:27:03</name>
<description>Speed:0</description>
<Point>
<coordinates>-76.0513,42.0894,247</coordinates>
</Point>
</Placemark>
<Placemark>
<name>502-2012-11-19 05:26:46</name>
<description>Speed:0</description>
<Point>
<coordinates>-76.0517,42.0886,287</coordinates>
</Point>
</Placemark>
....
<Placemark>
<name>525-2012-11-19 04:38:25</name>
<description>Speed:0</description>
<Point>
<coordinates>-76.0512,42.0894,178</coordinates>
</Point>
</Placemark>
<styleUrl>#thisStyle</styleUrl>
<LineString>
<tessellate>1</tessellate>
<altitudeMode>clampToGround</altitudeMode>
<coordinates>
-76.0513,42.0894,247
-76.0517,42.0886,287
....
-76.0512,42.0894,178
</coordinates></LineString></Document></kml>
Note: The above places where "..." appears there are about 50 more coordinate sets, I removed them for the sake of brevity, but since all coordinates are produced by a script if one works I know they all will. Can anyone nudge me in the right direction as to why my placemarks all show up, but no lines?
A LineString element is only valid inside a Placemark (or a MultiGeometry inside a Placemark):
<Placemark>
<LineString>
<tessellate>1</tessellate>
<altitudeMode>clampToGround</altitudeMode>
<coordinates>
-76.0513,42.0894,247
-76.0517,42.0886,287
-76.0512,42.0894,178
</coordinates>
</LineString>
</Placemark>
Example on Google Maps with your KML
Example on Google Maps with a Placemark containing the Linestring
You must either inline Style in the Placemark or reference the style in the Placemark using styleUrl element.
The last Placemark in your example needs to be rewritten like this:
<Placemark>
<name>525-2012-11-19 04:38:25</name>
<description>Speed:0</description>
<styleUrl>#thisStyle</styleUrl>
<LineString>
<tessellate>1</tessellate>
<altitudeMode>clampToGround</altitudeMode>
<coordinates>
-76.0513,42.0894,247
-76.0517,42.0886,287
...
-76.0512,42.0894,178
</coordinates>
</LineString>
</Placemark>
If your KML doesn't view correctly then it usually helps to validate the KML. You can use the KML Validator.

How to made KML doesnt import order of multigeometry

Hello Im writing some KML and when and I create the multigeomtry in the order
PlaceMark A
PlaceMark B
I cant select PlMark A beceause B is bigger, but when I have
PlaceMark B
PlaceMark A
Yes, because I think A is smaller and it was the last in be grapicated, my question is I cant have the Placemarks In order,there are any option in Kml to made selectable all the elements.
Thanks.
<?xml version="1.0" encoding="UTF-8"?>
<kml xmlns="http://earth.google.com/kml/2.0">
<Document>
<StyleMap id="StyF1"><Pair><key>normal</key><Style><IconStyle><Icon></Icon></IconStyle><PolyStyle><color>7d0000ff</color></PolyStyle></Style></Pair><Pair><key>highlight</key><Style><IconStyle><Icon></Icon></IconStyle><PolyStyle><color>7aFFFF8C</color></PolyStyle></Style></Pair></StyleMap>
<StyleMap id="StyU1"><Pair><key>normal</key><Style><IconStyle><Icon></Icon></IconStyle><PolyStyle><color>7d0000ff</color></PolyStyle></Style></Pair><Pair><key>highlight</key><Style><IconStyle><Icon></Icon></IconStyle><PolyStyle><color>7aFFFF8C</color></PolyStyle></Style></Pair></StyleMap>
<Placemark>
<name>A</name>
<description>
</description>
<visibility>1</visibility>
<tessellate>1</tessellate>
<styleUrl>#StyU1</styleUrl>
<MultiGeometry>
<Point>
<coordinates>-0.18806,39.78366</coordinates>
</Point>
<Polygon>
<outerBoundaryIs>
<LinearRing>
<coordinates>-0.18806,39.78261
-0.18701,39.7844286533479
-0.18911,39.7844286533479
-0.18806,39.78261</coordinates>
</LinearRing>
</outerBoundaryIs>
</Polygon>
</MultiGeometry>
</Placemark>
<Placemark>
<name>B</name>
<description>
</description>
<visibility>1</visibility>
<tessellate>1</tessellate>
<styleUrl>#StyF1</styleUrl>
<MultiGeometry>
<Point>
<coordinates>-0.18806,39.78501</coordinates>
</Point>
<Polygon>
<outerBoundaryIs>
<LinearRing>
<coordinates>-0.18806,39.78261
-0.18566,39.7867669219382
-0.19046,39.7867669219382
-0.18806,39.78261</coordinates>
</LinearRing>
</outerBoundaryIs>
</Polygon>
</MultiGeometry>
</Placemark>
</Document></kml>
If you want to order one line or polygon over another you can use the <gx:drawOrder> element.
Features with higher <gx:drawOrder> values are drawn on top of those with lower values so for example if you use a drawOrder of 2 for A and 1 for B then A is drawn on top of B. In other words, the features with lower drawOrder values are drawn first.
Don't forget to add the xmlns:gx="http://www.google.com/kml/ext/2.2" declaration to the kml tag and note that the documentation says it only applies to LineStrings but it also applies to Polygons and LinearRings.
<?xml version="1.0" encoding="UTF-8"?>
<kml xmlns="http://www.opengis.net/kml/2.2"
xmlns:gx="http://www.google.com/kml/ext/2.2">
...
<Placemark>
<name>A</name>
<MultiGeometry>
<Point>
<coordinates>-0.18806,39.78366</coordinates>
</Point>
<Polygon>
<gx:drawOrder>2</gx:drawOrder>
...
</Polygon>
</MultiGeometry>
</Placemark>
<Placemark>
<name>B</name>
<MultiGeometry>
<Point>
<coordinates>-0.18806,39.78501</coordinates>
</Point>
<Polygon>
<gx:drawOrder>1</gx:drawOrder>
...
</Polygon>
</MultiGeometry>
</Placemark>
Reference: https://developers.google.com/kml/documentation/kmlreference#gxdraworder

Google Earth KML

How do you links cities with a curve (line) in kml for Google Earth?
First, since you are on SO I'm assuming you are asking from a KML perspective and not just in the desktop application.
You would need to have the coordinates of the two cities. Then you would create a kml document like the following from the docs using your coordinates in the coordinates element (note that you don't need the "LookAt" element, but it will bring your camera to the relevant area):
<?xml version="1.0" encoding="UTF-8"?>
<kml xmlns="http://www.opengis.net/kml/2.2">
<Document>
<name>LineString.kml</name>
<open>1</open>
<LookAt>
<longitude>-122.36415</longitude>
<latitude>37.824553</latitude>
<altitude>0</altitude>
<range>150</range>
<tilt>50</tilt>
<heading>0</heading>
</LookAt>
<Placemark>
<name>unextruded</name>
<LineString>
<extrude>1</extrude>
<tessellate>1</tessellate>
<coordinates>
-122.364383,37.824664,0 -122.364152,37.824322,0
</coordinates>
</LineString>
</Placemark>
<Placemark>
<name>extruded</name>
<LineString>
<extrude>1</extrude>
<tessellate>1</tessellate>
<altitudeMode>relativeToGround</altitudeMode>
<coordinates>
-122.364167,37.824787,50 -122.363917,37.824423,50
</coordinates>
</LineString>
</Placemark>
</Document>
</kml>
If you don't have the city altitudes then leave them out and be sure to set the altitudeMode element to "clampToGround" and likely the tesselate element to "1" (meaning true). If you forget this your lines may disappear underground.

KML + Google Earth: Make a Polygon or GroundOverlay clickable?

Pretty simple question.
I've got some Polygons and GroundOverlays defined in KML. Is there a way to specify that they should be clickable, and (in Google Earth, at least) pop up an info balloon or similar when they are clicked?
Similarly, is it possible to give polygons/GroundOverlays any sort of mouseover behavior? e.g. change the icon or color when moused over?
Yes. Giving the Placemark a name and description will make it a clickable object in Google Earth and will open with an info window showing both. You can create rollover/mouseover behavior using stylemaps, here is an example that does both:
<?xml version="1.0" encoding="UTF-8"?>
<kml xmlns="http://www.opengis.net/kml/2.2">
<Document>
<name>Highlighted Icon</name>
<description>Place your mouse over the icon to see it display the new
icon</description>
<StyleMap id="exampleStyleMap">
<Pair>
<key>normal</key>
<!-- you could also use a <styleUrl> here instead of inlining -->
<Style>
<PolyStyle>
<color>7dff0000</color>
</PolyStyle>
</Style>
</Pair>
<Pair>
<key>highlight</key>
<!-- you could also use a <styleUrl> here instead of inlining -->
<Style>
<PolyStyle>
<color>7dffffff</color>
</PolyStyle>
</Style>
</Pair>
</StyleMap>
<!-- and now, a Placemark that uses the StyleMap -->
<Placemark>
<name>Roll over this polygon</name>
<description>this will show up when clicked</description>
<visibility>1</visibility>
<styleUrl>#exampleStyleMap</styleUrl>
<Polygon>
<tessellate>1</tessellate>
<altitudeMode>absolute</altitudeMode>
<outerBoundaryIs>
<LinearRing>
<coordinates>
-112.3372510731295,36.14888505105317,1784
-112.3356128688403,36.14781540589019,1784
-112.3368169371048,36.14658677734382,1784
-112.3384408457543,36.14762778914076,1784
-112.3372510731295,36.14888505105317,1784
</coordinates>
</LinearRing>
</outerBoundaryIs>
</Polygon>
</Placemark>
</Document>
</kml>

Resources