Managing a KML Linestring properties - kml

I am plotting a LineString. For some reason, I don't seem to effect the LineStyle. My code looks identical to many examples but no matter what color or width I place in the LineStyle, it always comes out as a thick blue line.
<?xml version="1.0" encoding="utf-8"?>
<kml xmlns="http://www.opengis.net/kml/2.2">
<Document>
<name>Qtr Min Grid Maker</name>
<LookAt>
<longitude>-121.5</longitude>
<latitude>38</latitude>
<altitude>0</altitude>
<range>740933.8825924395</range>
<tilt>0</tilt>
<heading>0</heading>
</LookAt>
<Folder>
<name>Grids</name>
<Style id="linestyle1">
<LineStyle>
<color>7f0000ff</color>
<width>1</width>
<gx:labelVisibility>1</gx:labelVisibility>
</LineStyle>
</Style>
<Placemark>
<name>QTR</name>
<visibility>0</visibility>
<open>1</open>
<styleUrl>#linestyle1</styleUrl>
<LineString>
<coordinates>
-124.75,40,0
-124.5,40,0
-124.25,40,0
-124,40,0
-123.75,40,0
-123.5,40,0
-123.25,40,0
-123,40,0
</coordinates>
</LineString>
</Placemark>
</Folder>
</Document>
</kml>

It works for me if I move the shared styles to the top level (inside the <Document> tag):
example
From the documentation (see the description of <StyleSelector>):
A style defined within a Feature is called an "inline style" and
applies only to the Feature that contains it. A style defined as the
child of a <Document> is called a "shared style." A shared style must
have an id defined for it. This id is referenced by one or more
Features within the <Document>.
Yours is neither a child of <Document> nor within a <Placemark>
<?xml version="1.0" encoding="utf-8"?>
<kml xmlns="http://www.opengis.net/kml/2.2">
<Document>
<Style id="linestyle1">
<LineStyle>
<color>7f0000ff</color>
<width>1</width>
<gx:labelVisibility>1</gx:labelVisibility>
</LineStyle>
</Style>
<name>Qtr Min Grid Maker</name>
<LookAt>
<longitude>-121.5</longitude>
<latitude>38</latitude>
<altitude>0</altitude>
<range>740933.8825924395</range>
<tilt>0</tilt>
<heading>0</heading>
</LookAt>
<Folder>
<name>Grids</name>
<Placemark>
<name>QTR</name>
<visibility>0</visibility>
<open>1</open>
<styleUrl>#linestyle1</styleUrl>
<LineString>
<coordinates>
-124.75,40,0
-124.5,40,0
-124.25,40,0
-124,40,0
-123.75,40,0
-123.5,40,0
-123.25,40,0
-123,40,0
</coordinates>
</LineString>
</Placemark>
</Folder>
</Document>
</kml>

Related

Variable Substitution in KML Icon Reference

How can I do variable substitution in a kml icon reference? I'm using Google Earth to load the kml, and my image doesn't appear for this simple example:
<?xml version="1.0" encoding="UTF-8"?>
<kml xmlns="http://www.opengis.net/kml/2.2">
<Document>
<Document>
<name>TestMap</name>
<Style id="Icon1">
<IconStyle>
<Icon>
<href>$[url]</href>
</Icon>
</IconStyle>
</Style>
<Placemark>
<name>Hello World</name>
<styleUrl>#Icon1</styleUrl>
<ExtendedData>
<Data name="url">
<value>http://magiccards.info/scans/en/al/232.jpg</value>
</Data>
</ExtendedData>
<Point>
<coordinates>
0,0,0
</coordinates>
</Point>
</Placemark>
</Document>
</Document>
</kml>
Variable substitution for extended data in KML only works in context of the description so you could show the placemark's data url via the description balloon.
<kml xmlns="http://www.opengis.net/kml/2.2">
<Document>
<name>Data+BalloonStyle</name>
<Style id="balloon-style">
<BalloonStyle>
<text>
<![CDATA[
$[name]<br>
<img src="$[url]"/>
]]>
</text>
</BalloonStyle>
</Style>
<Placemark>
<name>Hello World</name>
<styleUrl>#balloon-style</styleUrl>
<ExtendedData>
<Data name="url">
<value>http://magiccards.info/scans/en/al/232.jpg</value>
</Data>
</ExtendedData>
<Point>
<coordinates>-111.956,33.5043</coordinates>
</Point>
</Placemark>
</Document>
</kml>
See related tutorial for adding custom data which describes using the BalloonStyle Element as a Template
https://developers.google.com/kml/documentation/extendeddata
If you want to display a custom icon via IconStyle per placemark then you need to define an inline Style for each placemark with the appropriate URL.
<Placemark>
<name>Hello World</name>
<Style>
<IconStyle>
<Icon>
<href>http://magiccards.info/scans/en/al/232.jpg</href>
</Icon>
</IconStyle>
</Style>
<Point>
<coordinates>-111.956,33.5043</coordinates>
</Point>
</Placemark>

Changing map styles in google earth

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>.

Create KML route

I am trying to create a route based off lon & lat's. This is what i have so far, but it doesn't seem to be working correctly.
<?xml version="1.0" encoding="UTF-8"?>
<kml xmlns="http://www.opengis.net/kml/2.2">
<Document>
<PlaceMark>
<name>test</name>
<description>test Desc</description>
<Point>
<coordinates>-80.54400115,43.4250264</coordinates>
<coordinates>-80.52674314,43.43127701</coordinates>
...
</Point>
</PlaceMark>
</Document>
<kml>
Is the syntax correct? When i load it up in my maps app, it doesn't show the route.
Please see the KML reference
KML is XML which is case sensitive (PlaceMark is not the same as Placemark)
a <Point> is a single location
a line is a <LineString>
Your XML needs to be valid (</kml> is needed to close the opening <kml>).
example
KML from example above on Google Maps
<?xml version="1.0" encoding="UTF-8"?><kml xmlns="http://www.opengis.net/kml/2.2"> <Document>
<Placemark><name>test</name>
<description>test Desc</description>
<LineString>
<coordinates>
-80.54400115,43.4250264
-80.52674314,43.43127701
-80.5274517,43.43458707
-80.53223781,43.43876923
-80.54385782,43.44993036
-80.53949137,43.45723788
-80.53950793,43.46780893
-80.53352615,43.4730443
-80.53491389,43.47816267
-80.54136061,43.48417145
-80.54163034,43.48439869
</coordinates>
</LineString>
</Placemark></Document>
</kml>

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.

Resources