Apply specific Styles to lines in a MultiGeometry in KML - kml

Hello I have a multigeometry How has a Style like a rollover when you pass the mouse appair the lines, My question is the diferents linestring in the multigeometry have differents colors that possible?.
In the next example I have the placemark Durham Tees Valley when you select have a style but I would like have the two lines with differents colors.
Thanks
<?xml version="1.0" encoding="UTF-8"?>
<kml xmlns="http://earth.google.com/kml/2.2">
<Document>
<name>UK & Ireland, Flight Maps</name>
<open>1</open>
<LookAt>
<longitude>-3.478829007934099</longitude>
<latitude>52.50255557278696</latitude>
<altitude>0</altitude>
<range>730703.2034581316</range>
<tilt>53.03089122623036</tilt>
<heading>30.72599120906411</heading>
</LookAt>
<Style id="test">
<LineStyle>
<color>ff235523</color>
<width>0.5</width>
</LineStyle>
</Style>
<Style id="doc"><ListStyle><ItemIcon><state>open closed</state><href>http://maps.google.com/mapfiles/kml/shapes/airports.png</href></ItemIcon></ListStyle></Style>
<Style id="airportfolder"><ListStyle><ItemIcon><state>open closed</state><href>http://maps.google.com/mapfiles/kml/shapes/placemark_circle_highlight.png</href></ItemIcon></ListStyle></Style>
<Style id="info"><ListStyle><listItemType>checkHideChildren</listItemType><ItemIcon><state>open closed</state><href>http://www.barnabu.co.uk/files/icons/info.png</href></ItemIcon></ListStyle></Style>
<Style id="sh_spider"><IconStyle><scale>1.2</scale><Icon><href>http://maps.google.com/mapfiles/kml/shapes/placemark_circle_highlight.png</href></Icon></IconStyle><LabelStyle><color>ff001111</color><scale>1.4</scale></LabelStyle><LineStyle><width>0.5</width><color>ffff111f</color></LineStyle></Style>
<Style id="sn_spider"><IconStyle><scale>0.7</scale><Icon><href>http://maps.google.com/mapfiles/kml/shapes/placemark_circle_highlight.png</href></Icon></IconStyle><LabelStyle><color>ffb5b5b5</color><scale>0.9</scale></LabelStyle><LineStyle><color>00ff11ff</color></LineStyle></Style>
<StyleMap id="spider"><Pair><key>normal</key><styleUrl>#sn_spider</styleUrl></Pair><Pair><key>highlight</key><styleUrl>#sh_spider</styleUrl></Pair></StyleMap>
<Style id="2_sh_spider"><IconStyle><scale>1.2</scale><Icon><href>http://maps.google.com/mapfiles/kml/shapes/placemark_circle_highlight.png</href></Icon></IconStyle><LabelStyle><color>ff110011</color><scale>1.4</scale></LabelStyle><LineStyle><width>0.5</width><color>ff11111f</color></LineStyle></Style>
<Style id="2_sn_spider"><IconStyle><scale>0.7</scale><Icon><href>http://maps.google.com/mapfiles/kml/shapes/placemark_circle_highlight.png</href></Icon></IconStyle><LabelStyle><color>ff11ffb5</color><scale>0.9</scale></LabelStyle><LineStyle><color>001111ff</color></LineStyle></Style>
<StyleMap id="2_spider"><Pair><key>normal</key><styleUrl>#2_sn_spider</styleUrl></Pair><Pair><key>highlight</key><styleUrl>#2_sh_spider</styleUrl></Pair></StyleMap>
<styleUrl>#doc</styleUrl>
<Folder><name>Airports</name>
<styleUrl>#airportfolder</styleUrl>
<Placemark><name>Durham Tees Valley</name><description></description>
<Snippet maxLines="0"></Snippet><styleUrl>#2_spider</styleUrl><MultiGeometry><LineString><altitudeMode>relativeToGround</altitudeMode><coordinates>-1.426979,54.5105876,0 -1.37505058232182,54.3588196840161,8130.76624025246 -1.32350445540046,54.2070296447423,15640.4403479026 -1.27233575193875,54.0552177670135,22453.9881416349 -1.22153968418068,53.90338433094,28503.3309041539 -1.17111154230159,53.7515296120054,33728.0256022233 -1.12104669283672,53.5996538811612,38075.8688134745 -1.07134057714712,53.4477574049198,41503.4183257466 -1.02198870992187,53.2958404454444,43976.4271973102 -0.972986677715595,53.1439032606379,45470.1859409886 -0.924330137520422,52.9919461042286,45969.769413186 -0.876014815371306,52.8399692258547,45470.1859409886 -0.828036504983954,52.6879728711457,43976.4271973102 -0.780391066424406,52.5359572818033,41503.4183257466 -0.733074424809449,52.3839226956791,38075.8688134745 -0.686082569037039,52.2318693468513,33728.0256022233 -0.639411550545936,52.0797974656991,28503.3309041538 -0.593057482103787,51.9277072789755,22453.9881416349 -0.547016536622892,51.7755990098789,15640.4403479026 -0.501284946002942,51.623472878122,8130.76624025247 -0.455859000000019,51.4713291000001,0 </coordinates></LineString>
<LineString><altitudeMode>relativeToGround</altitudeMode><coordinates>-1.426979,54.5105876,0 -1.37505058232182,54.3588196840161,8130.76624025246 -1.32350445540046,54.2070296447423,15640.4403479026 -1.27233575193875,54.0552177670135,22453.9881416349 -1.22153968418068,53.90338433094,28503.3309041539 -1.17111154230159,53.7515296120054,33728.0256022233 -1.12104669283672,53.5996538811612,38075.8688134745 -1.07134057714712,53.4477574049198,41503.4183257466 -1.02198870992187,53.2958404454444,43976.4271973102 -0.972986677715595,53.1439032606379,45470.1859409886 -0.924330137520422,52.9919461042286,45969.769413186 -0.876014815371306,52.8399692258547,45470.1859409886 -0.828036504983954,52.6879728711457,43976.4271973102 -0.780391066424406,52.5359572818033,41503.4183257466 -0.733074424809449,52.3839226956791,38075.8688134745 -0.686082569037039,52.2318693468513,33728.0256022233 -0.639411550545936,52.0797974656991,28503.3309041538 -0.593057482103787,51.9277072789755,22453.9881416349 -0.547016536622892,51.7755990098789,15640.4403479026 -0.501284946002942,51.623472878122,8130.76624025247 -0.455859000000019,51.4713291000001,0 </coordinates></LineString>
<LineString><altitudeMode>relativeToGround</altitudeMode><coordinates>-1.426979,54.5105876,0 -1.46306991162193,54.6452657167915,8130.76624025246 -1.4994007562172,54.7799330335197,15640.4403479026 -1.5359743201564,54.9145894238809,22453.9881416349 -1.57279343190481,55.0492347596452,28503.3309041539 -1.6098609628193,55.1838689106202,33728.0256022233 -1.64717982796325,55.3184917446126,38075.8688134745 -1.6847529869399,55.4531031273904,41503.4183257466 -1.72258344474472,55.5877029226427,43976.4271973102 -1.76067425263717,55.7222909919396,45470.1859409886 -1.79902850903249,55.8568671946911,45969.769413186 -1.83764936041401,55.9914313881044,45470.1859409886 -1.87654000226647,56.1259834271408,43976.4271973102 -1.91570368003095,56.2605231644716,41503.4183257466 -1.95514369008209,56.3950504504321,38075.8688134745 -1.99486338072804,56.5295651329761,33728.0256022233 -2.03486615323379,56.6640670576277,28503.3309041538 -2.0751554628687,56.7985560674327,22453.9881416349 -2.11573481997855,56.933032002909,15640.4403479026 -2.15660779108317,57.0674947019956,8130.76624025247 -2.19777799999999,57.201944,0 </coordinates></LineString>
<Point><coordinates>-1.426979,54.5105876,0</coordinates></Point></MultiGeometry></Placemark>
</Folder>
</Document>
</kml>

No, see the KML FAQ, they address your question:
Can I assign different colors/styles to different geometries in a
MultiGeometry element?
The MultiGeometry element groups geometries
together in the same Placemark element. This allows the geometries to
share the same styling and to appear as one item in a list such as the
My Places pane in Google Earth.
Styles are set at the Placemark level, either using a styleUrl element
or a Style element. Therefore, individual geometries in that Placemark
cannot have different styles.
Also see the workaround which I found useful:
A frequently used workaround is to create a separate Placemark for
each geometry, allowing each one to have a different style. To prevent
a proliferation of items in a list, place them in a Folder that has a
ListStyle with a listItemType with checkHideChildren. In Google Earth,
for instance, this places all the Placemarks in the same folder
element in My Places, and prevents the user from opening it up to
display a large number of elements.

No, it's not possible. Multigeometry is a child of Placemark, which has the styleUrl element. You'd do better to break them up into different Placemark elements and group them on a Folder level.

Related

Unable to visualize large kml files in google earth

I am trying to use the google earth pro desktop application for visualizing IoT sensor data at different locations. Unfortunately, due to the limitations of google earth, I am unable to visualize 4GB of kml file at a time, as it throws the error "empty KML file".
I tried changing the memory cache limits under Tools -> Options -> Cache and there was no use.
I tried splitting the 4GB kml file into multiple smaller 70MB files and opening multiple files in google earth. It is becoming unresponsive and is loading very slow after opening two files.
The data is timeline data with sensor values from different locations. We need to visualize all (at least half) data so that we can use the timeline slider and see the changes over time.
It would be great to get some suggestions/alternatives to solve the issue.
Thanks.
If a KML file is very large then trying to display all the features at once can crash Google Earth Pro, affect performance with sluggish response, etc. Large KML files can be viewed in Google Earth if all or some of these techniques are applied to the KML.
NetworkLink
Folder Radio style or explicit visiblity=0
Number of Points per feature and geometry simplification
NetworkLink
A root .kml file can reference all the sub-KML files, but the referenced sub-files should have the visibility off so the user must manually check it to be visible. This will prevent all the data from being displayed all at once.
Here is the structure of the root KML file:
<?xml version="1.0" encoding="UTF-8"?>
<kml xmlns="http://www.opengis.net/kml/2.2">
<Document>
<NetworkLink>
<name>NetworkLinked sub-item1</name>
<visibility>0</visibility>
<Link>
<href> kml1.kml </href>
</Link>
</NetworkLink>
<NetworkLink>
<name>NetworkLinked sub-item2</name>
<visibility>0</visibility>
<Link>
<href> kml2.kml </href>
</Link>
</NetworkLink>
...
</Document>
</kml>
Radio Folder
You can further restrict what is displayed at a given time using radio folders.
Here's a radio folder example allowing the user to only choose one of the NetworkLinks at a time. This is used when the content is mutually exclusive and only one set of features should appear at any given time.
<?xml version="1.0" encoding="UTF-8"?>
<kml xmlns="http://www.opengis.net/kml/2.2">
<Document>
<Style id="rf">
<ListStyle>
<listItemType>radioFolder</listItemType>
</ListStyle>
</Style>
<Folder>
<name>One at a time example</name>
<open>1</open>
<description>Link 1 visible by default</description>
<styleUrl>#rf</styleUrl>
<NetworkLink>
<name>NetworkLinked sub-item-1</name>
<Link>
<href> kml1.kml </href>
</Link>
</NetworkLink>
<NetworkLink>
<name>NetworkLinked sub-item-2</name>
<visibility>0</visibility>
<Link>
<href> kml2.kml </href>
</Link>
</NetworkLink>
</Folder>
</Document>
</kml>
Number of Points per feature and geometry simplification
Size of the KML file and number of features is not the only issue to consider. A KML file with a single hi-res polygon having 350K points and 7000 inner holes can cause Google Earth performance issues. Such geometries would need to be simplified and the number of points reduced. You can use QGIS to open a KML file then apply a simplify algorithm on the polygon. In QGIS, select Vector menu -> Geometry tools -> Simplify then save the result.

how to keep polygon and name of the polygon over the polygon surface in kml

I have asked to keep polygon, name of the polygon and the corresponding icon in the places panel.
Can any suggest me how to do this in kml?
By default you only see the name label if your placemark has a Point geometry so for lines and polygons the name is not shown.
You can however create a MultiGeometry with both a Polygon and a Point (typically the center point or where you want to label to appear near). If you don't want the default yellow pushpin to appear just add a Style with an empty IconStyle href element to the Placemark.
<?xml version="1.0" encoding="utf-8"?>
<kml xmlns="http://www.opengis.net/kml/2.2">
<Placemark>
<name>polygon</name>
<Style>
<IconStyle>
<Icon/>
</IconStyle>
</Style>
<MultiGeometry>
<Point>
<coordinates>-122.4317195,37.801848</coordinates>
</Point>
<Polygon>
<outerBoundaryIs>
<LinearRing>
<coordinates>
-122.43193945401,37.801983684521
-122.431564131101,37.8020327731402
-122.431499536494,37.801715236748
-122.43187136387,37.8016634915437
-122.43193945401,37.801983684521
</coordinates>
</LinearRing>
</outerBoundaryIs>
</Polygon>
</MultiGeometry>
</Placemark>
</kml>
This multi-geometry method can be HIGHLY tedious if you have a couple hundred polygons (say, a grid/index) and you want to show their names.
My preference is to use something like QGIS/Arc, where I create a new vector file of polygon centroids (point file) that has the polygon attributes (including name/description). I save the new point file as a point KML and import into Google Earth. From their, I set a shared style for the point file, with the icon set to 0% opacity.
Example of Google Earth Polygons with Labels using above method

control of label visibility on placemarks

I have a kml file with many simple point placemarks each with a name that cover the USA. I am trying to find a way to control their label display so that the view is not cluttered at higher altitudes. I've seen mention the use of Regions but it appears this would have to be applied on each placemark. I know something must be available for this since GE is doing this very thing on the default layers, i.e. Populated Places. Further, there seems to be some default at work when I zoom far enough out the labels disappear without any input on my kml.
Any comments are appreciated!!
To control the display of labels in your KML you can either use Regions as you mentioned and/or a StyleMap with a normal and highlighted LabelStyle.
If you capture the HTTP traffic to Google Earth you'll notice the Borders and Labels default layer (among others) are implemented as KML files using Regions and nested NetworkLinks.
Regions
If you don't want to create a Region on every placemark then you could group your placemarks into folders and have a Region on the folder to control when placemarks are visible. Creating the regions correctly takes some trial and error. You may not even need to specify the min/max altitude -- an appropriate minLodPixels value to the region dimensions may be enough.
A tutorial on Regions can be found here.
https://developers.google.com/kml/documentation/regions
StyleMap
You may want to create a StyleMap where the normal Style has a LabelStyle with a scale of 0 to suppress the labels entirely or a smaller value to simply reduce the clutter.
<Style id="sn_style">
<LabelStyle>
<scale>0</scale>
</LabelStyle>
</Style>
<Style id="sh_style">
<LabelStyle>
<scale>1.1</scale>
</LabelStyle>
</Style>
<StyleMap id="msn_style">
<Pair>
<key>normal</key>
<styleUrl>#sn_style</styleUrl>
</Pair>
<Pair>
<key>highlight</key>
<styleUrl>#sh_style</styleUrl>
</Pair>
</StyleMap>
Had the Same Problem and I couldn't find any quick solution for the as my .kml contained almost 10k POI's. So what I did was adding the code offered by the FAQ, so my header would look like this:
<?xml version="1.0" encoding="utf-8" ?>
<kml xmlns="http://www.opengis.net/kml/2.2">
<Document><Folder><name>name</name><Style id="hideLabel"><LabelStyle><scale>0</scale></LabelStyle></Style>
And I changed the first placemark to this:
Placemark>
<name>name</name>
<styleUrl>#hideLabel</styleUrl>
<ExtendedData><SchemaData schemaUrl="#name">
<SimpleData name="Name">name</SimpleData>
<SimpleData name="Latitude">xxxx</SimpleData>
<SimpleData name="Longitude">yyyy</SimpleData>
</SchemaData></ExtendedData>
<Point><coordinates>xxxx,yyyy</coordinates></Point>
</Placemark>
After that I loaded the .kml into Google Earth and right-clicked onto it to select Properties. Select "Style, Color" tab and it should state the following:
The descendant(s) of this folder do not share the same Style. Click
the button below if you want to force all descendants to share the
same Style
Click the button below "Share Style" and it will temporarily hide all the labels.
Kind regards,
Thomas

How to create Google Earth KML network link that does not allow folder to be expanded

I have created a network link that references another KML file with actual data to be loaded into Google Earth. My issue is that the number of points in the referenced KML file is so large that it crashes Google Earth if the KML file folder underneath the Places tab in Google Earth is set to "Allow this folder to be expanded" (right-click KML, properties). By default, this checkbox is checked. I want to make it so that for every network link I create the folder by default will not be expandable.
I have looked up checkHideChildren in Google Earth KML tutorials, but that line provides no results, and I am not entirely sure where I am supposed to place the line in the Network Link KML.
Here is example code, if you could point me in the direction where to place this line of code, or an entirely different approach, it would be greatly appreciated!
<?xml version="1.0" encoding="UTF-8"?>
<kml xmlns="http://earth.google.com/kml/2.1">
<NetworkLink>
<name>
CPU
</name>
<refreshVisibility>1</refreshVisibility>
<Link id="GPS_Plotter Updater">
<href>CPU.kml</href>
<Style id="style1"><ListStyle>
<listItemType>checkHideChildren</listItemType> <-- this is the line that should be hiding the children points of the KML!
</ListStyle>
</Style>
<styleUrl>#style1</styleUrl>
<refreshMode>onInterval</refreshMode>
<refreshInterval>1</refreshInterval>
<viewRefreshMode>onRegion</viewRefreshMode>
<viewRefreshTime>1</viewRefreshTime>
</Link>
</NetworkLink>
</kml>
Try putting the Style element in the NetworkLink, not the Link element. Link doesn't take a style selector, but NetworkLink does. If that doesn't work, try a listItemType of radioFolder instead.
In addition to Mano Marks' suggestions you also need to move the styleUrl element to the NetworkLink otherwise it won't apply. Note in your example you have viewRefreshMode=onRegion but don't have a region defined for it.
Here's the complete working example to suppress the NetworkLink contents.
<?xml version="1.0" encoding="UTF-8"?>
<kml xmlns="http://www.opengis.net/kml/2.2">
<NetworkLink>
<name>CPU</name>
<styleUrl>#style1</styleUrl>
<Style id="style1">
<ListStyle>
<listItemType>checkHideChildren</listItemType>
</ListStyle>
</Style>
<Region>
<!-- define region here -->
</Region>
<refreshVisibility>1</refreshVisibility>
<Link id="GPS_Plotter_Updater">
<href>CPU.kml</href>
<refreshMode>onInterval</refreshMode>
<refreshInterval>1</refreshInterval>
<viewRefreshMode>onRegion</viewRefreshMode>
<viewRefreshTime>1</viewRefreshTime>
</Link>
</NetworkLink>
</kml>
You can catch errors like this by validating your KML. Try using the Galdos KML Validator.

KML file not showing correct location and polygon orientation. Syntax issue?

Hi I wrote a Javascript to output a KML file based on a polygon area marked on google maps api v3. The file used to worked correctly, showed the right location and polygon shape on Google Earth Pro
Now suddenly instead of showing the London Eye area in London it shows an area in Congo and the polygon doesnt even appear correctly on google earth. I tried to debug it appears that the coordinate seems to be causing the problem. However, when i save it to MyPlaces on google maps online it parses the KML and shows the shape and location properly. Thanks for your help. KML Below
<?xml version="1.0" encoding="UTF-8"?>
<kml xmlns="http://earth.google.com/kml/2.1">
<Document>
<name>test</name><description>test</description>
<Style id='style1'>
<LineStyle>
<width>5</width>
</LineStyle>
<PolyStyle>
<color>0FF00000</color>
<fill>1</fill>
<outline>1</outline>
</PolyStyle>
</Style>
<Placemark>
<name>?</name>
<styleUrl>#style1</styleUrl>
<Polygon>
<outerBoundaryIs>
<LinearRing>
<tessellate>1</tessellate>
<coordinates>
51.50519078602326, -0.12681582942195746,
51.50708732603467, -0.12381175532527777,
51.50553804573176, -0.1123104430694184,
51.50166461450478, -0.11462787165828558,
51.50519078602326, -0.12681582942195746,
</coordinates></LinearRing></outerBoundaryIs></Polygon></Placemark>
</Document>
</kml>
Your KML is invalid, and Google Earth is no longer as permissive as it was in accepting this type of invalid coordinates.
Specifically, you have an extra comma at end of each line in your KML -- so just remove them, or else add the optional altitude value after them.
Also remove the whitespace between the separate parts of the coordinate. Your coordinates will now be converted to three separate coordinates by Google Earth:
51.50519078602326,0,0 and -0.12681582942195746,0,0 and 0,0,0.
Change it to:
51.50519078602326,-0.12681582942195746,0
51.50708732603467,-0.12381175532527777,0
Or:
51.50519078602326,-0.12681582942195746
51.50708732603467,-0.12381175532527777
See https://developers.google.com/kml/documentation/kml_tut#polygons for a polygon example or the section and https://developers.google.com/kml/documentation/kmlreference#linearring for extra details.

Resources